关于python 和C++使用cv画矩形并填充颜色同时填充文字

16 篇文章 0 订阅
14 篇文章 1 订阅

python:

font = cv2.FONT_HERSHEY_SIMPLEX  # 使用默认字体
 cv2.rectangle(im, (10, 10), (110, 110), (0, 0, 255), thickness=2)
                    # cv2.floodFill()
                    cv2.rectangle(im, (113), int(110)), (int(300), int(135),
                                  (255, 0, 0), thickness=-1)
                    cv2.putText(im, class_name + ' ' + str(score), (int(113, int(126)), font, 0.6,
                                (255, 255, 255), 1)


c++:

//显示通用通用模板
int fontface = cv::FONT_HERSHEY_SIMPLEX;
double scale = 0.5;
int thickness = 1.5;
  int baseline = 0;
char buff[50]="hello";
cv::Size text = cv::getTextSize(buff, fontface, scale, thickness,
&baseline);
Mat dd=Mat(pair_p, false);
cv::rectangle(dd, cv::Point(0, 0),
cv::Point(text.width, (text.height + baseline)*3),
CV_RGB(255, 255, 255), CV_FILLED);


  cv::putText(dd, buff, cv::Point(0, text.height + baseline / 2.),
fontface, scale, CV_RGB(0, 0, 0), thickness, 8);
cv::imshow("detections", dd);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值