Skip to content

Dnn.BlobFromImage returns (-1 * -1) Mat #12520

@peterbence3

Description

@peterbence3

I'm using OpenCV 3.4.3 in java in order to import and use a convolutional neural network built with Caffe. However the function BlobFromImage is returning an empty Mat, and i'm getting the following error when calling the net.forward():

Code:

 import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.dnn.Dnn;
import org.opencv.dnn.Net;
import org.opencv.imgcodecs.Imgcodecs;

public class OpenCVTests {

	public static void main(String[] args) {

		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

		System.out.println("Loading caffe model...");
		Net net = Dnn.readNetFromCaffe("C:\\Program Files\\Docker\\volumes\\vol1\\model.prototxt");

		Mat image = Imgcodecs.imread("C:\\Users\\Administrator\\Desktop\\cat.jpg");
		System.out.println(image);

		Mat blob = Dnn.blobFromImage(image, 1.0f, new Size(224, 224));
		System.out.println(blob);

		net.setInput(blob);
		Mat result = net.forward();
		System.out.println(result);

	}
}

Output:

Loading caffe model...
Mat [ 224*224*CV_8UC3, isCont=true, isSubmat=false, nativeObj=0x19659e40, dataAddr=0x19678ac0 ]
Mat [ -1*-1*CV_32FC1, isCont=true, isSubmat=false, nativeObj=0x1965a070, dataAddr=0x197a3100 ]
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.3) Z:\Karbala\build tools\opencv-3.4.3\modules\dnn\src\layers\convolution_layer.cpp:233: error: (-215:Assertion failed) blobs.size() != 0 in function 'cv::dnn::ConvolutionLayerImpl::getMemoryShapes'
]
	at org.opencv.dnn.Net.forward_1(Native Method)
	at org.opencv.dnn.Net.forward(Net.java:62)
	at test.OpenCVTests.main(OpenCVTests.java:31)

Prototxt:

model.prototxt

Any help would be highly appreciated, thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions