mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Bazaar:Leptonica - Added text baselines finding with demo
git-svn-id: svn://ultimatepp.org/upp/trunk@1566 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
106c26c423
commit
21b934bd2d
10 changed files with 152 additions and 3 deletions
|
|
@ -29,4 +29,71 @@ bool PixRaster::GetRegionsBinary(int page)
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
// text baseline finding routine
|
||||
Array<Point> PixRaster::FindBaselines(int page)
|
||||
{
|
||||
PTA *pta;
|
||||
NUMA *numa;
|
||||
int res;
|
||||
l_int32 x, y;
|
||||
Array<Point> ptArray;
|
||||
|
||||
if(IsEmpty())
|
||||
return Array<Point>();
|
||||
page = getTruePage(page);
|
||||
|
||||
PIX *pix = pixaGetPix(pixa, page, L_CLONE);
|
||||
numa = pixFindBaselines(pix, &pta, 0);
|
||||
pixDestroy(&pix);
|
||||
if(!numa || !pta)
|
||||
return Array<Point>();
|
||||
for(int iPoint = 0; iPoint < ptaGetCount(pta); iPoint++)
|
||||
{
|
||||
res = ptaGetIPt(pta, iPoint, &x, &y);
|
||||
if(res)
|
||||
{
|
||||
numaDestroy(&numa);
|
||||
ptaDestroy(&pta);
|
||||
return Array<Point>();
|
||||
}
|
||||
ptArray.Add(Point(x, y));
|
||||
}
|
||||
numaDestroy(&numa);
|
||||
ptaDestroy(&pta);
|
||||
return ptArray;
|
||||
}
|
||||
*/
|
||||
|
||||
// text baseline finding routine
|
||||
Array<int> PixRaster::FindBaselines(int page)
|
||||
{
|
||||
NUMA *numa;
|
||||
int res;
|
||||
l_int32 y;
|
||||
Array<int> intArray;
|
||||
|
||||
if(IsEmpty())
|
||||
return Array<int>();
|
||||
page = getTruePage(page);
|
||||
|
||||
PIX *pix = pixaGetPix(pixa, page, L_CLONE);
|
||||
numa = pixFindBaselines(pix, NULL, 0);
|
||||
pixDestroy(&pix);
|
||||
if(!numa)
|
||||
return Array<int>();
|
||||
for(int iLine = 0; iLine < numaGetCount(numa); iLine++)
|
||||
{
|
||||
res = numaGetIValue(numa, iLine, &y);
|
||||
if(res)
|
||||
{
|
||||
numaDestroy(&numa);
|
||||
return Array<int>();
|
||||
}
|
||||
intArray.Add(y);
|
||||
}
|
||||
numaDestroy(&numa);
|
||||
return intArray;
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -110,4 +110,22 @@ bool PixRaster::FindSkewSweepAndSearch(
|
|||
|
||||
}
|
||||
|
||||
bool PixRaster::DeskewLocal(int page)
|
||||
{
|
||||
if(IsEmpty())
|
||||
return false;
|
||||
page = getTruePage(page);
|
||||
|
||||
PIX *sPix = pixaGetPix(pixa, page, L_CLONE);
|
||||
PIX *dPix = pixDeskewLocal(sPix, 0, 0, 0, 0.0, 0.0, 0.0);
|
||||
pixDestroy(&sPix);
|
||||
if(!dPix)
|
||||
return false;
|
||||
AddPIX(dPix, PIXRASTER_CLONE);
|
||||
SeekPage(PIXRASTER_LASTPAGE);
|
||||
pixDestroy(&dPix);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -238,6 +238,8 @@ class PixRaster : public Raster
|
|||
double minbsdelta,
|
||||
int page = PIXRASTER_CURPAGE);
|
||||
|
||||
bool DeskewLocal(int page = PIXRASTER_CURPAGE);
|
||||
|
||||
// NOTE : Leptonica has many more skew functions....
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -276,6 +278,8 @@ class PixRaster : public Raster
|
|||
// top level page segmenting
|
||||
bool GetRegionsBinary(int page = PIXRASTER_CURPAGE) ;
|
||||
|
||||
// text baseline finding routine
|
||||
Array<int> FindBaselines(int page = PIXRASTER_CURPAGE);
|
||||
|
||||
}; // END class PixRaster
|
||||
|
||||
|
|
|
|||
56
bazaar/TestLeptonica/BaseLine.cpp
Normal file
56
bazaar/TestLeptonica/BaseLine.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include "TestLeptonica.h"
|
||||
|
||||
static void BaseLine(PixRaster &pixRaster)
|
||||
{
|
||||
CHECKR(pixRaster.DeskewLocal(), "Deskew error");
|
||||
Array<int> intArray = pixRaster.FindBaselines();
|
||||
CHECKR(intArray.GetCount(), "FindBaselines error");
|
||||
PIX *pix = pixRaster;
|
||||
int width = pixRaster.GetWidth();
|
||||
for(int iLine = 0; iLine < intArray.GetCount(); iLine++)
|
||||
{
|
||||
int y = intArray[iLine];
|
||||
for(int x = 0; x < width; x++)
|
||||
pixSetPixel(pix, x, y, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TestLeptonica::onBaseLine()
|
||||
{
|
||||
String fileName;
|
||||
FileSelector fs;
|
||||
PIX *pix;
|
||||
|
||||
if(!PromptYesNo(
|
||||
"[= [* Text baseline analysis demo]&&"
|
||||
"Please select a scanned, 1 bpp text image&"
|
||||
"you can take 'keystone.png' from TestLeptonica folder if you like&&"
|
||||
"[* CONTINUE ??]]"
|
||||
))
|
||||
return;
|
||||
|
||||
fs.ReadOnlyOption();
|
||||
if(fs.ExecuteOpen("Please select image for text baseline analysis:"))
|
||||
{
|
||||
FileIn s;
|
||||
if(!s.Open(~fs))
|
||||
{
|
||||
PromptOK("Error opening image");
|
||||
s.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Loads pixraster from source raster
|
||||
CHECKR(pixRaster.Load(s), "Error loading image");
|
||||
s.Close();
|
||||
|
||||
// apply line removal algothithm
|
||||
BaseLine(pixRaster);
|
||||
|
||||
// refresh the PixRasterCtrl control with the new image contents
|
||||
pixRasterCtrl.Reload();
|
||||
pixRasterCtrl.SetPage(0);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ void TestLeptonica::onPageLayout()
|
|||
|
||||
if(!PromptYesNo(
|
||||
"[= [* Page layout analysis demo]&&"
|
||||
"Please select a scanned image with mixed text and graphics&"
|
||||
"Please select a 1 bpp scanned image with mixed text and graphics&"
|
||||
"you can take one from TestLeptonica folder if you like&&"
|
||||
"[* CONTINUE ??]]"
|
||||
))
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class TestLeptonica : public WithTestLeptonicaLayout<TopWindow>
|
|||
// button handlers
|
||||
void onLineRemoval(void);
|
||||
void onPageLayout(void);
|
||||
void onBaseLine(void);
|
||||
void onQuit(void);
|
||||
|
||||
// PIX raster
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
LAYOUT(TestLeptonicaLayout, 640, 400)
|
||||
ITEM(Button, PageLayoutButton, SetLabel(t_("Page layout test")).LeftPosZ(8, 92).TopPosZ(32, 15))
|
||||
ITEM(Button, BaseLineButton, SetLabel(t_("Baseline test")).Tip(t_("Find baseline of text lines of a scanned page")).LeftPosZ(8, 92).TopPosZ(56, 15))
|
||||
ITEM(Button, QuitButton, SetLabel(t_("\aQuit")).LeftPosZ(8, 92).BottomPosZ(9, 15))
|
||||
ITEM(PixRasterCtrl, pixRasterCtrl, SetFrame(InsetFrame()).HSizePosZ(108, 8).VSizePosZ(8, 8))
|
||||
ITEM(Button, LineRemovalButton, SetLabel(t_("Line removal test")).LeftPosZ(8, 92).TopPosZ(8, 15))
|
||||
ITEM(Button, LineRemovalButton, SetLabel(t_("Line removal test")).Tip(t_("Removes horizontal lines from a scanned paper drawing")).LeftPosZ(8, 92).TopPosZ(8, 15))
|
||||
ITEM(Button, PageLayoutButton, SetLabel(t_("Page layout test")).Tip(t_("Finds the layout of a page, separating graphics from text")).LeftPosZ(8, 92).TopPosZ(32, 15))
|
||||
END_LAYOUT
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ file
|
|||
TestLeptonica.h,
|
||||
LineRemoval.cpp,
|
||||
PageLayout.cpp,
|
||||
BaseLine.cpp,
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
|
|
|
|||
BIN
bazaar/TestLeptonica/keystone.png
Normal file
BIN
bazaar/TestLeptonica/keystone.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
|
|
@ -16,6 +16,7 @@ TestLeptonica::TestLeptonica()
|
|||
// connects button handlers
|
||||
LineRemovalButton <<= THISBACK(onLineRemoval);
|
||||
PageLayoutButton <<= THISBACK(onPageLayout);
|
||||
BaseLineButton <<= THISBACK(onBaseLine);
|
||||
QuitButton <<= THISBACK(onQuit);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue