乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      CvBox2D

       昵稱6290398 2011-10-20

      CvBox2D

      之前用到opencv最小外接矩形去表示一個(gè)類橢圓形的高度,特此記錄備查。

      對(duì)給定的 2D 點(diǎn)集,尋找最小面積的包圍矩形,使用函數(shù):

      CvBox2D  cvMinAreaRect2( const CvArr* points, CvMemStorage* storage=NULL ); 

         points
         點(diǎn)序列或點(diǎn)集數(shù)組
         storage
         可選的臨時(shí)存儲(chǔ)倉
        函數(shù) cvMinAreaRect2 通過建立凸外形并且旋轉(zhuǎn)外形以尋找給定 2D 點(diǎn)集的最小面積的包圍矩形。

      其中返回的2D盒子定義如下:

      typedef struct CvBox2D 
      { 
          CvPoint2D32f center; /* 盒子的中心 */ 
          CvSize2D32f size; /* 盒子的長和寬 */ 
          float angle; /* 水平軸與第一個(gè)邊的夾角,用弧度表示*/ 
      }CvBox2D; 
      注意夾角 angle 是水平軸逆時(shí)針旋轉(zhuǎn),與碰到的第一個(gè)邊(不管是高還是寬)的夾角。如下圖 

                                        2010-11-25 9-05-42

        可用函數(shù) cvBoxPoints(box[count], point); 尋找盒子的頂點(diǎn)

      1  void cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] ) 
      2  { 
      3      double angle = box.angle*CV_PI/180. 
      4      float a = (float)cos(angle)*0.5f; 
      5      float b = (float)sin(angle)*0.5f; 
      6  
      7      pt[0].x = box.center.x - a*box.size.height - b*box.size.width; 
      8      pt[0].y = box.center.y + b*box.size.height - a*box.size.width; 
      9      pt[1].x = box.center.x + a*box.size.height - b*box.size.width; 
      10     pt[1].y = box.center.y - b*box.size.height - a*box.size.width; 
      11     pt[2].x = 2*box.center.x - pt[0].x; 
      12     pt[2].y = 2*box.center.y - pt[0].y; 
      13     pt[3].x = 2*box.center.x - pt[1].x; 
      14     pt[3].y = 2*box.center.y - pt[1].y; 
      15 } 
      簡單證明此函數(shù)的計(jì)算公式:
       
         計(jì)算x,由圖可得到三個(gè)方程式: pt[1].x - pt[0].x = width*sin(angle) 
                                   pt[2].x - pt[1].x = height*cos(angle) 
                                   pt[2].x - pt[0].x = 2(box.center.x - pt[0].x)
         聯(lián)立方程可解得函數(shù)里的計(jì)算式,算 y 略。

      寫了個(gè)函數(shù)繪制CvBox2D

      1  void DrawBox(CvBox2D box,IplImage* img) 
      2  { 
      3      CvPoint2D32f point[4]; 
      4      int i; 
      5      for ( i=0; i<4; i++) 
      6      { 
      7          point[i].x = 0; 
      8          point[i].y = 0; 
      9      } 
      10     cvBoxPoints(box, point); //計(jì)算二維盒子頂點(diǎn) 
      11     CvPoint pt[4]; 
      12     for ( i=0; i<4; i++) 
      13     { 
      14         pt[i].x = (int)point[i].x; 
      15         pt[i].y = (int)point[i].y; 
      16     } 
      17     cvLine( img, pt[0], pt[1],CV_RGB(255,0,0), 2, 8, 0 ); 
      18     cvLine( img, pt[1], pt[2],CV_RGB(255,0,0), 2, 8, 0 ); 
      19     cvLine( img, pt[2], pt[3],CV_RGB(255,0,0), 2, 8, 0 ); 
      20     cvLine( img, pt[3], pt[0],CV_RGB(255,0,0), 2, 8, 0 ); 
      21 } 

       

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多