2012-04-05 110 views
1

我正在拍攝來自相機的圖像(使用UIImagePickerController)並將其保存到文檔目錄。如果從相機拍攝圖像未檢測到使用UIImagePickerControllerSourceTypeCamera

然後,我使用CIDetector APICIfacefeature API在不同的視圖控制器中獲取這些圖像以獲取正面部分。

問題是雖然我能夠正確獲取圖像,但並未檢測到人臉。如果我將相同的圖像存儲在它檢測到的主包中。

我不知道問題在哪裏??。我已經嘗試了一切。可能問題出在UIImage,或者可能是將圖像保存在文檔目錄或相機中的格式。

請幫忙。我會感謝你。

- (void) imagePickerController:(UIImagePickerController *)picker  didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                 NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString* path = [documentsDirectory stringByAppendingPathComponent: 
         [NSString stringWithString: @"SampleImage.jpg"] ]; 
    NSData* data = UIImageJPEGRepresentation(image, 0); 
    [data writeToFile:path atomically:YES]; 
    [picker dismissModalViewControllerAnimated:YES]; 
    FCVC *fcvc = [[FCVC alloc] initwithImage:image]; 

    [self.navigationController pushViewController:fcvc animated:YES]; 
} 

在FCVC的viewDidLoad中我打電話以下功能通過傳遞:

-(void)markFaces:(UIImage *)pic 
{ 
    CIImage* image = [CIImage imageWithCGImage:pic.CGImage]; 
    CGImageRef masterFaceImage; 

    CIDetector* detector = [CIDetector detectorOfType: CIDetectorTypeFace 
              context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]]; 

// create an array containing all the detected faces from the detector  
    NSArray* features = [detector featuresInImage:image]; 
    for(CIFaceFeature* faceFeature in features) 
    {  
     masterFaceImage = CGImageCreateWithImageInRect(facePicture.CGImage,CGRectMake(faceFeature.bounds.origin.x,faceFeature.bounds.origin.y, faceFeature.bounds.size.width,faceFeature.bounds.size.height)); 
    } 
    self.masterExtractedFace = [UIImage imageWithCGImage:masterFaceImage]; 
} 

在此先感謝。

回答

1

一個簡單的修正這一點,如果你使用的相機總是在肖像,是加入這個小片段:

NSDictionary* imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:6] forKey:CIDetectorImageOrientation]; 
NSArray* features = [detector featuresInImage:image options:imageOptions]; 

要弄清楚你是什麼方位,如果你需要它動態找出你的方向。

檢查kCGImagePropertyOrientation

+0

我怎麼能檢測LandScapeMode – siva 2012-07-23 11:51:17

+0

檢查kCGImagePropertyOrientation圖像 – sai 2012-07-27 05:58:47

相關問題