c++ - 实施哈里斯角检测
问题描述
我正在尝试实现哈里斯角检测。一步计算标量角值。我总是得到等于 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;
}
解决方案
推荐阅读
- javascript - 我有 2 个 mongoose 模式从中获取数据,然后将其作为响应发送,但始终在数据解析之前发送响应
- encryption - 如何使用 Google Cloud Build 和 Google Cloud KMS 从构建时解密的文件中读取变量
- java - 如何在 Eclipse 中按类别设置 JUnit 运行配置?
- ios - 选择选项卡时如何刷新或重新加载 WKwebview
- python - 从用户输入应用比较符号
- c# - 相同代码的等待和不同的线程ID
- excel - 聚合通配符搜索
- java - 如何使用数组中的坐标在谷歌地图上绘制多边形
- javascript - Ajax - 我提交后无法显示帖子
- button - (如何)我可以更改 F# Fable Elmish 中禁用按钮的字体颜色吗?