如何检测眼睛瞳孔和测量iPhone中瞳孔之间的距离

时间:2012-09-07 08:08:57

标签: ios core-image face-detection

我研究过很多关于人脸检测的例子,而且我使用CIDetectorHaarCascade_eye.xml在iPhone中检测到了眼睛。但我想检测眼睛的瞳孔,并想测量瞳孔之间的距离。请指导我,以便我能做到。

1 个答案:

答案 0 :(得分:4)

使用以下公式计算两点之间的距离:distance formula

这将获得双眼的中心点(由CIDetector检测到)并比较它们的位置以输出您正在寻找的测量值。

if(faceFeature.hasLeftEyePosition && faceFeature.hasRightEyePosition)
{
    CGPoint leftEyeCenter = faceFeature.leftEyePosition;
    CGPoint rightEyeCenter = faceFeature.rightEyePosition;

    float simpleDistance = rightEyeCenter.x - leftEyeCenter.x;
    //This finds the distance simply by comparing the x coordinates of the two pupils

    float complexDistance = fabsf(sqrtf(powf(leftEyeCenter.y - rightEyeCenter.y, 2) + powf(rightEyeCenter.x - leftEyeCenter.x, 2)));
    //This will return the diagonal distance between the two pupils allowing for greater distance if the pupils are not perfectly level.       
}