我是一名学生,学习深造。我有一个项目,并使用object_detection_tutorial (代码)来检测水稻植株的病害。我想打印有疾病的位置数,而不是类标签和评分(类似于下面的图像),但我不知道怎么做。所以我真的需要帮助来解决这个问题。谢谢你。
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()我想打印的图片如下image_result:

发布于 2019-10-14 19:05:19
首先,这与openCV没有什么关系,可能是tensorflow代码。
如果我没有弄错的话,代码使用这里中的这个函数。运行上面的代码,它返回(boxes, scores, classes, num),它对应于边界框,以及相应的置信度、类id和检测数量(这在您的情况下并不是很有用)。
假设(您说dao_on是类名)显示的消息包含类名和我猜您被抛到行中的分数:
display_str = str(class_name)无论如何,最简单的方法是复制这个函数,visualize_boxes_and_labels_on_image_array() (它是辅助的,而不是实际的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并不是真正的用途。
https://stackoverflow.com/questions/58373154
复制相似问题