实施哈里斯角点检测

问题描述 投票:0回答:1

我正在尝试实现哈里斯角点检测。步骤计算标量角值。我总是得到等于 0 的行列式。我错过了什么?我想我误解了计算行列式,以及我如何计算它。

int convolve(const Mat &image, int x, int y)
{
    // Coordinate around (x,y):
    //(y-1,x-1)   (y-1,x)     (y-1,x+1)
    //(y  ,x-1)   (y  ,x)     (y  ,x+1)
    //(y+1,x-1)   (y+1,x)     (y+1,x+1)    
    // suppose kernel 3x3
    double sum = 0.f;
    for (auto i = -1; i <= 1; i++)
    {
        for (auto j = -1; j <= 1; j++)
        {
            sum += image.at<double>(y+j,x+j);
        }
    }
    return sum;
}


Mat cal_Harris_Value(const Mat &image, const Mat &Ix, const Mat &Iy, float alpha, float threshold, float sigma, int widthKernel)
{
    auto Ix_square = cal_Ix_square(Ix); // Ix_square = Ix.mul(Ix)
    auto Iy_square = cal_Iy_square(Iy); // Iy_square = Iy.mul(Iy)
    auto Ix_Iy = cal_Ix_Iy(Ix, Iy);     // Ix_Iy     = Ix.mul(Iy)  

    // function clone_image : create image with the same type from  
    auto R_matrix = clone_image(image, CV_64F);

    int width = R_matrix.cols;
    int height = R_matrix.rows;

    for (auto y = 1; y < height - 1; y++)
    {
        for (auto x = 1; x < width - 1; x++)
        {
            //double ix_ix, iy_iy, ix_iy;

            auto ix_ix = convolve(Ix_square, x, y);
            auto iy_iy = convolve(Iy_square, x, y);
            auto ix_iy = convolve(Ix_Iy, x, y);
            auto trace = ix_ix + iy_iy;
            auto R = ix_ix * iy_iy - ix_iy * ix_iy - alpha * trace * trace;
            R_matrix.at<double>(y,x) = R;
        }
    }   


    return R_matrix;
}

c++ computer-vision feature-detection
1个回答
0
投票

以下是一些需要检查或考虑的事项:

图像区域:

确保计算 Harris 角点的像素周围区域具有足够的强度变化。如果强度恒定或接近恒定,则梯度值将很小,导致行列式接近 0。 导数计算:

仔细检查图像导数的计算 。确保您使用适当的滤波器或卷积核来进行准确的导数估计。 标准化:

有时,通过除以局部图像强度来标准化梯度可以帮助稳定计算。

© www.soinside.com 2019 - 2024. All rights reserved.