读取坐标数据并标记

从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);

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值