【问题标题】:OpenCV iOS video recording memory leakOpenCV iOS 视频录制内存泄漏
【发布时间】:2014-08-20 19:11:44
【问题描述】:

我在 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 for iOS 实现 OpenCV,这在这本书中有介绍。我已经使用我所经历的工具调查了这个问题,只有当我将记录属性设置为 YES 时才会发生这种情况。否则,我们都很好。现在我也看到了this post。但我不准备编辑 OpenCV 源代码,因为我不想每次 OpenCV 更新他们的框架时都这样做。但我需要尽快找到解决此问题的方法,如果人们愿意提供任何帮助,我将不胜感激。

【问题讨论】:

    标签: ios opencv memory-leaks


    【解决方案1】:

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-18
    相关资源
    最近更新 更多