1. 程式人生 > >opencv中在螢幕上每隔幾秒顯示一個點,並且儲存點的座標

opencv中在螢幕上每隔幾秒顯示一個點,並且儲存點的座標

<span style="font-size:18px;">#include<Windows.h>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/objdetect/objdetect.hpp>
#include<vector>
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
using namespace cv;
int main()
{
	const Size sizepx(900, 900);
	Mat screen(sizepx.width, sizepx.height, CV_32FC3);
	screen.setTo(Scalar(255, 0, 0));
	string filename = "E:data1.txt";
	ofstream outFile(filename.c_str(), ios::app);  //在檔案末尾寫入 
	vector<Point> vectorp;
	
	for (int i = 150; i < sizepx.height; i += 300)
	{
		for (int j = 150; j < sizepx.width; j += 300)
		{

			Point p = Point(i, j);
				circle(screen, p, 8, Scalar(0, 255, 0), -1);
				imshow("螢幕", screen);
				waitKey(3000);
				screen.setTo(Scalar(255, 0, 0));
				vectorp.push_back(p);
				cout << p.x << ' ' << p.y << endl;
			
		}
	}
	for (int i = 0; i<vectorp.size(); i++)
	{
		outFile << vectorp[i].x << ' ' << vectorp[i].y;   //每列資料用 tab 隔開   
		outFile << endl;
	}
	/*waitKey(0);*/
	return 0;
}</span>