OpenCV 筆記 1.1 簡單的讀圖片

背景知識:

OpenCV 筆記 1 安裝配置 與 Camera測試

 

 

簡單寫個接圖的範例

imread就是讀圖片

#include <iostream>
#include "opencv2/opencv.hpp"
#include <iostream>

using namespace cv;

int main()
{
	Mat frame;
	string imagePath = ".//pattern.png";
	frame = imread(imagePath, IMREAD_COLOR);

	string imgname;
	int f = 1;
	int ch;
	while (1) 
	{
		if (frame.empty()) break;         
		imshow("Camera", frame);

		int WK = waitKey(10);
		if (WK == 'q')
		{
			break;
		}
		else if (WK == 'a')
		{
			imgname = to_string(f++) + ".jpg";
			imwrite(imgname, frame);
		}
	}
	destroyAllWindows();
	std::cout << "Finished writing" << endl;
	std::cin.get();
	return 0;
}