Hello,
I am working on Rebol/OpenCV extension and I would like to add support for Unicode text input. I expected, that OpenCV will accept UTF-8 encoded texts in functions like imread
or imshow
, but at least on Windows it does not work…
When having for a test purpose code like:
std::string wstringToUtf8(const std::wstring &wstr) {
if (wstr.empty()) return std::string();
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
return strTo;
}
and later
// Define a window title with Unicode characters
std::wstring unicodeTitle = L"podběl";
std::string utf8Title = wstringToUtf8(unicodeTitle);
cv::imshow(utf8Title, resized_image);
cv::waitKey(0);
The title is not correct:
The same in other functions… so what am I missing?
Thanks,
Oldes