绘制矩形框 OpenCV

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);

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值