DennisLiu1993 / Fastest_Image_Pattern_Matching

C++ implementation of a ScienceDirect paper "An accelerating cpu-based correlation-based image alignment for real-time automatic optical inspection"
BSD 2-Clause "Simplified" License
802 stars 197 forks source link

角度容差设置问题 #49

Open xushaolei123 opened 11 months ago

xushaolei123 commented 11 months ago

您好,想请教一下使用实例图片Src1.bmp测试时,当角度容差允许值非零时,就会出现程序崩溃的情况,崩溃的程序位于MathToolDlg.cpp 1064行

DennisLiu1993 commented 11 months ago

可能是Windows造成的exception 試試這個解法 https://github.com/DennisLiu1993/Fastest_Image_Pattern_Matching/blob/main/README.md#special-note

xushaolei123 commented 11 months ago

谢谢博主,已经解决了,在types.hpp大致1847行添加下面代码,确实是windows的原因 inline RotatedRect::RotatedRect(const Point2f& _point1, const Point2f& _point2, const Point2f& _point3) { Point2f _center = 0.5f (_point1 + _point3); Vec2f vecs[2]; vecs[0] = Vec2f(_point1 - _point2); vecs[1] = Vec2f(_point2 - _point3); double x = std::max(norm(_point1), std::max(norm(_point2), norm(_point3))); double a = std::min(norm(vecs[0]), norm(vecs[1])); // check that given sides are perpendicular // this is the line you need to modify CV_Assert(std::fabs(vecs[0].ddot(vecs[1])) a <= FLT_EPSILON 9 x (norm(vecs[0]) norm(vecs[1])));

// wd_i stores which vector (0,1) or (1,2) will make the width
// One of them will definitely have slope within -1 to 1
int wd_i = 0;
if (std::fabs(vecs[1][1]) < std::fabs(vecs[1][0])) wd_i = 1;
int ht_i = (wd_i + 1) % 2;

float _angle = std::atan(vecs[wd_i][1] / vecs[wd_i][0]) * 180.0f / (float)CV_PI;
float _width = (float)norm(vecs[wd_i]);
float _height = (float)norm(vecs[ht_i]);

center = _center;
size = Size2f(_width, _height);
angle = _angle;

}