判断两幅Mat型的图片是否是相同的,然后进行相应的处理

来源:互联网 发布:黑客腾讯软件下载中心 编辑:程序博客网 时间:2024/05/18 02:29

1.怎么判断Mat型图片是否相同?

只需要判断每个像素点是否是相等的即可

2.代码说明

#include <iostream>#include <opencv2/opencv.hpp>using namespace std;using namespace cv;int main(){    //mat1 与 mat2 进行比较       //mat2 与 mat3 进行比较    Mat mat1 = Mat::zeros(100,100,CV_8UC1);    Mat mat2 = Mat::ones(100, 100, CV_8UC1);    Mat mat3 = Mat::ones(100, 100, CV_8UC1);    int Rows = mat1.rows;    int Cols = mat1.cols * mat1.channels();    int IsStopOutLoop = 0;    bool bRet = true;    do    {        for (int i = 0; i < Rows; i++)        {            uchar *data1 = mat2.ptr<uchar>(i);            uchar *data2 = mat3.ptr<uchar>(i);            for (int j = 0; j < Cols; j++)            {                if (data1[j] != data2[j])                {                    IsStopOutLoop++;                    bRet = false;                    break;                }            }            if (IsStopOutLoop != 0)                break;        }        //bRet = true;    } while (false);    if (bRet == false)    {        //如果两幅图片不相等  进行相应的处理  这里就用cout模拟了        cout << "这两幅Mat是不同的" << endl;    }    else    {        //如果两幅图片相等   进行相应的处理  这里就用cout模拟了        cout << "这两幅Mat图片是相同的" << endl;    }    system("pause");    return 0;}

3.实验结果展示

这里写图片描述

0 0