我正在開發一個應用程式,該應用程式使用 OpenCV 讀取影像檔案并使用 Tesseract 處理其上的文字。使用以下代碼 Tesseract 檢測不包含文本的額外矩形。
void Application::Application::OpenAndProcessImageFile(void)
{
OPENFILENAMEA ofn;
ZeroMemory(&ofn, sizeof(OPENFILENAMEA));
char szFile[260] = { 0 };
// Initialize remaining fields of OPENFILENAMEA structure
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = mWindow->getHandle();
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "JPG\0*.JPG\0PNG\0*.PNG\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
//open the picture dialog and select the image
if (GetOpenFileNameA(&ofn) == TRUE) {
std::string filePath = ofn.lpstrFile;
//load image
mImage = cv::imread(filePath.c_str());
//process image
tesseract::TessBaseAPI ocr = tesseract::TessBaseAPI();
ocr.Init(NULL, "eng");
ocr.SetImage(mImage.data, mImage.cols, mImage.rows, 3, mImage.step);
Boxa* bounds = ocr.GetWords(NULL);
for (int i = 0; i < bounds->n; i) {
Box* b = bounds->box[i];
cv::rectangle(mImage, { b->x,b->y,b->w,b->h }, { 0, 255, 0 }, 2);
}
ocr.End();
//show image
cv::destroyAllWindows();
cv::imshow("??lenmi? Resim", mImage);
}
}
這是輸出影像

如您所見,Tesseract 處理根本不包含單詞的區域。我怎樣才能解決這個問題?
uj5u.com熱心網友回復:
Tesseract 更基于字符識別而不是文本檢測。即使某些區域沒有文本,tesseract 也可以將某些特征視為文本。
您需要做的是使用文本檢測演算法首先檢測文本區域,然后應用tesseract。
您可以通過更改模型的輸入引數來獲得更多更好的結果。我只是使用了默認的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/361550.html
上一篇:在OpenCV中移動影像
下一篇:Opencv列印帶輪廓的文本
