我是人工智能的新手,我正在使用TensorFlow对象检测应用程序接口来检测图像上的产品,所以它已经检测到了对象,但我想要获得图像中每个对象的坐标Xmax、Xmin、Ymax和Ymin。
这是检测到对象的图像,在这种情况下,在图像中检测到2个对象。
图片:
我们可以看到我得到了对象的坐标,但它不清楚,输出中有3个以上的坐标,我只想获得坐标量,即图像中的对象数量。
这是提供输出的代码
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)
输出
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. ]]]
我想要得到这样的东西,但只得到边界框的坐标。我们假设它们是物体的坐标。
[0.16593058 0.06630109 0.8009524 0.5019088 ]
[0.15757088 0.5376015 0.8869156 0.9394863 ]
发布于 2019-04-08 21:20:10
你应该注意两件事:
因此,为了通过分数过滤检测,可以使用detection_scores
来决定过滤掉哪些索引(它们是排序的),并且可以将归一化坐标与原始图像大小相乘,以获得绝对坐标。规范化后的坐标是以[ymin, xmin, ymax, xmax]
格式给出的,因此您应该将第一个和第三个坐标与y_size
相乘,将第二个和第四个坐标与x_size
相乘。您可以通过评估image_tensor
的形状来计算x_size
和y_size
。
发布于 2020-06-09 05:14:24
代码:
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)])
https://stackoverflow.com/questions/55373454
复制相似问题