使用Tesseract文字提取之前,我们可以先使用opencv处理一下图片。最简单的例子如下所示: 登录后复制 //识别 void _characterIdentify() {string path = "C:/Users/Desktop/11/9.jpg"; Mat img = imread(path); cv::Mat gray, binary; // 转换为灰度图像 cv::cvtColor(img, gray, cv::COLOR_BGR2GRAY); cv::threshold(gray, binary, 0, 255, cv::THRESH_BINARY | cv::THRESH_OTSU); // 反转二进制图像,得到文字区域 cv::bitwise_not(binary, binary); //imshow("binary", binary); //waitKey(0); tesseract::TessBaseAPI ocr; int ret = ocr.Init("E:\\qt\\Project\\TesseractSample\\Debug\\tessdata", "chi_sim"); ocr.SetImage(binary.data, binary.cols, binary.rows, 1, binary.step1()); char* outText = ocr.GetUTF8Text(); std::string strrrr = Coding::UTF8ToGB2312(outText); std::cout << strrrr; delete[] outText; ocr.End();} 1.2.3.4.5.6.7.8.9.10.11.12.13.14. 原创作者: u_10486491 转载于: https://blog.51cto.com/u_10486491/11829962