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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • BigDecimal除法问题

    BigDecimal除法问题BigDecimal做除法时,尽量使用divide(BigDecimaldivisor,intscale,introundingMode),这个方法divisor:被除数  scale保留小数位数  roundingMode保留小数时采用的方法,一般使用BigDecimal.ROUND_UP(四舍五入)如果不指定保留小数位数,在遇到除不尽的情况下就会报错BigDecimal源码:…

    2022年6月15日
    32
  • TCP的三次握手与四次挥手理解及面试题(很全面)

    TCP的三次握手与四次挥手理解及面试题(很全面)本文经过借鉴书籍资料、他人博客总结出的知识点,欢迎提问序列号seq:占4个字节,用来标记数据段的顺序,TCP把连接中发送的所有数据字节都编上一个序号,第一个字节的编号由本地随机产生;给字节编上序号后,就给每一个报文段指派一个序号;序列号seq就是这个报文段中的第一个字节的数据编号。确认号ack:占4个字节,期待收到对方下一个报文段的第一个数据字节的序号;序列号表示报文…

    2022年5月5日
    34
  • Navicat:Access violation at address xxxxxxxxx in module ‘navicat.exe‘.Read of address xxxxxx

    Navicat:Access violation at address xxxxxxxxx in module ‘navicat.exe‘.Read of address xxxxxxNavicat:Accessviolationataddressxxxxxxxxxinmodule’navicat.exe’.Readofaddressxxxxxx在navicat中如果报了这个错误,则表示内存越界,需要重新注册windows的动态链接库;解决方案:打开cmd;在命令行中输入for%1in(%windir%\system32\*.dll)doregsvr32.exe/s%1回车运行;等待动态链接库刷新完成,重启mysql和navi.

    2022年8月22日
    39
  • MATLAB plotyy总结「建议收藏」

    MATLAB plotyy总结「建议收藏」当需要画出2个两个不同纵坐标的图时,此时的横坐标的图是相同的,在MATLAB中这个函数叫plotyy下面列举的是一个简单的画plotyy的应用几种不同的调用格式1、plotyy(X1,Y1,X2,Y2)2、plotyy(X1,Y1,X2,Y2,function)3、plotyy(X1,Y1,X2,Y2,’function1′,’function2′)4、[AX,H1,H2]=plotyy(___)5、plotyy(AX1,___)1、plotyy(X1,Y1,X2,Y2)直接简单地画

    2022年6月16日
    28
  • Java遍历取出Map集合key-value数据的4种方法

    Java遍历取出Map集合key-value数据的4种方法将map集合存数据与取出数据全部放在一个类MapTest中,方便阅读与查看随便创建一个包,在包中新建一个class文件,(也可以不建包,直接新建一个class文件)新建class文件MapTest.java,代码如下:importjava.util.HashMap;importjava.util.Iterator;importjava.util.Map;importjava.util…

    2022年5月30日
    77
  • 转换 datetime 和 smalldatetime 数据[通俗易懂]

    转换 datetime 和 smalldatetime 数据[通俗易懂]转换datetime和smalldatetime数据转换为datetime时,Microsoft®SQLServer™2000将拒绝所有无法识别为日期的值(包括1753年1月1日以前的日期)。当日期在适当的范围内(1900年1月1日到2079年6月6日)时,可将datetime值转换为smalldatetime。时间值被四舍五入

    2022年5月19日
    42

发表回复

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

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