从txt文本读取坐标并在一张图上标记,文本如下格式:
第一个是横坐标X第二个是Y。总共168对数据坐标
#include<iostream>
#include "opencv2/opencv.hpp"
#include<opencv2/imgproc/imgproc.hpp>
#include<fstream>
using namespace std;
using namespace cv;
void main()
{
Mat img=imread("3.jpg");
ifstream fin("7.txt");
string s;
int a[168]={0};
int b[168]={0};
int i=0,j=0;
int flg=0;
while(fin>>s) //这里是经过测试了的,每次读取一个数据
{
if(flg%2==0)
a[i++]=atoi(s.c_str());
else
b[j++]=atoi(s.c_str());
flg++;
//cout<<s<<endl;
}
for(int n=0;n<168;n++)
{
Point center=Point(a[n],b[n]);
circle(img,center,4,Scalar(155,155,155));
}
/*srand((unsigned)time(NULL)); 注意积累这种随机颜色的方法,一开始整b,g,r变量提示
莫名的错误,原来b和数组b同名了,
for(int n=0;n<168;n++)
{
int bb=rand()&255;
int gg=rand()&255;
int rr=rand()&255;
Point center=Point(a[n],b[n]);
circle(img,center,8,Scalar(bb,gg,rr));
}*/
imwrite("new.jpg",img);
}