OpenCV iOS视频录制内存泄漏

时间:2014-08-20 19:11:45

标签: ios opencv memory-leaks

我在answers.opencv.org上发布了这个,但回复一直很迟钝,所以我希望有人可以帮助我。

当您将摄像机设置为记录时,iOS的CvVideoCamera对象中存在巨大的内存泄漏。此问题之前已提出,根据this,甚至已解决上一版本。但是,当使用最新的框架并实现如此......

//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在大约20-30秒的录制后杀死应用程序。我知道iOS有一个积极的内核,但除非我录制视频,否则它永远不会给我带来麻烦。请注意,我没有包含所有代码。为了正确录制视频,您还需要做一些其他事情。此外,我还学习了如何使用适用于iOS的Instant OpenCV在iOS中实现OpenCV,这一点在本书中有所介绍。我使用我所经历的仪器调查了这个问题,这只有在我将record属性设置为YES时才会发生。否则,我们一切都很好。现在我也看到了this post。但我不打算编辑OpenCV源代码,因为每次OpenCV更新其框架时我都不想这样做。但我需要找到一种方法尽快解决这个问题,我非常感谢人们愿意提供的任何帮助。

1 个答案:

答案 0 :(得分:-1)

我想知道你是否得到任何解决方案。我遇到了一个稍微不同的问题,大部分泄漏发生在录制过程中。

对于您的问题,您可以fork opencv,并对文件进行更改。然后,您可以根据需要从OpenCV中提取更改。