【发布时间】:2021-12-11 19:58:22
【问题描述】:
我目前正在python中进行图像处理,tensorflow想为指定文件夹创建for循环python代码 这是特定文件夹的代码
import pathlib
PATH_TO_TEST_IMAGES_DIR = pathlib.Path('C:/Object_detection/models-master/research/object_detection/test_images')
TEST_IMAGE_PATHS = sorted(list(PATH_TO_TEST_IMAGES_DIR.glob("*.jpg")))
TEST_IMAGE_PATHS
我想在我的图像处理的这一部分创建一个for循环,以便它可以输出多张图像而无需右键单击另存为在jupyter笔记本中
def show_inference(model, image_path):
image_np = np.array(Image.open(image_path))
output_dict = run_inference_for_single_image(model, image_np)
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
output_dict['detection_boxes'],
output_dict['detection_classes'],
output_dict['detection_scores'],
category_index,
instance_masks=output_dict.get('detection_masks_reframed', None),
use_normalized_coordinates=True,
line_thickness=8)
display(Image.fromarray(image_np))
【问题讨论】:
-
据我了解,您想保存当前显示的图像,并为 TEST_IMAGE_PATHS 中的每个图像都这样做,是吗?你试过什么,你卡在哪里了?
-
是的。我想 cv2.imwrite() TEST_IMAGE_PATHS 目录中带有标签的每个图像。我想用 cv2.write() 制作一个 for 循环 python 代码。 jupyter notebook 中的显示图像是正确的。我只是想用python代码自动把所有带标签的图片保存在指定的文件夹里。
标签: python image tensorflow image-processing jupyter-notebook