namedWindow seems to modify locale settings (Bug #927)
Description
In C++, after creating a window with cv::namedWindow
, the behavior of the standard function sprintf
regarding decimal numbers changes. Specifically, the decimal separator character changes from a point '.' to a comma ',' in my case. My first impression is that it has to do with some locale settings.
I attach an example file that formats a number before and after calling cv::namedWindow
. I am using Ubuntu in Spanish (the decimal separator is the comma ','). The output I get is:
343.904804 343,904804My system:
- OpenCV 2.1.0
- gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
- Linux 2.6.32-28-generic #55-Ubuntu SMP Mon Jan 10 21:21:01 UTC 2011 i686 GNU/Linux
- Gnome 2.30.2 (compilation date: 2010-06-25)
- Localization: Spanish (Spain)
Related issues
related to Bug #3895: segmentation fault with Python interface | Done | 2014-09-05 |
Associated revisions
fixed #927 issue
fixed #927 issue
Merge pull request #927 from bitwangyaoyao:2.4_perf
Merge remote-tracking branch 'origin/2.4'
Pull requests:
#943 from jet47:cuda-5.5-support
#944 from jet47:cmake-2.8.11-cuda-fix
#912 from SpecLad:contributing
#934 from SpecLad:parallel-for
#931 from jet47:gpu-test-fixes
#932 from bitwangyaoyao:2.4_fixBFM
#918 from bitwangyaoyao:2.4_samples
#924 from pengx17:2.4_arithm_fix
#925 from pengx17:2.4_canny_tmp_fix
#927 from bitwangyaoyao:2.4_perf
#930 from pengx17:2.4_haar_ext
#928 from apavlenko:bugfix_3027
#920 from asmorkalov:android_move
#910 from pengx17:2.4_oclgfft
#913 from janm399:2.4
#916 from bitwangyaoyao:2.4_fixPyrLK
#919 from abidrahmank:2.4
#923 from pengx17:2.4_macfix
Conflicts:
modules/calib3d/src/stereobm.cpp
modules/features2d/src/detectors.cpp
modules/gpu/src/error.cpp
modules/gpu/src/precomp.hpp
modules/imgproc/src/distransform.cpp
modules/imgproc/src/morph.cpp
modules/ocl/include/opencv2/ocl/ocl.hpp
modules/ocl/perf/perf_color.cpp
modules/ocl/perf/perf_imgproc.cpp
modules/ocl/perf/perf_match_template.cpp
modules/ocl/perf/precomp.cpp
modules/ocl/perf/precomp.hpp
modules/ocl/src/arithm.cpp
modules/ocl/src/canny.cpp
modules/ocl/src/filtering.cpp
modules/ocl/src/haar.cpp
modules/ocl/src/hog.cpp
modules/ocl/src/imgproc.cpp
modules/ocl/src/opencl/haarobjectdetect.cl
modules/ocl/src/pyrlk.cpp
modules/video/src/bgfg_gaussmix2.cpp
modules/video/src/lkpyramid.cpp
platforms/linux/scripts/cmake_arm_gnueabi_hardfp.sh
platforms/linux/scripts/cmake_arm_gnueabi_softfp.sh
platforms/scripts/ABI_compat_generator.py
samples/ocl/facedetect.cpp
History
Updated by beuzel - over 13 years ago
that would maybe explain why my multi-threated application crashes sometimes in some windows dll around the locale code. unfortunately i don't have an callstack. i wondered who calls setting the locale. I am using an english windows 7 with german locale.
Updated by Alexander Shishkov about 13 years ago
fixed in 7277 revision
- Status changed from Open to Done
- (deleted custom field) set to fixed
Updated by Andrey Kamaev about 13 years ago
- Target version set to 2.4.0
- Description changed from In C++, after creating a window with cv::namedWindow, the behaviour of the st... to In C++, after creating a window with @cv::namedWindow@, the behavior of the s... More
- Assignee set to Alexander Shishkov
Updated by Andrey Kamaev over 12 years ago
- Category changed from highgui-images to highgui-gui
Updated by Steven Puttemans over 10 years ago
I would like to add that this bug still exists or that it is still available in Ubuntu 14.04!
I had a problem of atof function not working properly after calling the imshow function, which calls a namedWindow internally if it is not yet defined. Before calling the openCV code to visualise in between results, atof worked perfectly since it assumed that a '.' is used as decimal decimation. However, once the first imshow operation was called, the locale configuration was somehow copied and from that point atof function assumed a ',' as decimal decimation. After a close investigation it seems my localization configuration was set to Germany instead of the UK, and thus the switch was made. When I changed my localization to UK the problem was gone.
We should avoid this behaviour at all costs!
I am using Ubuntu 14.04 64 bit with latest 2.4 branch.
I have it built with Qt support if this makes any difference.
Can anyone of the original fixers look into this?
- Target version changed from 2.4.0 to 2.4.10
- HW Platform set to ARM
- Operating System set to Linux
- Affected version set to branch '2.4' (2.4-dev)
- Status changed from Done to Open
Updated by Steven Puttemans over 10 years ago
Like described here:
http://qt-project.org/doc/qt-4.8/qcoreapplication.html#locale-settings
This is expected behavior of Qt. I think we could avoid this by adding a
setlocale(LC_NUMERIC,"C")
right after the fact of initializing the QApplication. I will submit a pull request.
Updated by Steven Puttemans over 10 years ago
Fixes implemented in 2.4 branch! Pull request merged!
- Status changed from Open to Done
- Pull request set to https://github.com/Itseez/opencv/pull/3046