ios - Detect a face while my cam is open -


i need build app cam view, , should detect cam looking @ face, can point me in right direction? have built detects face on image, need work cam, here have done far:

- (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.     nsstring *path = [[nsbundle mainbundle] pathforresource:@"picture" oftype:@"jpg"];     nsurl *url = [nsurl fileurlwithpath:path];      cicontext *context = [cicontext contextwithoptions:nil];      ciimage *image = [ciimage imagewithcontentsofurl:url];      nsdictionary *options = @{cidetectoraccuracy: cidetectoraccuracyhigh};      cidetector *detector = [cidetector detectoroftype:cidetectortypeface context:context options:options];      nsarray *features = [detector featuresinimage:image];  } 

i have done following:

-(void)viewwillappear:(bool)animated{     _session = [[avcapturesession alloc] init];     [_session setsessionpreset:avcapturesessionpresetphoto];      avcapturedevice *inputdevice = [avcapturedevice defaultdevicewithmediatype:avmediatypevideo];      nserror *error;     avcapturedeviceinput *deviceinput = [avcapturedeviceinput deviceinputwithdevice:inputdevice error:&error];      if([_session canaddinput:deviceinput]){         [_session addinput:deviceinput];     }      avcapturevideopreviewlayer *previewlayer = [[avcapturevideopreviewlayer alloc] initwithsession:_session];     [previewlayer setvideogravity:avlayervideogravityresizeaspectfill];     calayer *rootlayer = [[self view] layer];     [rootlayer setmaskstobounds:yes];      cgrect frame = self.framecapture.frame;     [previewlayer setframe:frame];      [rootlayer insertsublayer:previewlayer atindex:0];     [_session startrunning];  }  -(void)captureoutput:(avcaptureoutput *)captureoutput didoutputmetadataobjects:(nsarray *)metadataobjects fromconnection:(avcaptureconnection *)connection{     for(avmetadataobject *metadataobject in metadataobjects) {         if([metadataobject.type isequaltostring:avmetadataobjecttypeface]) {             _facedetectedlabel.text = @"face detected";         }     } } 

but still not detecting faces, doing wrong?

you should add metadata output before you'll have data.

avcapturemetadataoutput *metadataoutput = [[avcapturemetadataoutput alloc] init]; // create serial queue handle metadata output dispatch_queue_t metadataqueueoutput = dispatch_queue_create("com.yourappname.metadataqueue.outputqueue", dispatch_queue_serial); [metadataoutput setmetadataobjectsdelegate:self queue:metadataqueueoutput]; if ([_session canaddoutput:metadataoutput]) {     [strongself.session addoutput:metadataoutput]; } // set object types interested, should not check type in output callback metadataoutput.metadataobjecttypes = @[avmetadataobjecttypeface]; 

that should work. let me know if does


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -