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