我使用下面的代碼來設置ROI並裁剪圖像。Opencv在iPhone中裁剪圖像的錯誤
cv::Mat testMat = [CaptureViewController cvMatWithImage:self.storeImage];
cv::Rect roi(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
cv :: Mat image_roi;
image_roi = testMat (roi);
self.CroppedImage = [CaptureViewController imageWithCVMat:image_roi];
UIImageWriteToSavedPhotosAlbum(self.CroppedImage, self, nil,nil);
但我得到下面的錯誤:
<Error>: CGContextDrawImage: invalid context 0x0
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows)
我設置斷點,並在這裏測試是在哪裏我得到上述錯誤image_roi = testMat (roi);
。
但我無法追查這個問題的原因。在上面的代碼中,我錯了嗎?