import dlib
import cv2
pth = r"0001_01.jpg"
pth2 = r"OIP-C.jpg"
img = dlib.load_rgb_image(pth2)
detector = dlib.get_frontal_face_detector()
dets = detector(img, 1)
print(dets) # pth: rectangles[[(171, 201) (438, 468)]] 一个人
# pth2: rectangles[[(17, 18) (53, 54)], [(53, 18) (89, 54)], [(177, 38) (213, 74)], [(217, 34) (253, 70)]] four people
print(type(dets))
img2 = cv2.imread(pth2)
# image_for_nms_box = cv2.rectangle(image_for_nms_box, (x1, y1), (x2, y2), (0,255,0), 2)
# img2 = cv2.rectangle()
print(len(dets))
for d in dets:
x1, y1 = d.left(), d.top()
x2, y2 = d.right(), d.bottom()
img2 = cv2.rectangle(img2, (x1, y1), (x2, y2), (0,255,0), 2)
cv2.imwrite("OIP-C_boxes.jpg", img2)
原图:
检测后的图: