资源描述:
《opencv学习笔记(六):使用opencv画线、矩形、椭圆、多边形线、多边形体等》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、在MFC中我们经常会画线、矩形、椭圆、多边形等几何结构,opencv为我们提供了已经封装好的函数来实现该功能,而且简单方便。下面提供一下例子,是Opencv安装以后自带的小程序,学习完现在的程序你可以学会以下知识:(1)生成随机数,使用RNG类(2)画线(3)画矩形(4)画椭圆(5)画圆(6)输出文字、文本(7)如果不熟悉Opencv的还能学会point结构体的使用,Scalar结构使用。具体可以看下面的小例子。在vs2010下运行一下就会明白了!#include"stdafx.h"#include"opencv2/core/core.hpp"#include"opencv2/highgui/
2、highgui.hpp"#includeusingnamespacecv;voidhelp(){ printf("ThisprogramdemonstratesOpenCVdrawingandtextoutputfunctions." "Usage:" " ./drawing");}staticScalarrandomColor(RNG&rng){ inticolor=(unsigned)rng; returnScalar(icolor&255,(icolor>>8)&255,(icolor>>16)&255);}intmain(){ help(); ch
3、arwndname[]="DrawingDemo"; constintNUMBER=100; constintDELAY=5; intlineType=CV_AA;//changeitto8toseenon-antialiasedgraphics inti,width=1000,height=700; intx1=-width/2,x2=width*3/2,y1=-height/2,y2=height*3/2; RNGrng(0xFFFFFFFF); Matimage=Mat::zeros(height,width,CV_8UC3); imshow(wndname,image); waitKe
4、y(DELAY);otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationof
5、StateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand for(i=0;i6、line(image,pt1,pt2,randomColor(rng),rng.uniform(1,10),lineType); imshow(wndname,image); if(waitKey(DELAY)>=0) return0; } for(i=0;i7、,10); rectangle(image,pt1,pt2,randomColor(rng),MAX(thickness,-1),lineType); imshow(wndname,image); if(waitKey(DELAY)>=0) return0; } for(i=0;i