cv2.imwrite() will not write the image to another directory if the directory does not exist. First you need to create a directory before trying to write to it:
import os dirname = 'test' os.mkdir(dirname)
Here you can either write to the directory without changing the working directory:
cv2.imwrite(os.path.join(dirname, face_file_name), image)
Or change the working directory and omit the directory prefix, depending on your needs:
os.chdir(dirname) cv2.imwrite(face_file_name, image)
source share