Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using OpenCV dnn module as dll, Net::forward() error

Hello

Question : OpenCV DNN module, cv::dnn::Net::forward causes error and that Net::forward() is in a DLL that i made before. Since it came from DLL, debug messages are not displayed on Console window.

  1. Is there any way to display debug messages came from DLL that contains OpenCV?

  2. Is there a Special way to run cv::dnn::Net::forward() from DLL?

Situation : I have made .weight file and .cfg file through Yolov3 of Darknet to run it in OpenCV dnn module.

Language is C++.

Here is my code:

//Initialize Net, darkConfig = yolov3-tiny-obj.cfg darkModel = ...
Net net = readNetFromDarknet(darkConfig, darkModel);
net.setPreferableBackend(DNN_BACKEND_OPENCV);
net.setPreferableTarget(DNN_TARGET_CPU);

//Get Classes Names, ex Bird, Dog...
string classesFile = "obj.names";
ifstream ifs(classesFile.c_str());
string line;
while (getline(ifs, line))
{
    classes.push_back(line);
    cout << line << endl;
}

VideoCapture cap(0);
if (cap.isOpened() == false)
{
    cerr << "No cam" << endl;
    return -1;
}

Mat frame;
while (true)
{
    cap >> frame;
    if (frame.empty()) break;
    Mat blob;

    // Create a 4D blob from a frame.
    blobFromImage(frame, blob, 1 / 255.0, Size(288, 288), Scalar(0, 0, 0), true, false);

    //Sets the input to the network
    net.setInput(blob);

    // Runs the forward pass to get output of the output layers
    vector<Mat> outs;

    //BUT THIS LINE ALWAYS CAUSES ERROR
    net.forward(outs, getOutputsNames(net));

    // Remove the bounding boxes with low confidence
    postprocess(frame, outs);

    cv::imshow("Frame", frame);

    if (cv::waitKey(1) == 27)
        break;
}
return 0;

This Code works well when it is built by Visual Studio C++.

But When it is built as DLL and linked to another, the cv::dnn::Net::forward() causes error.

Other Net class' methods works well like Net::setInput() etc.

Even this error cannot be debugged like so :

image description

Conclusion:

  1. cv::dnn::Net::forward() works well in general C++ project.

  2. When that project is built as DLL and linked to another C++project, the only Net::forward() causes error.

How to solve this problem?

Thank you.

Using OpenCV dnn module as dll, Net::forward() error

Hello

Question : OpenCV DNN module, cv::dnn::Net::forward causes error and that Net::forward() is in a DLL that i made before. Since it came from DLL, debug messages are not displayed on Console window.

  1. Is there any way to display debug messages came from DLL that contains OpenCV?

  2. Is there a Special way to run call cv::dnn::Net::forward() from DLL?

Situation : I have made .weight file and .cfg file through Yolov3 of Darknet to run it in OpenCV dnn DNN module.

Language is C++.

Here is my code:Code:

//Initialize Net, darkConfig = yolov3-tiny-obj.cfg darkModel = ...
Net net = readNetFromDarknet(darkConfig, darkModel);
net.setPreferableBackend(DNN_BACKEND_OPENCV);
net.setPreferableTarget(DNN_TARGET_CPU);

//Get Classes Names, ex Bird, Dog...
string classesFile = "obj.names";
ifstream ifs(classesFile.c_str());
string line;
while (getline(ifs, line))
{
    classes.push_back(line);
    cout << line << endl;
}

VideoCapture cap(0);
if (cap.isOpened() == false)
{
    cerr << "No cam" << endl;
    return -1;
}

Mat frame;
while (true)
{
    cap >> frame;
    if (frame.empty()) break;
    Mat blob;

    // Create a 4D blob from a frame.
    blobFromImage(frame, blob, 1 / 255.0, Size(288, 288), Scalar(0, 0, 0), true, false);

    //Sets the input to the network
    net.setInput(blob);

    // Runs the forward pass to get output of the output layers
    vector<Mat> outs;

    //BUT THIS LINE ALWAYS CAUSES ERROR
    net.forward(outs, getOutputsNames(net));

    // Remove the bounding boxes with low confidence
    postprocess(frame, outs);

    cv::imshow("Frame", frame);

    if (cv::waitKey(1) == 27)
        break;
}
return 0;

This Code works well when it is built by Visual Studio C++.

But When it is built as DLL and linked to another, the cv::dnn::Net::forward() causes error.

Other Net class' methods works well like don't cause error Net::setInput() etc.

Even this error cannot be debugged like so :

image description

Conclusion:

  1. cv::dnn::Net::forward() works well in general C++ project.

  2. When that project is built as DLL and linked to another C++project, the only Net::forward() causes error.

How to solve this problem?

Thank you.

click to hide/show revision 3
retagged

updated 2019-12-02 00:38:33 -0600

berak gravatar image

Using OpenCV dnn module as dll, Net::forward() error

Hello

Question : OpenCV DNN module, cv::dnn::Net::forward causes error and that Net::forward() is in a DLL that i made before. Since it came from DLL, debug messages are not displayed on Console window.

  1. Is there any way to display debug messages came from DLL that contains OpenCV?

  2. Is there a Special way to call cv::dnn::Net::forward() from DLL?

Situation : I have made .weight file and .cfg file through Yolov3 of Darknet to run it in OpenCV DNN module.

Language is C++.

Here is my Code:

//Initialize Net, darkConfig = yolov3-tiny-obj.cfg darkModel = ...
Net net = readNetFromDarknet(darkConfig, darkModel);
net.setPreferableBackend(DNN_BACKEND_OPENCV);
net.setPreferableTarget(DNN_TARGET_CPU);

//Get Classes Names, ex Bird, Dog...
string classesFile = "obj.names";
ifstream ifs(classesFile.c_str());
string line;
while (getline(ifs, line))
{
    classes.push_back(line);
    cout << line << endl;
}

VideoCapture cap(0);
if (cap.isOpened() == false)
{
    cerr << "No cam" << endl;
    return -1;
}

Mat frame;
while (true)
{
    cap >> frame;
    if (frame.empty()) break;
    Mat blob;

    // Create a 4D blob from a frame.
    blobFromImage(frame, blob, 1 / 255.0, Size(288, 288), Scalar(0, 0, 0), true, false);

    //Sets the input to the network
    net.setInput(blob);

    // Runs the forward pass to get output of the output layers
    vector<Mat> outs;

    //BUT THIS LINE ALWAYS CAUSES ERROR
    net.forward(outs, getOutputsNames(net));

    // Remove the bounding boxes with low confidence
    postprocess(frame, outs);

    cv::imshow("Frame", frame);

    if (cv::waitKey(1) == 27)
        break;
}
return 0;

This Code works well when it is built by Visual Studio C++.

But When it is built as DLL and linked to another, the cv::dnn::Net::forward() causes error.

Other Net class' methods don't cause error Net::setInput() etc.

Even this error cannot be debugged like so :

image description

Conclusion:

  1. cv::dnn::Net::forward() works well in general C++ project.

  2. When that project is built as DLL and linked to another C++project, the only Net::forward() causes error.

How to solve this problem?

Thank you.