首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从tensorflow对象检测中获取边界框[Xmax,Xmin,Ymax,Ymin]

如何从tensorflow对象检测中获取边界框[Xmax,Xmin,Ymax,Ymin]
EN

Stack Overflow用户
提问于 2019-03-27 17:13:39
回答 2查看 2.1K关注 0票数 1

我是人工智能的新手,我正在使用TensorFlow对象检测应用程序接口来检测图像上的产品,所以它已经检测到了对象,但我想要获得图像中每个对象的坐标Xmax、Xmin、Ymax和Ymin。

这是检测到对象的图像,在这种情况下,在图像中检测到2个对象。

图片:

我们可以看到我得到了对象的坐标,但它不清楚,输出中有3个以上的坐标,我只想获得坐标量,即图像中的对象数量。

这是提供输出的代码

代码语言:javascript
运行
复制
with detection_graph.as_default():
    with tf.Session(graph=detection_graph) as sess:
        image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
        detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
        detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
        detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
        num_detections = detection_graph.get_tensor_by_name('num_detections:0')

        print(detection_graph.get_tensor_by_name('detection_boxes:0'))

        for image_path in TEST_IMAGE_PATHS:
            boxes = detect_objects(image_path)
            print(boxes)

输出

代码语言:javascript
运行
复制
Tensor("detection_boxes:0", dtype=float32)
[[[0.16593058 0.06630109 0.8009524  0.5019088 ]
  [0.15757088 0.5376015  0.8869156  0.9394863 ]
  [0.5966009  0.88420665 0.6564093  0.9339011 ]
  ...
  [0.         0.         0.         0.        ]
  [0.         0.         0.         0.        ]
  [0.         0.         0.         0.        ]]]

我想要得到这样的东西,但只得到边界框的坐标。我们假设它们是物体的坐标。

代码语言:javascript
运行
复制
[0.16593058 0.06630109 0.8009524  0.5019088 ]
[0.15757088 0.5376015  0.8869156  0.9394863 ]
EN

回答 2

Stack Overflow用户

发布于 2019-04-08 21:20:10

你应该注意两件事:

  1. 这些是所有(通常是100个) top detections.
  2. These的坐标都是以标准化坐标给出的。

因此,为了通过分数过滤检测,可以使用detection_scores来决定过滤掉哪些索引(它们是排序的),并且可以将归一化坐标与原始图像大小相乘,以获得绝对坐标。规范化后的坐标是以[ymin, xmin, ymax, xmax]格式给出的,因此您应该将第一个和第三个坐标与y_size相乘,将第二个和第四个坐标与x_size相乘。您可以通过评估image_tensor的形状来计算x_sizey_size

票数 1
EN

Stack Overflow用户

发布于 2020-06-09 05:14:24

代码:

代码语言:javascript
运行
复制
for box in boxes[0]:
    xmin, ymin, xmax, ymax =box
    bboxes.append([int(ymin *640),int(xmin*480) , int((ymax-ymin)*640), int((xmax-xmin)*480)])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55373454

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档