If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
-
mael15
- Super wx Problem Solver

- Posts: 451
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Post
by mael15 » Fri Dec 06, 2019 3:51 pm
Hi,
I started using opencv2 and it uses
for the float decimal point. Now I myself use wxLocale for the language of my program resulting in:
// As we get our decimal point separator from Win32 and not the
// CRT there is a possibility of mismatch between them and this
// can easily happen if the user code called setlocale()
// instead of using wxLocale to change the locale. And this can
// result in very strange bugs elsewhere in the code as the
// assumptions that formatted strings do use the decimal
// separator actually fail, so check for it here.
wxASSERT_MSG
(
wxString::Format("%.3f", 1.23).find(str) != wxString::npos,
"Decimal separator mismatch -- did you use setlocale()?"
"If so, use wxLocale to change the locale instead."
);
so what can I do? I can hardly make opencv use wxLocale, can I? Just remove setlocale and hope for the best?
-
doublemax
- Moderator

- Posts: 15507
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
Post
by doublemax » Fri Dec 06, 2019 4:59 pm
When is this called and when do you get the assert? Can you make sure that wxLocale is only initialized after openCV?
I also found some posts that indicate openCV might change the locale inside any of its functions. That would be really annoying, then you'd have to wrap each openCV call and reset the locale afterwards.
Or, if you're on Windows only and use a relatively new version of VS, you could move all openCV stuff into a separate thread and use _configthreadlocale() to make locale settings not global but unique per thread.
https://docs.microsoft.com/en-us/cpp/c- ... ew=vs-2019
Use the source, Luke!
-
mael15
- Super wx Problem Solver

- Posts: 451
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Post
by mael15 » Fri Dec 06, 2019 5:28 pm
doublemax wrote: ↑Fri Dec 06, 2019 4:59 pm
When is this called and when do you get the assert? Can you make sure that wxLocale is only initialized after openCV?
It is called when I use
https://docs.opencv.org/3.4/dd/d1a/grou ... db65a25d2d to detect circles in an image and the assert appears when I close the program later. I would not know how to make sure wxLocale is initialized after opencv.
doublemax wrote: ↑Fri Dec 06, 2019 4:59 pm
I also found some posts that indicate openCV might change the locale inside any of its functions. That would be really annoying, then you'd have to wrap each openCV call and reset the locale afterwards.
Or, if you're on Windows only and use a relatively new version of VS, you could move all openCV stuff into a separate thread and use _configthreadlocale() to make locale settings not global but unique per thread.
https://docs.microsoft.com/en-us/cpp/c- ... ew=vs-2019
I actually am on Windows only with the vs 2019, so the thread option should be perfect, a bit complicated but as long as it works...
thanx!
