在opencv中旋转箭头

时间:2012-11-04 17:46:26

标签: c++ opencv polyline

我写了这段代码来在opencv MAT图像上绘制块箭头,但是我的问题是,是否有更简单的方法来旋转图像? 是否有必要对其进行详细编码,或者在opencv中是否有旋转转置或翻转方法?

void Arrow( Mat img, int i ) 
    {  
  int lineType = 8;
  Point arrow_points[1][7];
if (i == 1) { //left  
  arrow_points[0][0] = Point( 90*mp, 60*mp );
  arrow_points[0][1] = Point( 90*mp, 40*mp );
  arrow_points[0][2] = Point( 50*mp, 40*mp );
  arrow_points[0][3] = Point( 50*mp, 30*mp );
  arrow_points[0][4] = Point( 10*mp, 50*mp );
  arrow_points[0][5] = Point( 50*mp, 70*mp );
  arrow_points[0][6] = Point( 50*mp, 60*mp );
};
if (i == 2) { //right 
  arrow_points[0][0] = Point( 20*mp, 60*mp );
  arrow_points[0][1] = Point( 20*mp, 40*mp );
  arrow_points[0][2] = Point( 60*mp, 40*mp );
  arrow_points[0][3] = Point( 60*mp, 30*mp );
  arrow_points[0][4] = Point( 100*mp, 50*mp );
  arrow_points[0][5] = Point( 60*mp, 70*mp );
  arrow_points[0][6] = Point( 60*mp, 60*mp );
};
if (i == 3) { //down
  arrow_points[0][0] = Point( 60*mp, 20*mp );
  arrow_points[0][1] = Point( 40*mp, 20*mp );
  arrow_points[0][2] = Point( 40*mp, 60*mp );
  arrow_points[0][3] = Point( 30*mp, 60*mp );
  arrow_points[0][4] = Point( 50*mp, 100*mp );
  arrow_points[0][5] = Point( 70*mp, 60*mp );
  arrow_points[0][6] = Point( 60*mp, 60*mp );
};
  const Point* ppt[1] = { arrow_points[0] };
  int npt[] = { 7 };
  fillPoly( img,
        ppt,
        npt,
           1,
      Scalar( 250, 0, 0 ),
    lineType );
}

1 个答案:

答案 0 :(得分:0)

旋转是一种仿射变换。查看仿射变换的文档:

http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.html