OpenCV25(绘制线和显示文字,Mat类型)

来源:互联网 发布:网络消费者的心理特征 编辑:程序博客网 时间:2024/05/17 05:15

本程序的功能是读取txt中数据,然后在显示到对应的图像上。


// 视频.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "highgui.h"#include "cv.h"#include "cxcore.h"#include <iostream>#include <fstream>#include <vector>using namespace std;using namespace cv;int _tmain(int argc, _TCHAR* argv[]){char cpath[500] = {0};// 使用的数据ifstream in("xxx.txt"); char* num = {NULL};char c;vector<int> XYais;bool hasNum(0);int dv(0);bool lessthan0(0);// * 获得X和Y的坐标while(in.get(c)){....}if( c == ',' && hasNum){if(lessthan0)dv = -dv;XYais.push_back(dv);hasNum = 0;dv = 0;lessthan0 = 0;}}// * 载入图像,绘制点ofstream f;f.open("llll.txt");int xp,yp;cout<<XYais.size()<<endl;int j = 0;char showMsg[20] = ""; for(int i=0; i< XYais.size(); i++,j++){Mat Img;sprintf(cpath,"zzzz%d.bmp",j); Img = imread(cpath,CV_LOAD_IMAGE_UNCHANGED);// xy轴line(Img,Point(128,0),Point(128,255),Scalar(0,255,0),1,8,0); // 画线line(Img,Point(0,128),Point(255,128),Scalar(0,255,0),1,8,0);xp = XYais[i];i++;yp = XYais[i];// 存储路径 sprintf(cpath,"aaaaimage%d_x%d_y%d.bmp",j,xp,yp); //1909sprintf(showMsg,"P%d(X%d,Y%d)",j,xp,yp);cout<<"("<<xp<<","<<yp<<")"<<endl;f<<"("<<xp<<","<<yp<<")"<<endl; xp = -xp*128/951 + 128;// 化归到256*256 1909 2Lyp = -yp*128/951 + 128;// 显示控制     putText(Img,showMsg,Point(100,100),CV_FONT_HERSHEY_SIMPLEX,0.5,Scalar(255,100,0),2,2); // 显示字符circle(Img,Point(xp,yp),2,Scalar(0,0,255),1,8,0); // 画圈imshow("1",Img);imwrite(cpath,Img);waitKey(3);Img.release();}f.close();return 0;}


0 0
原创粉丝点击