I have written the code to recognize text in images using Tesseract and OpenCV.But while I am executing their is no problem with code but it is showing some linker error. I am using tesseract4.0 with visual studios.
#include "stdafx.h"
#include <string>
#include <opencv2/opencv.hpp>
#include "tesseract/baseapi.h"
#include "leptonica/allheaders.h"
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
string outText;
string imPath = "Images/newspaper2.jpeg";
// Create Tesseract object
tesseract::TessBaseAPI *ocr = new tesseract::TessBaseAPI();
// Initialize tesseract to use English (eng) and the LSTM OCR engine.
ocr->Init("tessdata", "eng", tesseract::OEM_TESSERACT_ONLY);
// Set Page segmentation mode to PSM_AUTO (3)
ocr->SetPageSegMode(tesseract::PSM_AUTO);
// Open input image using OpenCV
Mat im = imread(imPath, IMREAD_COLOR);
// Set image data
ocr->SetImage(im.data, im.cols, im.rows, 3, im.step);
// Run Tesseract OCR on image
outText = string(ocr->GetUTF8Text());
// print recognized text
cout << outText << endl; // Destroy used object and release memory ocr->End();
return EXIT_SUCCESS;
}
My error looks like this.
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol closesocket opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol connect opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol htons opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol recv opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol select opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol send opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol gethostbyname opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol socket opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Thanks for the help.
Figured out the solution to above problem. Actually I was trying to run a 64 bit code and use a32 bit library. So there was a linking error. So now again build tesseract for 32 bit and use it will work. For reference you can see here https://github.com/tesseract-ocr/tesseract/issues/1490.