idxs = cv2.dnn.NMSBoxes(boxes, confidences, confident, threshold)
You can see that the source code is NMS between categories,there is no incoming category-related information.The NMS of object detection is based on the category, so this is the essential reason for the difference between the two results.Therefore the following changes should be made,with python:
def NMSBoxes_fix(boxes, confidences, confidence_thre, nms_thre, class_id):
class_id_set = set(class_id)
result = []
for cls in class_id_set:
cls_boxes = []
cls_confidences = []
indices = [i for i, c in enumerate(class_id) if c == cls]
for i in indices:
cls_boxes.append(boxes[i])
cls_confidences.append(confidences[i])
idxs = cv2.dnn.NMSBoxes(cls_boxes, cls_confidences, confidence_thre, nms_thre)
for i in idxs:
result.append([indices[i[0]]])
return np.array(result)
idxs = cv2.dnn.NMSBoxes(boxes, confidences, confident, threshold)You can see that the source code is NMS between categories,there is no incoming category-related information.The NMS of object detection is based on the category, so this is the essential reason for the difference between the two results.Therefore the following changes should be made,with python:
def NMSBoxes_fix(boxes, confidences, confidence_thre, nms_thre, class_id):class_id_set = set(class_id)result = []for cls in class_id_set:cls_boxes = []cls_confidences = []indices = [i for i, c in enumerate(class_id) if c == cls]for i in indices:cls_boxes.append(boxes[i])cls_confidences.append(confidences[i])idxs = cv2.dnn.NMSBoxes(cls_boxes, cls_confidences, confidence_thre, nms_thre)for i in idxs:result.append([indices[i[0]]])return np.array(result)