简体   繁体   English

如何将数据集的图像列表保存(写入)到新文件夹-openCV Python?

[英]How to save (write) a list of images from a dataset into a new folder - openCV Python?

I'm so much newbie in openCV/Python tasks. 我是openCV / Python任务的新手。 I use Python 3.7 and openCV 4 running by a JNotebook. 我使用JNotebook运行的Python 3.7和openCV 4。 The question: I wanna save just 1,000 images from a dataset with 10,000 pictures, extracting them from it and write only those 1,000.jpeg in a new folder, is it possible using openCV package in Python? 问题:我只想从具有10,000张图片的数据集中保存1,000张图片,从中提取它们,然后仅将1,000.jpeg写入新文件夹中,是否可以在Python中使用openCV包? I've already had a list of names (1,000 images). 我已经有一个名称列表(1000张图像)。

If you need just to copy files, you even don't need OpenCV tools: 如果您只需要复制文件,则甚至不需要OpenCV工具:

out_folder_path = '...'
in_folder_path = '...'
images_to_save_names = [...]
for image_name in images_to_save_names:
    cur_image_path = os.path.join(in_folder_path, image_name)
    cur_image_out_path = os.path.join(out_folder_path, image_name)
    shutil.copyfile(cur_image_path, cur_image_out_path)

If you have image names and their binary data from some specific DS file(.csv, .hdf, etc), you can use cv2.imwrite(path, image) instead of copying. 如果您具有某个特定DS文件(.csv,.hdf等)中的图片名称及其二进制数据,则可以使用cv2.imwrite(path, image)代替复制。

假设您已在计算机上正确安装了OpenCV,则可以首先使用img = cv.imread(filename)读取图像,然后使用cv.imwrite(filename, img)写入cv.imwrite(filename, img)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从一个文件夹中提取图像,对其进行处理并使用 python、opencv 保存到另一个文件夹中 - Extract images from one folder, process it and save into another folder with python, opencv Python/OpenCV - 如何按字母顺序从文件夹中加载所有图像 - Python/OpenCV - how to load all images from folder in alphabetical order 如何将图像从列表下载到 Python 中的文件夹 - How to download images from a list to a folder in Python Python/Opencv 将多个图像保存到具有不同名称的文件夹中 - Python/Opencv save multiple images to folder with different names 新的python。 我想将算法应用于文件夹中的不同图像,并将新图像保存在另一个文件夹中。 生物学研究图像 - new in python. I want to apply an algorithm to different images from a folder and save the new ones in another folder. Biology research images 如何将 web 抓取的图片保存到文件夹中? (Python) - How to save images to a folder from web scraping? (Python) 从文件夹中读取自己的多张图像并另存为数据集以进行培训 - Read Own Multiple Images from folder and Save as a Dataset for Training 如何将修改后的图像列表保存到另一个文件夹? - How to save a list of modified images into another folder? Python将图像保存到文件夹中 - Python save images into the folder 使用OpenCV和Python保存多个图像 - Save multiple images with OpenCV and Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM