Ask Your Question

Revision history [back]

Opencv 3.4.6 Tensorflow c++ crashes on setInput

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();