我想知道这是一个错误还是我不理解。
示例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无法更改它?
答案 0 :(得分:2)
这是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);