我研究过很多关于人脸检测的例子,而且我使用CIDetector
和HaarCascade_eye.xml
在iPhone中检测到了眼睛。但我想检测眼睛的瞳孔,并想测量瞳孔之间的距离。请指导我,以便我能做到。
答案 0 :(得分:4)
使用以下公式计算两点之间的距离:
这将获得双眼的中心点(由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.
}