def check_opencv_accuracy(image_paths, bounding_boxes_map):
detection_scores = []
filters_path = os.path.expanduser("~/anaconda3/share/OpenCV/haarcascades/haarcascade_frontalface_default.xml")
cascade_classifier = cv2.CascadeClassifier(filters_path)
for path in tqdm.tqdm(image_paths):
image = cv2.cvtColor(cv2.imread(path), cv2.COLOR_BGR2GRAY)
image_bounding_box = shapely.geometry.box(0, 0, image.shape[1], image.shape[0])
face_bounding_box = bounding_boxes_map[os.path.basename(path)]
# Only try to search for faces if they are larger than 1% of image. If they are smaller,
# ground truth bounding box is probably incorrect
if face.geometry.get_intersection_over_union(image_bounding_box, face_bounding_box) > 0.01:
value = 1 if does_opencv_detect_face_correctly(image, face_bounding_box, cascade_classifier) else 0
detection_scores.append(value)
print("OpenCV accuracy is {}".format(np.mean(detection_scores)))
评论列表
文章目录