I hav done some preety good stuff with tesseract ocr and api in linux now i
wanted to integrate my windows code in linux but
i am not able to find how to add dependencies (dll's) in linux also am not
able to find .so files for tesseract ocr !!!
If any1 hav any information related to programming tesseract in linux guys
help me out !!!!!!
PS I am attaching my tesseract api code in attachment
--
--
You received this message because you are subscribed to the Google
Groups "tesseract-ocr" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/tesseract-ocr?hl=en
---
You received this message because you are subscribed to the Google Groups
"tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
/*We use PSM_AUTO in our iPhone app (ScanBizCards) but for small images
> perhaps using another mode will achieve what you need. Here is the
> list of options:
>
> PSM_AUTO, // Fully automatic page segmentation.
> PSM_SINGLE_COLUMN, // Assume a single column of text of
> variable
> sizes.
> PSM_SINGLE_BLOCK, // Assume a single uniform block of text.
> (Default.)
> PSM_SINGLE_LINE, // Treat the image as a single text line.
> PSM_SINGLE_WORD, // Treat the image as a single word.
> PSM_SINGLE_CHAR, // Treat the image as a single character.
>
> Patrick
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dirent.h"
#include <baseapi.h>
#include<platform.h>
#include<publictypes.h>
#include <allheaders.h>
#include <fstream>
#include<direct.h>
using namespace std;
static void list_directory (const char *dirname,const char *destname);
static void tess(char *f_name,char *d_name);
Pix* FindImages(Pix* pix) ;
char* fname;
int main(int argc, char *argv[])
{
int i;
//PATH of Image directory
char* d="G:\\Accuracy_Data\\a";
char* c="\\TesseractOCROutput";
char e[100];
strcpy(e,d);
strcat(e,c);
mkdir(e);
/* For each directory in command line */
i = 1;
while (i < argc) {
list_directory (argv[i],NULL);
i++;
}
/* List current working directory if no arguments on command line */
if (argc == 1) {
list_directory (d,e);
}
return EXIT_SUCCESS;
}
/*
* List files and directories within a directory.
*/
static void list_directory(const char *dirname,const char *destname)
{
DIR *dir;
struct dirent *ent;
char* temp;
char* txt="txt";
/* Open directory stream */
dir = opendir (dirname);
if (dir != NULL) {
/* Print all files and directories within the directory */
while ((ent = readdir (dir)) != NULL) {
switch (ent->d_type) {
case DT_REG:
printf ("%s\n", ent->d_name);
char buf[200];
char buf1[200];
strcpy(buf1,destname);
strcat(buf1,"\\");
strcat(buf1,ent->d_name);
strcpy(buf,dirname);
strcat(buf,"\\");
strcat(buf,ent->d_name);
tess(buf,buf1);
break;
//delete[] buf;
case DT_DIR:
//printf ("%s/\n", ent->d_name);
break;
default:
printf ("%s*\n", ent->d_name);
}
}
closedir (dir);
} else {
/* Could not open directory */
printf ("Cannot open directory %s\n", dirname);
exit (EXIT_FAILURE);
}
}
static void tess(char *f_name,char *d_name)
{
//VARIABLE DECLARATIONS.....................
ofstream fout;
Pix *pix,*pix_l,*pix_b;
BOX *box;
char buf1[500];
l_int32 i,nwords;
char* outText;
//STRING* outText;
char *f_name1,*f_name2;
tesseract::TessBaseAPI api;
pix = pixRead(f_name);
pix_l=FindImages(pix);
//pixWrite("G:\\Accuracy_Data\\a\\result3\\1.png",pix_l,IFF_PNG);
f_name1="G:\\Accuracy_Data\\a\\";
f_name2="";
//TESSERACT....................................
api.Init(f_name, "hin");
api.SetImage(pix);
api.SetPageSegMode(tesseract:: PSM_AUTO);
tesseract::PageIterator* it = api.AnalyseLayout();
i=0;
while(it->Next(tesseract::RIL_TEXTLINE))
{
sprintf(buf1,"%s%d.png",f_name1,i);
pix_b=it->GetBinaryImage(tesseract::RIL_TEXTLINE);
pix_l=FindImages(pix_b);
//if(pix_l->colormap->n==2)
//{
// printf("Image is FOUND at %d BLOCK !!",i);
//}
pixWrite(buf1,pix_l,IFF_PNG);
i++;
}
//pixWrite(f_name1,pix_l,IFF_PNG);
/*Boxa* boxes=api.GetComponentImages(tesseract::RIL_BLOCK,true,NULL,NULL);
nwords=boxaGetCount(boxes);
for(int i=0;i<nwords;i++)
{
box=boxaGetBox(boxes,i,L_CLONE);
api.SetRectangle(box->x,box->y,box->w,box->h);
pix_b=pixDrawBoxa(pix,boxes,boxes->box[i]->w,NULL);
pixWrite(f_name1,pix_b,IFF_PNG);
outText=api.GetUTF8Text();
sprintf(buf1,"%s.txt",d_name);
fout.open(buf1);
fout<<outText;
fout.close();
}
*/
//api.ProcessPages(f_name,NULL,0,outText);
//WRITING TO FILE ...............................
//sprintf(buf1,"%s.txt",d_name);
//fout.open(buf1);
//fout<<outText;
//fout.close();
//CLEAN .........................................
api.Clear();
api.End();
pixDestroy(&pix);
pixDestroy(&pix_b);
}
Pix* FindImages(Pix* pix)
{
const double kMinRectangularFraction = 0.125;
// Fraction of width or height to consider image completely used.
const double kMaxRectangularFraction = 0.75;
// Fraction of width or height to allow transition from kMinRectangularFraction
// to kMaxRectangularFraction, equivalent to a dy/dx skew.
const double kMaxRectangularGradient = 0.1; // About 6 degrees.
// Minimum image size to be worth looking for images on.
const int kMinImageFindSize = 100;
// Scale factor for the rms color fit error.
const double kRMSFitScaling = 8.0;
// Min color difference to call it two colors.
const int kMinColorDifference = 16;
// Pixel padding for noise blobs and partitions when rendering on the image
// mask to encourage them to join together. Make it too big and images
// will fatten out too much and have to be clipped to text.
const int kNoisePadding = 4;
// Not worth looking at small images.
if (pixGetWidth(pix) < kMinImageFindSize ||
pixGetHeight(pix) < kMinImageFindSize)
return pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
// Reduce by factor 2.
Pix *pixr = pixReduceRankBinaryCascade(pix, 1, 0, 0, 0);
//pixDisplayWrite(pixr, textord_tabfind_show_images);
// Get the halftone mask directly from Leptonica.
l_int32 ht_found = 0;
Pix *pixht2 = pixGenHalftoneMask(pixr, NULL, &ht_found,
NULL);
pixDestroy(&pixr);
if (!ht_found && pixht2 != NULL)
pixDestroy(&pixht2);
if (pixht2 == NULL)
return pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
// Expand back up again.
Pix *pixht = pixExpandReplicate(pixht2, 2);
// pixDisplayWrite(pixht, textord_tabfind_show_images);
pixDestroy(&pixht2);
// Fill to capture pixels near the mask edges that were missed
Pix *pixt = pixSeedfillBinary(NULL, pixht, pix, 8);
pixOr(pixht, pixht, pixt);
pixDestroy(&pixt);
// Eliminate lines and bars that may be joined to images.
Pix* pixfinemask = pixReduceRankBinaryCascade(pixht, 1, 1, 3, 3);
pixDilateBrick(pixfinemask, pixfinemask, 5, 5);
// pixDisplayWrite(pixfinemask, textord_tabfind_show_images);
Pix* pixreduced = pixReduceRankBinaryCascade(pixht, 1, 1, 1, 1);
Pix* pixreduced2 = pixReduceRankBinaryCascade(pixreduced, 3, 3, 3, 0);
pixDestroy(&pixreduced);
pixDilateBrick(pixreduced2, pixreduced2, 5, 5);
Pix* pixcoarsemask = pixExpandReplicate(pixreduced2, 8);
pixDestroy(&pixreduced2);
// pixDisplayWrite(pixcoarsemask, textord_tabfind_show_images);
// Combine the coarse and fine image masks.
pixAnd(pixcoarsemask, pixcoarsemask, pixfinemask);
pixDestroy(&pixfinemask);
// Dilate a bit to make sure we get everything.
pixDilateBrick(pixcoarsemask, pixcoarsemask, 3, 3);
Pix* pixmask = pixExpandReplicate(pixcoarsemask, 16);
pixDestroy(&pixcoarsemask);
// if (textord_tabfind_show_images)
pixWrite("junkexpandedcoarsemask.png", pixmask, IFF_PNG);
// And the image mask with the line and bar remover.
pixAnd(pixht, pixht, pixmask);
pixDestroy(&pixmask);
// if (textord_tabfind_show_images)
pixWrite("junkfinalimagemask.png", pixht, IFF_PNG);
// Make the result image the same size as the input.
Pix* result = pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
pixOr(result, result, pixht);
pixDestroy(&pixht);
return result;
}