且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从相机以OpenCV Mat格式捕获静止图像

更新时间:2023-01-23 08:52:55

我已经找到解决问题的方法.

I have found the solution for my problem.

解决方案是:

通过在OpenCv Camera类中重写此方法:"createVideoPreviewLayer"

by overriding this method in the OpenCv Camera Class : "createVideoPreviewLayer"

它应该看起来像这样:

- (void)createVideoPreviewLayer;
{

    self.parentView.layer.sublayers = nil;
    if (captureVideoPreviewLayer == nil) {
        captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc]
        initWithSession:self.captureSession];
    }

    if (self.parentView != nil) {
        captureVideoPreviewLayer.frame = self.parentView.bounds;
        captureVideoPreviewLayer.videoGravity =
        AVLayerVideoGravityResizeAspectFill;
        [self.parentView.layer addSublayer:captureVideoPreviewLayer];
    }
    NSLog(@"[Camera] created AVCaptureVideoPreviewLayer");
}

您应将此行添加到"createVideoPreviewLayer"方法中,以解决 问题:

you should add this line to the "createVideoPreviewLayer" method will solve the problem :

self.parentView.layer.sublayers = nil;

,您需要使用暂停方法而不是停止方法