opencv 绘图 cvLine cvRectangle cvCircle cvEllipse cvEllipseBox cvFillPoly cvConvexPoly cvPolyLine[通俗易懂]

opencv 绘图 cvLine cvRectangle cvCircle cvEllipse cvEllipseBox cvFillPoly cvConvexPoly cvPolyLine[通俗易懂]常用宏定义:#defineCV_RGB(r,g,b)cvScalar((b),(g),(r),0)#defineCV_FILLED-1#defineCV_AA16#definecvDrawRectcvRectangle#definecvDrawLinecvLine#definecvDrawCirclecvCircle#definec

大家好,又见面了,我是你们的朋友全栈君。

常用宏定义:

#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");
}


opencv 绘图 cvLine cvRectangle cvCircle cvEllipse cvEllipseBox cvFillPoly cvConvexPoly cvPolyLine[通俗易懂]

######################################################################################

/* 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);
}


opencv 绘图 cvLine cvRectangle cvCircle cvEllipse cvEllipseBox cvFillPoly cvConvexPoly cvPolyLine[通俗易懂]

#######################################################

/* 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");
}


opencv 绘图 cvLine cvRectangle cvCircle cvEllipse cvEllipseBox cvFillPoly cvConvexPoly cvPolyLine[通俗易懂]

opencv 绘图 cvLine cvRectangle cvCircle cvEllipse cvEllipseBox cvFillPoly cvConvexPoly cvPolyLine[通俗易懂]

opencv 绘图 cvLine cvRectangle cvCircle cvEllipse cvEllipseBox cvFillPoly cvConvexPoly cvPolyLine[通俗易懂]

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/161540.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • CISCO mds FC光纤交换机配置参考资料

    CISCO mds FC光纤交换机配置参考资料(一)有几个概念必须明确一下(与brocade不同的地方):(1)brocade直接划分zone.而mds要在vsan下划分zone,mds可以先划分几个vsan,每个vsan包括几个zone.(2)brocase默认的端口是打开的,而mds默认的端口是关闭的(3)mds有一个默认的zone:”TheDefaultZo…

    2022年5月11日
  • 光棍节程序员闯关秀过关全攻略(附带小工具)[通俗易懂]

    光棍节程序员闯关秀过关全攻略(附带小工具)[通俗易懂]光棍节程序员闯关秀过关全攻略。程序员的寂寞谁能懂?"SF光棍节程序员闯关秀"智力挑战小游戏火热上线,看看你能闯到第几关?游戏地址:http://segmentfault.com

    2022年7月1日
  • 从程序员到项目经理 技术荒废了_it售前工程师

    从程序员到项目经理 技术荒废了_it售前工程师从程序员到项目经理(一):为什么要当项目经理“从程序员到项目经理”,这个标题让我想起了很久以前一本书的名字《从Javascript到Java》。然而,从Javascript到Java充其量只是工具的更新,而从程序员到项目经理,却是一个脱胎换骨的过程。从Javascript到Java,是一个取巧的方法;而从程序员到项目经理,却并无捷径可走,必须从内而外的改变和提升。一.为什么要当项目经理

    2022年9月2日
  • 【综合帖】Java并发多线程编程学习专栏

    本帖主要用于记录Java多线程或并发编程的一些学习书籍和一些优秀的博文,方便自己学习并发多线程编程的知识!也为了通过自己的学习整理出学习笔记,输出一个java并发编程的专栏。让自己的学习的知识沉淀下来!本篇记录的博文或者些图片内容都来自互联网,如果有任何侵权或者疑问,可以联系我!

    2022年2月26日
  • xshell安装步骤_oracle安装sid已在使用

    xshell安装步骤_oracle安装sid已在使用1.安装xhost[root@oracle11~]#yumwhatprovides”*/xhost”Loadedplugins:fastestmirrorLoadingmirrorspeedsfromcachedhostfile*base:mirrors.163.com*extras:mirrors.aliyun.com*updates:mirrors.aliyun.combase/7/x86_64/filelists_db

    2022年9月3日
  • Whoosh_emil是什么意思

    Whoosh_emil是什么意思先了解基本概念和步骤:QuickStart   Whoosh是一个索引文本和搜索文本的类库,他可以为你提供搜索文本的服务,比如如果你在创建一个博客的软件,你可以用whoosh为它添加添加一个搜索功能以便用户来搜索博客的入口下面是一个简短的例子:&gt;&gt;&gt;fromwhoosh.indeximportcreate_in&gt;&gt;&gt;fromwhoos…

    2022年10月22日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号