I would like to subtract a background of an image usine OpenCV on iOS with Objective-C++ and I am currently facing a termination due to memory issue, whenever I want to apply the BackgroundSubtractorMOG2 method to the input pictures.
I was researching on the topic, however I haven't find any useful answers. I am applying the BackgroundSubtractorMOG2 method properly, passing the right arguments. I also have checked the Diagnostics in my Edit Scheme and my Zombie Objects are disabled, so that shouldn't cause the problem. I am thinking, whether the processing power of the phone could be the problem.
I am passing in my function a background image and and the same background image with a person in it. I would like to subtract the person from the image somehow.
My code is:
// Subtracts two images: the image taken from the background image
-(cv::Mat) subtractBackground:(cv::Mat)backPic fromImage:(cv::Mat)inImage {
if (!inImage.data) {
NSLog(@"Unable to the picture image");
} else if (!backPic.data) {
NSLog(@"Unable to open background");
}
cv::Mat fgMaskMOG2;
int history = 2;
int distance_threshold = 16;
bool shadow_detection = true;
cv::Mat frame[2] = { backPic, inImage};
cv::Ptr<cv::BackgroundSubtractorMOG2> createSubtractor = new cv::BackgroundSubtractorMOG2(history, distance_threshold, shadow_detection);
for(int i = 0; i < 2; i++) {
createSubtractor->operator()(frame[i], fgMaskMOG2);
}
return fgMaskMOG2;
}