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)
错误回溯(最近一次通话) 在 38 for n in range(0,len(onlyfiles)): 39#保存并显示带标签的图像。 ---> 40 save_image(image [:,:,::-1]) 41图片(fname,onlyfiles [n]) 42 imshow(图片)
save_image中的(数据,fname,swap_channel) 2,如果swap_channel: 3数据=数据[...,::-1] ----> 4 cv2.imwrite(fname,data)
错误:OpenCV(4.1.0)/io/opencv/modules/imgcodecs/src/loadsave.cpp:662:错误:(-2:未指定错误)在函数'imwrite_中找不到指定扩展名的编写器'
答案 0 :(得分:0)
save_image函数的默认文件名是/home/sunil/image/
,看起来像目录,没有扩展名。尝试将函数定义更改为
def save_image(data, fname = '/home/sunil/image/processed.jpg', swap_channel = True):
或者,也许是因为您要将多个文件保存到同一目录中,所以请引入一种文件名模式:
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)
然后调用如下函数:
save_image(image[: ,: , ::-1], n=n)