[英]Python/OpenCV: Save pictures with defined path and name
would like to save an image in a defined path and with a defined name.想要将图像保存在定义的路径中并具有定义的名称。 The path is fixed, but the name from a variable.
路径是固定的,但名称来自变量。 With the name alone is no problem as you see above but how can i input the fixed path?
正如您在上面看到的,仅使用名称是没有问题的,但是我如何输入固定路径?
import cv2
img_name = "TEST"
cam = cv2.VideoCapture(0)
cam.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
while(True):
ret, frame = cam.read()
cv2.imshow('preview',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
img_name = "{}.jpg".format(img_name)
cv2.imwrite(img_name, frame)
break
cam.release()
cv2.destroyAllWindows()
Thanks and best regards :)谢谢和最好的问候:)
import os
import cv2
img_name = "TEST"
cam = cv2.VideoCapture(0)
cam.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
while(True):
ret, frame = cam.read()
cv2.imshow('preview',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
img_name = os.path.join("your_path_here", "{}.jpg".format(img_name))
cv2.imwrite(img_name, frame)
break
cam.release()
cv2.destroyAllWindows()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.