2013-04-02 40 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

相关问题