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)
上一篇 2022年7月24日 下午8:16
下一篇 2022年7月24日 下午8:36


相关推荐

  • linux:ubantu中pycharm专业版安装

    linux:ubantu中pycharm专业版安装1 下载 linux 版本安装包 2 解压压缩包查找到文件名以后复制 输入进下面的命令 进入 PyCharm 文件的 bin 目录 cd bin 最后 通过运行下面的命令来运行 PyCharm 安装程序 shpycharm sh amp 或者 sh pycharm sh 有这个界面即是解压成功的 pycharm 可用 软件的运行文件为 sh 激活程序激活成功教程 下

    2026年3月27日
    2
  • mysql批量写入数据_mysql查询效率

    mysql批量写入数据_mysql查询效率文章目录一、前言二、批量插入前准备1、插入到数据表的字段2、计算一行字段占用的空间3、在数据里做插入操作的时候,整体时间的分配三、批量插入数据测试1、SQL语句的大小限制2、查看服务器上的参数:3、计算一次能插入的最大行记录4、测试插入数据比对(1)插入11W条数据,按照每次10,600,1000,20000,80000来测试:(2)加大数据量到24w(3)加大测试量到42W5、如果插入的值就是s…

    2026年4月17日
    3
  • docker(11)Dockerfile 中的COPY与ADD 命令[通俗易懂]

    docker(11)Dockerfile 中的COPY与ADD 命令[通俗易懂]前言Dockerfile中提供了两个非常相似的命令COPY和ADD,本文尝试解释这两个命令的基本功能,以及其异同点,然后总结其各自适合的应用场景。Build上下文的概念在使用dock

    2022年7月31日
    11
  • 内置函数和匿名函数

    内置函数什么是内置函数在聊内置函数之前,我们先来回顾一下普通函数的基础知识。问:函数怎么调用?答:函数名()现在我们在自己的程序里打印一下自己的名字,该怎么打的呀?print('x

    2022年3月29日
    48
  • jQuery中delegate和on的用法与区别详细解析

    jQuery中delegate和on的用法与区别详细解析在 jQuery1 7 中 delegate 已被 on 取代 对于早期版本 它仍然使用事件委托的最有效手段 在事件绑定和委派 delegate 和 on 在一般情况下 这两种方法是等效的 delegate 指定的元素 属于被选元素的子元素 添加一个或多个事件处理程序 并规定当这些事件发生时运行的函数 复制代码代码如下 jQuery1 4 3 elements delegate selector events data handler jQuer

    2026年3月26日
    2
  • 软引用 SoftReference

    软引用 SoftReferenceimportjava lang ref SoftReferenc 软引用 demo 和使用 redis 缓存类似 先查内存中是否缓存 有则直接内存获取 反之则重新创建 再装载入内存中缓存起来 在一些开源框架中经常使用 author tiger create 2021 09 1220 34 publicclassS publicstatic String args Tigerti

    2025年6月6日
    10

发表回复

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

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