/*! * pixUpDownDetectDwa() * * Input: pixs (1 bpp, deskewed, English text, 150 - 300 ppi) * &conf (<return> confidence that text is rightside-up) * mincount (min number of up + down; use 0 for default) * debug (1 for debug output; 0 otherwise) * Return: 0 if OK, 1 on error * * Notes: * (1) Faster (DWA) version of pixUpDownDetect(). * (2) This is a special case (but typical and slightly faster) of * pixUpDownDetectGeneralDwa(), where the pixels identified * through the HMT (hit-miss transform) are not clipped by * a truncated word mask pixm. See pixUpDownDetectGeneral() * for usage and other details. * (3) The returned confidence is the normalized difference * between the number of detected up and down ascenders, * assuming that the text is either rightside-up or upside-down * and not rotated at a 90 degree angle. */ l_int32 pixUpDownDetectDwa(PIX *pixs, l_float32 *pconf, l_int32 mincount, l_int32 debug) { return pixUpDownDetectGeneralDwa(pixs, pconf, mincount, 0, debug); }
main(int argc, char **argv) { char *filein; l_int32 i, orient; l_float32 upconf1, upconf2, leftconf1, leftconf2, conf1, conf2; PIX *pixs, *pixt1, *pixt2; static char mainName[] = "flipdetect_reg"; if (argc != 2) exit(ERROR_INT(" Syntax: flipdetect_reg filein", mainName, 1)); filein = argv[1]; if ((pixt1 = pixRead(filein)) == NULL) exit(ERROR_INT("pixt1 not made", mainName, 1)); pixs = pixConvertTo1(pixt1, 130); pixDestroy(&pixt1); fprintf(stderr, "\nTest orientation detection\n"); startTimer(); pixOrientDetect(pixs, &upconf1, &leftconf1, 0, 0); fprintf(stderr, "Time for rop orient test: %7.3f sec\n", stopTimer()); makeOrientDecision(upconf1, leftconf1, 0, 0, &orient, 1); startTimer(); pixOrientDetectDwa(pixs, &upconf2, &leftconf2, 0, 0); fprintf(stderr, "Time for dwa orient test: %7.3f sec\n", stopTimer()); if (upconf1 == upconf2 && leftconf1 == leftconf2) { printStarredMessage("Orient results identical"); fprintf(stderr, "upconf = %7.3f, leftconf = %7.3f\n", upconf1, leftconf1); } else { printStarredMessage("Orient results differ"); fprintf(stderr, "upconf1 = %7.3f, upconf2 = %7.3f\n", upconf1, upconf2); fprintf(stderr, "leftconf1 = %7.3f, leftconf2 = %7.3f\n", leftconf1, leftconf2); } pixt1 = pixCopy(NULL, pixs); fprintf(stderr, "\nTest orient detection for 4 orientations\n"); for (i = 0; i < 4; i++) { pixOrientDetectDwa(pixt1, &upconf2, &leftconf2, 0, 0); makeOrientDecision(upconf2, leftconf2, 0, 0, &orient, 1); if (i == 3) break; pixt2 = pixRotate90(pixt1, 1); pixDestroy(&pixt1); pixt1 = pixt2; } pixDestroy(&pixt1); fprintf(stderr, "\nTest mirror reverse detection\n"); startTimer(); pixMirrorDetect(pixs, &conf1, 0, 1); fprintf(stderr, "Time for rop mirror flip test: %7.3f sec\n", stopTimer()); startTimer(); pixMirrorDetectDwa(pixs, &conf2, 0, 0); fprintf(stderr, "Time for dwa mirror flip test: %7.3f sec\n", stopTimer()); if (conf1 == conf2) { printStarredMessage("Mirror results identical"); fprintf(stderr, "conf = %7.3f\n", conf1); } else { printStarredMessage("Mirror results differ"); fprintf(stderr, "conf1 = %7.3f, conf2 = %7.3f\n", conf1, conf2); } fprintf(stderr, "\nSafer version of up-down tests\n"); pixUpDownDetectGeneral(pixs, &conf1, 0, 10, 1); pixUpDownDetectGeneralDwa(pixs, &conf2, 0, 10, 1); if (conf1 == conf2) fprintf(stderr, "Confidence results are identical\n"); else fprintf(stderr, "Confidence results differ\n"); pixDestroy(&pixs); exit(0); }