我想在我的iOS应用程序中实现OpenCV。使用CvVideoCamera拍摄照片
CvVideoCamera非常棒,因为它具有委托方法,可以让我处理相机预览的每一帧,但我不知道如何提取一帧并将其保存为图像(又名拍摄照片)。
我该如何做到这一点?
谢谢
我想在我的iOS应用程序中实现OpenCV。使用CvVideoCamera拍摄照片
CvVideoCamera非常棒,因为它具有委托方法,可以让我处理相机预览的每一帧,但我不知道如何提取一帧并将其保存为图像(又名拍摄照片)。
我该如何做到这一点?
谢谢
我发现了一个简单的方法,用CvVideoCamera拍照。这不是一个理想的方法,但它很容易。在另一个线程中,他们建议覆盖opencv相机方法。 (Capturing a still image from camera in OpenCV Mat format)
在我的方法中,您只需要有一个名为taken_image的额外属性以及拍照的方法。
@property cv::Mat taken_image;
- (void)processImage:(cv::Mat&)image {
// Some processing over the image
...
self.taken_image = image.clone();
}
- (IBAction)takePhoto:(id)sender {
printf("Take Photo..\n");
[camera stop];
cv::Mat rgb_image;
cv::Mat bgr_image = _taken_image.clone();
// Change the color scheme for iOS
cv::cvtColor(bgr_image, rgb_image, CV_RGB2BGR);
// Here you have your image
UIImage *img = MatToUIImage(rgb_image);
...
...
[self dismissViewControllerAnimated:YES completion:nil];
}
那么..我的解决方案是最好的方法,但它仍然有效。我会做屏幕截图,我保存到我的相册。这是我的代码
-(IBAction)takePhoto:(id)sender {
UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
CGRect cropRect = CGRectMake(0 ,0 ,imageView.frame.size.width,imageView.frame.size.height);
CGImageRef imageRef = CGImageCreateWithImageInRect([screenshot CGImage], cropRect);
CGImageRelease(imageRef);
UIImageWriteToSavedPhotosAlbum(screenshot , nil, nil, nil);
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(screenshot , nil, nil, nil);
}
我唯一的问题是质量问题。我怎么能提高他的质量?
最好的问候, 纳扎尔
我没有在iOS应用开发经验,但你可以从这个链接一些帮助。 http://docs.opencv.org/doc/tutorials/ios/video_processing/video_processing.html#processing-frames – Vivek
你不能使用'cv :: imwrite'或任何ios用来保存你正在处理的图像吗? – Miki
事情是我不想在处理过程中保存图像(在processImage方法上),我只是想在按下UIButton时保存图像。 – javorosas