opencv篇---目标检测得到的目标框快速绘制

目标检测得到的目标框快速绘制

由于代码产生的结果没有在图片上进行展示,难以验证结果的准确性,需要绘制在图片上进行展示确保结果的准确性
于是就编写了下面的代码, 且可以让相同的类型绘制相同的颜色。

import cv2
import colorsys


img = cv2.imread('11.jpg')

result_dict = {'cls': [0, 1, 8, 11, 11, 11, 11], 'pro': [0.93, 0.976, 0.992, 0.996, 0.99, 0.99, 0.987], 'x': [965, 1055, 1004, 219, 516, 0, 377], 'y': [180, 745, 291, 46, 3, 140, 0], 'w': [84, 267, 97, 233, 48, 264, 168], 'h': [255, 308, 182, 158, 55, 256, 120]}

num_classes = 20
hsv_tuples = [(x / num_classes, 1., 1.) for x in range(num_classes)]
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))


cls_li = []
for i in range(len(result_dict["cls"])):
    cls, x, y, w, h = result_dict["cls"][i], result_dict["x"][i], result_dict["y"][i], result_dict["w"][i], result_dict["h"][i]
    left_top = (x, y)
    right_bottom = (x + w, y + h)

    cv2.rectangle(img, left_top, right_bottom, color=colors[int(cls)], thickness=3)
    cv2.putText(img, 'key', (0, 0), cv2.FONT_HERSHEY_COMPLEX_SMALL, 2, (255, 0, 0))

cv2.imwrite("xx1.jpg", img)
# cv2.waitKey()
# cv2.destroyAllWindows()

结果如图所示
在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

心惠天意

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值