Rectangle 画矩形
C++: Mat类
void rectangle(Mat& img,Point pt1, Point pt2, const Scalar&color,
int thickness=1,int lineType=8, int shift=0)
void rectangle(Mat& img,cvPoint(x, y), cvPoint(x + w, y + h), Scalar(255, 0, 0),
int thickness=1, int lineType=8,int shift=0)
参数:
·img – 画矩形的对象
·pt1 – 矩形的一个顶点,左上角的.
·pt2 – 另一个顶点,右下角的.
·rec – 确定矩形的另一种方式,给左上角坐标和长宽
·color – 指定矩形的颜色或亮度(灰度图像),scalar(255,0,255)既可指定.
·thickness – 矩形边框的粗细. 负值(like CV_FILLED)表示要画一个填充的矩形
·lineType – 边框线型. (
8 (or 0) - 8-connected line(8邻接)连接 线。
4 - 4-connected line(4邻接)连接线。
CV_AA - antialiased 线条。)
·shift –坐标点的小数点位数
例1:
short * p = ((short*)(pResults + 1)) + 6 * i;//表示检测到的人脸区域
int x = p[0]; //检测到的人脸区域的左上角坐标及宽高
int y = p[1];
int w = p[2];
int h = p[3];
rectangle(gray, Point(x, y), Point(x + w, y + h), Scalar(0, 0, 255), 2, 8);//利用左上角坐标及宽高
例2:
int x = cvRound(shape[0].x);
int y = cvRound(shape[17].y-10);
int w = cvRound(shape[14].x-shape[0].x);
int h = cvRound(shape[7].y - shape[17].y);
//画出红色矩形框
rectangle(pic_RGB, Point(x,y),Point(x+w,y+h), Scalar(0, 0, 255), 3, 8, 0);