• 略带点艺术气息的目标检测框


    🔱前言 

            如果说作为一名程序员,我要求我自己要不断的求证,那么同时作为一名热爱艺术的人,我则无法忍受主流的那种“丑陋”目标检测框(下图),所以这篇文章也就应用而生了。

    在这里插入图片描述


    纯原创,略带点科技艺术气息的目标检测框

    🔱检测框展览

    🔱在实际应用中效果的展览

     📍Face

     📍Body

    🔱Code柜

     📍magic_bbox.py

     📍demo.py


    🔱检测框展览

    🔱在实际应用中效果的展览

     📍Face

     📍Body

    🔱Code柜

     📍magic_bbox.py

    1. # -*- coding: UTF-8 -*-
    2. """
    3. @Time : 2022-9-15
    4. @Author : 江子良
    5. @Email : 2642898145@qq.com
    6. """
    7. import cv2
    8. import numpy as np
    9. class Magic_Bbox(object):
    10. def __init__(self, color=(255, 255, 0), threasould=0.16):
    11. self.color = color
    12. self.threasould = threasould
    13. self.out_img = np.array([])
    14. def draw(self, old_image, b, draw_type):
    15. if draw_type == '0':
    16. cv2.rectangle(old_image, (b[0], b[1]), (b[2], b[3]), self.color, 1)
    17. b0_, b1_, b2_, b3_ = int((b[2]-b[0])*self.threasould), int((b[3]-b[1])*self.threasould), int((b[2]-b[0])*self.threasould), int((b[3]-b[1])*self.threasould)
    18. # 左上
    19. cv2.line(old_image, (b[0], b[1]), (b[0], b[1] + b1_), self.color, 4, 4)
    20. cv2.line(old_image, (b[0], b[1]), (b[0] + b0_, b[1]), self.color, 4, 4)
    21. # 右下
    22. cv2.line(old_image, (b[2], b[3]), (b[2], b[3] - b3_), self.color, 4, 4)
    23. cv2.line(old_image, (b[2], b[3]), (b[2] - b2_, b[3]), self.color, 4, 4)
    24. # 左下
    25. cv2.line(old_image, (b[0], b[3]), (b[0], b[3] - b3_), self.color, 4, 4)
    26. cv2.line(old_image, (b[0], b[3]), (b[0] + b0_, b[3]), self.color, 4, 4)
    27. # 右上
    28. cv2.line(old_image, (b[2], b[1]), (b[2], b[1] + b1_), self.color, 4, 4)
    29. cv2.line(old_image, (b[2], b[1]), (b[2] - b2_, b[1]), self.color, 4, 4)
    30. elif draw_type == '1':
    31. cv2.rectangle(old_image, (b[0], b[1]), (b[2], b[3]), self.color, 1)
    32. b0_, b1_, b2_, b3_ = 25, 25, 25, 25
    33. temp = 10
    34. # 左上
    35. cv2.line(old_image, (b[0] - temp, b[1] - temp), (b[0], b[1] + b1_), self.color, 4, 4)
    36. cv2.line(old_image, (b[0] - temp, b[1] - temp), (b[0] + b0_, b[1]), self.color, 4, 4)
    37. # 右下
    38. cv2.line(old_image, (b[2] + temp, b[3] + temp), (b[2], b[3] - b3_), self.color, 4, 4)
    39. cv2.line(old_image, (b[2] + temp, b[3] + temp), (b[2] - b2_, b[3]), self.color, 4, 4)
    40. # 左下
    41. cv2.line(old_image, (b[0] - temp, b[3] + temp), (b[0], b[3] - b3_), self.color, 4, 4)
    42. cv2.line(old_image, (b[0] - temp, b[3] + temp), (b[0] + b0_, b[3]), self.color, 4, 4)
    43. # 右上
    44. cv2.line(old_image, (b[2] + temp, b[1] - temp), (b[2], b[1] + b1_), self.color, 4, 4)
    45. cv2.line(old_image, (b[2] + temp, b[1] - temp), (b[2] - b2_, b[1]), self.color, 4, 4)
    46. elif draw_type == '2':
    47. cv2.rectangle(old_image, (b[0], b[1]), (b[2], b[3]), self.color, 1)
    48. b0_, b1_, b2_, b3_ = 25, 25, 25, 25
    49. temp = 10
    50. # 左上
    51. cv2.line(old_image, (b[0] - temp, b[1] - temp), (b[0] - temp, b[1] + b1_ - temp), self.color, 4, 4)
    52. cv2.line(old_image, (b[0] - temp, b[1] - temp), (b[0] - temp + b0_, b[1] - temp), self.color, 4, 4)
    53. # 右下
    54. cv2.line(old_image, (b[2] + temp, b[3] + temp), (b[2] + temp, b[3] - b3_ + temp), self.color, 4, 4)
    55. cv2.line(old_image, (b[2] + temp, b[3] + temp), (b[2] + temp - b2_, b[3] + temp), self.color, 4, 4)
    56. # 左下
    57. cv2.line(old_image, (b[0] - temp, b[3] + temp), (b[0] - temp, b[3] - b3_ + temp), self.color, 4, 4)
    58. cv2.line(old_image, (b[0] - temp, b[3] + temp), (b[0] - temp + b0_, b[3] + temp), self.color, 4, 4)
    59. # 右上
    60. cv2.line(old_image, (b[2] + temp, b[1] - temp), (b[2] + temp, b[1] + b1_ - temp), self.color, 4, 4)
    61. cv2.line(old_image, (b[2] + temp, b[1] - temp), (b[2] + temp - b2_, b[1] - temp), self.color, 4, 4)
    62. return old_image
    63. def show(self, img):
    64. cv2.imshow('fame', img)
    65. cv2.waitKey(0)

     📍demo.py

    @Time    : 2022-9-15
    @Author  : 江子良
    @Email   : 2642898145@qq.com
    @param: img | 这个参数是要传入准备被作画的图片
    @param:bbox| 这个参数是要传入准备作画的目标框位置 格式:(xmin,ymin,xmax,ymax)
    @pararm:type| 这个参数是一一对应上面3种不同的目标检测框
    @pararm:color| 请根据RGB表自行设置哦!
    """
    RGB颜色对照表戳这里~http://t.csdn.cn/9z0SF

    How to use? 

    1. from magic_bbox import Magic_Bbox
    2. import numpy as np
    3. import cv2
    4. if __name__ == "__main__":
    5. img = np.zeros((320, 320, 3), np.uint8) # 生成一个空灰度图像用于演示
    6. bbox = (60, 60, 260, 260) # 生成一个bbox用于演示
    7. color = (255,255,0)
    8. '''
    9. type: 0 | 1 | 2
    10. '''
    11. mb = Magic_Bbox(color=color)
    12. img = mb.draw(img, bbox, '1')
    13. mb.show(img)

    完毕!

    如果大家觉得有用的话,欢迎三连喔~

  • 相关阅读:
    哪一款除甲醛产品效果好 家用针对除甲醛的净化器品牌
    XFeat:速度精度远超superpoint的轻量级图像匹配算法
    WebUtils
    前端周刊第二十六期
    [附源码]Python计算机毕业设计Django网文论坛管理系统
    getTask方法: 实现救急线程存活keepAliveTime
    骑士精神 ← IDA*
    51-41 Stable Video Diffusion,高质量视频生成新时代
    idea工具,debug模式小技巧,调试正确姿势。快进收藏夹。
    【etcd】go etcd实战一:etcd基本使用
  • 原文地址:https://blog.csdn.net/qq_51831335/article/details/126869395