失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python opencv保存图片到指定路径_OpenCV-将图像保存到所选的特定文件夹

python opencv保存图片到指定路径_OpenCV-将图像保存到所选的特定文件夹

时间:2023-05-15 06:31:03

相关推荐

python opencv保存图片到指定路径_OpenCV-将图像保存到所选的特定文件夹

I'm learning OpenCV and Python. I captured some images from my webcam and saved them. But they are being saved by default into the local folder. I want to save them to another folder from direct path. How do I fix it?

解决方案

The solution provided by ebeneditos works perfectly.

But if you have cv2.imwrite() in several sections of a large code snippet and you want to change the path where the images get saved, you will have to change the path at every occurrence of cv2.imwrite() individually.

As Soltius stated, here is a better way. Declare a path and pass it as a string into cv2.imwrite()

import cv2

import os

img = cv2.imread('1.jpg', 1)

path = 'D:/OpenCV/Scripts/Images'

cv2.imwrite(os.path.join(path , 'waka.jpg'), img)

cv2.waitKey(0)

Now if you want to modify the path, you just have to change the path variable.

Edited based on solution provided by Kallz

如果觉得《python opencv保存图片到指定路径_OpenCV-将图像保存到所选的特定文件夹》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。