0

I'm trying to implement Harris Corner detection. In step compute scalar cornerness value. I always get determinant equal 0. What am i missing? I think i misunderstood about compute determinant, how i compute this.

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;
}

Blind
  • 99
  • 1
  • 11
  • This is not complete code, the error could be anywhere. What is `Ix` and `Iy`? – Cris Luengo May 21 '20 at 15:47
  • **Ix** and **Iy** are an approximations of the derivatives – one for horizontal changes, and one for vertical (using Sobel kernels). In func ```cal_Harris_Value```, i expected for **R** matrix. I make sure parameters and every function had been call in func ```cal_Harris_Value``` were correct. – Blind May 21 '20 at 17:24
  • i dont know the line :```auto R = ix_ix * iy_iy - ix_iy * ix_iy - alpha * trace * trace;``` is correct or not. – Blind May 21 '20 at 17:25
  • `ix_ix * iy_iy - ix_iy * ix_iy` is the determinant. You say this is always equal to zero. One reason could be that `Ix` and `Iy` are not correct. This is why I'm asking to see a [mre]. It helps figuring out where the problem is. – Cris Luengo May 21 '20 at 18:59
  • Check this answer: [Why determinant is not 0](https://stackoverflow.com/a/74716389/5520444) – Tony Power Dec 07 '22 at 12:47

0 Answers0