我设法用swift连接openCV CvVideoCamera,但我目前想要保存第一帧,以便我以后可以屏蔽它。 以下是我目前在.mm文件中所做的一些示例
- (id)initWithController:(UIViewController<CvCameraDelegate>*)c andImageView:(UIImageView*)iv
{
delegate = c;
imageView = iv;
videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
self->videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
videoCamera.defaultFPS = 30;
videoCamera.delegate = self;
return self;
}
- (void)processImage:(cv::Mat &)img {
//Here I want to convert only the first frame to ycrcb
cv::cvtColor(firstFrame, ycrcb, COLOR_BGR2YCrCb);
//...rest of my code on all the other frames then masking it with first frame
}
ViewController.swift代码
override func viewDidLoad() {
super.viewDidLoad()
camera = OpenCVWrapper(controller: self, andImageView: imgView)
}
@IBAction func startTranslating(_ sender: UIButton) {
camera.start()
}