使用来自poitr的OPENCV代码进行图像比较

IMAGE COMPARISON USING OPENCV code from poitr

本文关键字:代码 图像 比较 OPENCV poitr      更新时间:2023-10-16

HI我找到了这个代码来比较图像

cv::Mat img1 = ...
cv::Mat img2 = ...
cv::Mat result = ...
int threshold = (double)(img1.rows * img1.cols) * 0.7; 
cv::compare(img1 , img2  , result , cv::CMP_EQ );
int similarPixels  = countNonZero(result);
if ( similarPixels  > threshold ) {
   cout << "similar" << endl;
}

但由于我是OPENCV的新手,我不知道"cv::Mat img1=…"的值是什么请帮助我,并尝试使用图像路径作为值的代码,但它给出了一个错误

void compare(const MatND& src1, const MatND& src2, MatND& dst, int cmpop)

compare函数取4个参数,这是;

•src1 – The first source array
•src2 – The second source array; must have the same size and same type as src1
•value – The scalar value to compare each array element with
•dst – The destination array; will have the same size as src1 and type= CV_8UC1

据我所知,这张照片有一些类似fiducial points的坐标系(X / Y )

例如;

1 45 123
2 56 164
3 64 147

并将这些点存储在数组中,然后将数组发送到比较函数中,以找到匹配器。

如果你想进行图像比较,我的建议是你可以搜索feret database,它可以免费用于研究。

您可以使用imread将图像加载到cv::Mat img1,例如

cv::Mat img1 = imread("c:\test.bmp");    // To load an RGB image