以下のコードを使用して ROI を設定し、画像をトリミングしました。
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 );
。
しかし、この問題の原因を突き止めることができませんでした。上記のコードのどこかが間違っていますか?