opencvc函数(三)

自定义的绘制图形函数

1、【DrawEllipse( )函数】

  自定义的绘制函数,实现了绘制不同角度、相同尺寸的椭圆

[html]  view plain  copy
  1. <span style="font-size:18px;">  声明:</span>  
[html]  view plain  copy
  1. <span style="font-size:18px;">void DrawEllipse( Mat img, double angle );//绘制椭圆</span>  
  定义:
[html]  view plain  copy
  1. <span style="font-size:18px;">void DrawEllipse( Mat img, double angle )  
  2. {  
  3.     int thickness = 2;  
  4.     int lineType = 8;  
  5.   
  6.     ellipse( img,  
  7.         Point( WINDOW_WIDTH/2, WINDOW_WIDTH/2 ),  
  8.         Size( WINDOW_WIDTH/4, WINDOW_WIDTH/16 ),  
  9.         angle,  
  10.         0,  
  11.         360,  
  12.         Scalar( 255, 129, 0 ),  
  13.         thickness,  
  14.         lineType );  
  15. }</span>  
[html]  view plain  copy
  1. <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,  
  2.                         double angle, double startAngle, double endAngle,  
  3.                         const Scalar& color, int thickness = 1,  
  4.                         int lineType = LINE_8, int shift = 0);</span></pre><br>  
  5. <p></p>  
  6. <pre></pre>  
  7. <h2><a name="t2"></a>2、【DrawFilledCircle( )函数】</h2>  
  8. <p></p>  
  9. <p>  <span style="font-size:18px">自定义的绘制函数,实现了<span style="color:#ff0000">实心圆</span>的绘制。<br>  
  10. </span></p>  
  11. <p><span style="font-size:18px">  声明:</span><br>  
  12. <span style="font-size:18px">void DrawFilledCircle( Mat img, Point center );//绘制圆</span><br>  
  13. </p>  
  14. <p> <span style="font-size:18px"> 定义:</span></p>  
  15. <p></p><pre name="code" class="html"><span style="font-size:18px;">void DrawFilledCircle( Mat img, Point center )  
  16. {  
  17.     int thickness = -1;  
  18.     int lineType = 8;  
  19.   
  20.     circle( img,  
  21.         center,  
  22.         WINDOW_WIDTH/32,  
  23.         Scalar( 0, 0, 255 ),  
  24.         thickness,  
  25.         lineType );  
  26. }</span></pre><pre name="code" class="html"><span style="font-size:18px;">CV_EXPORTS void circle(InputOutputArray img, Point center, int radius,  
  27.                        const Scalar& color, int thickness = 1,  
  28.                        int lineType = LINE_8, int shift = 0);  
  29. </span></pre><p></p>  
  30. <h2><a name="t3"></a>3、【DrawPolygon( )函数】</h2>  
  31. <p> <span style="font-size:18px"> 自定义的绘制函数,实现了<span style="color:#ff0000">凹多边形</span>的绘制。<br>  
  32. </span></p>  
  33. <p><span style="font-size:18px">  声明:</span></p>  
  34. <p><span style="font-size:18px">void DrawPolygon( Mat img );//绘制多边形</span></p>  
  35. <p><span style="font-size:18px">  定义 :</span></p>  
  36. <p></p><pre name="code" class="html"><span style="font-size:18px;">void DrawPolygon( Mat img )  
  37. {  
  38.     int lineType = 8;  
  39.   
  40.     //创建一些点  
  41.     Point rookPoints[1][20];  
  42.     rookPoints[0][0]  = Point(    WINDOW_WIDTH/4,   7*WINDOW_WIDTH/8 );  
  43.     rookPoints[0][1]  = Point(  3*WINDOW_WIDTH/4,   7*WINDOW_WIDTH/8 );  
  44.     rookPoints[0][2]  = Point(  3*WINDOW_WIDTH/4,  13*WINDOW_WIDTH/16 );  
  45.     rookPoints[0][3]  = Point( 11*WINDOW_WIDTH/16, 13*WINDOW_WIDTH/16 );  
  46.     rookPoints[0][4]  = Point( 19*WINDOW_WIDTH/32,  3*WINDOW_WIDTH/8 );  
  47.     rookPoints[0][5]  = Point(  3*WINDOW_WIDTH/4,   3*WINDOW_WIDTH/8 );  
  48.     rookPoints[0][6]  = Point(  3*WINDOW_WIDTH/4,     WINDOW_WIDTH/8 );  
  49.     rookPoints[0][7]  = Point( 26*WINDOW_WIDTH/40,    WINDOW_WIDTH/8 );  
  50.     rookPoints[0][8]  = Point( 26*WINDOW_WIDTH/40,    WINDOW_WIDTH/4 );  
  51.     rookPoints[0][9]  = Point( 22*WINDOW_WIDTH/40,    WINDOW_WIDTH/4 );  
  52.     rookPoints[0][10] = Point( 22*WINDOW_WIDTH/40,    WINDOW_WIDTH/8 );  
  53.     rookPoints[0][11] = Point( 18*WINDOW_WIDTH/40,    WINDOW_WIDTH/8 );  
  54.     rookPoints[0][12] = Point( 18*WINDOW_WIDTH/40,    WINDOW_WIDTH/4 );  
  55.     rookPoints[0][13] = Point( 14*WINDOW_WIDTH/40,    WINDOW_WIDTH/4 );  
  56.     rookPoints[0][14] = Point( 14*WINDOW_WIDTH/40,    WINDOW_WIDTH/8 );  
  57.     rookPoints[0][15] = Point(    WINDOW_WIDTH/4,     WINDOW_WIDTH/8 );  
  58.     rookPoints[0][16] = Point(    WINDOW_WIDTH/4,   3*WINDOW_WIDTH/8 );  
  59.     rookPoints[0][17] = Point( 13*WINDOW_WIDTH/32,  3*WINDOW_WIDTH/8 );  
  60.     rookPoints[0][18] = Point(  5*WINDOW_WIDTH/16, 13*WINDOW_WIDTH/16 );  
  61.     rookPoints[0][19] = Point(    WINDOW_WIDTH/4,  13*WINDOW_WIDTH/16 );  
  62.   
  63.     const Point* ppt[1] = { rookPoints[0] };  
  64.     int npt[] = { 20 };  
  65.   
  66.     fillPoly( img,  
  67.         ppt,  
  68.         npt,  
  69.         1,  
  70.         Scalar( 255, 255, 255 ),  
  71.         lineType );  
  72. }</span></pre><pre name="code" class="html"><span style="font-size:18px;">CV_EXPORTS void fillPoly(Mat& img, const Point** pts,  
  73.                          const int* npts, int ncontours,  
  74.                          const Scalar& color, int lineType = LINE_8, int shift = 0,  
  75.                          Point offset = Point() );  
  76. </span></pre><span style="font-size:18px"><br>  
  77. </span><p></p>  
  78. <h2><a name="t4"></a><span style="font-size:18px">4、【DrawLine( )函数】</span></h2>  
  79. <p></p>  
  80. <p><span style="font-size:18px">  自定义的绘制函数,实现了<span style="color:#ff0000">线</span>的绘制。<br>  
  81. </span></p>  
  82. <p><span style="font-size:18px">  声明:</span></p>  
  83. <p><span style="font-size:18px">void DrawLine( Mat img, Point start, Point end );//绘制线段<br>  
  84. </span></p>  
  85. <p><span style="font-size:18px">  定义:</span></p>  
  86. <p></p><pre name="code" class="html"><span style="font-size:18px;">void DrawLine( Mat img, Point start, Point end )  
  87. {  
  88.     int thickness = 2;  
  89.     int lineType = 8;  
  90.     line( img,  
  91.         start,  
  92.         end,  
  93.         Scalar( 0, 0, 0 ),  
  94.         thickness,  
  95.         lineType );  
  96. }</span></pre><pre name="code" class="html"><span style="font-size:18px;">void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,  
  97.                      int thickness = 1, int lineType = LINE_8, int shift = 0);  
  98. </span></pre><br>  
  99. <p></p>  
  100.      
0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HySmiley

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值