GVKun编程网logo

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

2

对于想了解OpenCV-将图像保存到所选的特定文件夹的读者,本文将是一篇不可错过的文章,我们将详细介绍opencv保存图片到指定路径,并且为您提供关于Android11:将文件保存到所选文件夹、and

对于想了解OpenCV-将图像保存到所选的特定文件夹的读者,本文将是一篇不可错过的文章,我们将详细介绍opencv保存图片到指定路径,并且为您提供关于Android 11:将文件保存到所选文件夹、android – 如何将图像保存到外部存储器而不是保存在内部、Android – 将图像保存在特定文件夹中、bash – 使用curl命令将文件保存到特定文件夹的有价值信息。

本文目录一览:

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

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

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

答案1

小编典典

ebeneditos提供的解决方案运行完美。

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

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

import cv2import osimg = cv2.imread(''1.jpg'', 1)path = ''D:/OpenCV/Scripts/Images''cv2.imwrite(os.path.join(path , ''waka.jpg''), img)cv2.waitKey(0)

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

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

Android 11:将文件保存到所选文件夹

Android 11:将文件保存到所选文件夹

如何解决Android 11:将文件保存到所选文件夹?

在我的应用程序中,我使用 ActivityResultContracts.opendocumentTree() 来让用户选择设备存储中的文件夹并允许对其进行访问。 但是,在 Android 11 上,如果我尝试在所选文件夹中保存文件,则会出现以下异常: SecurityException: Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from ProcessRecord ...要求您使用 ACTION_OPEN_DOCUMENT 或相关 API 获取访问权限

在 Android 10 上 - 一切正常。 那么,如何将文件保存到 Android 11 上的选定文件夹?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

android – 如何将图像保存到外部存储器而不是保存在内部

android – 如何将图像保存到外部存储器而不是保存在内部

我不明白为什么人们说这是保存在外部存储器,因为当我使用这个代码,我签入我的SD卡没有文件

代码这个

OutputStream imageFileOS;
        int imageNum = 0;
        Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        File imagesFolder = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES),"Punch");
        if(!imagesFolder.exists()){
            imagesFolder.mkdirs(); // <----
        }
        String fileName = "image_" + String.valueOf(imageNum) + ".jpg";
        File output = new File(imagesFolder,fileName);
        while (output.exists()){
            imageNum++;
            fileName = "image_" + String.valueOf(imageNum) + ".jpg";
            output = new File(imagesFolder,fileName);
        }
        Uri uriSavedImage = Uri.fromFile(output);
        imageIntent.putExtra(MediaStore.EXTRA_OUTPUT,uriSavedImage);

当我运行代码并检查时,它有“内存/图片/打孔/图像_0.jpg”中的文件
但在SD卡中看不到(SD卡=外部存储卡16 GB)
请帮我 ..

解决方法

我认为你对getExternalStorageDirectory的作用感到困惑.

它获取由设备制造商指定的主存储目录.这通常是“sdcard”.注释中指定的“External_sd”实际上是辅助存储目录,不会在给定方法中返回.

这仍然不是受保护的内部存储,并且可以在连接时由Pcs安装和访问.

来自android文档:

Note: don’t be confused by the word “external” here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card,but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

Android – 将图像保存在特定文件夹中

Android – 将图像保存在特定文件夹中

我需要将使用我的应用程序拍摄的照片保存在特定文件夹中.我已经阅读了很多这个问题的解决方案,但我无法使它们中的任何一个工作,所以我寻求帮助.

MainActivity.java

public void onClick(View v) {

    Intent camera = new Intent(
            android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    //Folder is already created
    String dirName = Environment.getExternalStorageDirectory().getPath()
            + "/MyAppFolder/MyApp" + n + ".png";

    Uri uriSavedImage = Uri.fromFile(new File(dirName));
    camera.putExtra(MediaStore.EXTRA_OUTPUT,uriSavedImage);
    startActivityForResult(camera,1);

    n++;
}

AndroidManifest.xml中

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

解决方法

通过以下代码,它对我来说很好.

private void createDirectoryAndSaveFile(Bitmap imagetoSave,String fileName) {

    File direct = new File(Environment.getExternalStorageDirectory() + "/DirName");

    if (!direct.exists()) {
        File wallpaperDirectory = new File("/sdcard/DirName/");
        wallpaperDirectory.mkdirs();
    }

    File file = new File(new File("/sdcard/DirName/"),fileName);
    if (file.exists()) {
        file.delete();
    }
    try {
        FileOutputStream out = new FileOutputStream(file);
        imagetoSave.compress(Bitmap.CompressFormat.JPEG,100,out);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printstacktrace();
    }
}

bash – 使用curl命令将文件保存到特定文件夹

bash – 使用curl命令将文件保存到特定文件夹

我想从一些链接下载文件,并保存到我在终端编写的特定文件夹。使用curl命令下载文件到特定文件夹时,必须写什么特定选项?
你有点不具体。我不认为你可以给一个路径卷曲,但你可以CD到位置,下载和CD回来。
cd target/path && { curl -O URL ; cd -; }

这将只有在路径存在时下载。下载将保留远程文件名。下载后,将返回原始位置。

这会帮助你吗?

如果这比你的问题更复杂,你可以使用:

curl -o target/path/filename URL

注意第一个例子中的大O,第二个小O。

关于OpenCV-将图像保存到所选的特定文件夹opencv保存图片到指定路径的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Android 11:将文件保存到所选文件夹、android – 如何将图像保存到外部存储器而不是保存在内部、Android – 将图像保存在特定文件夹中、bash – 使用curl命令将文件保存到特定文件夹等相关知识的信息别忘了在本站进行查找喔。

本文标签: