0 前言

在前面我们将utils文件夹中的visualization_utils进行了改造,现在将检测出来的数量输出乘列表的格式,以便后续的数据处理

1 改造visualization_utils

打开visualization_utils这个文件,大约在700行左右的地方,将return image改成return counterBoxs
AI学习(十):将检测出来的数量输出

2 改变自带的物体检测代码

打开自带的物体检测模型,将最后一组代码改变,红框位置为改变的地方,此处改变的改变的意思就是将每一个输出的结果都放入data的列表中,并且每3个元素就计算依次最大值。
AI学习(十):将检测出来的数量输出

代码附上~

data = []
i = 0
range_number = 0
for image_path in TEST_IMAGE_PATHS:
  image = Image.open(image_path)
  # the array based representation of the image will be used later in order to prepare the
  # result image with boxes and labels on it.
  image_np = load_image_into_numpy_array(image)
  # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
  image_np_expanded = np.expand_dims(image_np, axis=0)
  # Actual detection.
  output_dict = run_inference_for_single_image(image_np, detection_graph)
  # Visualization of the results of a detection.
  geshu = vis_util.visualize_boxes_and_labels_on_image_array(
      image_np,
      output_dict['detection_boxes'],
      output_dict['detection_classes'],
      output_dict['detection_scores'],
      category_index,
      instance_masks=output_dict.get('detection_masks'),
      use_normalized_coordinates=True,
      line_thickness=8)
  data.append(geshu)
  print(geshu)
  print(data)
  plt.figure(figsize=IMAGE_SIZE)
  plt.imshow(image_np)
  i = i+1
  if i == 3:
    i = 0
    c1 = data[-1]
    c2 = data[-2]
    c3 = data[-3]
    zuida = max(c1,c2,c3)
    print(zuida)

3 输出结果展示

AI学习(十):将检测出来的数量输出
AI学习(十):将检测出来的数量输出
后面还有好多图片省略啦~,都是一样的

相关文章:

  • 2021-12-24
  • 2021-12-07
  • 2021-08-25
  • 2021-11-05
  • 2021-08-26
  • 2021-12-11
  • 2021-10-08
  • 2021-05-21
猜你喜欢
  • 2021-11-28
  • 2022-12-23
  • 2021-09-28
  • 2021-08-08
  • 2021-07-03
  • 2021-05-22
  • 2022-12-23
相关资源
相似解决方案