java - 尝试使用 Highgui.imread (OpenCV + Android) 加载图像

标签 java android opencv image-processing

我尝试加载图像:

    File root = Environment.getExternalStorageDirectory();
    File file = new File(root, "image.gif");
    Mat m = Highgui.imread(file.getAbsolutePath());
    if(file.exists()){
        showToast("Height: " + m.height() + " Width: " + m.width());
    }

但是size=0(高/宽)。

最佳答案

文件存在的事实并不意味着 OpenCV 能够读取其内容。

你应该做的是:

Mat m = Highgui.imread(file.getAbsolutePath());
if (img.data)
{
     showToast("Height: " + m.height() + " Width: " + m.width());
}
else
{
     // print error and abort execution
}

imread() 的文档末尾有一个大注释声明如下:

The function determines the type of an image by the content, not by the file extension.

您应该在继续之前检查文档。在尝试更复杂的内容之前,请确保您可以编写一个简单的 OpenCV 应用程序来加载和显示磁盘中的图像。

关于java - 尝试使用 Highgui.imread (OpenCV + Android) 加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10752556/

相关文章:

在 Eclipse 中创建一个独立的可执行文件

java - 更新 JList 模型导致 StackOverflowError

java - java 中有关 SQL 语法的错误,而查询在 MySQL 中正常工作

android - Droidparts ClearableEditText

android - 如何在 View 中显示首选项

c++ - Ubuntu 14.04上编译openCV程序错误

java - 适用于 Java 2.1 和 MongoDB 的 Play 框架

java - struts 2 中的动态角色

Android 应用程序 IF 语句未按预期运行

python opencv crop使用等高线层次结构