ios video recording memory leak
Fair warning: This is a long post.
Let me also preface this by saying that I have to created an iOS app that uses OpenCV to track objects thanks to the awesome functionality of the OpenCV library for an internship. That's right I'm a student (computer engineering major) so bear with me as I am still learning AND I just picked up iOS development this summer for the internship. The problem I am having however doesn't seem to be anything I am doing it seems that there is a tremendous memory leak in the CvVideoCamera object for ios when you set the video camera to record. This issue has been brought up before and was even resolved for the last version according to this. However, when using the latest framework and implementing like so....
//ViewController header (note I am not including all the importing that happens before this)
@interface ViewController : UIViewController<CvVideoCameraDelegate>
{
....
IBOutlet UIImageView*imageView; //image view used for video feed
CvVideoCamera*videoCamera; //OpenCV video camera
}
@property (retain, nonatomic) CvVideoCamera*videoCamera;
//end header file
//ViewController implementation file (compiled as .mm aka objective-c++)
@interface ViewController()
@end
@implementation ViewController
@synthesize videoCamera;
-(void)viewDidLoad
{
....
//OpenCV Camera setup
self.videoCamera=[[CvVideoCamera alloc] initWithParentView:imageView];
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack; //select camera
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288; //set resolution
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait; //set orientation
self.videoCamera.recordVideo = YES; //set record video to YES to record video
self.videoCamera.defaultFPS = 30; //default frames per second
self.videoCamera.grayscaleMode = NO; //grayscale mode
self.videoCamera.delegate = self; //set up delegate
....
}
#ifdef __cplusplus
-(void)processImage(cv::Mat&)image
{
//do some open cv stuff
//for example
cvtColor(image, image, CV_BGR2GRAY);
}
#endif
iOS kills the app after about 20-30 seconds of recording due to memory pressure. I understand that iOS has an aggressive kernel but it never gives me problems unless I record the video. Please note that I have not included all the code. There are some other things you have to do in order to properly record the video. And also I learned how to implement OpenCV in iOS using Instant OpenCV for iOS and this is covered in that book. I have investigated the issue using instruments from what I have experienced, this only happens when I set the record property to YES. Otherwise, we're all good. Now I have also seen this post. But I am not up for editing OpenCV source code because I will not want to do this every time OpenCV updates their framework. But I need to find a way to resolve this issue as soon as possible and I would greatly appreciate any help that people are willing to provide.
Please start by dropping old C api like CvVideoCamera and use VideoCapture instead. That could already be the solution to your problem... it is known that the old C-API still has unfixed bugs!
VideoCapture is a C++ API that does not support iOS. iOS is written in objective-c, a strict superset of C. So that's not going to work. Thanks for the response though.
Oops did not know that! My apologies. I am wondering however how they will tackle the iOS support once openCV drops the C-API in release 3.0.0 then ...