iOSFace Service(檢測)

來源:互聯網
上載者:User

iOSFace Service(檢測)

iOS的CoreImage已經內建了臉部偵測的介面,檢測準確率一般,尤其是側臉,基本上就檢測不到。不過跟其他同類產品比較,也還算是不相上下吧。用起來很簡單:

 

    CIImage* image = [CIImage imageWithCGImage:aImage.CGImage];        NSDictionary  *opts = [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh                                                      forKey:CIDetectorAccuracy];    CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace                                              context:nil                                              options:opts];        //得到面部資料    NSArray* features = [detector featuresInImage:image];

 

最後的features中就是檢測到的全部臉部資料,可以用如下方式計算位置:

 

    for (CIFaceFeature *f in features)    {        CGRect aRect = f.bounds;                NSLog(@"%f, %f, %f, %f", aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height);         //眼睛和嘴的位置         if(f.hasLeftEyePosition) NSLog(@"Left eye %g %g\n", f.leftEyePosition.x, f.leftEyePosition.y);         if(f.hasRightEyePosition) NSLog(@"Right eye %g %g\n", f.rightEyePosition.x, f.rightEyePosition.y);         if(f.hasMouthPosition) NSLog(@"Mouth %g %g\n", f.mouthPosition.x, f.mouthPosition.y);    }

注意,檢測到的位置是臉部資料在圖片上的座標(在uiimage上的,不是uiimageview上的),如果需要在視圖上繪製範圍,則需要進行座標轉換(y軸方向相反),並且也要注意圖片在視圖上的縮放等。

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.