Opencv 3.4.6 Tensorflow c++ crashes on setInput

asked 2019-09-19 02:21:37 -0600

Hello,

I have tried searching everywhere but I can't seem to get an answer for this. I wrote this code in python and it works perfectly fine but can't get it to work in c++. Any help would be greatly appreciated.

Python version:

tensorflowNet = cv2.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'frozen_inference_graph.pbtxt') 
img = cv2.imread('images/test/DSC_0274.JPG')
rows, cols, channels = img.shape
tensorflowNet.setInput(cv2.dnn.blobFromImage(img, size=(640, 640), swapRB=True, crop=False))
networkOutput = tensorflowNet.forward()

The same c++ version that doesnt work static dnn::Net net1 = cv::dnn::readNetFromTensorflow("frozen_inference_graph.pb", "frozen_inference_graph.pbtxt");

    cv::Mat img = cv::imread("DSC_0274.JPG");

    Mat inputBlob = dnn::blobFromImage(img, 1.0, Size(640,640), cv::Scalar(), true, false);
    net1.setInput(inputBlob); // Crashes here with memory access error. net1 is a valid object and I can access its functions. What am i doing wrong?
    Mat result = net1.forward();
edit retag flag offensive close merge delete

Comments

Check image size in C++

LBerger gravatar imageLBerger ( 2019-09-19 03:52:08 -0600 )edit

Hey, thanks for the reply!

It says 3 channels with size, 2304 x 4096. I tried resizing it to 640,640 but it still crashes. Any other ideas? The code looks identical to me for python and c++. Thanks again!

RootbeerDev gravatar imageRootbeerDev ( 2019-09-19 04:48:59 -0600 )edit

Can you check opencv version ? python print (cv2.getBuildInformation())

c++ cout<<getbuildinformation()< p="">

LBerger gravatar imageLBerger ( 2019-09-19 09:02:44 -0600 )edit