Something is wrong with VS2015 C++ Environment when using OpenCV DNN module [closed]

asked 2018-11-28 01:11:48 -0600

StefanCepa995 gravatar image

updated 2018-11-28 01:38:01 -0600

I have a problem that I cannot understand at all. Me and a colleague of mine both have OpenCV 3.3.0 and Visual Studio 2015 installed on our machines (v14 compiler). For some reason calls to OpenCV DNN module methods such as readNetFromTensorflow work on his machine and on mine they do not. The code is pretty basic, as you can see I have also tried to use createTensorflowImporter and the result is always the same. Every time I run it through debugger network_layers variable has only one element and its NULL. Once again, the code works perfectly fine on colleagues machine, but I will post the code anyways along with the screenshot from debugger.

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <vector>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;
using namespace cv;
using namespace cv::dnn;

class CharNet {

private:
    Net network;
    string output_layer;

public:

    CharNet(string path) {
        try {

            cv::Ptr <Importer> imp = createTensorflowImporter(path);

            if (imp == NULL) {
                cout << "Failed to Load .pb file" << endl;
            }
            else {
                cout << "Successfully loaded .pb file" << endl;
                cout << "Default Name: " << imp->getDefaultName() << endl;
                imp->populateNet(network);
            }


            //network = readNetFromTensorflow(path);

            vector<String> network_layers = network.getLayerNames();
            cout << "There are " << network_layers.size() << " layers" << endl;
            for (int i = 0; i < network_layers.size(); i++) {
                cout << network_layers[i] << endl;
                if ( network_layers[i].find("Softmax") != std::string::npos ) {
                   output_layer = network_layers[i];
                   break;
                }
            }

        }
        catch (cv::Exception& e) {
            cerr << "Exception: " << e.what() << endl;
            if (network.empty()) {
                cerr << "Can't load the model" << endl;
            }
        }
    }



};

int main(int argc, char** argv) {



    cout << "***** OPENCV VERSION *****" << endl;
    cout << "OpenCV version : " << CV_VERSION << endl;
    cout << "Major version : " << CV_MAJOR_VERSION << endl;
    cout << "Minor version : " << CV_MINOR_VERSION << endl;
    cout << "Subminor version : " << CV_SUBMINOR_VERSION << endl;
    cout << "\n";

    string model = "C:/Users/stefan_cepa995/source/repos/OpenCV_Test/OpenCV_Test/tf_model.pb";

    CharNet* obj = new CharNet(model);

    return 0;

}

Note that I have tried both relative and absolute paths, the result is the same.

Here is screenshot of all the variables in the program while running the debugger:

C:\fakepath\Screenshot_56.png

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by berak
close date 2018-11-28 01:37:37.789169

Comments

please do not post duplicates here, rather edit your previous question

(also, screenshots of errors are useless here, since those can't be quoted or indexed for search)

((and, ummm, you're trying to debug a release project ?))

berak gravatar imageberak ( 2018-11-28 01:37:33 -0600 )edit

have a look here and update your outdated opencv libs !

berak gravatar imageberak ( 2018-11-28 01:46:20 -0600 )edit
1

I am sorry. I have been so stuck on this problem I did not realize I posted a duplicate question. I apologize it wont happen again. If this information you gave me does not help, I will update my previous quesiton. Thank you

StefanCepa995 gravatar imageStefanCepa995 ( 2018-11-28 01:50:18 -0600 )edit

there is no more createTensorflowImporter() method in current 3.4 or master.

seriously, noone will be able to reproduce your problem like that.

(and again, you can only successfully debug a DEBUG project. everything you see in RELEASE mode is bogus)

berak gravatar imageberak ( 2018-11-28 01:55:34 -0600 )edit