Drawing opencv?
How would I draw a CvBox2D in OpenCV? Is there any similar function to cvRe开发者_Python百科ctangle?
CODE EXAMPLES WOULD BE APPRECIATED
Thanks
There isn't a function like cvRectangle for CvBox2D. This is the structure of CvBox2D:
typdef struct {
CvPoint2D32f center;
CvSize2D32f size;
float angle;
} CvBox2D;
You can use cvBoxPoints to get the points of the rectangle and then draw the rectangle as a set of lines.
void cvBoxPoints(CvBox2D box, CvPoint2D32f pt[]);
You can even use cvPolyLine to draw the lines easier.
void cvPolyLine(CvArr* img, CvPoint** pts, int* npts, int contours, int isClosed, CvScalar color, int thickness=1, int lineType=8, int shift=0 )
Function to draw rotated rect in iplimage.
void DrawRotatedRect( IplImage * iplSrc,CvBox2D rect,CvScalar color, int thickness CV_DEFAULT(1),int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));
void DrawRotatedRect( IplImage * iplSrc,CvBox2D rect,CvScalar color, int thickness, int line_type, int shift )
{
CvPoint2D32f boxPoints[4];
cvBoxPoints(rect, boxPoints);
cvLine(iplSrc,cvPoint((int)boxPoints[0].x, (int)boxPoints[0].y),cvPoint((int)boxPoints[1].x, (int)boxPoints[1].y),color,thickness,line_type,shift);
cvLine(iplSrc,cvPoint((int)boxPoints[1].x, (int)boxPoints[1].y),cvPoint((int)boxPoints[2].x, (int)boxPoints[2].y),color,thickness,line_type,shift);
cvLine(iplSrc,cvPoint((int)boxPoints[2].x, (int)boxPoints[2].y),cvPoint((int)boxPoints[3].x, (int)boxPoints[3].y),color,thickness,line_type,shift);
cvLine(iplSrc,cvPoint((int)boxPoints[3].x, (int)boxPoints[3].y),cvPoint((int)boxPoints[0].x, (int)boxPoints[0].y),color,thickness,line_type,shift);
}
精彩评论