微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

plt.show仅显示“对象检测/ test_images”文件夹中的30张图像中的一张图像

如何解决plt.show仅显示“对象检测/ test_images”文件夹中的30张图像中的一张图像

我的图像测试文件夹中确实有30张要显示的图像。当我运行代码时,仅显示一张图像。我有点困惑,因为我已经使用了for循环来显示所有图像。它只显示了30张图像中的一张。
我试图在不同的窗口上显示测试图像文件夹中的所有图像。不确定代码有什么问题吗?

与图像读取和显示有关的代码

import cv2
import numpy as np
import tkinter
import matplotlib

这是必需的,因为笔记本存储在object_detection文件夹中。

sys.path.append("..")

# This is needed to display the images.
#matplotlib inline  
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
from matplotlib import pyplot as plt
matplotlib.use( 'tkagg' )
from PIL import Image



# Path to image
PATH_TO_TEST_IMAGES_DIR = 'D:/Newfolder/models/research/object_detection/test_images'
TEST_IMAGE_PATHS = [ os.path.join(PATH_TO_TEST_IMAGES_DIR,'image{}.jpg'.format(i)) for i in range(1,30) ]
# Size,in inches,of the output images.
IMAGE_SIZE = (12,8)
# Number of classes the object detector can identify
NUM_CLASSES = 3


all_images_expanded = []

for path in TEST_IMAGE_PATHS:
    image = cv2.imread(path)
    image_rgb = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
    image_expanded = np.expand_dims(image_rgb,axis=0)
    # keep on list
    all_images_expanded.append(image_expanded)

# Perform the actual detection by running the model with the image as input
(Boxes,scores,classes,num) = sess.run(
    [detection_Boxes,detection_scores,detection_classes,num_detections],Feed_dict={image_tensor: image_expanded})
# Draw the results of the detection (aka 'visulaize the results')

vis_util.visualize_Boxes_and_labels_on_image_array(
    image,np.squeeze(Boxes),np.squeeze(classes).astype(np.int32),np.squeeze(scores),category_index,use_normalized_coordinates=True,line_thickness=8,min_score_thresh=0.60)
plt.figure(figsize=IMAGE_SIZE)
plt.imshow(image)

plt.show()

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。