在 OpenCV 的 namedWindow 之前或之后初始化 Tesseract
Initialise Tesseract before or after namedWindow from OpenCV
我想知道这是一个错误还是我不明白什么。
示例 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)
区别:
创建窗口和初始化的顺序。
编辑:
locale = std::setlocale(LC_CTYPE, nullptr);
ASSERT_HOST(!strcmp(locale, "C"));
此断言失败。这是否意味着opencv设置了语言环境,而tesseract无法更改它?
这是一个已知的问题。看看github问题,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);
相关文章:
- 在 OpenCV 的 namedWindow 之前或之后初始化 Tesseract
- 使用大括号或括号初始化成员变量
- 不同的类或结构初始化方法之间的性能差异是什么?
- 在 C++20 之前和之后初始化 std::atomic
- 如何在初始化列表中的构造函数之后初始化变量/对象?
- 检查对是否为空或未初始化
- C++ 提升:在构建器之后初始化端点
- 是函数本地静态默认或价值初始化
- 具有从特定范围的随机数初始化特征矩阵或向量初始化特征矩阵或向量的有效方法
- 如何在函数调用之后初始化变量,例如新表达式提供
- MFC和OpenGL CView,C ,Glew之后初始化OpenGL
- '='应初始化所有枚举成员或仅初始化第一个枚举成员;
- 在声明C++之后初始化常量变量
- 初始化时统一或直接初始化
- 在malloc()之后初始化结构中对ptr的引用
- 值初始化:默认初始化或零初始化
- 大括号或相等初始化与构造函数委托
- 当静态或动态初始化时
- 是一个初始化为未确定值或未初始化的本地作用域变量
- 在构造函数之后初始化boost::asio套接字