日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

tesseract-ocr3.02字符识别过程操作步骤

發布時間:2023/11/27 生活经验 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tesseract-ocr3.02字符识别过程操作步骤 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、? 從http://code.google.com/p/tesseract-ocr/downloads/list下載tesseract-ocr-3.02-vs2008tesseract-ocr-3.02.chi_sim.tartesseract-ocr-3.02.02.tartesseract-ocr-3.02.02-doc-html.tarleptonica-1.68-win32-lib-include-dirs相關文件;

2、? 將所有文件存放在E:\OCR\tesseract_ocr3.02文件夾下并解壓縮;

3、? 打開tesseract-ocr-3.02-vs2008文件夾下的tesseract.sln工程;

4、? 將tesseract-ocr-3.02.02文件夾下的對應文件如apiccmain等復制到E:\OCR\tesseract_ocr3.02\tesseract-ocr-3.02-vs2008\tesseract-ocr文件夾下,把leptonica-1.68-win32-lib-include-dirs文件夾下的include文件夾復制到E:\OCR\tesseract_ocr3.02\tesseract-ocr-3.02-vs2008文件夾下,將tesseract_ocr3.02\tesseract-ocr-3.02.02\tesseract-ocr\vs2008\port文件夾下的文件復制到E:\OCR\tesseract_ocr3.02\tesseract-ocr-3.02-vs2008\tesseract-ocr\vs2008\port文件夾下,將leptonica-1.68-win32-lib-include-dirs文件夾下lib文件夾復制到tesseract_ocr3.02\tesseract-ocr-3.02-vs2008文件夾下;

5、? 將ccmain文件夾下的equationdetect.cpp文件中的static const STRING kCharsToEx[] = {"'", "`","\"", "\\", ",", ".", "〈", "〉", "《", "》", "」", "「", ""};修改成static const STRING kCharsToEx[] = {"'", "`","\"", "\\", ",",".","<",?">",?? "<<",">>",? ""};(注:不改動編譯時始終出錯,其它方法暫未發現,3.01版本中沒有此文件,編譯3.01不用對源文件作任何修改)

6、?重新編譯整個Solution;

7、?創建一個控制臺空工程,配置環境仿照tesseract工程,并在執行文件夾下創建一個tessdata文件夾,里面存放chi_sim.traineddata數據文件,示例代碼如下:

?

#include "allheaders.h"
#include "baseapi.h"
#include "basedir.h"
#include "strngs.h"
#include "tesseractmain.h"
#include "tprintf.h"int main(int argc, char **argv)
{tesseract::TessBaseAPI api;STRING tessdata_dir;truncate_path(argv[0], &tessdata_dir);int rc = api.Init(tessdata_dir.string(), NULL);if (rc) {fprintf(stderr, ("Could not initialize tesseract.\n"));exit(1);}api.End();// Make the order of args a bit more forgiving than it used to be.const char* lang = "chi_sim";//engconst char* image = "E:\\OCR\\tesseract_ocr3.02\\tesseract-ocr-3.02-vs2008\\tesseract-ocr\\vs2008\\Debug\\ABC.tif";//NULL;const char* output = "E:\\OCR\\tesseract_ocr3.02\\tesseract-ocr-3.02-vs2008\\tesseract-ocr\\vs2008\\Debug\\xxxxx";//NULL;tesseract::PageSegMode pagesegmode = tesseract::PSM_AUTO;int arg = 1;api.SetOutputName(output);rc = api.Init(tessdata_dir.string(), lang, tesseract::OEM_DEFAULT,&(argv[arg]), argc - arg, NULL, NULL, false);if (rc){fprintf(stderr, ("Could not initialize tesseract.\n"));exit(1);}if (api.GetPageSegMode() == tesseract::PSM_SINGLE_BLOCK){api.SetPageSegMode(pagesegmode);}tprintf("Tesseract Open Source OCR Engine v%s with Leptonica\n", tesseract::TessBaseAPI::Version());FILE* fin = fopen(image, "rb");if (fin == NULL) {fprintf(stderr, ("Cannot open input file: %s\n"), image);exit(2);}fclose(fin);PIX   *pixs;if ((pixs = pixRead(image)) == NULL){fprintf(stderr, ("Unsupported image type.\n"));exit(3);}pixDestroy(&pixs);STRING text_out;if (!api.ProcessPages(image, NULL, 0, &text_out)) {fprintf(stderr, ("Error during processing.\n"));}bool output_hocr = false;api.GetBoolVariable("tessedit_create_hocr", &output_hocr);bool output_box = false;api.GetBoolVariable("tessedit_create_boxfile", &output_box);STRING outfile = output;outfile += output_hocr ? ".html" : output_box ? ".box" : ".txt";FILE* fout = fopen(outfile.string(), "wb");if (fout == NULL) {fprintf(stderr, ("Cannot create output file %s\n"), outfile.string());exit(1);}fwrite(text_out.string(), 1, text_out.length(), fout);fclose(fout);return 0;                      // Normal exit
}

?

以上代碼編譯運行成功,直接輸入整幅圖像進行字符識別,效果一般。

總結

以上是生活随笔為你收集整理的tesseract-ocr3.02字符识别过程操作步骤的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

歡迎分享!

轉載請說明來源于"生活随笔",并保留原作者的名字。

本文地址:tesseract-ocr3.02字符识别过程操作步骤