如何将从网络摄像头拍摄的图像保存到特定位置
How to save images taken from Webcam to a specific location
> if key == ord('s'):
> cv2.imwrite(os.path.join("\ima", x+'.jpg'), img=frame)
> webcam.release()
> cv2.waitKey(1650)
> cv2.destroyAllWindows()
ima 是我要保存图像的文件夹。当我 运行 以上代码时,我没有收到任何错误,但图像根本没有保存。
您需要完整路径。如果保存位置在您当前的工作目录中,您可以使用 os.getcwd() 或者您可以手动输入它,即:“C:\ima”
import os
os.path.join(os.getcwd(),"ima","newfile.jpg")
> if key == ord('s'):
> cv2.imwrite(os.path.join("\ima", x+'.jpg'), img=frame)
> webcam.release()
> cv2.waitKey(1650)
> cv2.destroyAllWindows()
ima 是我要保存图像的文件夹。当我 运行 以上代码时,我没有收到任何错误,但图像根本没有保存。
您需要完整路径。如果保存位置在您当前的工作目录中,您可以使用 os.getcwd() 或者您可以手动输入它,即:“C:\ima”
import os
os.path.join(os.getcwd(),"ima","newfile.jpg")