当前位置: 首页 > 工具软件 > CIDetector > 使用案例 >

第五篇 人脸分析CIDetector

厉永宁
2023-12-01

参考一个人脸识别的Demo

demo地址 http://code4app.com/ios/5195a56f6803fa4273000000

废话不多 直接上代码

        CIImage *iImage = [CIImage imageWithCGImage:oldImage.CGImage];
        NSDictionary  *opts = [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh
                                                          forKey:CIDetectorAccuracy];
        CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
                                                  context:nil
                                                  options:opts];
        //Pull out the features of the face and loop through them
        NSArray* features = [detector featuresInImage:iImage];
        if ([features count]==0) {
            NSLog(@">>>>> 人脸监测【失败】啦 ~!!!");
            [self scaleToFitImageView2:fitHead];
        }else{
            NSLog(@">>>>> 人脸监测【成功】~!!!>>>>>> ");
            for (int i = 0; i<[features count]; i++ ) {
                
                CIFaceFeature *f = [features objectAtIndex:i];
                CGRect faceFrame = f.bounds;//faceFrame的(0,0)点是从左下角开始的;
            }
        }



 类似资料: