python - 使用 TensorFlow 对象检测 API 遍历目录
问题描述
我正在尝试遍历包含多个图像的目录,并使用 TensorFlow 对它们进行对象分析。我正在尝试修改用于分析单个图像的代码,但无法使其正常工作。它分析第一张图像,显示它然后停止。我希望关闭图像/按键盘上的一个键会提示分析和显示下一个,但事实并非如此。该程序继续运行(我认为),但没有任何反应。
# 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()
解决方案
结果一个文件以 .jpg 结尾,其余的都是 .JPG
if filename.lower().endswith(".jpg"):
解决了我的问题。哎呀。
推荐阅读
- c++ - C++ 性能 std::array 与 std::vector
- algorithm - 最小化在池中解决债务的交易成本
- c# - 在 Hololens 上的 C# Unity 中找不到模块 C++ .dll
- html - 是否有可能将静态页面连接到我用 Django 制作的 web 应用程序?
- arrays - Mongoose - 查找数组没有任何匹配项的文档
- python - Python中的逃生通道
- java - 如何在使用 spark joinWith 创建 Tuple2 时修复 UnsupportedOperationException
- javascript - Sequelize 分页中的 SQL 语法错误,但在第一页上有效?
- .net - 未定义或导入预定义类型“System.Collections.Generic.IReadOnlyCollection`1”
- excel - 如何将可变范围的行和列从一个工作簿复制到另一个工作簿?