Opencv conflict namedWindow() and sscanf()

asked 2015-05-30 22:17:45 -0500

Hello! I have a problem when sharing cv::namedWindow() or cv::imshow() with sscanf() and strtod(). If sscanf() is above namedWindow(), it works fine, but if you put the after cv::namedWindow(), all numeric values are rounded off to whole numbers. Please help solve this problem!

a working script:

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <stdio.h>

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

//example 1
    std::string data="20.911111111";
    double value;
    value = strtod(data.c_str(), NULL);
    std::cout<<value<<'\n';


//example 2
    char szOrbits[] = "365.24 29.53";
    char* pEnd;
    double d1, d2;
    sscanf(szOrbits, "%lf %lf" , &d1, &d2 );
    printf ("The moon completes %.2f orbits per Earth year.\n", d1/d2);

    cv::namedWindow( "test1", 0);

    return 0;
}

---------------result----------------------

20.9111

The moon completes 12.37 orbits per Earth year.


a non-working script:

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <stdio.h>

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


     cv::namedWindow( "test2", 0);

//example 1
    std::string data="20.911111111";
    double value;
    value = strtod(data.c_str(), NULL);
    std::cout<<value<<'\n';


//example 2
    char szOrbits[] = "365.24 29.53";
    char* pEnd;
    double d1, d2;
    sscanf(szOrbits, "%lf %lf" , &d1, &d2 );
    printf ("The moon completes %.2f orbits per Earth year.\n", d1/d2);



    return 0;
}

---------------result----------------------

20

The moon completes inf orbits per Earth year.


edit retag flag offensive close merge delete

Comments

which os / opencv version is it ? are you using qt ?

there have been bugs in the past, where some layer of gui code was messing with the locale, this sounds related

berak gravatar imageberak ( 2015-05-31 01:23:22 -0500 )edit

I use OS Ubuntu 14.04 with OpenCV 2.4.9 and do not use QT. Whether it was fixed in version 2.4.11?

tyutyuginslava gravatar imagetyutyuginslava ( 2015-05-31 17:42:27 -0500 )edit

Thank you. I began to use version 3.0.0. It was working!

tyutyuginslava gravatar imagetyutyuginslava ( 2015-06-09 18:29:18 -0500 )edit