OpenCV 代码读取图像并进行比较

#include <opencv2 / opencv.hpp> #include

使用命名空间 cv; 使用命名空间 std;

int main(int argc,char ** argv){Mat image; image = imread(“C:\ Users \ Development \ Documents \ Visual Studio 2013 \ Projects \ ImageIn.bmp”,CV_LOAD_IMAGE_GRAYSCALE); //读取文件

if (!image.data)                              // Check for invalid input
{
    cout << "Could not open or find the image" << std::endl;
    return -1;
}

Mat witout = imread("C:\\Users\\Development\\Documents\\Visual Studio 2013\\Projects\\ImageWitOut.bmp", CV_LOAD_IMAGE_GRAYSCALE);;
Mat cvout = Mat(image.size(), image.type(), Scalar(255));

imshow("witout", witout);
imshow("cvout", cvout);

Mat diff = (witout == cvout);

namedWindow("Difference", WINDOW_AUTOSIZE);// Create a window for display.
imshow("Difference", diff);                   // Show our image inside it.

waitKey(0);                                          // Wait for a keystroke in the window
return 0;

}