0

我正在尝试从红外图像中检测瞳孔并计算瞳孔的中心。在我的设置中,我使用了一个对红外光敏感的相机,并在镜头上添加了一个可见光滤镜,并在相机周围添加了两个红外 LED。但是,我得到的图像模糊不是很清晰,这可能是由于相机分辨率低造成的,其最大分辨率约为 700x500。

在处理过程中,我做的第一件事就是将这个 RGB 图像转换为灰度图像,但是结果很糟糕。结果一无所获。

int main()
{
    //load image
    cv::Mat src = cv::imread("11_13_2013_15_36_09.jpg");
    cvNamedWindow("original");
    cv::imshow("original", src);
    cv::waitKey(10);
    if (src.empty())
    {
        std::cout << "failed to find the image";
        return -1;
    }

    // Invert the source image and convert to graysacle
    cv::Mat gray;
    cv::cvtColor(~src, gray, CV_BGR2GRAY);
    cv::imshow("image1", gray);
    cv::waitKey(10);

    // Convert to binary image by thresholding it
    cv::threshold(gray, gray, 220, 255, cv::THRESH_BINARY);
    cv::imshow("image2", gray);
    cv::waitKey(10);

    // Find all contours
    std::vector<std::vector<cv::Point>>contours;
    cv::findContours(gray.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

    // Fill holes in each contour
    cv::drawContours(gray, contours, -1, CV_RGB(255, 255, 255), -1);
    cv::imshow("image3", gray);
    cv::waitKey(10);
    for (int i = 0; i < contours.size(); i++)
    {
        double area = cv::contourArea(contours[i]);
        cv::Rect rect = cv::boundingRect(contours[i]);
        int radius = rect.width / 2;

        // If controu is big enough and has round shape
        // Then it is the pupil
        if (area >= 800 &&
            std::abs(1 - ((double)rect.width / (double)rect.height)) <= 0.3 &&
            std::abs(1 - (area / (CV_PI * std::pow(radius, 2)))) <= 0.3)
        {
            cv::circle(src, cv::Point(rect.x + radius, rect.y + radius), radius, CV_RGB(255, 0, 0), 2);
        }
    }
    cv::imshow("image", src);
    cvWaitKey(0);
}

转换原始图像时,灰色图像很糟糕,有人知道更好的解决方案吗?我对此完全陌生。对于查找圈子的其余代码,如果您有任何意见,请告诉我。而且我还需要在原始图像上增加两个闪光(光点)的位置,有人知道吗?谢谢。

4

1 回答 1

0

在阈值化之前尝试均衡和过滤源图像;)

于 2014-01-23T04:36:40.867 回答