Background.
AOI software needs to use the OCR feature to recognize the texts on the chips. Because our vision software is based on OpenCV, so the first choice is text module in opencv_contrib.
Procedures.
1. OCR module is not in standard OpenCV package. It is in text module of OpenCV_Contrib. It can be 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 solution can directly build. The output is liblept171d.dll and liblept171d.lib.
4. Get the Tesseract from https://github.com/tesseract-ocr/tesseract. Create the .includeleptonica folder, copy all the header file from . esseract-vs2012libleptinclude (The root folder is in step 3) to it. Create the .lib folder, copy all the step 3 build generated files(The .dll and .lib) in . esseract-vs2012uildlib to it. Set the project property of tesseract, change the include folder path "......include" and "......includeleptonica" to "....include" and "....includeleptonica". Then can build the Tessrect project, the output is libtesseract304d.dll and libtesseract304d.lib.
The AddIdTohOCR has compile error, change the content as below can solve the problem.
static void AddIdTohOCR(STRING* hocr_str, const std::string base, int num1, int num2) { unsigned long bufsize = base.length() + 2 * kMaxIntSize; char *id_buffer = new char[bufsize]; if (num2 >= 0) { snprintf(id_buffer, bufsize - 1, "%s_%d_%d", base.c_str(), num1, num2); } else { snprintf(id_buffer, bufsize - 1, "%s_%d", base.c_str(), num1); } id_buffer[bufsize - 1] = '