【发布时间】:2018-07-24 14:56:38
【问题描述】:
我正在使用 Tesseract 阅读日语文本。我正在从 OCR 获取以下文本。
æ—¥ä»~請求書
C++ 代码
extern "C" _declspec(dllexport) char* _cdecl Test(char* imagePath)
{
char *outText;
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api->Init("D:\\tessdata", "jpn", tesseract::OcrEngineMode::OEM_TESSERACT_ONLY))
{
fprintf(stderr, "Could not initialize tesseract.\n");
}
api->SetPageSegMode(tesseract::PageSegMode::PSM_AUTO);
outText = api->GetUTF8Text();
return outText;
}
c#
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern string Test(string imagePath);
void Tessrect()
{
string result = Test("D:\\japan4.png");
byte[] bytes = System.Text.Encoding.Default.GetBytes(result);
MessageBox.Show(System.Text.Encoding.UTF8.GetString(bytes));
}
上面的代码在窗口英语中运行良好。但它不适用于窗口日本。它在窗口的日本操作系统中给出了错误的输出。
谁能指导我如何正确使用日本窗口?
【问题讨论】:
-
我想你会想给它 UTF-16 而不是 UTF-8,因为 winapi 主要处理这个......我猜?
-
文中有BOM说明是什么类型的吗?如果没有,请尝试 UTF-8 或 Shift-JIS。
-
我已经尝试过使用 UTF-8 和 Shift-JIS。但没有帮助我