Try downloading the image using Highgui.imread (OpenCV + Android)

I am trying to upload 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 size = 0 (height / width).

+3
source share
2 answers

The fact that the file exists does not mean that OpenCV was able to read its contents.

Instead, you should:

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

At the end of the documentation imread(), a big note is noted:

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

Before proceeding, you must check the documents. Make sure you can write a simple OpenCV application that downloads and displays an image from disk before proceeding with more complex things.

+5
source

try using

IplImage orgImage= cvLoadImage(fileName); 

JavaCV. , OpenCV.

-2

All Articles