def draw_bbox(image, bboxes, class_i, show_label=True):
# 将中心点坐标与w,h通过变化为左上角与右下角坐标
bboxes_change = np.copy(bboxes)
bboxes[:,0:2]=bboxes_change[:,0:2]-0.5*bboxes_change[:,2:4]
bboxes[:, 0:2] = bboxes_change[:, 0:2] + 0.5 * bboxes_change[:, 2:4] """
bboxes: [x_min, y_min, x_max, y_max] format coordinates.
"""
image_h, image_w, _ = image.shape
hsv_tuples = [(1.0 * x / 90, 1., 1.) for x in range(90)]
colors = list(map(lambda x: colorsys.hsv_to_rgb(*x), hsv_tuples))
colors = list(map(lambda x: (int(x[0] * 255), int(x[1] * 255), int(x[2] * 255)), colors))
for i, bbox in enumerate(bboxes):
coor = np.array(bbox[:4], dtype=np.int32)
fontScale = 0.5
class_ind = int(class_i)
bbox_color = colors[class_ind]
bbox_thick = int(0.6 * (image_h + image_w) / 600)
# bbox_thick = int(400 / 600)
c1, c2 = (coor[0], coor[1]), (coor[2], coor[3])
cv2.rectangle(image, c1, c2, bbox_color, bbox_thick) # 已经在图片上画了矩形 if show_label:
bbox_mess = '%s: %d' % ('class = ', class_ind)
t_size = cv2.getTextSize(bbox_mess, 0, fontScale, thickness=bbox_thick//2)[0]
cv2.rectangle(image, c1, (c1[0] + t_size[0], c1[1] - t_size[1] - 3), bbox_color, -1) # filled
cv2.putText(image, bbox_mess, (c1[0], c1[1]-2), cv2.FONT_HERSHEY_SIMPLEX, fontScale, (0, 0, 0), bbox_thick//2, lineType=cv2.LINE_AA) # 添加文字
# 图片 添加的文字 左上角坐标 字体 字体大小 颜色 字体粗细
return image

最新文章

  1. ASP.NET MVC为字段设置多语言显示 [转]
  2. Android之聊天室设计与开发
  3. android开发Tost工具类管理(一)
  4. Qt5制作鼠标悬停显示Hint的ToolTip
  5. Node.js连接MySQL数据库及构造JSON的正确姿势
  6. ArcGIS导出辖区边界点坐标
  7. 给input元素添加float. 去除IE6 下input的空隙
  8. jquery中div悬浮嵌套按钮效果
  9. jmeter JDBC请求连接测试mysql数据库
  10. 易语言关于使用CURL,网页_访问,网页_访问S,网页_访问_对象,鱼刺(winHttpW)发送Get性能测试
  11. linq 在查询表达式中处理 null 值
  12. Java数据持久层框架 MyBatis之API学习十(Logging详解)
  13. WPF自学入门(五)WPF依赖属性
  14. Git Push:error: Couldn't set refs/remotes/origin/master;error: update_ref failed for ref 'refs/remot
  15. Spring笔记02_注解_IOC
  16. 将arguments转换成数组的方法
  17. BZOJ3709 Bohater 贪心
  18. jQuery子页面获取父页面元素并绑定事件
  19. 【原创】自己动手写一个能操作redis的客户端
  20. day34 GIL锁 线程队列 线程池

热门文章

  1. Hebye 深度学习中Dropout原理解析
  2. UiPath:Log Message: Column 'user_role' does not belong to table .非说这个列不存在,记录一下看看怎么解决
  3. Git命令行操作(三)
  4. zz独家专访AI大神贾扬清:我为什么选择加入阿里巴巴?
  5. Jmeter压力并发测试
  6. map的基本操作
  7. VeeValidate——vue2.0表单验证插件
  8. day 22
  9. 官方入门教程和文档 | Visual Studio
  10. 关于被malloc分配内存的指针