尝试加载图像与Highgui.imread(+ OpenCV的Andr​​oid版) [英] Try to load image with Highgui.imread (OpenCV + Android)

查看:202
本文介绍了尝试加载图像与Highgui.imread(+ OpenCV的Andr​​oid版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试加载图像:

    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());
    }

但大小= 0(高度/宽度)。

But the size=0 (height/width).

推荐答案

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

The fact that the file exists doesn't mean that OpenCV was able to read its contents.

你应该做的却是:

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

有是在<一的文档的最后一个大笔记href=\"http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html#Mat%20imread%28const%20string&%20filename,%20int%20flags%29\"相对=nofollow> imread() 指出以下:

There is a big note at the end of the docs of imread() that states the following:

的功能由内容确定的图像的类型,而不是由文件扩展名。

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

您应该在继续之前检查文档。请确保您可以编写负载和冒险更复杂的东西之前,从盘面显示图像的简单的OpenCV的应用程序。

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.

这篇关于尝试加载图像与Highgui.imread(+ OpenCV的Andr​​oid版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆