2017-05-08 2 views
0

En OpenCV je dois détecter le visage et les yeux. mais mon code ne fonctionne pas, voici mon code s'il vous plaît vérifier, cela ne fonctionne pas. Mais même code que j'essaie dans CvVideoCamera alors mon code fonctionne correctement. un seul problème yeux n'est pas la détection.IOS Il est possible CvPhotoCamera [OpenCV] nous pouvons détecter le visage

@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); 
    } 


} 

Répondre