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, 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?
opencv version ? os ? did you build the python bindings ?
can you put your model somewhere, so ppl can try to reproduce the problem ?
The OpenCV used in C++ is the default one coming with OpenVino, version 4.3, the OpenCV used in python is version 4.4. I am running my code on Windows10. The model can be found at this link (I am using the deploy version): https://github.com/ishay2b/VanillaCNN/tree/master/ZOO