0
Hello. I would like to know how to create a folder every time the program is run and save to a specific location.
Currently it saves the file where the code is.
This is my current code:
import cv2
from datetime import datetime
import numpy as up
def main(args):
camera_port1 = 0
nFrames = 30
camera1 = cv2.VideoCapture(camera_port1)
data = datetime.now().strftime("%Y-%m-%d__%H-%M-%S")
file1 =("camera_1_{}.png".format(data))
print ("Digite <ESC> para sair / <s> para Salvar")
emLoop= True
while(emLoop):
retval1, img1 = camera1.read()
cv2.imshow('Foto1',img1)
k = cv2.waitKey(100)
if k == 27:
emLoop= False
elif k == ord('s'):
cv2.imwrite(file1,img1)
emLoop= False
cv2.destroyAllWindows()
camera1.release()
return 0
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))
Change the
file1
, to a directory, for example:C:\\Users\\nome_do_usuario\\Envs\\ambiente_python\\Lib\\site-packages\\cv2\\data\\imagem.png
plus the file name. The codefile1 =("camera_1_{}.png".format(data))
. Or use libraries to find a directoryos.path.dirname(cv2.__file__)
. Finally, read about the library the– danieltakeshi
Windows or Unix?
– JJoao