如何使用 for 循环和 glob 进程将图像保存到文件夹中?

问题描述

for fil in glob.glob("disgust Original/*.jpg"):
  data = pyplot.imread(fil)
  detector = MTCNN()
  faces = detector.detect_faces(data)
  if not os.path.exists('Result'):
    os.makedirs('Result')
  for i in range(len(faces)):
    x1,y1,width,height = faces[i]['Box']
    x2,y2 = x1 + width,y1 + height
    pyplot.subplot(1,len(faces),i+1)
    pyplot.axis('off')
    pyplot.imshow(data[y1:y2,x1:x2])
    img = cv2.cvtColor(data[y1:y2,x1:x2],cv2.COLOR_BGR2GRAY)
    outfile=("Final gray-"+(fil)+"-Final Result.jpg")
    cv2.imwrite('Result/'+outfile,img)
    print(outfile)
  pyplot.show()

我想知道为什么它在循环后没有保存图像,而是只显示它^^" 非常感谢您的帮助

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)