意外的Harris探测器结果

时间:2015-12-22 14:19:51

标签: c++ opencv

我将垂直和水平渐变加载到此处发布的函数中,并计算构成角点响应的总和。为什么只找到边界像素,我的阈值为0,否则图像上有0个角。对于渐变,我使用了sobel算子。

查看下面的输出图片。

Output image

for (int i = 0; i < width; i++)
{
    for (int j = 0; j < height; j++)
    {
        if ((i - search_size / 2 < 0 || i + search_size / 2 > image1.rows - 1) || (j - search_size / 2 < 0 || j + search_size / 2 > image1.cols - 1)) {
            continue;
        }

        double Ix2 = 0, Iy2 = 0, Ixy = 0;

        double detM=0;
        double traceM=0;
        double R = 0;

        for (int m = i-search_size /2; m < i + search_size /2 ; m++){
            for (int n = j-search_size /2; n < j + search_size/2 ; n++){

                gauss = exp(-(((i - m) * (i - m)) + ((j - n) * (j - n))) / gaus_del);
                //Compute Ix^2 , Iy^2 and Ixy
                Ix2 += gauss*(image1.at<float>(m, n)*image1.at<float>(m, n));
                Iy2 += gauss*(image2.at<float>(m, n)*image2.at<float>(m, n));
                Ixy += gauss*(image1.at<float>(m, n)*image2.at<float>(m, n));
            }
        }



        detM = (Ix2*Iy2 - Ixy*Ixy);
        traceM = Ix2*Ix2 + Iy2*Iy2;

        R = detM / traceM;
        //cout <<i+j<< endl;
        //  std::cout << "R :" << Iy2 << endl;
        if (R > threshold)
        {
            circle(image, cv::Point2f(i, j), 3.5, cv::Scalar(255, 255, 0), 1, 5);
            cout << "corner found" << endl;
        }
    }
}
编辑:我现在正在使用uchars,结果看起来好多了 new result 2

0 个答案:

没有答案