【问题标题】:Finding the bounding box coordinates in tensorflow object在 tensorflow 对象中查找边界框坐标
【发布时间】:2018-08-17 09:56:08
【问题描述】:

您好,我是 tensorflow 对象检测 api 的新手,我正在尝试查找图像中对象的边界框坐标。我写了以下代码,但它不起作用。

 def find_bounding_boxes(image, graph):
      with graph.as_default():
        with tf.Session() as sess:
          width, height = image.size 
          boxes = graph.get_tensor_by_name('detection_boxes:0')
          np.squeeze(boxes)
          ymin = boxes[0][1][0]*height
          xmin = boxes[0][1][1]*width
          ymax = boxes[0][1][2]*height
          xmax = boxes[0][1][3]*width
          print ('Top left')
          print (xmin,ymin,)
          print ('Bottom right')
          print (xmax,ymax)

我得到以下输出:

Top left
Tensor("mul_3:0", dtype=float32) Tensor("mul_2:0", dtype=float32)
Bottom right
Tensor("mul_5:0", dtype=float32) Tensor("mul_4:0", dtype=float32)
Top left
Tensor("mul_7:0", dtype=float32) Tensor("mul_6:0", dtype=float32)
Bottom right
Tensor("mul_9:0", dtype=float32) Tensor("mul_8:0", dtype=float32)
Top left
Tensor("mul_11:0", dtype=float32) Tensor("mul_10:0", dtype=float32)
Bottom right
Tensor("mul_13:0", dtype=float32) Tensor("mul_12:0", dtype=float32)

【问题讨论】:

    标签: tensorflow object-detection bounding-box


    【解决方案1】:

    我也在寻找如何在 tensorflow 对象检测 API 中找到坐标,我找到了这个答案。它对我有用:

    width = image.size
    height = image.size
    i = 1
    ymin = boxes[0][i][0]*height
    xmin = boxes[0][i][1]*width
    ymax = boxes[0][i][2]*height
    xmax = boxes[0][i][3]*width
    
    print ('Top left')
    print (xmin,ymin)
    print ('Bottom right')
    print (xmax,ymax)
    

    我不知道你如何定义width, height = image.size,我这样做时会出错。

    编辑:我想通了,我改变了:

    来自

    width, height = image.size

    width = image.shape[1] height = image.shape[0]

    它给了我图像的真实宽度和高度。如果有人想找到多个边界框的坐标,请按照我在此link 的回答。

    【讨论】:

      猜你喜欢
      • 2019-09-30
      • 2018-08-01
      • 1970-01-01
      • 2019-10-11
      • 2022-10-24
      • 1970-01-01
      • 2020-05-24
      • 1970-01-01
      • 2016-12-21
      相关资源
      最近更新 更多