The problem is that you are not using a separator between the directory name and the file name. What your code does, is join the nome
with the framesObtidos
to form a single filename. See the example below:
dir1 = "Dir1/"
dir2 = "Dir2"
arquivo = "arquivo.png"
print(dir1 + dir2 + arquivo) # Saída: Dir1/Dir2arquivo.png
To fix this problem just add "\\"
amid nome
and framesObtidos
thus:
cv2.imwrite("Banco-de-Faces\\" + nome + "\\" + str(framesObtidos) + ".png", imagemRosto)
One improvement you can make in your code is to use the function os.path.join
to merge directories with the filename using a suitable separator for your operating system. This way, you avoid conflicts and also make the code more organized and beautiful. Example:
filename = os.path.join("Banco-de-Faces", nome, str(framesObtidos) + ".png")
cv2.imwrite(filename, imagemRosto)