不知道是bug还是我没看懂。
示例 1:
tesseract::TessBaseAPI *api;
api = new tesseract::TessBaseAPI();
if (api->Init(NULL, "eng")) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
namedWindow( window_name, CV_WINDOW_NORMAL );
结果:
Works fine.
示例 2:
namedWindow( window_name, CV_WINDOW_NORMAL );
tesseract::TessBaseAPI *api;
api = new tesseract::TessBaseAPI();
if (api->Init(NULL, "eng")) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
结果:
!strcmp(locale, "C"):Error:Assert failed:in file baseapi.cpp, line 192
Segmentation fault (core dumped)
区别:
创建窗口的顺序和tesseract的初始化。
编辑:
locale = std::setlocale(LC_CTYPE, nullptr);
ASSERT_HOST(!strcmp(locale, "C"));
此断言失败。这是否意味着 opencv 设置了区域设置而 tesseract 无法更改它?
最佳答案
这是 tesseract 的一个已知问题。看着 github issue Tesseract 团队目前正在努力解决它。 作为临时解决方案,您可以使用以下代码包装所有 tesseract 调用
// set locale to "C" for tesseract
char *old_ctype = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
// some tesseract function, this is just an example.
tesseract::TessBaseAPI api;
api.InitForAnalysePage();
// restore your previous locale
setlocale(LC_ALL, old_ctype);
free(old_ctype);
关于c++ - 在 OpenCV 的 namedWindow 之前或之后初始化 Tesseract,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52677337/