1 /*====================================================================*
2 - Copyright (C) 2001 Leptonica. All rights reserved.
3 -
4 - Redistribution and use in source and binary forms, with or without
5 - modification, are permitted provided that the following conditions
6 - are met:
7 - 1. Redistributions of source code must retain the above copyright
8 - notice, this list of conditions and the following disclaimer.
9 - 2. Redistributions in binary form must reproduce the above
10 - copyright notice, this list of conditions and the following
11 - disclaimer in the documentation and/or other materials
12 - provided with the distribution.
13 -
14 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *====================================================================*/
26
27 /*
28 * cornertest.c
29 *
30 * e.g., use on witten.png
31 */
32
33 #include "allheaders.h"
34
35 #define LINE_SIZE 29
36
37
main(int argc,char ** argv)38 int main(int argc,
39 char **argv)
40 {
41 char *filein, *fileout;
42 l_int32 x, y, n, i;
43 PIX *pixs;
44 PTA *pta;
45 PTAA *ptaa, *ptaa2, *ptaa3;
46 static char mainName[] = "cornertest";
47
48 if (argc != 3)
49 return ERROR_INT(" Syntax: cornertest filein fileout", mainName, 1);
50 filein = argv[1];
51 fileout = argv[2];
52
53 setLeptDebugOK(1);
54 if ((pixs = pixRead(filein)) == NULL)
55 return ERROR_INT("pixs not made", mainName, 1);
56
57 /* Clean noise in LR corner of witten.tif */
58 pixSetPixel(pixs, 2252, 3051, 0);
59 pixSetPixel(pixs, 2252, 3050, 0);
60 pixSetPixel(pixs, 2251, 3050, 0);
61
62 pta = pixFindCornerPixels(pixs);
63 ptaWriteStream(stderr, pta, 1);
64
65 /* Test pta and ptaa I/O */
66 #if 1
67 ptaa = ptaaCreate(3);
68 ptaaAddPta(ptaa, pta, L_COPY);
69 ptaaAddPta(ptaa, pta, L_COPY);
70 ptaaAddPta(ptaa, pta, L_COPY);
71 ptaaWriteStream(stderr, ptaa, 1);
72 ptaaWrite("/tmp/junkptaa", ptaa, 1);
73 ptaa2 = ptaaRead("/tmp/junkptaa");
74 ptaaWrite("/tmp/junkptaa2", ptaa2, 1);
75 ptaaWrite("/tmp/junkptaa3", ptaa, 0);
76 ptaa3 = ptaaRead("/tmp/junkptaa3");
77 ptaaWrite("/tmp/junkptaa4", ptaa3, 0);
78 ptaaDestroy(&ptaa);
79 ptaaDestroy(&ptaa2);
80 ptaaDestroy(&ptaa3);
81 #endif
82
83 /* mark corner pixels */
84 n = ptaGetCount(pta);
85 for (i = 0; i < n; i++) {
86 ptaGetIPt(pta, i, &x, &y);
87 pixRenderLine(pixs, x - LINE_SIZE, y, x + LINE_SIZE, y, 5,
88 L_FLIP_PIXELS);
89 pixRenderLine(pixs, x, y - LINE_SIZE, x, y + LINE_SIZE, 5,
90 L_FLIP_PIXELS);
91 }
92
93 pixWrite(fileout, pixs, IFF_PNG);
94
95 pixDestroy(&pixs);
96 ptaDestroy(&pta);
97 ptaDestroy(&pta);
98 return 0;
99 }
100
101