您的位置:首页 > 编程语言 > C语言/C++

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

2017-06-16 15:24 531 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: