opencv 绘图 cvLine cvRectangle cvCircle cvEllipse cvEllipseBox cvFillPoly cvConvexPoly cvPolyLine
来源:互联网 发布:前端优化实现etag 编辑:程序博客网 时间:2024/06/05 06:28
常用宏定义:
#define CV_RGB( r, g, b ) cvScalar( (b), (g), (r), 0 )#define CV_FILLED -1#define CV_AA 16
#define cvDrawRect cvRectangle#define cvDrawLine cvLine#define cvDrawCircle cvCircle#define cvDrawEllipse cvEllipse#define cvDrawPolyLine cvPolyLine
########################################################3
直线 cvLine()
/* Draws 4-connected, 8-connected or antialiased line segment connecting two points */CVAPI(void) cvLine( CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness CV_DEFAULT(1), int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) );
array:输入图像
pt1、pt2:直线的两点 CvPoint()结构
typedef struct CvPoint{ int x; int y;}CvPoint;
color:边的颜色 CvScalar结构
typedef struct CvScalar{ double val[4];}CvScalar;这种结构是四个双精度浮点型变量的集合,前三个分别代表红、绿、蓝通道
常用的便捷宏指令CV_RGB(r, g, b)
###############################################################
矩形 cvRectagle()
/* Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2), if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn */CVAPI(void) cvRectangle( CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness CV_DEFAULT(1), int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));
pt1和pt2为对顶角
thickness参数可设置为CV_FILL,其值是-1,表示使用color填充内部 在圆形和矩阵等很多封闭图形函数都可用
################################################################
圆形 cvCircle()
/* Draws a circle with specified center and radius. Thickness works in the same way as with cvRectangle */CVAPI(void) cvCircle( CvArr* img, CvPoint center, int radius, CvScalar color, int thickness CV_DEFAULT(1), int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));
center:圆中心 CvPoint()结构
radius:圆半径
##############################################################
椭圆 cvEllipse() cvEllipseBox
/* Draws ellipse outline, filled ellipse, elliptic arc or filled elliptic sector, depending on <thickness>, <start_angle> and <end_angle> parameters. The resultant figure is rotated by <angle>. All the angles are in degrees */CVAPI(void) cvEllipse( CvArr* img, CvPoint center, CvSize axes, double angle, double start_angle, double end_angle, CvScalar color, int thickness CV_DEFAULT(1), int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));
axes:CvSize()结构,height和width参数分别表示椭圆的长短半轴长
typedef struct CvSize{ int width; int height;}CvSize;
angle:指偏离主轴的角度,从X轴算起,逆时针为正
start_angle和end_angle表示弧线可是和结束位置的角度。因此,一个完整的椭圆必须分别将这两个值分别设为0度和360度
CV_INLINE void cvEllipseBox( CvArr* img, CvBox2D box, CvScalar color, int thickness CV_DEFAULT(1), int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) ){ CvSize axes; axes.width = cvRound(box.size.width*0.5); axes.height = cvRound(box.size.height*0.5); cvEllipse( img, cvPointFrom32f( box.center ), axes, box.angle, 0, 360, color, thickness, line_type, shift );}
box:CvBox2D结构
typedef struct CvBox2D{ CvPoint2D32f center; /* Center of the box. */ CvSize2D32f size; /* Box width and length. */ float angle; /* Angle between the horizontal axis */ /* and the first side (i.e. length) in degrees */}CvBox2D;
####################################################################
void paint(void){IplImage *src=cvLoadImage("lena.jpg");if (src == NULL){exit(0);}cvLine(src, cvPoint(3, 3), cvPoint(3, 300), CV_RGB(255, 255, 255), 1, 8);cvRectangle(src, cvPoint(10, 10), cvPoint(100, 100), CV_RGB(255, 255, 255), 1);cvCircle(src, cvPoint(350, 350), 50, CV_RGB(255, 255, 255), 1);cvEllipse(src, cvPoint(200, 200), cvSize(100, 50), 90, 0, 360, CV_RGB(255, 255, 255), 1, 8);CvSize2D32f size=cvSize2D32f(100, 50);CvBox2D box;box.center.x = 100;box.center.y = 300;box.size = size;box.angle = 90;cvEllipseBox(src, box, CV_RGB(255, 255, 255), 1, 8, 0);cvNamedWindow("src");cvShowImage("src", src);cvWaitKey(0);cvReleaseImage(&src);cvDestroyWindow("src");}
######################################################################################
/* Fills convex or monotonous polygon. */CVAPI(void) cvFillConvexPoly( CvArr* img, const CvPoint* pts, int npts, CvScalar color, int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));
cvFillConvexPoly()一次只能画一个多边形,而且只能画凸多边形
pts:存储点的数组
npts:存储点的数目
void convexPoly(void){IplImage *Image1;CvPoint PointArray1[6];int PolyVertexNumber;int Shift; CvSize ImageSize1 = cvSize(1000,700); Image1 = cvCreateImage(ImageSize1, IPL_DEPTH_8U, 3); PointArray1[0]=cvPoint(200,200); PointArray1[1]=cvPoint(400,100); PointArray1[2]=cvPoint(650,230); PointArray1[3]=cvPoint(800,300); PointArray1[4]=cvPoint(900,550); PointArray1[5]=cvPoint(100,400); CvScalar Color=CV_RGB(255,255,255); PolyVertexNumber=6; Shift=0; cvFillConvexPoly(Image1,PointArray1,PolyVertexNumber,Color,CV_AA,Shift); cvNamedWindow("FillConvexPoly",0); cvShowImage("FillConvexPoly",Image1); cvWaitKey(0); cvSaveImage("poly.jpg",Image1); cvReleaseImage(&Image1);}
#######################################################
/* Fills an area bounded by one or more arbitrary polygons */CVAPI(void) cvFillPoly( CvArr* img, CvPoint** pts, const int* npts, int contours, CvScalar color, int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) );/* Draws one or more polygonal curves */CVAPI(void) cvPolyLine( CvArr* img, CvPoint** pts, const int* npts, int contours, int is_closed, CvScalar color, int thickness CV_DEFAULT(1), int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) );
npts:由记数点构成的数组,与多边形对应
is_closed为true:则起点和终点连线;否则,不连线
void fillPoly(void){IplImage *src=cvLoadImage("lena.jpg");if (src == NULL)exit(0);CvPoint** pt=new CvPoint*[1];pt[0]=new CvPoint[6];pt[0][0]=cvPoint(100, 100);pt[0][1]=cvPoint(400, 50);pt[0][2]=cvPoint(500, 400);pt[0][3]=cvPoint(300, 500);pt[0][4]=cvPoint(200, 300);pt[0][5]=cvPoint(50, 400);int *npt=new int[1];npt[0]=6;int contours=1;cvFillPoly(src, pt, npt, contours, CV_RGB(255, 255, 255), 8);//cvPolyLine(src, pt, npt, contours, 1, CV_RGB(255, 255, 255));//is_closed为true则将起点和终点连线//cvPolyLine(src, pt, npt, contours, 0, CV_RGB(255, 255, 255));//is_closed为false则不将起点和终点连线cvNamedWindow("src");cvShowImage("src", src);cvWaitKey(0);cvReleaseImage(&src);cvDestroyWindow("src");}
0 0
- opencv 绘图 cvLine cvRectangle cvCircle cvEllipse cvEllipseBox cvFillPoly cvConvexPoly cvPolyLine
- OpenCV繪圖的實作-cvCircle,cvEllipse,cvEllipseBox
- OpenCV绘图之多边形函数cvFillPoly,cvPolyLine,cvFillConvexPoly
- OpenCV学习笔记之十 (cvFillPoly&cvPolyLine)
- cvFillConvexPoly cvFillPoly cvPolyLine
- cvCircle and cvRectangle
- openCV基本绘图函数----画椭圆函数cvEllipse
- cvPolyLine与cvFillPoly的用法
- cvPolyLine与cvFillPoly的用法
- cvPolyLine与cvFillPoly的用法
- cvPolyLine与cvFillPoly的用法
- cvPolyLine与cvFillPoly的用法
- Opencv画图函数整理 及 cvCircle cvLine 只能画出黑白两种颜色问题 解决
- openCV基本绘图函数----画直线函数cvLine
- openCV基本绘图函数----画圆函数cvCircle
- Opencv cvCircle函数
- Opencv cvCircle函数
- opencv中的cvCircle函数
- sizeof用法汇总
- cookie 编程
- java 使用 fastjson 处理 json
- searchbar下的搜索图标及textfiled样式修改
- 《博弈论基础》mooc学习感想
- opencv 绘图 cvLine cvRectangle cvCircle cvEllipse cvEllipseBox cvFillPoly cvConvexPoly cvPolyLine
- CSS 小技巧1——水平居中和垂直居中的方法
- auto_ptr源码
- 如何给linux添加新硬盘
- 杭电ACM1222——Wolf and Rabbit~~最大公约数
- [Selenium 2]—WebDriver 驱动说明
- 20世纪《福布斯》二十本最具影响力的商业书籍
- svn cleanup failed–previous operation has not finished; run cleanup if it was interrupted
- Unity3D NGUI图集切成图片