【问题标题】:Loop through a directory using TensorFlow Object Detection API使用 TensorFlow 对象检测 API 遍历目录
【发布时间】:2020-01-14 12:19:56
【问题描述】:

我正在尝试遍历包含多个图像的目录,并使用 TensorFlow 对它们进行对象分析。我正在尝试修改用于分析单个图像的代码,但无法使其正常工作。它分析第一张图像,显示它然后停止。我希望关闭图像/按键盘上的一个键会提示分析和显示下一个,但事实并非如此。程序继续运行(我认为),但没有任何反应。

我正在修改来自https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10/blob/master/Object_detection_image.py的代码

# Name of the directory containing the images to be analysed
DIR_NAME = 'testImages'

# Path to directory containing images to be analysed
PATH_TO_DIR = os.path.join(CWD_PATH, DIR_NAME)

# Iterate through the files to be analysed in the directory
for filename in os.listdir(PATH_TO_DIR):
    if filename.endswith(".jpg"):
        image = cv2.imread(filename)
        image = cv2.resize(image, (800,600))
        image_expanded = np.expand_dims(image, axis=0)
        (boxes, scores, classes, num) = sess.run(
            [detection_boxes, detection_scores, detection_classes, num_detections],
            feed_dict={image_tensor: image_expanded})
        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)
        cv2.imshow('Object detector', image)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

【问题讨论】:

  • 您按了键盘上的任何键吗?你在cv2.destroyAllWindows() 之前有cv2.waitKey(0),这意味着程序在销毁窗口之前等待你的输入。尝试按任意键,应显示第二张图像。
  • 我希望会是这种情况,但是当我按下一个键时它会关闭窗口,我的 python shell 显示“>>>”并且我的 Anaconda Prompt 只是在第一次停止时保持静止显示图像。

标签: python loops tensorflow object-detection


【解决方案1】:

原来一个文件以 .jpg 结尾,其余的都是 .JPG

if filename.lower().endswith(".jpg"):

解决了我的问题。哎呀。

【讨论】:

    猜你喜欢
    • 2021-02-01
    • 2017-12-02
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多