【问题标题】:IOS IT is possible CvPhotoCamera [OpenCV] we can detect faceIOS IT 是可能的 CvPhotoCamera [OpenCV] 我们可以检测人脸
【发布时间】:2017-10-06 13:06:30
【问题描述】:

在 openCV 中,我必须检测面部和眼睛。但我的代码不起作用,这是我的代码,请检查,这不起作用。但是我在 CvVideoCamera 中尝试的相同代码然后我的代码工作正常。只有一个问题是眼睛没有检测到。

@property (nonatomic, strong) CvPhotoCamera* photoCamera;
 cv::CascadeClassifier faceCascade

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *pathToFaceCascade = [[NSBundle mainBundle] pathForResource:@"haarcascade_frontalface_alt" ofType:@"xml"];
    if (pathToFaceCascade == nil) {
        [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Cannot find path for resource haarcascade_frontalface_alt.xml" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
        return;
    }

    if (!faceCascade.load([pathToFaceCascade UTF8String])) {
        [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Cannot load haarcascade_frontalface_alt.xml" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
        return;
    }




    photoCamera = [[CvPhotoCamera alloc]
                   initWithParentView:imageView];
    photoCamera.delegate = self;
    photoCamera.defaultAVCaptureDevicePosition =
    AVCaptureDevicePositionFront;
    photoCamera.defaultAVCaptureSessionPreset =
    AVCaptureSessionPresetPhoto;
    photoCamera.defaultAVCaptureVideoOrientation =
    AVCaptureVideoOrientationPortrait;
    [photoCamera start];

    [self.view addSubview:imageView];



       // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)photoCamera:(CvPhotoCamera*)camera
      capturedImage:(UIImage *)image;
{
    [camera stop];
    imageView.image = image;

    // [takePhotoButton setEnabled:NO];
    // [startCaptureButton setEnabled:YES];
}
-(IBAction)takePhotoButtonPressed:(id)sender;
{
    [photoCamera takePicture];



}

#ifdef __cplusplus
//...Working Good
-(void)processImage:(Mat &)image
{
    Mat bwImage;
    cvtColor(image, bwImage, CV_BGRA2GRAY);

    equalizeHist(bwImage, bwImage);

    std::vector<cv::Rect> faces;
    faceCascade.detectMultiScale(bwImage, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));

    char buffer[64];
    static int number = 0;
    sprintf(buffer, "(%d, %d) - Detected: %ld %d", bwImage.cols, bwImage.rows, faces.size(), number++);
    String str(buffer);
    putText(image, str, cvPoint(20, 20), 0, 0.5, cvScalar(255, 255, 255, 255));

    for (int i = 0; i < faces.size(); i++) {
        cv::rectangle(image, cvPoint(faces[i].x, faces[i].y), cvPoint(faces[i].x + faces[i].width, faces[i].y + faces[i].height), cvScalar(0, 255, 255, 255), 2.0);
    }


}

【问题讨论】:

    标签: ios opencv face-detection


    【解决方案1】:

    据我所知,在 OpenCV 中没有面部标志检测。您可以使用dlib。这是一个非常有用的项目:https://github.com/zweigraf/face-landmarking-ios

    【讨论】:

    • 好的,我试试这个。谢谢你的帮助。
    猜你喜欢
    • 2013-12-30
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    • 2012-02-04
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 2014-01-31
    相关资源
    最近更新 更多