202 #include <config_auto.h>
206 #include "allheaders.h"
209 static const char *textsel1 =
"x oo "
215 static const char *textsel2 =
" oo x"
221 static const char *textsel3 =
"xxxxxx"
227 static const char *textsel4 =
"xxxxxx"
234 static const l_int32 DefaultMinUpDownCount = 70;
235 static const l_float32 DefaultMinUpDownConf = 8.0;
236 static const l_float32 DefaultMinUpDownRatio = 2.5;
239 static const l_int32 DefaultMinMirrorFlipCount = 100;
240 static const l_float32 DefaultMinMirrorFlipConf = 5.0;
243 static void pixDebugFlipDetect(
const char *filename,
PIX *pixs,
244 PIX *pixhm, l_int32 enable);
278 l_float32 *pleftconf,
283 l_float32 upconf, leftconf;
286 PROCNAME(
"pixOrientCorrect");
288 if (!pixs || pixGetDepth(pixs) != 1)
289 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
296 if (pupconf) *pupconf = upconf;
297 if (pleftconf) *pleftconf = leftconf;
306 L_INFO(
"text orientation not determined; no rotation\n", procName);
307 if (protation) *protation = 0;
311 L_INFO(
"text is oriented up; no rotation\n", procName);
312 if (protation) *protation = 0;
316 L_INFO(
"landscape; text oriented left; 90 cw rotation\n", procName);
317 if (protation) *protation = 90;
321 L_INFO(
"text oriented down; 180 cw rotation\n", procName);
322 if (protation) *protation = 180;
326 L_INFO(
"landscape; text oriented right; 270 cw rotation\n", procName);
327 if (protation) *protation = 270;
331 L_ERROR(
"invalid orient flag!\n", procName);
407 l_float32 *pleftconf,
413 PROCNAME(
"pixOrientDetect");
415 if (!pixs || pixGetDepth(pixs) != 1)
416 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
417 if (!pupconf && !pleftconf)
418 return ERROR_INT(
"nothing to do", procName, 1);
420 mincount = DefaultMinUpDownCount;
471 l_float32 absupconf, absleftconf;
473 PROCNAME(
"makeOrientDecision");
476 return ERROR_INT(
"&orient not defined", procName, 1);
478 if (upconf == 0.0 || leftconf == 0.0) {
479 L_INFO(
"not enough confidence to get orientation\n", procName);
483 if (minupconf == 0.0)
484 minupconf = DefaultMinUpDownConf;
486 minratio = DefaultMinUpDownRatio;
487 absupconf = L_ABS(upconf);
488 absleftconf = L_ABS(leftconf);
492 if (upconf > minupconf && absupconf > minratio * absleftconf)
494 else if (leftconf > minupconf && absleftconf > minratio * absupconf)
496 else if (upconf < -minupconf && absupconf > minratio * absleftconf)
498 else if (leftconf < -minupconf && absleftconf > minratio * absupconf)
502 lept_stderr(
"upconf = %7.3f, leftconf = %7.3f\n", upconf, leftconf);
504 lept_stderr(
"Confidence is low; no determination is made\n");
564 l_int32 countup, countdown, nmax;
565 l_float32 nup, ndown;
566 PIX *pix0, *pix1, *pix2, *pix3, *pixm;
567 SEL *sel1, *sel2, *sel3, *sel4;
569 PROCNAME(
"pixUpDownDetect");
572 return ERROR_INT(
"&conf not defined", procName, 1);
574 if (!pixs || pixGetDepth(pixs) != 1)
575 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
577 mincount = DefaultMinUpDownCount;
600 l_int32 i, nbox, x, y, w, h;
608 for (i = 0; i < nbox; i++) {
612 pixRasterop(pixm, x + npixels, y - 6, w - 2 * npixels, h + 13,
622 pix1 =
pixHMT(NULL, pix0, sel1);
623 pix2 =
pixHMT(NULL, pix0, sel2);
624 pixOr(pix1, pix1, pix2);
629 pixDebugFlipDetect(
"/tmp/lept/orient/up.png", pixs, pix1, debug);
635 pix1 =
pixHMT(NULL, pix0, sel3);
636 pix2 =
pixHMT(NULL, pix0, sel4);
637 pixOr(pix1, pix1, pix2);
642 pixDebugFlipDetect(
"/tmp/lept/orient/down.png", pixs, pix1, debug);
649 nup = (l_float32)(countup);
650 ndown = (l_float32)(countdown);
651 nmax = L_MAX(countup, countdown);
653 *pconf = 2. * ((nup - ndown) / sqrt(nup + ndown));
656 if (pixm) pixWriteDebug(
"/tmp/lept/orient/pixm1.png", pixm, IFF_PNG);
657 lept_stderr(
"nup = %7.3f, ndown = %7.3f, conf = %7.3f\n",
659 if (*pconf > DefaultMinUpDownConf)
661 if (*pconf < -DefaultMinUpDownConf)
723 l_int32 count1, count2, nmax;
724 l_float32 nleft, nright;
725 PIX *pix0, *pix1, *pix2, *pix3;
728 PROCNAME(
"pixMirrorDetect");
731 return ERROR_INT(
"&conf not defined", procName, 1);
733 if (!pixs || pixGetDepth(pixs) != 1)
734 return ERROR_INT(
"pixs not defined or not 1 bpp", procName, 1);
736 mincount = DefaultMinMirrorFlipCount;
751 pixOr(pix0, pix0, pixs);
755 pix1 =
pixHMT(NULL, pix0, sel1);
758 pixDebugFlipDetect(
"/tmp/lept/orient/right.png", pixs, pix1, debug);
763 pix2 =
pixHMT(NULL, pix0, sel2);
766 pixDebugFlipDetect(
"/tmp/lept/orient/left.png", pixs, pix2, debug);
770 nright = (l_float32)count1;
771 nleft = (l_float32)count2;
772 nmax = L_MAX(count1, count2);
778 *pconf = 2. * ((nright - nleft) / sqrt(nright + nleft));
781 lept_stderr(
"nright = %f, nleft = %f\n", nright, nleft);
782 if (*pconf > DefaultMinMirrorFlipConf)
784 if (*pconf < -DefaultMinMirrorFlipConf)
805 pixDebugFlipDetect(
const char *filename,
819 pixWriteDebug(filename, pixt, IFF_PNG);
PIX * pixReduceRankBinaryCascade(PIX *pixs, l_int32 level1, l_int32 level2, l_int32 level3, l_int32 level4)
pixReduceRankBinaryCascade()
void boxDestroy(BOX **pbox)
boxDestroy()
l_int32 boxaGetCount(BOXA *boxa)
boxaGetCount()
l_ok boxGetGeometry(BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
BOXA * pixConnComp(PIX *pixs, PIXA **ppixa, l_int32 connectivity)
pixConnComp()
PIX * pixOrientCorrect(PIX *pixs, l_float32 minupconf, l_float32 minratio, l_float32 *pupconf, l_float32 *pleftconf, l_int32 *protation, l_int32 debug)
pixOrientCorrect()
l_ok makeOrientDecision(l_float32 upconf, l_float32 leftconf, l_float32 minupconf, l_float32 minratio, l_int32 *porient, l_int32 debug)
makeOrientDecision()
l_ok pixMirrorDetect(PIX *pixs, l_float32 *pconf, l_int32 mincount, l_int32 debug)
pixMirrorDetect()
l_ok pixUpDownDetect(PIX *pixs, l_float32 *pconf, l_int32 mincount, l_int32 npixels, l_int32 debug)
pixUpDownDetect()
l_ok pixOrientDetect(PIX *pixs, l_float32 *pupconf, l_float32 *pleftconf, l_int32 mincount, l_int32 debug)
pixOrientDetect()
PIX * pixHMT(PIX *pixd, PIX *pixs, SEL *sel)
pixHMT()
PIX * pixMorphSequence(PIX *pixs, const char *sequence, l_int32 dispsep)
pixMorphSequence()
PIX * pixMorphCompSequence(PIX *pixs, const char *sequence, l_int32 dispsep)
pixMorphCompSequence()
l_ok pixSetMaskedCmap(PIX *pixs, PIX *pixm, l_int32 x, l_int32 y, l_int32 rval, l_int32 gval, l_int32 bval)
pixSetMaskedCmap()
void pixDestroy(PIX **ppix)
pixDestroy()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixCreateTemplate(const PIX *pixs)
pixCreateTemplate()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
PIX * pixOr(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixOr()
PIX * pixAnd(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixAnd()
PIX * pixXor(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixXor()
PIX * pixConvert1To4Cmap(PIX *pixs)
pixConvert1To4Cmap()
l_ok pixRasterop(PIX *pixd, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, PIX *pixs, l_int32 sx, l_int32 sy)
pixRasterop()
PIX * pixRotate90(PIX *pixs, l_int32 direction)
pixRotate90()
PIX * pixRotateOrth(PIX *pixs, l_int32 quads)
pixRotateOrth()
SEL * selCreateFromString(const char *text, l_int32 h, l_int32 w, const char *name)
selCreateFromString()
void selDestroy(SEL **psel)
selDestroy()
void lept_stderr(const char *fmt,...)
lept_stderr()
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()