Esempio n. 1
0
void LandmarkDetector::innerEyeCorners(Landmarks &l)
{
    cv::Point3d nosetip = l.get(Landmarks::Nosetip);
    cv::Point2d nose2d = converter.MeshToMapCoords(depth, cv::Point2d(nosetip.x, nosetip.y));
    nose2d.x -= cropStartX;
    nose2d.y -= cropStartY;

    // Y coordinate
    int h = depth.h;
    Face::LinAlg::Vector pitsAlongY(h);
    for (int y = 0; y < h; y++)
    {
        int count = 0;
        for (int x = nose2d.x - stripeWidth/2; x <= nose2d.x + stripeWidth/2; x++)
        {
            count = curvature.pits.isSet(x, y) ? count+1 : count;
        }
        pitsAlongY(y) = count;
    }
    Face::LinAlg::Vector smoothedPits = pitsAlongY.smooth(pitsStripeSmoothKernel);

    int eyes2dY = smoothedPits.maxIndex(nose2d.y - maxYDistanceFromNosetipToEyes,
                                        nose2d.y - minYDistanceFromNosetipToEyes);
    if (eyes2dY < 0)
    {
        std::cerr << "Y coordinate of inner eye corners not found" << std::endl;
        return;
    }

    // X coordinate
    int w = depth.w;
    Face::LinAlg::Vector pitsAlongX(w);
    for (int x = 0; x < w; x++)
    {
        int count = 0;
        for (int y = eyes2dY - stripeWidth/2; y <= eyes2dY + stripeWidth/2; y++)
        {
            count = curvature.pits.isSet(x,y) ? count+1 : count;
        }
        pitsAlongX(x) = count;
    }
    smoothedPits = pitsAlongX.smooth(pitsStripeSmoothKernel);

    int leftEye2dX = smoothedPits.maxIndex(nose2d.x - maxXDistanceFromNosetipToEyes,
                                           nose2d.x - minXDistanceFromNosetipToEyes);
    if (leftEye2dX < 0)
    {
        std::cerr << "X coordinate of left inner eye corner not found" << std::endl;
    }
    else
    {
        l.set(Landmarks::LeftInnerEye,
              converter.MapToMeshCoords(depth, cv::Point2d(leftEye2dX + cropStartX, eyes2dY + cropStartY)));
    }

    int rightEye2dX = smoothedPits.maxIndex(nose2d.x + minXDistanceFromNosetipToEyes,
                                            nose2d.x + maxXDistanceFromNosetipToEyes);

    if (rightEye2dX < 0)
    {
        std::cerr << "X coordinate of right inner eye corner not found" << std::endl;
    }
    else
    {
        l.set(Landmarks::RightInnerEye,
              converter.MapToMeshCoords(depth, cv::Point2d(rightEye2dX + cropStartX, eyes2dY + cropStartY)));
    }
}