Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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;

}

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

C:\fakepath\Screenshot_56.png

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

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