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;

}