CvVideoCamera使用情况的Simple example无法正常工作。显示在委托人的processImage中修改的图像,没有任何更改。

ViewController.h:

#import <UIKit/UIKit.h>
#import <opencv2/videoio/cap_ios.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIButton *btnStart;
@property (weak, nonatomic) IBOutlet UIImageView *myimg;

@end


ViewController.mm:

#import "ViewController.h"
#import <opencv2/videoio/cap_ios.h>

@interface ViewController ()<CvVideoCameraDelegate>
@property (strong, nonatomic) CvVideoCamera *videoCamera;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.videoCamera = [[CvVideoCamera alloc] initWithParentView:self.myimg];
    [self.videoCamera setDelegate:self];
    self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
    self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPresetHigh;
    self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
    self.videoCamera.defaultFPS = 30;
    self.videoCamera.useAVCaptureVideoPreviewLayer = YES;
}

- (IBAction)actionStart:(id)sender {
    [self.videoCamera start];
}

- (void)processImage:(cv::Mat &)image;
{
    cv::Mat image_copy;
    cvtColor(image, image_copy, CV_BGRA2BGR);
    bitwise_not(image_copy, image_copy);
    cvtColor(image_copy, image, CV_BGR2BGRA);
}


按下按钮后,正常的摄像机流将被渲染,没有任何干预的痕迹。我也尝试绘制形状,甚至在image.release()内调用processImage都无效。

我想我这里缺少明显的东西。
There's the example repository

This is what I'm getting on the screen

最佳答案

这是问题的根源:

self.videoCamera.useAVCaptureVideoPreviewLayer = YES;


一旦删除,一切都会按预期进行。

07-28 12:37