1
我正在拍攝來自相機的圖像(使用UIImagePickerController
)並將其保存到文檔目錄。如果從相機拍攝圖像未檢測到使用UIImagePickerControllerSourceTypeCamera
然後,我使用CIDetector API
和CIfacefeature 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];
}
在此先感謝。
我怎麼能檢測LandScapeMode – siva 2012-07-23 11:51:17
檢查kCGImagePropertyOrientation圖像 – sai 2012-07-27 05:58:47