def detect(img_file, detector_xml_path, dest_img_file):
img = cv2.imread(img_file)
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
detector = cv2.CascadeClassifier(detector_xml_path)
min_size = (min(50, gray_img.shape[0] // 10), min(50, gray_img.shape[1] // 10))
hits = detector.detectMultiScale(gray_img, 1.1, 4, 0, min_size)
#cv2.groupRectangles(hits, 2)
print(hits)
hits_img = np.copy(img)
for (x,y,w,h) in hits:
cv2.rectangle(hits_img, (x,y), (x+w, y+h), (0,0,255), 2)
cv2.imwrite(dest_img_file, hits_img)
评论列表
文章目录