Python 我如何在带有目标检测的图像上打印数字而不是类别标签和分数
我是一名学生,学习深入。我有一个项目,使用object_detection_教程(代码如下)检测水稻植株的疾病。我想打印有疾病的位置编号,而不是类别标签和分数(如下图所示),但我不知道如何打印。所以我真的需要帮助来解决这个问题。谢谢你Python 我如何在带有目标检测的图像上打印数字而不是类别标签和分数,python,tensorflow,object-detection,Python,Tensorflow,Object Detection,我是一名学生,学习深入。我有一个项目,使用object_detection_教程(代码如下)检测水稻植株的疾病。我想打印有疾病的位置编号,而不是类别标签和分数(如下图所示),但我不知道如何打印。所以我真的需要帮助来解决这个问题。谢谢你 with detection_graph.as_default(): with tf.Session(graph=detection_graph) as sess: image_tensor = detection_graph.get_te
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')
for i in TEST_IMAGE_PATHS:
image = Image.open(i)
image_np = load_image_into_numpy_array(image)
image_np_expanded = np.expand_dims(image_np, axis=0)
(boxes, scores, classes, num) = sess.run(
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: image_np_expanded})
vis_util.visualize_boxes_and_labels_on_image_array(image_np,np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=2)
cv2.imshow("image_np", image_np)
cv2.waitKey()
我想打印图像如下
图像输出结果:
首先,这与openCV关系不大,可能是tensorflow代码 如果我没有弄错的话,代码将使用来自的函数。运行上述代码将返回与边界框相对应的
(框、分数、类、num)
,以及相应的置信度分数、类id和检测次数(这在您的情况下没有真正的帮助)
假设(你说dao_on
是类名)显示的消息包含类名和分数,我猜你会被扔到第二行:
display_str = str(class_name)
无论如何,最简单的方法是复制此函数,可视化\u image\u array()上的\u box\u和\u labels\u(
(它是辅助的,不是实际的tensorflow),并用所需的字符串替换所有引用显示字符串的代码。我猜这就是被检测到的物体的数量?如果您只有一门课,那么:
for i in range(min(max_boxes_to_draw, boxes.shape[0])):
# delete all code in the block
display_str = i
# Draw all boxes onto image.
for box, color in box_to_color_map.items():
除了显示图像之外,OpenCV并没有真正被使用。你最好包含图像,而不是重定向到另一个站点。也许detectron的代码可以帮助你,在github上查找代码。谢谢Ahmed Emad.FesianXu,你能给我详细的建议吗。谢谢,但我有4个类,如果图像上有一个以上的病变部位,有一个或多个类别,我想增加每个病变部位的数量(从1到全部),不管它是什么类别。那我该怎么办呢。请说清楚一点你到底在问什么。我不明白。如果有更多的死亡位置,例如来自不同类别的2个,他们应该如何标记?对不起,没有给你明确的问题。我按照你的建议解决了这个问题。非常感谢。如果你觉得答案有用,你可以接受,让其他人知道这个问题有一个有效的解决方案(也可能是upvote)。