呼叫 cvCopy(orgImage, result) 時程式崩潰,調試顯示影像變數正常,但 CMD 提示錯誤。
cvCopy 要求源影像與目標影像具備相同尺寸、相同深度、相同通道數。代碼中:
IplImage *dst11 = cvCreateImage(dst_size11, dst->depth, dst->nChannels);
但 dst_size11 可能與 cvGetSize(orgImage) 不一致,或 rectInImage 區域超出邊界導致 ROI 設定異常。
cvRect 參數順序為 (x, y, width, height),代碼中誤用 rheight, rwidth 導致寬高顛倒cvCreateImage(cvSize(rect.width, rect.height), ...)cvSetImageROI 回傳值(非零表示失敗)CvRect rect = cvRect(rx, ry, rwidth, rheight); // 修正寬高順序
IplImage *subImg = cvCreateImage(cvSize(rect.width, rect.height),
orgImage->depth, orgImage->nChannels);
cvSetImageROI(orgImage, rect);
cvCopy(orgImage, subImg); // 此處尺寸深度已匹配
cvResetImageROI(orgImage);
在拷貝前印出兩影像的 width, height, depth, nChannels, widthStep,確保完全一致。