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 * overlap_reg.c 00018 * 00019 * Tests the function that combines boxes that overlap into 00020 * their bounding regions. 00021 */ 00022 00023 #include "allheaders.h" 00024 00025 /* Determines maximum size of boxes */ 00026 static const l_float32 maxsize[] = {5.0, 10.0, 15.0, 20.0, 25.0, 26.0, 27.0}; 00027 00028 00029 main(int argc, 00030 char **argv) 00031 { 00032 l_int32 i, k, x, y, w, h; 00033 BOX *box; 00034 BOXA *boxa1, *boxa2; 00035 PIX *pix1, *pix2, *pixd; 00036 PIXA *pixa; 00037 L_REGPARAMS *rp; 00038 00039 if (regTestSetup(argc, argv, &rp)) 00040 return 1; 00041 00042 for (k = 0; k < 7; k++) { 00043 srand(45617); 00044 pixa = pixaCreate(2); 00045 boxa1 = boxaCreate(0); 00046 for (i = 0; i < 500; i++) { 00047 x = (l_int32)(600.0 * (l_float64)rand() / (l_float64)RAND_MAX); 00048 y = (l_int32)(600.0 * (l_float64)rand() / (l_float64)RAND_MAX); 00049 w = (l_int32) 00050 (1.0 + maxsize[k] * (l_float64)rand() / (l_float64)RAND_MAX); 00051 h = (l_int32) 00052 (1.0 + maxsize[k] * (l_float64)rand() / (l_float64)RAND_MAX); 00053 box = boxCreate(x, y, w, h); 00054 boxaAddBox(boxa1, box, L_INSERT); 00055 } 00056 00057 pix1 = pixCreate(660, 660, 1); 00058 pixRenderBoxa(pix1, boxa1, 1, L_SET_PIXELS); 00059 pixaAddPix(pixa, pix1, L_INSERT); 00060 boxa2 = boxaCombineOverlaps(boxa1); 00061 pix2 = pixCreate(660, 660, 1); 00062 pixRenderBoxa(pix2, boxa2, 1, L_SET_PIXELS); 00063 pixaAddPix(pixa, pix2, L_INSERT); 00064 00065 pixd = pixaDisplayTiledInRows(pixa, 1, 1500, 1.0, 0, 50, 2); 00066 pixDisplayWithTitle(pixd, 100, 100 + 100 * k, NULL, rp->display); 00067 regTestWritePixAndCheck(rp, pixd, IFF_PNG); 00068 fprintf(stderr, "%d: n_init = %d, n_final = %d\n", 00069 k, boxaGetCount(boxa1), boxaGetCount(boxa2)); 00070 pixDestroy(&pixd); 00071 boxaDestroy(&boxa1); 00072 boxaDestroy(&boxa2); 00073 pixaDestroy(&pixa); 00074 } 00075 00076 regTestCleanup(rp); 00077 return 0; 00078 } 00079 00080