如何设置绘制框的最小阈值?

问题描述 投票:0回答:1

我有一个对象检测模型,我使用opencv来检测我的自定义类。

我只想在模型达到95%或更高时才输出框。

有没有办法可以配置?

(额外问题:我可以设置它以便只显示置信度最高的对象吗?例子:凸轮分别检测到两个对象,信心分别为98%和91%。我希望它只输出98%的对象框。 )

如果您需要它,这是我使用opencv的推理代码。

with detection_graph.as_default():
  with tf.Session(graph=detection_graph) as sess:
    while True:
      ret, image_np = cap.read()
      image_np_expanded = np.expand_dims(image_np, axis=0)
      image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
      boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
      scores = detection_graph.get_tensor_by_name('detection_scores:0')
      classes = detection_graph.get_tensor_by_name('detection_classes:0')
      num_detections = detection_graph.get_tensor_by_name('num_detections:0')

      (boxes, scores, classes, num_detections) = sess.run(
          [boxes, scores, classes, num_detections],
          feed_dict={image_tensor: image_np_expanded})

      vis_util.visualize_boxes_and_labels_on_image_array(
          image_np,
          np.squeeze(boxes),
          np.squeeze(classes).astype(np.int32),
          np.squeeze(scores),
          category_index,
          use_normalized_coordinates=True,
          line_thickness=6)

      cv2.imshow('object detection', cv2.resize(image_np, (800, 600)))
      if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break
tensorflow object-detection object-detection-api
1个回答
0
投票

好的,回答我自己的问题。我花了1分钟才发现自己。

这是可视化框的功能。它的输入参数在源代码中有很好的解释。

object_detection / utils的/ visualization_utils.visualize_boxes_and_labels_on_image_array(...)

对于我的情况,我只需要设置

min_score_thresh=.95max_boxes_to_draw=1在调用此函数时。

© www.soinside.com 2019 - 2024. All rights reserved.