python – 在TensorFlow对象检测API教程中获取边界框坐标

前端之家收集整理的这篇文章主要介绍了python – 在TensorFlow对象检测API教程中获取边界框坐标前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我是python和Tensorflow的新手.我试图从Tensorflow Object Detection API运行object_detection_tutorial文件,
但是当检测到物体时,我无法找到可以获取边界框坐标的位置.

相关代码

  1. # The following processing is only for single image
  2. detection_Boxes = tf.squeeze(tensor_dict['detection_Boxes'],[0])
  3. detection_masks = tf.squeeze(tensor_dict['detection_masks'],[0])

我假设边界框被绘制的地方是这样的:

  1. # Visualization of the results of a detection.
  2. vis_util.visualize_Boxes_and_labels_on_image_array(
  3. 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)
  4. plt.figure(figsize=IMAGE_SIZE)
  5. plt.imshow(image_np)

我尝试打印output_dict [‘detection_Boxes’],但我不确定数字是什么意思.有很多.

  1. array([[ 0.56213236,0.2780568,0.91445708,0.69120586],[ 0.56261235,0.86368728,0.59286624,0.8893863 ],[ 0.57073039,0.87096912,0.61292225,0.90354401],[ 0.51422435,0.78449738,0.53994244,0.79437423],

……

  1. [ 0.32784131,0.5461576,0.36972913,0.56903434],[ 0.03005961,0.02714229,0.47211722,0.44683522],[ 0.43143299,0.09211366,0.58121657,0.3509962 ]],dtype=float32)

我找到了类似问题的答案,但我没有一个名为Box的变量.我怎样才能获得坐标?谢谢!

最佳答案

I tried printing output_dict[‘detection_Boxes’] but I am not sure what
the numbers mean

您可以自己查看代码. visualize_Boxes_and_labels_on_image_array定义为here.

请注意,您正在传递use_normalized_coordinates = True.如果你跟踪函数调用,你会看到你的数字[0.56213236,0.691205]等是图像坐标所在的值[ymin,xmin,ymax,xmax]:

  1. (left,right,top,bottom) = (xmin * im_width,xmax * im_width,ymin * im_height,ymax * im_height)

函数计算:

  1. def draw_bounding_Box_on_image(image,ymin,xmax,color='red',thickness=4,display_str_list=(),use_normalized_coordinates=True):
  2. """Adds a bounding Box to an image.
  3. Bounding Box coordinates can be specified in either absolute (pixel) or
  4. normalized coordinates by setting the use_normalized_coordinates argument.
  5. Each string in display_str_list is displayed on a separate line above the
  6. bounding Box in black text on a rectangle filled with the input 'color'.
  7. If the top of the bounding Box extends to the edge of the image,the strings
  8. are displayed below the bounding Box.
  9. Args:
  10. image: a PIL.Image object.
  11. ymin: ymin of bounding Box.
  12. xmin: xmin of bounding Box.
  13. ymax: ymax of bounding Box.
  14. xmax: xmax of bounding Box.
  15. color: color to draw bounding Box. Default is red.
  16. thickness: line thickness. Default value is 4.
  17. display_str_list: list of strings to display in Box
  18. (each to be shown on its own line).
  19. use_normalized_coordinates: If True (default),treat coordinates
  20. ymin,xmax as relative to the image. Otherwise treat
  21. coordinates as absolute.
  22. """
  23. draw = ImageDraw.Draw(image)
  24. im_width,im_height = image.size
  25. if use_normalized_coordinates:
  26. (left,ymax * im_height)

猜你在找的Python相关文章