Ask Your Question

lorenzo's profile - activity

2020-05-05 08:16:10 -0600 received badge  Famous Question (source)
2019-07-24 04:30:05 -0600 received badge  Notable Question (source)
2019-01-21 21:29:51 -0600 received badge  Popular Question (source)
2017-12-14 13:44:20 -0600 received badge  Supporter (source)
2017-12-14 13:38:22 -0600 commented answer OpenCV + Darknet - Error when initializing darknet

Very fast and complete answer. Thank you so much!!

2017-12-14 13:35:21 -0600 marked best answer OpenCV + Darknet - Error when initializing darknet

Hi! I'm an university student and for my thesis work I have to perform object detection using YOLO.

I read the related paper and I completed all of the command line examples located at https://pjreddie.com/darknet/yolo/.

Now I have to do the same using OpenCV. I'm using Xubuntu 16.04 LTS x64, OpenCV 3.3.1 and Qt Creator 4.5.0.

For the moment I'm stuck at these few lines because I can't succeed to initialize the network.

#include <opencv2/core.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/dnn/shape_utils.hpp>
#include <iostream>

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

int main()
{
    // The path to the .cfg file with text description of the network architecture.
    String modelConfiguration = "/home/lorenzo/Scrivania/yolo-9000/darknet/cfg/yolo-9000.cfg";
    // The path to the .weights file with learned network.
    String modelBinary = "/home/lorenzo/Scrivania/yolo-9000/yolo9000-weights/yolo-9000.weights";

    //! [Initialize network]
    //Reads a network model stored in Darknet model files.
    dnn::Net net = readNetFromDarknet(modelConfiguration, modelBinary);
    //! [Initialize network]

    if (net.empty())
    {
        cerr << "Can't load network by using the following files: " << endl;
        cerr << "cfg-file:     " << modelConfiguration << endl;
        cerr << "weights-file: " << modelBinary << endl;
        exit(-1);
    }

    return 0;
}

It returns me the following error.

OpenCV Error: Parsing error (Failed to parse NetParameter file: /home/lorenzo/Scrivania/yolo-9000/darknet/cfg/yolo-9000.cfg) in ReadNetParamsFromCfgFileOrDie,
                      file /home/lorenzo/Scrivania/opencv-3.3.1/modules/dnn/src/darknet/darknet_io.cpp, line 612
terminate called after throwing an instance of 'cv::Exception'
what():  /home/lorenzo/Scrivania/opencv-3.3.1/modules/dnn/src/darknet/darknet_io.cpp:612:
            error: (-212) Failed to parse NetParameter file: /home/lorenzo/Scrivania/yolo-9000/darknet/cfg/yolo-9000.cfg in function ReadNetParamsFromCfgFileOrDie

I opened the file at "/home/lorenzo/Scrivania/opencv-3.3.1/modules/dnn/src/darknet/darknet_io.cpp" and I found the following code at lines 609:614.

void ReadNetParamsFromCfgFileOrDie(const char *cfgFile, darknet::NetParameter *net)
        {
            if (!darknet::ReadDarknetFromCfgFile(cfgFile, net)) {
                CV_Error(cv::Error::StsParseError, "Failed to parse NetParameter file: " + std::string(cfgFile));
            }
        }

The output of cv::getBuildInformation() is the following.

General configuration for OpenCV 3.3.1 =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2017-12-13T21:08:24Z
    Host:                        Linux 4.10.0-42-generic x86_64
    CMake:                       3.5.1
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2
      SSE4_1 (3 files):          + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (2 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (8 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                /usr/bin/c++  (ver 5.4.0)
    C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 ...
(more)
2017-12-14 13:35:21 -0600 received badge  Scholar (source)
2017-12-14 11:55:22 -0600 asked a question OpenCV + Darknet - Error when initializing darknet

OpenCV + Darknet - Error when initializing darknet Hi! I'm an university student and for my thesis work I have to perfo