CIFaceFeature指出错误

时间:2012-06-15 11:45:39

标签: objective-c ios xcode face-detection

这只是我尝试过的一些非常标准的代码。我想要做的是在一张非常稳定的肖像图像上放置两个眼球和一张嘴。这是我尝试过的:

 CIImage *image = [CIImage imageWithCGImage: [tim.image CGImage]];

CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options: [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey: CIDetectorAccuracy]];

NSArray *feats = [detector featuresInImage: image];

for (CIFaceFeature *faceFeature in feats) {

    if (faceFeature.hasLeftEyePosition) {

        eyeLeft.center = faceFeature.leftEyePosition;
    }

    if (faceFeature.hasRightEyePosition) {

        eyeRight.center = faceFeature.rightEyePosition;
    }

    if (faceFeature.hasMouthPosition) {

        moth.center = faceFeature.mouthPosition;
    }
}

问题是我的图像确实翻译了他们的中心,但是到了一个非常尴尬的位置(AKA不是正确的位置)!虽然它们确实以正确的距离关系出现,但除了嘴巴在顶部。这意味着:

嘴巴在上面,几厘米处有两个眼球,相距几厘米。因此根据图像视图正确缩放它们,它们只是在错误的plac中

2 个答案:

答案 0 :(得分:10)

CIImageUIImage坐标系是反向的,因此您必须翻译坐标。 例如:

CGPoint ciMmouthCenter = faceFeature.mouthPosition;
CGPoint uiMmouthCenter;
uiMouthCenter.x = tim.image.size.width - ciMouthCenter.x;
uiMouthCenter.y = tim.image.size.height - ciMouthCenter.y;

答案 1 :(得分:2)

你应该使用apple的'SquareCam'应用程序。它将正方形放置在任何方向前后摄像头的正确位置。对于我的应用程序,我只是将代码从“SquareCam”中删除,该代码确定了'faceRect'。对于mouthPosition,我沿着faceRect插入了x值和y值的百分比。