2013-09-27 1 views
2

Apple의 얼굴 탐지 API로 간단한 개념 증명을 얻으려고합니다. 나는 애플의 SquareCam을 포함한 다른 몇가지 예를 들어 봤는데, 내가가는 API를 얻을 수있는 올바른 패턴을 다음하고 같이이에 따라이 하나 https://github.com/jeroentrappers/FaceDetectionPOCObjective-C : No 내가하는 일 CIDetector는 항상 nil입니다.

, 그것은 보인다,하지만 난 붙어입니다. 내가 무엇을해도 내 얼굴 검출기의 CIDetector는 항상 무의미합니다 !!!

나는 도움, 단서 - 힌트 - 제안을 진심으로 감사 할 것입니다!

-(void)initCamera{ 
session = [[AVCaptureSession alloc]init]; 

AVCaptureDevice *device; 
/* 
if([self frontCameraAvailable]){ 
    device = [self frontCamera]; 
}else{ 
    device = [self backCamera]; 
}*/ 

device = [self frontCamera]; 
isUsingFrontFacingCamera = YES; 
NSError *error = nil; 

AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; 

if(input && [session canAddInput:input]){ 
    [session addInput:input]; 
}else{ 
    NSLog(@"Error %@", error); 
    //make this Dlog... 
} 


videoDataOutput = [[AVCaptureVideoDataOutput alloc]init]; 
NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject: 
            [NSNumber numberWithInt:kCMPixelFormat_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]; 
[videoDataOutput setVideoSettings:rgbOutputSettings]; 
[videoDataOutput setAlwaysDiscardsLateVideoFrames:YES]; 

videoDataOutputQueue = dispatch_queue_create("VideoDataOutputQueue", DISPATCH_QUEUE_SERIAL); 
[videoDataOutput setSampleBufferDelegate:self queue:videoDataOutputQueue]; 
[[videoDataOutput connectionWithMediaType:AVMediaTypeVideo]setEnabled:YES]; 

if ([session canAddOutput:videoDataOutput]) { 
    [session addOutput:videoDataOutput]; 
} 




[self embedPreviewInView:self.theImageView]; 



[session startRunning]; 



} 



-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{ 

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate); 
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer options:(__bridge NSDictionary *)attachments]; 


if(attachments){ 
    CFRelease(attachments); 
} 



UIDeviceOrientation curDeviceOrientation = [[UIDevice currentDevice] orientation]; 


NSDictionary *imageOptions = @{CIDetectorImageOrientation:[self exifOrientation:curDeviceOrientation] }; 


NSDictionary *detectorOptions = @{CIDetectorAccuracy: CIDetectorAccuracyLow}; 

CIDetector *faceDetector = [CIDetector detectorOfType:CIFeatureTypeFace context:nil options:detectorOptions]; 


NSArray *faceFeatures = [faceDetector featuresInImage:ciImage options:imageOptions]; 
if([faceFeatures count]>0){ 
    NSLog(@"GOT a face!"); 
    NSLog(@"%@", faceFeatures); 

} 


dispatch_async(dispatch_get_main_queue(), ^(void) { 
    //NSLog(@"updating main thread"); 
}); 


} 

답변

0

내가 너무 커서 같은 문제가있어서 this 문서를 사용하고 있다고 가정합니다. 실제로 코드에 버그가 있습니다. 검출기 유형이 아니라 CIDetectorSmile보다 CIDetectorTypeFace이라고

CIDetector *smileDetector = [CIDetector detectorOfType:CIDetectorTypeFace 
          context:context 
          options:@{CIDetectorTracking: @YES, 
             CIDetectorAccuracy: CIDetectorAccuracyLow}]; 

참고 : CIDetector 인스턴스화 같은 보일 것이다. CIDetectorSmile 때문에이 코드를 사용, 그냥 미소 (그리고 모든 얼굴을) 추출, 오히려 검출기 유형과 기능 옵션입니다 : 내가 시작 위치를 잘 그 기사가

NSArray *features = [smileDetector featuresInImage:image options:@{CIDetectorSmile: @YES}]; 
+0

을,하지만 난 결정 그냥 얼굴 인식을 먼저 시도해보십시오. 이 시점에서 나는 CIDetector의 인스턴스를 어떻게 또는 어디에서 인스턴스화할지에 상관없이 여전히 아무런 문제가 없다는 사실에 좌절감을 느낍니다. 나는 모든 올바른 프레임 워크를 올바르게 가져 왔음을 확신합니다. 이전에 언급했듯이, 나는 다른 얼굴 검출 예제의 패턴 중 일부를 따르려고하기 때문에이 코드의 대부분이 어디에서 왔는지 알 수 있습니다. 행복하게 전체 소스를 공유하기 때문에 내가 뭘 잘못하고 있는지 알고 싶습니다. –

+0

WOW. 참으로 나는 그것을 완전히 놓쳤다. 고맙습니다! CIDetectorTypeFace. ** 얼굴 손바닥 ** –

1
CIDetector *smileDetector = [CIDetector detectorOfType:CIDetectorTypeFace 
          context:context 
          options:@{CIDetectorTracking: @YES, 
             CIDetectorAccuracy: CIDetectorAccuracyLow}]; 
NSArray *features = [smileDetector featuresInImage:image options:@{CIDetectorSmile:@YES}]; 
if (([features count] > 0) && (((CIFaceFeature *)features[0]).hasSmile)) { 
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(didFinishWritingImage), features); 
} else { 
    self.label.text = @"Say Cheese!" 
} 
관련 문제