OpenCV-将图像保存到所选的特定文件夹 [英] OpenCV - Saving images to a particular folder of choice

查看:1812
本文介绍了OpenCV-将图像保存到所选的特定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习OpenCV和Python.我从网络摄像头捕获了一些图像并将其保存.但是默认情况下会将它们保存到本地文件夹中.我想将它们从直接路径保存到另一个文件夹.我如何解决它?

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?

推荐答案

ebeneditos提供的解决方案效果很好.

The solution provided by ebeneditos works perfectly.

但是,如果您在大型代码段的多个部分中都有cv2.imwrite(),并且想要更改保存图像的路径,则每次出现cv2.imwrite()时,都必须分别更改路径.

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.

正如Soltius所说,这是一种更好的方法.声明路径并将其作为字符串传递给cv2.imwrite()

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)

现在,如果要修改路径,只需更改path变量.

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

根据Kallz提供的解决方案进行编辑

Edited based on solution provided by Kallz

这篇关于OpenCV-将图像保存到所选的特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆