[英]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.