Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv::dnn::blobFromImage() works in python but fails in c++

I am using opencv dnn.Net with the same network and with the same image in python and C++. While in python everything is ok, in C++ I get an access violation error from an opencv.dll.

Here is my code in python:

net = cv2.dnn.readNet(model, config, "Caffe")
    input_img = cv2.imread(image_path)
    blob = cv2.dnn.blobFromImage(input_img, 0.0, (40, 40), 0, False, False, cv2.CV_32F )
    net.setInput(blob)
    result = net.forward()

In this case no errors and I get the expected output.

Now the code in c++:

net = cv::dnn::readNet(model, config, "Caffe");
    cv::Mat blob;
    blob = cv::dnn::blobFromImage(input_image, 1.0, cv::Size(40,40), cv::Scalar(0,0,0), false, false, CV_32F);
    net.setInput(blob);
    net.forward();

In this case I get access violation as I run net.forward().

Both images are the same, and the are alreay 40x40, 3 channels. model and config are the same paths in python and c++ so the same caffe`model is being used.

Here is the error transcript in case this can be a hint:

Exception thrown at 0x00007FFD2C1B12DE (vcruntime140.dll) in my_exe.exe: 0xC0000005: Access violation reading location 0x000001F972DB9000.

Why is the code failing in C++? How can I fix it?

cv::dnn::blobFromImage() works in python but fails in c++

I am using opencv dnn.Net with the same network and with the same image in python and C++. While in python everything is ok, in C++ I get an access violation error from an opencv.dll.

Here is my code in python:

net = cv2.dnn.readNet(model, config, "Caffe")
    input_img = cv2.imread(image_path)
    blob = cv2.dnn.blobFromImage(input_img, 0.0, 1.0, (40, 40), 0, False, False, cv2.CV_32F )
    net.setInput(blob)
    result = net.forward()

In this case no errors and I get the expected output.

Now the code in c++:

net = cv::dnn::readNet(model, config, "Caffe");
    cv::Mat blob;
    blob = cv::dnn::blobFromImage(input_image, 1.0, cv::Size(40,40), cv::Scalar(0,0,0), false, false, CV_32F);
    net.setInput(blob);
    net.forward();

In this case I get access violation as I run net.forward().

Both images are the same, and the are alreay 40x40, 3 channels. model and config are the same paths in python and c++ so the same caffe`model is being used.

Here is the error transcript in case this can be a hint:

Exception thrown at 0x00007FFD2C1B12DE (vcruntime140.dll) in my_exe.exe: 0xC0000005: Access violation reading location 0x000001F972DB9000.

Why is the code failing in C++? How can I fix it? it?