Skip to content

Dnn.blobFromImage() produces an invalid Mat in Android #10802

@IamTechknow

Description

@IamTechknow
System information (version)
  • OpenCV => 3.4.0
  • Operating System / Platform => Android 8.1 (arm64) (Google Pixel)
  • Compiler => Android Studio 3.0.1
Detailed description

I tried to get the DNN SSD Caffe example to work on Android with no success so far. This may be related to #10422 but I'm not sure because I get no CvException, instead I just get an invalid Mat object. This first happens when calling Dnn.blobFromImage(), then calling Dnn.setInput() and Dnn.forward() yielded no exception or response. I can verify that the DNN is successfully loaded, and the image to be object detected is also load successfully by Imgcodecs.imread(), but the Dnn.forward() call will yield an invalid Mat object.

What should happen instead is if there really is an error an exception is thrown, or there is no error and the detection succeeds and a Mat object with the classification probabilities is available.

Steps to reproduce

Here is a repository which may be built and deployed onto an Android 5.1+ device to reproduce the problem. For my repository I used the native libraries from the downloadable Android SDK from the releases page. To avoid slow APK loading and large repository size, I decided to make a symlink to the JNI libraries and also require the files to be added to the device ahead of time.

Make a breakpoint at MainActivity.java:74 in Android Studio:

Mat detection = dnn.forward("detection_out");

When the breakpoint is reached, evaluate the following statements:

Imgcodecs.imread(getPath(IMAGE_FILE))
Dnn.blobFromImage(Imgcodecs.imread(getPath(IMAGE_FILE)), 1.0, new Size(WIDTH, HEIGHT), MEAN, false, false)

Verify the imread() returns a Mat object with dimensions 480 * 720 * CV_32F, but the Mat object from Dnn.blobFromImage() returns a Mat object with dimensions -1 * -1 * CV_32F.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions