OpenCv画矩形有两个函数,一个是C的API,还有一个C++的API。在应用时一定要注意,不然就会出现错误。
void cvRectangle( CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int line_type=8, int shift=0 );
这个是C语言的API。
void cv::rectangle( CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int line_type=8, int shift=0 );
这个是C++语言的API。
-
img
- 图像. pt1
- 矩形的一个顶点。 pt2
- 矩形对角线上的另一个顶点 color
- 线条颜色 (RGB) 或亮度(灰度图像 )(grayscale image)。 thickness
- 组成矩形的线条的粗细程度。取负值时(如 CV_FILLED)函数绘制填充了色彩的矩形。 line_type
- 线条的类型。见cvLine的描述 shift
- 坐标点的小数点位数。
函数 cvRectangle 通过对角线上的两个顶点绘制矩形。 调用时,一般可以如下赋值,(C++版本)
Mat colorImage
cv::rectangle(colorImage,cvpoint(10,10),cvpoint(20,20),cvscalar(0,255,255),1,8,0);
将会画出一个左上坐标为(10,10),右下坐标为(20,20)的矩形。