代码如下:
#define POLYGON_AMOUNT 2 void test() { //同时绘制两个多边形,一个是三角形,一个是正方形。 CvPoint** points = new CvPoint* [POLYGON_AMOUNT]; //两个多边形,各有几个点 int npts[POLYGON_AMOUNT] = {0}; /* 三角形的点的相关信息 */ npts[0] = 3; points[0] = new CvPoint[3]; points[0][0] = cvPoint(200, 40); points[0][1] = cvPoint(150, 80); points[0][2] = cvPoint(250, 80); /* 正方形的相关信息 */ npts[1] = 4; points[1] = new CvPoint[4]; points[1][0] = cvPoint(150, 100); points[1][1] = cvPoint(250, 100); points[1][2] = cvPoint(250, 200); points[1][3] = cvPoint(150, 200); CvScalar polycolor; polycolor.val[0] = 0; polycolor.val[1] = 0; polycolor.val[2] = 0xFF; polycolor.val[3] = 0; //IplImage * pImage=cvCreateImage(size, pIplImage->depth, pIplImage->nChannels); //填充多边形。 cvFillPoly(pImage, points, npts, POLYGON_AMOUNT, polycolor); //绘制多边形。可以用不同颜色来突出显示。 cvPolyLine(pImage, points, npts, POLYGON_AMOUNT, 1, polycolor, 2); }