#include
#include
int main(int argc,char* argv[])
{
/* 创建一个空图 */
CvSize size = cvSize(400, 400);
IplImage * testImage = cvCreateImage(size, IPL_DEPTH_8U, 3);
for(int y = 0; y < testImage->height; y++){
unsigned char * Pout = (unsigned char *)(testImage->imageData + y * testImage->widthStep);
for(int x = 0; x < testImage->width; x++){
Pout[3 * x + 0] = 200;
Pout[3 * x + 1] = 200;
Pout[3 * x + 2] = 200;
}
}
/* 创建画图的相关参数 */
CvPoint** point1 = new CvPoint* [2];
point1[0] = new CvPoint[3];
point1[1] = new CvPoint[4];
point1[0][0] = cvPoint(200, 40); /* 三角形的点的相关信息 */
point1[0][1] = cvPoint(150, 80);
point1[0][2] = cvPoint(250, 80);
point1[1][0] = cvPoint(150, 100); /* 正方形的相关信息 */
point1[1][1] = cvPoint(250, 100);
point1[1][2] = cvPoint(250, 200);
point1[1][3] = cvPoint(150, 200);
int npts[2] = {3, 4};/* 三角形有三个有效点正方形有四个有效点 */
CvScalar color = cvScalar(200, 100, 250);/* 颜色参数 */
cvFillPoly(testImage, point1, npts, 2, color);
CvPoint** point2 = new CvPoint* [2];
point2[0] = new CvPoint[3];
point2[1] = new CvPoint[4];
point2[0][0] = cvPoint(100, 40);
point2[0][1] = cvPoint(50, 80);
point2[0][2] = cvPoint(150, 80);
point2[1][0] = cvPoint(50, 100);
point2[1][1] = cvPoint(150, 100);
point2[1][2] = cvPoint(150, 200); /* 参数的相关含义如上 */
point2[1][3] = cvPoint(50, 200);
cvPolyLine(testImage, point2, npts, 2, 1, color);/* PolyLine 函数的使用*/
cvNamedWindow("show");
cvShowImage("show", testImage);
cvWaitKey(0);
cvReleaseImage(&testImage);/* 释放相关资源 */
cvDestroyAllWindows();
return 0;
}