如何判断两幅图像是否完全一样呢?
<1>遍历两幅图像的每一个像素点,对两幅图像的相同位置像素点进行比较
#include <opencv2/opencv.hpp>
#include <stdio.h>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat mat1 = Mat::zeros(100,100,CV_8UC1);
Mat mat2 = Mat::zeros(100,100,CV_8UC1);
int diff=0;
bool bRet=true;
for(int i=0;i<mat1.rows;i++)
{
uchar *data1 = mat1.ptr<uchar>(i);//指向图像每一行的像素点
uchar *data2 = mat2.ptr<uchar>(i);
for(int j=0;j<mat1.cols*mat1.channels();j++)
{
if(data1[j] != data2[j])
{
diff++;
bRet=false;
break;
}
}
if(diff != 0)
break;
}
if(bRet==false)
{
printf("这两幅Mat是不同的\n");
printf("不同点的个数:%d",diff);
}
else
{
printf("这两幅Mat是相同的\n");
}
cv::waitKey(0);
}