Ask Your Question
0

iOS OpenCV image tearing

asked 2017-07-03 22:55:21 -0600

Novice user here with Xcode (developing an iOS app using the simulator at the moment) and OpenCV 3, and I'm trying to extract a section of a larger image. However when I try to display this subimage the top part is fine but the bottom part tears. image description.

The code I'm using (Objective-C++) is:

cv::Rect roiRect( imageRect.origin.x, imageRect.origin.y, imageRect.size.width, imageRect.size.height);
Mat bgrImage = [self cvMatFromUIImage:image];
Mat subImage = bgrImage( roiRect);
[self.imageView setImage:[ self UIImageFromCVMat:subImage]];

The UIImage to/from OpenCV Mat conversion functions (that appear in a number of web sites) appear to be working elsewhere. The 'imageRect' is a CGRect structure that specifies the area of interest in the main image in the OpenCV Image coordinate values.

Any ideas as to what is causing this would be appreciated.

Susan

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-07-10 02:19:29 -0600

Sorry but I've not been able to respond to my own question until about now. It turns out that the code I posted above was form a function and so the variables were placed on the stack but (I suspect) the data was in the heap. When the function exited, it destroyed the Mat variables and released the heap data. However the iOS image code (running in another thread) still retained a pointer. The bottom part of the image memory was being over-written in the heap (when it was reallocated to something else). Anyway, I've reworked the code to keep references as necessary and the problem has gone away. Susan

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-07-03 22:55:21 -0600

Seen: 455 times

Last updated: Jul 10 '17