Crop Mat image on OpenCV 2.4.3 (iOS)

I am trying to crop images coming out of a video stream using OpenCV for iOS. I'm not trying to do anything, just crop the image and show it. I tried this one , and this one does not work for me. As a delegate method, I get the current cv :: Mat image, so I only need code that will create a cropping effect.

I could do something as complex as this if necessary, but I only need a rectangular culture, so I think there is an easier way. I just don’t understand why ROI setup doesn’t work for me!

cv::Rect myROI(10, 10, 100, 100); cv::Mat croppedImage = src(myROI); src.copyTo(croppedImage); [displayView setImage:[UIImage imageWithCVMat:src]]; 

^^^ does not work, just displaying the original image

+6
source share
1 answer

The problem in your code is that by copying an src image, you are copying the entire image into a cropped image. Two possibilities are possible:

1 - Without copying data. This is the same as you. But without the second step. In this case, croppedImage is not a real copy pointing to the data allocated in src .:

 cv::Mat croppedImage = src(myRoi); 

2 - with copying data.

 cv::Mat croppedImage; cv::Mat(src, myRoi).copyTo(croppedImage) 

(one linear method is cv::Mat croppedImage = cv::Mat(src, myRoi).clone(); )

+22
source

All Articles