【问题标题】:OpenCV3.0 - Imgcodecs.imread returns empty fileOpenCV3.0 - Imgcodecs.imread 返回空文件
【发布时间】:2016-11-07 12:42:26
【问题描述】:

我是 OpenCV 的新手 - 在 Android 上使用 OpenCV310。

当我对存在的文件调用 Imgcodecs.imread 时,我总是得到一个空的 Mat。 有人可以帮帮我吗?

代码是:

File root = Environment.getExternalStorageDirectory();
File file = new File(root, "1.jpg");
Log.e(getString(R.string.app_name), "File exists: " + file.exists());
Log.e(getString(R.string.app_name), "Trying to read: " + file.getAbsolutePath());
Mat BGRMat = Imgcodecs.imread(file.getAbsolutePath(),Imgcodecs.CV_LOAD_IMAGE_COLOR);
if(BGRMat.empty())
{
      Log.e(getString(R.string.app_name), "Failed, Empty! Details: " + BGRMat);
}
else
{
      Log.e(getString(R.string.app_name), "Success! Details: " + BGRMat);
} 

我得到的日志是:


07-05 20:53:26.941 28555-28555/com.sunshine.spotdetector E/SpotDetector:文件存在:真实
07-05 20:53:26.941 28555-28555/com.sunshine.spotdetector E/SpotDetector:尝试阅读: /storage/emulated/0/1.jpg
07-05 20:53:26.941 28555-28555/com.sunshine.spotdetector E/SpotDetector:失败,空! 详细信息:Mat [ 0*0*CV_8UC1, isCont=false, isSubmat=false, nativeObj=0x7f97b2a660, dataAddr=0x0]

提前致谢!

【问题讨论】:

    标签: android opencv imread


    【解决方案1】:

    让我回答我自己的问题。这是一个愚蠢的错误: 我忘了添加android.permission.READ_EXTERNAL_STORAGE, 所以它返回 0 大小的 Mat

    【讨论】:

    • 如果正确,您应该接受自己的答案。
    猜你喜欢
    • 2019-10-12
    • 2021-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-23
    • 2014-12-13
    • 2016-02-06
    相关资源
    最近更新 更多