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