Build OpenCV text (OCR) module on Windows

Source: Internet
Author: User

Background.

AOI software needs to use the OCR feature to recognize the texts on the chips. Because Our vision software are based on OpenCV and so the first choice is the text module in Opencv_contrib.

Procedures.

1. OCR module is not in the standard OpenCV. It's in text module of Opencv_contrib. It can downloaded from Opencv_contrib.

2. The core of OCR is using tesseract, and tesseract depends on leptonica, so need to build leptonica and Tesseract first.

3. Get the Leptonica from https://github.com/ charlesw/tesseract-vs2012. This project can directly build. The output Is liblept171d.dll and  Liblept171d.lib .

4. Get the Tesseract from https://github.com/ Tesseract-ocr/tesseract. Copy liblept171d.lib to .\tesseract\lib folder. Create the. \tesseract\include\leptonica folder, copy all the header file from .\ Tesseract-vs2012\liblept\include (the root folder is in step 3).  set the project property of Tesseract, change the Include folder path. \.. \.. \include "and ". \.. \.. \include\leptonica "to ". \.. \include "and ". \.. \include\leptonica ". Then can build the Tessrect project, the output Is libtesseract304d.dll and& nbsp libtesseract304d.lib .

5. Use CMake to config the OpenCV solution. Copy the text module from Opencv_contrib to. \opencv\sources\modules. Run Cmake_gui, there is 3 options need to set. lept_library, tesseract_include_dir, tesseract_library. Tesseract_include_dir set to .../tesseract/api. After set, can run CMake to config and generate the solution.

6. Build the OpenCV solution. If there is header files can not find errors, find and copy them from Tesseract to the API folder. There may is a compile error with std::numeric_limits<double>::min (); ADD below code before the function use it.

#undef #undef min

7. Download the language test data from Https://github.com/tesseract-ocr/tessdata. What am I use is the eng.traineddata. Put it to. \tesseract\tessdata.

8. After build OpenCV successfully and then you can create the TESTOPENCV project with the below function, before running it, Need to copy the Liblept171d.dll and Libtesseract304d.dll to the output folder (where the exe file is put).

usingOcrtesseract =cv::text::ocrtesseract;voidTESTOCR () {Cv::mat Mat= Cv::imread (". \\data\\OCRTest.png"); if(Mat.empty ())return; STD::stringOutput_text; Char*datapath ="C:/tesseract-build/tesseract/tessdata"; CV::P TR<OCRTesseract> PTROCR =ocrtesseract::create (DataPath); PTROCR-Run (Mat, output_text); cout<< Output_text <<Endl;}

Build OpenCV text (OCR) module on Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.