简体   繁体   English

如何将修改后的图像列表保存到另一个文件夹?

[英]How to save a list of modified images into another folder?

def gcd(m, n):
  fm = []
for i in range(1, m + 1):
  if (m % i) == 0:
    fm.append(i)
fn = []
for j in range(1, n + 1):
  if (n % i) == 0:
    fn.append(j)
cf = []
for f in fm:
  if f in fn:
  cf.append(f)
return (cf[-1]) for i in pick:
  if scores[i] > min_threshold:
  box = boxes_pixels[i]
box = np.round(box).astype(int)# Draw bounding box.
image = cv2.rectangle(
  image, (box[1], box[0]), (box[3], box[2]), (0, 255, 0), 2)
label = "{}:{:.2f}".format(int(classes[i]), scores[i])

print(classes[i], end = ' ')# Draw label(class index and probability).
draw_label(image, (box[1], box[0]), label)
print(box[1])

print(box[1], box[0], box[3], box[2])# im = image.crop((105, 10, 131, 53))
cropped_image = image[10: 53, 105: 131]
else :
  continue
for n in range(0, len(onlyfiles)): #Save and display the labeled image.
save_image(image[: ,: , ::-1])
Image(fname, onlyfiles[n])
imshow(image)

def save_image(data, fname = '/home/sunil/image/', swap_channel = True):
  if swap_channel:
  data = data[..., ::-1]
cv2.imwrite(fname, data)

error Traceback (most recent call last) in 38 for n in range(0, len(onlyfiles)): 39 #Save and display the labeled image. 错误38中对于范围(0,len(onlyfiles))中的n的回溯(最近一次调用最后一次):39#保存并显示带标签的图像。 ---> 40 save_image(image[:, :, ::-1]) 41 Image(fname,onlyfiles[n]) 42 imshow(image) ---> 40 save_image(图像[:,:: ::-1])41图像(fname,onlyfiles [n])42 imshow(图像)

in save_image(data, fname, swap_channel) 2 if swap_channel: 3 data = data[..., ::-1] ----> 4 cv2.imwrite(fname, data) 在save_image(data,fname,swap_channel)中2如果swap_channel:3 data = data [...,::-1] ----> 4 cv2.imwrite(fname,data)

error: OpenCV(4.1.0) /io/opencv/modules/imgcodecs/src/loadsave.cpp:662: error: (-2:Unspecified error) could not find a writer for the specified extension in function 'imwrite_' 错误:OpenCV(4.1.0)/io/opencv/modules/imgcodecs/src/loadsave.cpp:662:错误:(-2:未指定错误)在函数“ imwrite_”中找不到指定扩展名的编写器

Default filename for your save_image function is /home/sunil/image/ looks like a directory and has no extension. save_image函数的默认文件名是/home/sunil/image/看起来像一个目录,没有扩展名。 Try changing the function definition to 尝试将函数定义更改为

def save_image(data, fname = '/home/sunil/image/processed.jpg', swap_channel = True):

or maybe, since you want to save multiple files into a same directory, introduce a pattern for file name: 或者,由于您要将多个文件保存到同一目录中,请引入一种文件名模式:

def save_image(data, fname = '/home/sunil/image/processed_{n:03d}.jpg', swap_channel = True, n=0):
    if swap_channel:
        data = data[..., ::-1]
        cv2.imwrite(fname.format(n=n), data)

then call the function like: 然后像下面这样调用函数:

save_image(image[: ,: , ::-1], n=n)

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

相关问题 重命名多个图像并使用python保存到另一个文件夹 - Rename multiple images and save into another folder with python 如何从一个文件夹中调整多个图像的大小,将它们转换为灰度并将它们保存到另一个文件夹中? - How to resize multiple images from a folder, convert them into grayscale and save them into another folder? 在文件夹中转换RGBA图像并将其以'.pgm'格式保存到另一个文件夹 - Converting RGBA Images in a folder and save it to another folder in '.pgm' format 如何搜索目录中的图像并将它们保存到另一个文件夹中? - How do I search through images in the directory and save them into another folder? 如何将数据集的图像列表保存(写入)到新文件夹-openCV Python? - How to save (write) a list of images from a dataset into a new folder - openCV Python? 逐个打开图像,绘制矩形,然后保存在另一个文件夹中 - Open images one by one, draw rectangle and then save in another folder Python将图像保存到文件夹中 - Python save images into the folder 如何在文件夹中创建图像列表及其名称 - How to create a list of images and their names in a folder 如何将图像从列表下载到 Python 中的文件夹 - How to download images from a list to a folder in Python 如何将多个图像从一个文件夹移动到 python 中的另一个文件夹? - how to move multiple images from a folder to another folder in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM