Leptonica 1.68
C Image Processing Library
|
00001 /*====================================================================* 00002 - Copyright (C) 2001 Leptonica. All rights reserved. 00003 - This software is distributed in the hope that it will be 00004 - useful, but with NO WARRANTY OF ANY KIND. 00005 - No author or distributor accepts responsibility to anyone for the 00006 - consequences of using this software, or for whether it serves any 00007 - particular purpose or works at all, unless he or she says so in 00008 - writing. Everyone is granted permission to copy, modify and 00009 - redistribute this source code, for commercial or non-commercial 00010 - purposes, with the following restrictions: (1) the origin of this 00011 - source code must not be misrepresented; (2) modified versions must 00012 - be plainly marked as such; and (3) this notice may not be removed 00013 - or altered from any source or modified source distribution. 00014 *====================================================================*/ 00015 00016 /* 00017 * flipdetect_reg.c 00018 * 00019 * Tests 90 degree orientation of text and whether the text is 00020 * mirror reversed. Compares the rasterop with dwa implementations 00021 * for speed. Shows the typical 'confidence' outputs from the 00022 * functions in flipdetect.c. 00023 */ 00024 00025 #include <stdio.h> 00026 #include <stdlib.h> 00027 #include "allheaders.h" 00028 00029 static void printStarredMessage(const char *msg); 00030 00031 main(int argc, 00032 char **argv) 00033 { 00034 char *filein; 00035 l_int32 i, orient; 00036 l_float32 upconf1, upconf2, leftconf1, leftconf2, conf1, conf2; 00037 PIX *pixs, *pixt1, *pixt2; 00038 static char mainName[] = "flipdetect_reg"; 00039 00040 if (argc != 2) 00041 exit(ERROR_INT(" Syntax: flipdetect_reg filein", mainName, 1)); 00042 00043 filein = argv[1]; 00044 00045 if ((pixt1 = pixRead(filein)) == NULL) 00046 exit(ERROR_INT("pixt1 not made", mainName, 1)); 00047 pixs = pixConvertTo1(pixt1, 130); 00048 pixDestroy(&pixt1); 00049 00050 fprintf(stderr, "\nTest orientation detection\n"); 00051 startTimer(); 00052 pixOrientDetect(pixs, &upconf1, &leftconf1, 0, 0); 00053 fprintf(stderr, "Time for rop orient test: %7.3f sec\n", stopTimer()); 00054 00055 makeOrientDecision(upconf1, leftconf1, 0, 0, &orient, 1); 00056 00057 startTimer(); 00058 pixOrientDetectDwa(pixs, &upconf2, &leftconf2, 0, 0); 00059 fprintf(stderr, "Time for dwa orient test: %7.3f sec\n", stopTimer()); 00060 00061 if (upconf1 == upconf2 && leftconf1 == leftconf2) { 00062 printStarredMessage("Orient results identical"); 00063 fprintf(stderr, "upconf = %7.3f, leftconf = %7.3f\n", 00064 upconf1, leftconf1); 00065 } 00066 else { 00067 printStarredMessage("Orient results differ"); 00068 fprintf(stderr, "upconf1 = %7.3f, upconf2 = %7.3f\n", upconf1, upconf2); 00069 fprintf(stderr, "leftconf1 = %7.3f, leftconf2 = %7.3f\n", 00070 leftconf1, leftconf2); 00071 } 00072 00073 pixt1 = pixCopy(NULL, pixs); 00074 fprintf(stderr, "\nTest orient detection for 4 orientations\n"); 00075 for (i = 0; i < 4; i++) { 00076 pixOrientDetectDwa(pixt1, &upconf2, &leftconf2, 0, 0); 00077 makeOrientDecision(upconf2, leftconf2, 0, 0, &orient, 1); 00078 if (i == 3) break; 00079 pixt2 = pixRotate90(pixt1, 1); 00080 pixDestroy(&pixt1); 00081 pixt1 = pixt2; 00082 } 00083 pixDestroy(&pixt1); 00084 00085 fprintf(stderr, "\nTest mirror reverse detection\n"); 00086 startTimer(); 00087 pixMirrorDetect(pixs, &conf1, 0, 1); 00088 fprintf(stderr, "Time for rop mirror flip test: %7.3f sec\n", stopTimer()); 00089 00090 startTimer(); 00091 pixMirrorDetectDwa(pixs, &conf2, 0, 0); 00092 fprintf(stderr, "Time for dwa mirror flip test: %7.3f sec\n", stopTimer()); 00093 00094 if (conf1 == conf2) { 00095 printStarredMessage("Mirror results identical"); 00096 fprintf(stderr, "conf = %7.3f\n", conf1); 00097 } 00098 else { 00099 printStarredMessage("Mirror results differ"); 00100 fprintf(stderr, "conf1 = %7.3f, conf2 = %7.3f\n", conf1, conf2); 00101 } 00102 00103 fprintf(stderr, "\nSafer version of up-down tests\n"); 00104 pixUpDownDetectGeneral(pixs, &conf1, 0, 10, 1); 00105 pixUpDownDetectGeneralDwa(pixs, &conf2, 0, 10, 1); 00106 if (conf1 == conf2) 00107 fprintf(stderr, "Confidence results are identical\n"); 00108 else 00109 fprintf(stderr, "Confidence results differ\n"); 00110 00111 pixDestroy(&pixs); 00112 exit(0); 00113 } 00114 00115 00116 void 00117 printStarredMessage(const char *msg) 00118 { 00119 fprintf(stderr, "****************************************************\n"); 00120 fprintf(stderr, "*********** %s ***********\n", msg); 00121 fprintf(stderr, "****************************************************\n"); 00122 return; 00123 } 00124 00125