iOS CvVideoCamera Mat on other Thread

asked 2015-01-13 06:48:54 -0500

bystam gravatar image

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!

edit retag flag offensive close merge delete

Comments

Please, I suffer from the same problem

leandro fantin gravatar imageleandro fantin ( 2016-08-15 15:27:46 -0500 )edit

@leandro fantin - Please do not post answers, if you don't have one.

berak gravatar imageberak ( 2016-08-15 18:45:29 -0500 )edit