Leptonica 1.68
C Image Processing Library

warper_reg.c

Go to the documentation of this file.
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  *   warper_reg.c
00018  */
00019 
00020 #include <math.h>
00021 #include "allheaders.h"
00022 
00023 static void DisplayResult(PIXA *pixac, PIX **ppixd, l_int32 newline);
00024 static void DisplayCaptcha(PIXA *pixac, PIX *pixs, l_int32 nterms,
00025                            l_uint32 seed, l_int32 newline);
00026 
00027 static const l_int32 size = 4;
00028 static const l_float32 xmag[] = {3.0, 4.0, 5.0, 7.0};
00029 static const l_float32 ymag[] = {5.0, 6.0, 8.0, 10.0};
00030 static const l_float32 xfreq[] = {0.11, 0.10, 0.10, 0.12};
00031 static const l_float32 yfreq[] = {0.11, 0.13, 0.13, 0.15};
00032 static const l_int32 nx[] = {4, 3, 2, 1};
00033 static const l_int32 ny[] = {4, 3, 2, 1};
00034 
00035 
00036 main(int    argc,
00037      char **argv)
00038 {
00039 l_int32       i, k, newline;
00040 PIX          *pixs, *pixt, *pixg, *pixd;
00041 PIXA         *pixac;
00042 L_REGPARAMS  *rp;
00043 
00044     if (regTestSetup(argc, argv, &rp))
00045         return 1;
00046 
00047     pixs = pixRead("feyn-word.tif");
00048     pixt = pixAddBorder(pixs, 25, 0);
00049     pixg = pixConvertTo8(pixt, 0);
00050 
00051     for (k = 0; k < size; k++) {
00052         pixac = pixaCreate(0);
00053         for (i = 0; i < 50; i++) {
00054             pixd = pixRandomHarmonicWarp(pixg, xmag[k], ymag[k], xfreq[k],
00055                                          yfreq[k], nx[k], ny[k], 7 * i, 255);
00056             newline = (i % 10 == 0) ? 1 : 0;
00057             DisplayResult(pixac, &pixd, newline);
00058         }
00059         pixd = pixaDisplay(pixac, 0, 0);
00060         regTestWritePixAndCheck(rp, pixd, IFF_PNG);
00061         pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00062         pixaDestroy(&pixac);
00063         pixDestroy(&pixd);
00064     }
00065 
00066     pixDestroy(&pixt);
00067     pixDestroy(&pixg);
00068 
00069     for (k = 1; k <= 4; k++) {
00070         pixac = pixaCreate(0);
00071         for (i = 0; i < 50; i++) {
00072             newline = (i % 10 == 0) ? 1 : 0;
00073             DisplayCaptcha(pixac, pixs, k, 7 * i, newline);
00074         }
00075         pixd = pixaDisplay(pixac, 0, 0);
00076         regTestWritePixAndCheck(rp, pixd, IFF_PNG);
00077         pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00078         pixaDestroy(&pixac);
00079         pixDestroy(&pixd);
00080     }
00081 
00082     pixDestroy(&pixs);
00083     regTestCleanup(rp);
00084     return 0;
00085 }
00086 
00087 
00088 static void
00089 DisplayResult(PIXA    *pixac,
00090               PIX    **ppixd,
00091               l_int32  newline)
00092 {
00093 l_uint32  color;
00094 PIX      *pixt;
00095 
00096     color = 0;
00097     color = ((rand() >> 16) & 0xff) << L_RED_SHIFT |
00098             ((rand() >> 16) & 0xff) << L_GREEN_SHIFT |
00099             ((rand() >> 16) & 0xff) << L_BLUE_SHIFT;
00100     pixt = pixColorizeGray(*ppixd, color, 0);
00101     pixSaveTiled(pixt, pixac, 1, newline, 20, 32);
00102     pixDestroy(&pixt);
00103     pixDestroy(ppixd);
00104     return;
00105 }
00106 
00107 
00108 static void
00109 DisplayCaptcha(PIXA    *pixac,
00110               PIX      *pixs,
00111               l_int32   nterms,
00112               l_uint32  seed,
00113               l_int32   newline)
00114 {
00115 l_uint32  color;
00116 PIX      *pixd;
00117 
00118     color = 0;
00119     color = ((rand() >> 16) & 0xff) << L_RED_SHIFT |
00120             ((rand() >> 16) & 0xff) << L_GREEN_SHIFT |
00121             ((rand() >> 16) & 0xff) << L_BLUE_SHIFT;
00122     pixd = pixSimpleCaptcha(pixs, 25, nterms, seed, color, 0);
00123     pixSaveTiled(pixd, pixac, 1, newline, 20, 32);
00124     pixDestroy(&pixd);
00125     return;
00126 }
00127 
00128 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines