Ask Your Question

Pawan's profile - activity

2019-07-16 00:26:15 -0600 marked best answer DNN module different results on windows and ubuntu for a custom yolov2 based model[SOLVED]

System information (version)

  • OpenCV => 4.0.1
  • Operating System / Platform => Windows 10 64 Bit
  • Compiler => Visual Studio 2015

  • Operating System / Platform => Ubuntu 18.04.1 LTS 64 Bit

  • Compiler => gcc 7.4.0

Detailed description

I have a custom network based on tiny yolov2 and it is trained using the darknet framework. Now when i do inference using this network on windows the results are as expected, But on ubuntu results are very different and not as expected. - on windows

char_det_win1

  • on ubuntu

char_detection_ubuntu1

I have tried different version of opencv (4.01, 3.4.4, 3.4.2) and on windows the results are always correct but on ubuntu thery are always wrong.

Also i have tried darknet's C++ API and results in it are correct on both windows and ubuntu but i cannot use it because its CPU inference is very slow compared to opencv's.

Also it might look as if only the bbox's are wrong but sometimes the number of objects detected are are also less on ubuntu compared to windows.

The issue seems to be only for this network, i have tried tiny-yolov3, tiny-yolov2 and SSD on both windows and ubuntu and they work fine on both platforms.

Steps to reproduce

model files and test images

#include <string>
#include <vector>
#include <opencv2/opencv.hpp>

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

float confThreshold = 0.5; // Confidence threshold
float nmsThreshold = 0.4;  // Non-maximum suppression threshold
int inpWidth = 288;  // Width of network's input image
int inpHeight = 128; // Height of network's input image
vector<string> classes;

void postprocess(Mat& frame, const vector<Mat>& out);
void drawPred(int classId, float conf, int left, int top, int right, int bottom, Mat& frame);
vector<String> getOutputsNames(const Net& net)

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

    classes.push_back("char");

    std::string image_file_path = "images/img_6.jpg";
    Mat frame = cv::imread(image_file_path);

    Net net = readNetFromDarknet("net.cfg", "net.weights");
    net.setPreferableBackend(DNN_BACKEND_OPENCV);
    net.setPreferableTarget(DNN_TARGET_CPU);

    Mat blob;   
    blobFromImage(frame, blob, 1 / 255.0, cv::Size(inpWidth, inpHeight), Scalar(0, 0, 0), true, false);

    vector<Mat> outs;
    net.forward(outs, getOutputsNames(net));

    postprocess(frame, outs);

    imshow("detections", detection_img);
    cv::waitKey(0);

}

vector<String> getOutputsNames(const Net& net)
{
    static vector<String> names;
    if (names.empty())
    {
        //Get the indices of the output layers, i.e. the layers with unconnected outputs
        vector<int> outLayers = net.getUnconnectedOutLayers();

        //get the names of all the layers in the network
        vector<String> layersNames = net.getLayerNames();

        // Get the names of the output layers in names
        names.resize(outLayers.size());
        for (size_t i = 0; i < outLayers.size(); ++i)
            names[i] = layersNames[outLayers[i] - 1];
    }
    return names;
}

void postprocess(Mat& frame, const vector<Mat>& outs)
{
    vector<int> classIds;
    vector<float> confidences;
    vector<Rect> boxes;

    for (size_t i = 0; i < outs.size(); ++i)
    {
        // Scan through all the bounding boxes output from the network and keep only the
        // ones with high confidence scores. Assign the box's class label as the class
        // with the highest score for the box.
        float* data = (float*)outs[i].data;
        for (int j ...
(more)
2019-07-15 21:48:28 -0600 received badge  Self-Learner (source)
2019-07-15 08:44:35 -0600 answered a question DNN module different results on windows and ubuntu for a custom yolov2 based model[SOLVED]

The issue was related to region layer's output anchor size normalization and was in solved in PR #14070 as mentioned by

2019-07-12 02:53:46 -0600 received badge  Editor (source)
2019-07-12 02:53:46 -0600 edited question DNN module different results on windows and ubuntu for a custom yolov2 based model[SOLVED]

DNN module different results on windows and ubuntu for a custom yolov2 based model System information (version) OpenCV

2019-07-12 02:51:52 -0600 asked a question DNN module different results on windows and ubuntu for a custom yolov2 based model[SOLVED]

DNN module different results on windows and ubuntu for a custom yolov2 based model System information (version) OpenCV

2019-05-06 02:17:18 -0600 commented answer How to process output of detection network when batch of images is used as network input

thanks was able to parse network output using this information.

2019-05-06 02:17:09 -0600 commented answer How to process output of detection network when batch of images is used as network input

thanks man was able to parse network output using this information.

2019-05-06 00:28:42 -0600 asked a question How to process output of detection network when batch of images is used as network input

How to process output of detection network when batch of images is used as network input I have a yolov3 network trained

2017-10-07 00:36:49 -0600 asked a question cv::cudacodec::VideoReader unable to Play rtsp stream

cv::cudacodec::VideoReader unable to Play rtsp stream System information OpenCV => 3.3.0 Operating System / Platfor

2017-10-06 01:02:46 -0600 commented question Can't open RTSP stream with OpenCV cuda video_reader

@gopalkildoliya i am also facing the same error. were you able to solve this ?

2017-09-13 01:33:38 -0600 received badge  Enthusiast
2017-09-11 08:36:55 -0600 asked a question Why does cuda::VideoCapture consumes more memory than videocapture

Why does cuda::VideoCapture consumes more memory than videocapture I have created a simple program which plays a 1280 x

2016-04-29 02:10:34 -0600 asked a question Segmentation Fault When OpenCV Program run as a Video Filter Plugin for VLC

I Downloaded the OpenCV 3.1 source code and compiled it using MinGW. Make Files are generated using CMake. I also turned on the CMake_GNUtoMS option CMake so that .lib files are generated along with .a files.

Now i have written a VLC OpenCV filter which conatins Code for FaceDetection (reference). This filter compiles fine (linked to opencv_world310.lib) but when i run a test program which tells VLC to use this Filter i get a Segmentation Fault at cv::CascadeClassifier::load(cv::String const&). I have tried running it after linking this Filter against opencv_world310.dll.a but the same Error persists.

Filter code:

using namespace cv;

struct filter_sys_t
{
    CascadeClassifier detector;
};


static int  OpenFilter ( vlc_object_t * );
static void CloseFilter( vlc_object_t * );

static picture_t *Filter( filter_t *, picture_t * );

vlc_module_begin ()
    // Set vlc Description, Shortname, Capability, Category .etc
    set_callbacks( OpenFilter, CloseFilter )
vlc_module_end ()


static int OpenFilter( vlc_object_t *p_this )
{
    filter_t *p_filter = (filter_t*)p_this;

    filter_sys_t *p_sys;

    /* Allocate the memory needed to store the decoder's structure */
    if( ( p_filter->p_sys = p_sys =
          (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
    {
        return VLC_ENOMEM;
    }

    //init the video_filter_event_info_t struct

    //create the VIDEO_FILTER_EVENT_VARIABLE


    cv::String f = "C:\\OpenCV\\sources\\data\\haarcascades\\haarcascade_frontalface_alt.xml";

    msg_Dbg(p_filter, "going to load detector");

    bool loaded = p_sys->detector.load(f);

    msg_Dbg( p_filter, "detector loaded %d", loaded);

    if (!loaded)
    {
        return VLC_EGENERIC;
    }

    return VLC_SUCCESS;
}

/*****************************************************************************
 * CloseFilter: clean up the filter
 *****************************************************************************/
static void CloseFilter( vlc_object_t *p_this )
{
    filter_t *p_filter = (filter_t*)p_this;
    filter_sys_t *p_sys = p_filter->p_sys;

    free( p_sys );

    var_Destroy( p_filter->p_libvlc, VIDEO_FILTER_EVENT_VARIABLE);
}

/****************************************************************************
 * Filter: Check for faces and raises an event when one is found.
 ****************************************************************************/
static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{
    msg_Dbg( p_filter, "Entered Filter()");
    int groundThreshold = 2;
    double scaleStep = 1.1;
    Size minimalObjectSize(80, 80);
    Size maximalObjectSize(200, 200);

    IplImage** p_img = NULL;
    filter_sys_t *p_sys = p_filter->p_sys;

    if ((!p_pic) )
    {
        msg_Err( p_filter, "no image array" );
        return NULL;
    }

    //cast the picture_t to array of IplImage*
    p_img = (IplImage**) p_pic;

    //check the image array for validity
    if ((!p_img[0]))    //1st plane is 'I' i.e. greyscale
    {
        msg_Err( p_filter, "no image" );
        return NULL;
    }
    msg_Dbg( p_filter, "Going to convert iplImage to MAT");
    Mat img = cvarrToMat(p_img);
    Mat image_grey;
    // Convert input to greyscale 
    cvtColor(img, image_grey, CV_BGR2GRAY);

    //perform face detection
    std::vector<Rect> found;

    msg_Dbg( p_filter, "Going to detect face");
    //// Detect faces
    p_sys->detector.detectMultiScale(image_grey, found, scaleStep, groundThreshold, 0 | 2, minimalObjectSize,maximalObjectSize);

    ////// Draw the results into mat 
    if (found.size() > 0) {
        msg_Dbg( p_filter, "Faces Found: %d", found.size());
            for (int i = 0; i <= found.size() - 1; i++) {

                    rectangle(img, found[i].br(), found[i].tl(), Scalar(0, 255, 0), 1, 8, 0);

            }
    }
    return p_pic;
}

BUT when i run the FaceDetection Code as a independent program (linked against the same .lib/.a and Using Same opencv_world310.dll) it Works Good.

ERROR that i get:

Program received signal SIGSEGV, Segmentation fault.
0x0c300bcd in cv::CascadeClassifier::load(cv::String const&) ()
   from C:\Windows\SysWOW64\libopencv_world310.dll
(gdb) bt
#0  0x0c300bcd in cv::CascadeClassifier::load(cv::String const&) ()
   from C:\Windows\SysWOW64\libopencv_world310.dll
#1  0x088593a8 in ?? ()
#2  0x6a7bef8a in module_need ()
   from C:\test\libvlccore.dll
#3  0x0925a2c1 in vlc_entry_license__1_1_0g ()
   from C:\test\libopencv_wrapper_plugin.dll
#4  0x00000001 in ...
(more)