2013-04-02 74 views

回答

1
for (CIFaceFeature *ff in features) { 

    // find the correct position for the square layer within the previewLayer 

    // the feature box originates in the bottom left of the video frame. 

    // (Bottom right if mirroring is turned on) 

    CGRect faceRect = [ff bounds]; 



    // flip preview width and height 

    CGFloat temp = faceRect.size.width; 

    faceRect.size.width = faceRect.size.height; 

    faceRect.size.height = temp; 

    temp = faceRect.origin.x; 

    faceRect.origin.x = faceRect.origin.y; 

    faceRect.origin.y = temp; 

    // scale coordinates so they fit in the preview box, which may be scaled 

    CGFloat widthScaleBy = previewBox.size.width/clap.size.height; 

    CGFloat heightScaleBy = previewBox.size.height/clap.size.width; 

    faceRect.size.width *= widthScaleBy; 

    faceRect.size.height *= heightScaleBy; 

    faceRect.origin.x *= widthScaleBy; 

    faceRect.origin.y *= heightScaleBy; 



    if (isMirrored) 

     faceRect = CGRectOffset(faceRect, previewBox.origin.x + previewBox.size.width - faceRect.size.width - (faceRect.origin.x * 2), previewBox.origin.y); 

    else 

     faceRect = CGRectOffset(faceRect, previewBox.origin.x, previewBox.origin.y); 

你可以得到臉部RECT但ü需要精細的圖像

這將幫助ü獲得每個位置

-(void)markFaces:(CIImage *)image 
{ 
    // draw a CI image with the previously loaded face detection picture 
    @autoreleasepool { 
     CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace 
                context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracy forKey:CIDetectorAccuracyHigh]]; 

     // create an array containing all the detected faces from the detector 
     NSArray* features = [detector featuresInImage:image]; 

     NSLog(@"The Address Of CIImage In: %p %s",image,__FUNCTION__); 
     NSLog(@"Array Count %d",[features count]); 


     NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 


     if([features count]==0) 
     { 
      //No image is present 
     } 
     else 
     { 
      for(CIFaceFeature* faceFeature in features) 
      { 

       if(faceFeature.hasMouthPosition) 
       { 
        // Your code based on the mouth position 
       } 


       if (faceFeature.hasLeftEyePosition) { 
       // Write your code Note: points are mirrored point so u need to take care of that 

       } 
       if (faceFeature.hasRightEyePosition) { 
       // Write your code Note: points are mirrored point so u need to take care of that 

       } 

       } 
} 
} 
+0

感謝您的回覆。我會試一試,讓你知道! – 3DNewbie

+0

@ 3DNewbie永遠歡迎 – Spynet

+0

我已經完成了檢測眼睛。但我的問題是在眼睛上畫一個覆蓋圖像?如何做到這一點?即不規則的圓形或正方形,我需要在眼睛上覆蓋圖像。 – 3DNewbie

0

蘋果iOS 5及更高版本的眼球,在內部提供了這種功能。

請參閱該蘋果文檔中有關同:

http://developer.apple.com/library/mac/#documentation/graphicsimaging/Conceptual/CoreImaging/ci_detect_faces/ci_detect_faces.html

在這個例子中,他們都在做同樣的,因爲你需要 - 面部及眼部檢測。

希望這會對你有所幫助。

*同時檢查這些link1link2,它包含檢測區域的圖像覆蓋。我想這就是你要找的。

+0

Thnaks爲您的答覆。我的意圖是將重疊圖像放在眼睛的位置上。怎麼做?即不規則的圓形或正方形,我需要在眼睛上覆蓋圖像。 – 3DNewbie

+0

在其他兩個鏈接中,您可以找到相同的地方,只在其中放置圖像。 – Mrunal

+0

沒有其他兩個鏈接在圖像上繪製圓圈,而不是將圓圈圖像放在眼睛上!你能指導我嗎? – 3DNewbie

相關問題