5

I followed the instructions I found in form of tessesract on how to includ baseapi.h.

i am using:

vs2010
Version tesseract 3.01

i try to understand how to use baseapi.h.

test program:

#define __MSW32__

 #include "baseapi.h"

using namespace  tesseract;

int _tmain(int argc, _TCHAR* argv[])

{

   TessBaseAPI *myTestApi;

   myTestApi=new TessBaseAPI();

   //myTestApi->Init("d:/temp.jpg","eng");

   return 0;

}

form gide:

add the following folders to Additional Include Directories (properties) - to resolve file not found issues after including "baseapi.h"

tesseract-3.01/api

tesseract-3.01/ccmain

tesseract-3.01/ccutil

tesseract-3.01/ccstruct enter image description here

added the following libs to "Properties/Linker/Input/Additional Dependancies" in order to use the Tesseract and Leptonica libs libtesseract.lib;liblept.lib

enter image description here // added the following paths to "Properties/Linker/General/Additional Library Directories" in order to find the Tesseract and Leptonica libs tesseract-3.01/vs2010/Release tesseract-3.01/vs2008/lib

enter image description here

And I try to run now

enter image description here

So I try to find libs libtesseract.lib and replaced with libtesseract_tessopt.lib and then run enter image description here

1>------ Build started: Project: test4, Configuration: Debug Win32 ------
1>  test4.cpp
1>test4.obj : error LNK2019: unresolved external symbol "public: __thiscall tesseract::TessBaseAPI::TessBaseAPI(void)" (??0TessBaseAPI@tesseract@@QAE@XZ) referenced in function _wmain
1>c:\users\eran0708\documents\visual studio 2010\Projects\test4\Debug\test4.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Is anything known solution to the problem?

thanks,

eran

![enter image description here][6]

![enter image description here][7]

1

2 Answers 2

3

This is what I did to compile it:

1.) Copy all header files into one includedirectory, so later only §(TESS_DIR)\include has to be added to the include directories.

copy the leptonica headers into $(TESS_DIR)\include\leptonica.

2.) Open vs2010\tesseract.sln and compile all configurations. Then copy all lib files into $(TESS_DIR)\lib\debug and $(TESS_DIR)\lib\release. Then add those directories to the build settings.

3.) Copy the compiled libtesseract.dll and liblept168.dll as well as the folder tessdata, containg eng.traineddata, to the Release folder of your project.

4.) Add these libraries as additional dependencies:

libtesseract.lib
liblept168.lib

5.) #include <baseapi.h>

1
  • 1
    I found another solution Go to your release-3.01\vs2010 open project with vs2010 and press build Solution and now it will work added the following libs to "Properties/Linker/Input/Additional Dependancies" in order to use the Tesseract and Leptonica libs libtesseract.lib;liblept.lib Nov 17, 2011 at 10:09
0

I figured it out, if you are using visual studios 2010 and are using windows forms / designer you can add it easily this way with no issues

1) add the following projects to your project ( i am warning you once, do not add the tesseract solution, or change any setting in the projects you add, unless you love to hate yourself ) ccmain ccstruct ccutil classify cube cutil dict image libtesseract nutral_networks textord viewer wordrec

you can add the others but you don’t really want all that built into your project do you? naaa, build those separately

2) go to your project properties and add libtesseract as a reference, you can now that it is visible as a project, this will make it so that your project builds fast without examining the millions of warnings within tesseract. [common properties]->[add reference]

3) right click your project in the solution explorer and click project dependencies, make sure it is dependant on libtesseract or even all of them, it just means they build before your project.

4) the tesseract 2010 visual studio projects contain a number of configuration settings aka release, release.dll, debug, debug.dll, it seems that the release.dll settings produce the right files. First, set the solution output to release.dll. Click your project properties. Then click configuration manager. If that is not available, do this, click the SOLUTION's properties in the solution tree and click configuration tab, you will see a list of projects and the associated configuration settings. You will notice your project is not set to release.dll even though the output is. If you took the second route you still need to click configuration manager. Then you can edit the settings, click new on your projects settings and call it release.dll...exactly the same as the rest of them and copy the settings from release. Do the same thing for Debug, so that you have a debug.dll name copied from debug settings. wheew...almost done

5) Don’t try to change tesseracts settings to match yours....that wont work ....and when the new release comes out you wont be able to just "throw it in" and go. Accept the fact that in this state your new modes are Release.dll and Debug.dll. don’t stress out...you can go back when its is finished and remove the projects from your solution.

6) Guess where the libraries and dll’s come out? in your project, you may or may not need to add the library directories. Some people say to dump all the headers into a single folder so they only need to add one folder to the includes but not me. I want to be able to delete the tesseract folder and reload it from the zips without extra work....and be fully ready to update in one move or restore it if I made a mess of the code. Its a bit of work and you can to it with code instead of the settings which is the way i do it, but you should include all the folders that contain header files within the 2010 tesseract project folder and leave them alone.

7) there is no need to add any files to your project. just these lines of code..... I have included some additional code that converts from one foreign data set to the tiff friendly version with no need to save / load file. aren’t I nice?

8) now you can fully debug in debug.dll and release.dll, once you have successfully built it into your project even once you can remove all the added projects and it will be peeerfect. no extra compiling or errors. fully debugable, all natural.

9) If I remember right, I could not get around the fact I had to copy the files in 2008/lib/ into my projects release folder….darn it.

In my projects “functions.h” I put
#pragma comment (lib, "liblept.lib" ) 
#define _USE_TESSERACT_ 
#ifdef _USE_TESSERACT_ 
#pragma comment (lib, "libtesseract.lib" ) 
#include <baseapi.h> 
#endif 
#include <allheaders.h> 

in my main project I put this in a class as a member: tesseract::TessBaseAPI *readSomeNombers;

and of course I included “functions.h” somewhere

then I put this in my classes constructor:

readSomeNombers = new tesseract::TessBaseAPI(); 
readSomeNombers ->Init(NULL, "eng" ); 
readSomeNombers ->SetVariable( "tessedit_char_whitelist", "0123456789,." ); 

then I created this class member function: and a class member to serve as an output, don’t hate, I don’t like returning variables. Not my style. The memory for the pix does not need to be destroyed when used inside a member function this way I believe and my test suggest this is a safe way to call these functions. But by all means, you can do whatever.

void Gaara::scanTheSpot() 
{ 
    Pix *someNewPix; 
    char* outText; 
    ostringstream tempStream; 
    RECT tempRect; 
    someNewPix = pixCreate( 200 , 40 , 32 ); 
    convertEasyBmpToPix( &scanImage, someNewPix, 87, 42 ); 

    readSomeNombers ->SetImage(someNewPix); 
    outText = readSomeNombers ->GetUTF8Text(); 
    tempStream.str(""); 
    tempStream << outText; 
    classMemeberVariable = tempStream.str(); 
//pixWrite( "test.bmp", someNewPix, IFF_BMP ); 
} 

The object that has the information that I want to scan is in memory and is pointed to by &scanImage. It is from the “EasyBMP” library but that is not important.

Which I deal with in a function in “functions.h”/ “functions.cpp” by the way, i am doing a little extra processing here while i am in the loop, namely thinning the characters and making it black and white and reversing black and white which is unnessesry. At this phase in my development I am still looking for ways to improve the recognition. Though for my proposes this has not yielded bad data yet. My view is to use the default Tess data for simplicity. I am acting heuristically to solve a very complex problem.

void convertEasyBmpToPix( BMP *sourceImage, PIX *outputImage, unsigned startX, unsigned startY ) 
{ 
    int endX = startX + ( pixGetWidth( outputImage ) ); 
    int endY = startY + ( pixGetHeight( outputImage ) ); 
    unsigned destinationX; 
    unsigned destinationY = 0; 
    for( int yLoop = startY; yLoop < endY; yLoop++ ) 
    { 
        destinationX = 0; 
        for( int xLoop = startX; xLoop < endX; xLoop++ ) 
        { 
            if( isWhite( &( sourceImage->GetPixel( xLoop, yLoop ) ) ) ) 
            { 
                pixSetRGBPixel( outputImage, destinationX, destinationY, 0,0,0 ); 
            } 
            else 
            { 
                pixSetRGBPixel( outputImage, destinationX, destinationY, 255,255,255 ); 
            } 
            destinationX++; 
        } 
        destinationY++; 
    } 
} 
bool isWhite( RGBApixel *image ) 
{ 
    if( 
        //destination->SetPixel( x, y, source->GetPixel( xLoop, yLoop ) ); 
        ( image->Red   < 50 ) || 
        ( image->Blue  < 50 ) || 
        ( image->Green < 50 ) 
        ) 
    { 
        return false; 
    } 
    else 
    { 
        return true; 
    } 
} 

one thing i dont like is the way I declare the size of the pix outside the function. It seems if I try to do it within the function I have unexpected results....if the memory is alocated while inside it is destroed when I leave.

g m a i l Certainly not my most elegant work but I also gutted the hell out of it for simplicity. Why I bother to share this I don't know. I should have kept it to myself. What is my name? Kage.Sabaku.No.Gaara

before i let you go i should mention the subtle differences between my windows form app and the default settings. namely i use "multi-byte" character set. project properties...and such..give a dog a bone, maybe a vote?

p.p.s. I hate to say it but I made one change to host.c if you use 64 bit you can do the same. Otherwise your on your own.....but my reason was a bit insane you dont have to, kinda silly actually

typedef unsigned int uinT32; 
#if (_MSC_VER >= 1200)            //%%% vkr for VC 6.0 
typedef _int64 inT64; 
typedef unsigned _int64 uinT64; 
#else 
typedef long long int inT64; 
typedef unsigned long long int uinT64; 
#endif                           //%%% vkr for VC 6.0 
typedef float FLOAT32; 
typedef double FLOAT64; 
typedef unsigned char BOOL8; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.