def matchDetectionsOverlap(self, detections, truthDetections, frameSize):
self.log.info("Calculating overlap for each detection..")
truthCanvas = np.zeros((frameSize[0], frameSize[1], 1), np.uint8)
for truthDetection in truthDetections:
truthCanvas[truthDetection['ymin']:truthDetection['ymax'], truthDetection['xmin']:truthDetection['xmax']] = 255
overlapRatios = []
for detection in detections:
detectionCanvas = np.zeros((frameSize[0], frameSize[1], 1), np.uint8)
detectionCanvas[detection['ymin']:detection['ymax'], detection['xmin']:detection['xmax']] = 255
canvas = cv2.bitwise_and(detectionCanvas, truthCanvas)
detectionCount = np.count_nonzero(detectionCanvas)
overlapCount = np.count_nonzero(canvas)
overlap = (overlapCount*1.0)/detectionCount
overlapRatios.append(overlap)
return overlapRatios
评论列表
文章目录