我尝试加载图像:
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/