函数原型:
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) );
第一个参数:CvArr* img ::源图像,可画多边形于这个图片上;
第二个参数:CvPoint** pts:折线的顶点指针数组,也就是相应各个顶点的度度座标;
第三个参数:const int* npts:折线的顶点个数数组,也就是我现在要画两个多边形,一个是4个顶点,另一个多边形是5个顶点,那么这个数组为:int npts[2] = {4,5};
第四个参数:int contours:折线的线段数量,如第三个参数说明所示,我想画两个多边形,那这个参数就是2,如果想画4个多边形,这个参数就是4,以此类推;
第五个参数:int is_closed:标示所示多边形是否是封闭的,这个很容易理解;
第六个参数:CvScalar color:所画多边形的线段颜色或是填充颜色;
第七个参数:int line_type CV_DEFAULT:线段的粗细;
代码示例如下:
#include<cv.h>
#include<highgui.h>
using namespace std;
void main()
{
IplImage* image = cvLoadImage("C:\\Users\\lenovo\\Desktop\\11.png");
cvNamedWindow("test", CV_WINDOW_AUTOSIZE);
CvPoint cvrve1[] = { 10, 10, 10, 100, 100, 100, 100, 10 };
CvPoint cvrve2[] = { 30, 30, 30, 130, 130, 130, 130, 30 ,150,20};
CvPoint* cvrver[2] = { cvrve1, cvrve2 }; //折线的顶点指针数组,也就是相应各个顶点的度度座标;
int npts[2] = { 4, 5 }; //拆线的顶点个数数组
int contous = 2; //折线的线段数量
int iscurveclosed = 1; //标示所示多边形是否是封闭的
int thickline = 1;
cvPolyLine(image, cvrver, npts, contous, iscurveclosed, CV_RGB(255, 0, 0), thickline);
//cvFillPoly(image, cvrver, npts, contous, CV_RGB(0,255,255),thickline);
cvShowImage("test", image);
cvWaitKey(0);
cvReleaseImage(&image);
cvDestroyAllWindows();
}
函数运行结果如下:
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) );
参数与上现一个函数一样,与上一个函数的区别是,这一个函数是填充多边形的,代码示例如下:
#include<cv.h>
#include<highgui.h>
using namespace std;
void main()
{
IplImage* image = cvLoadImage("C:\\Users\\lenovo\\Desktop\\11.png");
cvNamedWindow("test", CV_WINDOW_AUTOSIZE);
CvPoint cvrve2[] = { 30, 30, 30, 130, 130, 130, 130, 30 ,150,20};
CvPoint* cvrver[1] = { cvrve2 };
int npts[1] = { 5 };
int contous = 1;
int iscurveclosed = 1;
int thickline = 1;
cvFillPoly(image, cvrver, npts, contous, CV_RGB(0,255,255),thickline);
cvShowImage("test", image);
cvWaitKey(0);
cvReleaseImage(&image);
cvDestroyAllWindows();
}
结果如下: