Hello!
I have a quick question regarding the memory management of cv::Mat instances that come through the processImage when using CvVideoCamera on iOS. I sort of just want to do the following:
- (void)processImage:(Mat&)image; { dispatch_async(heavyProcessingQueue, ^(void) { doHeavyProcessing(image); }); }
This results in a crash inside the doHeavyProcessing function, probably since it's run on another thread, and that the memory of image is overwritten by the camera just before the next call to processImage.
I have sort of solved this by doing the following:
- (void)processImage:(Mat&)image; { __block Mat imageCopy = image.clone(); dispatch_async(heavyProcessingQueue, ^(void) { doHeavyProcessing(imageCopy); }); }
but the clone()-call is quite expensive to do when trying to maintain high framerates.
Is there any way to make the new thread "own" the memory of the image Mat without actually copying the matrix data?
Thanks in advance!