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

查看:82
本文介绍了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天全站免登陆