[Python] opencv2 commonly used codes for drawing pedestrian detection frames

import cv2
import numpy as np

def cv_imread(filePath):
    cv_img = cv2.imdecode(np.fromfile(filePath,dtype=np.uint8), -1)
    return cv_img

# 需要可视化的图片地址
img_path = ‘’
# 对应图片的检测结果
detection_result = []

# 如果路径中包含中文,则需要用函数cv_imread的方式来读取,否则会报错
img = cv_imread(img_path)
 # 可视化
for bb in detection_result:
    # bb的格式为:[xmin, ymin, xmax, ymax]
    cv2.rectangle(img, (int(bb[0]), int(bb[1])),
                        (int(bb[2]), int(bb[3])),
                         (255, 0, 0), 2)

cv2.imshow('1', img)
cv2.waitKey(0)

Guess you like

Origin blog.csdn.net/weixin_38705903/article/details/109738394