java 尝试使用 Highgui.imread (OpenCV + Android) 加载图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10752556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Try to load image with Highgui.imread (OpenCV + Android)
提问by ChHaupt
I try to load an image:
我尝试加载图像:
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());
}
But the size=0 (height/width).
但大小=0(高/宽)。
回答by karlphillip
The fact that the file exists doesn't mean that OpenCV was able to read its contents.
文件存在的事实并不意味着 OpenCV 能够读取其内容。
What you should be doing instead is:
你应该做的是:
Mat m = Highgui.imread(file.getAbsolutePath());
if (img.data)
{
showToast("Height: " + m.height() + " Width: " + m.width());
}
else
{
// print error and abort execution
}
There is a big note at the end of the docs of imread()
that states the following:
在文档的末尾有一个重要的注释imread()
,说明如下:
The function determines the type of an image by the content, not by the file extension.
该函数根据内容而不是文件扩展名确定图像的类型。
You should check the docs before proceeding. Make sure you can write a simple OpenCV application that loads and displays an image from the disk before adventuring on more complex stuff.
在继续之前,您应该检查文档。在尝试更复杂的东西之前,请确保您可以编写一个简单的 OpenCV 应用程序,从磁盘加载和显示图像。
回答by Keshan De Silva
try to use
尝试使用
IplImage orgImage= cvLoadImage(fileName);
It is working on JavaCV wrapper. But i don't no will it work on pure OpenCV.
它正在处理 JavaCV 包装器。但我不知道它不会在纯 OpenCV 上工作。