自定义的绘制图形函数
1、【DrawEllipse( )函数】
自定义的绘制函数,实现了绘制不同角度、相同尺寸的椭圆。
- <span style="font-size:18px;"> 声明:</span>
- <span style="font-size:18px;">void DrawEllipse( Mat img, double angle );//绘制椭圆</span>
- <span style="font-size:18px;">void DrawEllipse( Mat img, double angle )
- {
- int thickness = 2;
- int lineType = 8;
- ellipse( img,
- Point( WINDOW_WIDTH/2, WINDOW_WIDTH/2 ),
- Size( WINDOW_WIDTH/4, WINDOW_WIDTH/16 ),
- angle,
- 0,
- 360,
- Scalar( 255, 129, 0 ),
- thickness,
- lineType );
- }</span>
- <span style="font-size:18px;"></span><pre name="code" class="html"><span style="font-size:18px;">CV_EXPORTS void ellipse(InputOutputArray img, Point center, Size axes,
- double angle, double startAngle, double endAngle,
- const Scalar& color, int thickness = 1,
- int lineType = LINE_8, int shift = 0);</span></pre><br>
- <p></p>
- <pre></pre>
- <h2><a name="t2"></a>2、【DrawFilledCircle( )函数】</h2>
- <p></p>
- <p> <span style="font-size:18px">自定义的绘制函数,实现了<span style="color:#ff0000">实心圆</span>的绘制。<br>
- </span></p>
- <p><span style="font-size:18px"> 声明:</span><br>
- <span style="font-size:18px">void DrawFilledCircle( Mat img, Point center );//绘制圆</span><br>
- </p>
- <p> <span style="font-size:18px"> 定义:</span></p>
- <p></p><pre name="code" class="html"><span style="font-size:18px;">void DrawFilledCircle( Mat img, Point center )
- {
- int thickness = -1;
- int lineType = 8;
- circle( img,
- center,
- WINDOW_WIDTH/32,
- Scalar( 0, 0, 255 ),
- thickness,
- lineType );
- }</span></pre><pre name="code" class="html"><span style="font-size:18px;">CV_EXPORTS void circle(InputOutputArray img, Point center, int radius,
- const Scalar& color, int thickness = 1,
- int lineType = LINE_8, int shift = 0);
- </span></pre><p></p>
- <h2><a name="t3"></a>3、【DrawPolygon( )函数】</h2>
- <p> <span style="font-size:18px"> 自定义的绘制函数,实现了<span style="color:#ff0000">凹多边形</span>的绘制。<br>
- </span></p>
- <p><span style="font-size:18px"> 声明:</span></p>
- <p><span style="font-size:18px">void DrawPolygon( Mat img );//绘制多边形</span></p>
- <p><span style="font-size:18px"> 定义 :</span></p>
- <p></p><pre name="code" class="html"><span style="font-size:18px;">void DrawPolygon( Mat img )
- {
- int lineType = 8;
- //创建一些点
- Point rookPoints[1][20];
- rookPoints[0][0] = Point( WINDOW_WIDTH/4, 7*WINDOW_WIDTH/8 );
- rookPoints[0][1] = Point( 3*WINDOW_WIDTH/4, 7*WINDOW_WIDTH/8 );
- rookPoints[0][2] = Point( 3*WINDOW_WIDTH/4, 13*WINDOW_WIDTH/16 );
- rookPoints[0][3] = Point( 11*WINDOW_WIDTH/16, 13*WINDOW_WIDTH/16 );
- rookPoints[0][4] = Point( 19*WINDOW_WIDTH/32, 3*WINDOW_WIDTH/8 );
- rookPoints[0][5] = Point( 3*WINDOW_WIDTH/4, 3*WINDOW_WIDTH/8 );
- rookPoints[0][6] = Point( 3*WINDOW_WIDTH/4, WINDOW_WIDTH/8 );
- rookPoints[0][7] = Point( 26*WINDOW_WIDTH/40, WINDOW_WIDTH/8 );
- rookPoints[0][8] = Point( 26*WINDOW_WIDTH/40, WINDOW_WIDTH/4 );
- rookPoints[0][9] = Point( 22*WINDOW_WIDTH/40, WINDOW_WIDTH/4 );
- rookPoints[0][10] = Point( 22*WINDOW_WIDTH/40, WINDOW_WIDTH/8 );
- rookPoints[0][11] = Point( 18*WINDOW_WIDTH/40, WINDOW_WIDTH/8 );
- rookPoints[0][12] = Point( 18*WINDOW_WIDTH/40, WINDOW_WIDTH/4 );
- rookPoints[0][13] = Point( 14*WINDOW_WIDTH/40, WINDOW_WIDTH/4 );
- rookPoints[0][14] = Point( 14*WINDOW_WIDTH/40, WINDOW_WIDTH/8 );
- rookPoints[0][15] = Point( WINDOW_WIDTH/4, WINDOW_WIDTH/8 );
- rookPoints[0][16] = Point( WINDOW_WIDTH/4, 3*WINDOW_WIDTH/8 );
- rookPoints[0][17] = Point( 13*WINDOW_WIDTH/32, 3*WINDOW_WIDTH/8 );
- rookPoints[0][18] = Point( 5*WINDOW_WIDTH/16, 13*WINDOW_WIDTH/16 );
- rookPoints[0][19] = Point( WINDOW_WIDTH/4, 13*WINDOW_WIDTH/16 );
- const Point* ppt[1] = { rookPoints[0] };
- int npt[] = { 20 };
- fillPoly( img,
- ppt,
- npt,
- 1,
- Scalar( 255, 255, 255 ),
- lineType );
- }</span></pre><pre name="code" class="html"><span style="font-size:18px;">CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
- const int* npts, int ncontours,
- const Scalar& color, int lineType = LINE_8, int shift = 0,
- Point offset = Point() );
- </span></pre><span style="font-size:18px"><br>
- </span><p></p>
- <h2><a name="t4"></a><span style="font-size:18px">4、【DrawLine( )函数】</span></h2>
- <p></p>
- <p><span style="font-size:18px"> 自定义的绘制函数,实现了<span style="color:#ff0000">线</span>的绘制。<br>
- </span></p>
- <p><span style="font-size:18px"> 声明:</span></p>
- <p><span style="font-size:18px">void DrawLine( Mat img, Point start, Point end );//绘制线段<br>
- </span></p>
- <p><span style="font-size:18px"> 定义:</span></p>
- <p></p><pre name="code" class="html"><span style="font-size:18px;">void DrawLine( Mat img, Point start, Point end )
- {
- int thickness = 2;
- int lineType = 8;
- line( img,
- start,
- end,
- Scalar( 0, 0, 0 ),
- thickness,
- lineType );
- }</span></pre><pre name="code" class="html"><span style="font-size:18px;">void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
- int thickness = 1, int lineType = LINE_8, int shift = 0);
- </span></pre><br>
- <p></p>
-
顶
- 0
-
踩