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 * sorttest.c 00018 * 00019 * Tests sorting of connected components by various attributes, 00020 * in increasing or decreasing order. 00021 */ 00022 00023 #include <stdio.h> 00024 #include <stdlib.h> 00025 #include "allheaders.h" 00026 00027 00028 main(int argc, 00029 char **argv) 00030 { 00031 char *filein; 00032 l_int32 i, n, ns; 00033 BOX *box; 00034 BOXA *boxa, *boxas; 00035 PIX *pixs, *pixt; 00036 PIXA *pixa, *pixas, *pixas2; 00037 static char mainName[] = "sorttest"; 00038 00039 if (argc != 2) 00040 exit(ERROR_INT(" Syntax: sorttest filein", mainName, 1)); 00041 00042 filein = argv[1]; 00043 00044 if ((pixs = pixRead(filein)) == NULL) 00045 exit(ERROR_INT("pixs not made", mainName, 1)); 00046 00047 #if 0 00048 boxa = pixConnComp(pixs, NULL, 8); 00049 n = boxaGetCount(boxa); 00050 00051 boxas = boxaSort(boxa, L_SORT_BY_PERIMETER, L_SORT_DECREASING, NULL); 00052 ns = boxaGetCount(boxas); 00053 fprintf(stderr, "Number of cc: n = %d, ns = %d\n", n, ns); 00054 boxaWrite("/tmp/junkboxa.ba", boxas); 00055 00056 for (i = 0; i < n; i++) { 00057 box = boxaGetBox(boxas, i, L_CLONE); 00058 pixRenderBox(pixs, box, 2, L_FLIP_PIXELS); 00059 boxDestroy(&box); 00060 } 00061 pixWrite("/tmp/junkout.png", pixs, IFF_PNG); 00062 boxaDestroy(&boxa); 00063 boxaDestroy(&boxas); 00064 #endif 00065 00066 00067 #if 1 00068 boxa = pixConnComp(pixs, &pixa, 8); 00069 n = pixaGetCount(pixa); 00070 00071 pixas = pixaSort(pixa, L_SORT_BY_Y, L_SORT_INCREASING, NULL, L_CLONE); 00072 ns = pixaGetCount(pixas); 00073 fprintf(stderr, "Number of cc: n = %d, ns = %d\n", n, ns); 00074 pixaWrite("/tmp/junkpixa.pa", pixas); 00075 pixas2 = pixaRead("/tmp/junkpixa.pa"); 00076 pixaWrite("/tmp/junkpixa2.pa", pixas2); 00077 00078 pixt = pixaDisplayOnLattice(pixas, 100, 100); 00079 pixWrite("/tmp/junkpix.png", pixt, IFF_PNG); 00080 boxaWrite("/tmp/junkboxa.ba", pixas->boxa); 00081 pixDestroy(&pixt); 00082 pixaDestroy(&pixa); 00083 pixaDestroy(&pixas); 00084 pixaDestroy(&pixas2); 00085 boxaDestroy(&boxa); 00086 #endif 00087 00088 pixDestroy(&pixs); 00089 exit(0); 00090 } 00091 00092