首页 > 解决方案 > 如何使用 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()

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

标签: google-colaboratoryglobface-detectionopencv-python

解决方案


推荐阅读