OpenCV视频处理教程问题

OpenCV视频处理教程问题

本文介绍了OpenCV视频处理教程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OpenCV网站上关注了,并设法将其编译并安装在设备上。但是,当我单击开始按钮时,什么都看不见。显然我的-(void)processImage:(Mat&)image 回调都不被调用。您能给我一些提示是什么问题吗?

I followed the iOS video processing tutorial on the OpenCV site and managed to compile and install it on the device. However when I click on the "Start" button, nothing visible happens. Apparently neither my - (void)processImage:(Mat&)image callback is never called. Could you give me some hints what could be the problem?

我检查了一些内容:


  • actionStart 被调用,并且两行日志都显示YES

  • 自身对象分配给 self.videoCamera.delegate

  • imageView 有效并且在屏幕上可见

  • videoCamera 开始方法称为

  • actionStart is called, and both log lines prints YES
  • the self object is valid when assigned to self.videoCamera.delegate
  • imageView is valid and visible on the screen
  • videoCamera is initialized when its start method is called

我使用iPhone 3GS进行测试。

I use a iPhone 3GS for testing.

这是我的ViewController.h的完整资源:

Here is the full source of my ViewController.h:

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

@interface ViewController : UIViewController <CvVideoCameraDelegate>
{
    IBOutlet UIImageView* imageView;
    IBOutlet UIButton* button;

    CvVideoCamera* videoCamera;
}

- (IBAction)actionStart:(id)sender;

@property (nonatomic, strong) CvVideoCamera* videoCamera;

@end

和ViewController.mm:

and ViewController.mm:

@implementation ViewController

@synthesize videoCamera;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
    self.videoCamera.delegate = self;

    self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront;
    self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
    self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
    self.videoCamera.defaultFPS = 30;
    self.videoCamera.grayscaleMode = NO;

}

#pragma mark - UI Actions

- (IBAction)actionStart:(id)sender;
{
    [self.videoCamera start];
    NSLog(@"video camera running: %d", [self.videoCamera running]);
    NSLog(@"capture session loaded: %d", [self.videoCamera captureSessionLoaded]);
}

#pragma mark - Protocol CvVideoCameraDelegate

- (void)processImage:(cv::Mat&)image
{
    // Do some OpenCV stuff with the image
    cv::Mat image_copy;
    cvtColor(image, image_copy, CV_BGRA2BGR);

    // invert image
    bitwise_not(image_copy, image_copy);
    cvtColor(image_copy, image, CV_BGR2BGRA);
}

@end


推荐答案

我在iPhone 4上进行了测试,效果很好。也许iPhone 3GS没有前置摄像头?然后,您必须更改此行: self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront 更改为 self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack

I tested on an iPhone 4 and it works well. Maybe the iPhone 3GS doesn't have a front facing camera? Then you have to change this line: self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront to self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack

这篇关于OpenCV视频处理教程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 16:46