72#include <config_auto.h>
75#include "allheaders.h"
78static SELA *makeCheckerboardCornerSela(l_int32 size, l_int32 dilation,
79 l_int32 nsels,
PIXA *pixadb);
80static PIXA *makeCheckerboardCornerPixa(l_int32 size, l_int32 dilation,
83static const char selnames[64] =
"s_diag1 s_diag2 s_cross1 s_cross2";
110pixFindCheckerboardCorners(
PIX *pixs,
119PIX *pix1, *pix2, *pix3;
124 if (ppix_corners) *ppix_corners = NULL;
125 if (ppta_corners) *ppta_corners = NULL;
127 return ERROR_INT(
"pixs not defined", __func__, 1);
128 if (size <= 0) size = 7;
130 return ERROR_INT(
"size too small", __func__, 1);
131 if (dilation < 1 || dilation > 5)
132 return ERROR_INT(
"dilation not in [1 ...5]", __func__, 1);
133 if (nsels != 2 && nsels != 4)
134 return ERROR_INT(
"nsels not 2 or 4", __func__, 1);
137 sela = makeCheckerboardCornerSela(size, dilation, nsels, pixadb);
139 return ERROR_INT(
"sela not made", __func__, 1);
141 pix1 = selaDisplayInPix(sela, 15, 3, 15, 2);
146 pix1 = pixUnionOfMorphOps(pixs, sela, L_MORPH_HMT);
147 if (pixadb) pixaAddPix(pixadb, pix1,
L_CLONE);
153 if (pixadb) pixaAddPix(pixadb, pix2,
L_CLONE);
156 pix3 = pixThinConnected(pix2,
L_THIN_FG, 8, 0);
157 if (pixadb) pixaAddPix(pixadb, pix3,
L_CLONE);
160 boxa1 = pixConnCompBB(pix3, 8);
166 sel = selMakePlusSign(15, 2);
167 pix1 = pixDisplaySelectedPixels(pixs, pix3, sel, 0xff000000);
173 *ppix_corners = pix3;
177 *ppta_corners = pta1;
199makeCheckerboardCornerSela(l_int32 size,
209 if (size <= 0) size = 7;
211 return (
SELA *)ERROR_PTR(
"size too small", __func__, NULL);
212 if (dilation < 1 || dilation > 5)
213 return (
SELA *)ERROR_PTR(
"dilation not in [1 ...5]", __func__, NULL);
214 if (nsels != 2 && nsels != 4)
215 return (
SELA *)ERROR_PTR(
"nsels not 2 or 4", __func__, NULL);
217 if ((pixa1 = makeCheckerboardCornerPixa(size, dilation, nsels)) == NULL)
218 return (
SELA *)ERROR_PTR(
"pixa for sels not made", __func__, NULL);
220 pix1 = pixaDisplayTiledInColumns(pixa1, 4, 8.0, 15, 2);
223 sa = sarrayCreateWordsFromString(selnames);
224 sela = selaCreateFromColorPixa(pixa1, sa);
228 return (
SELA *)ERROR_PTR(
"sela not made", __func__, NULL);
250makeCheckerboardCornerPixa(l_int32 size,
254PIX *pix1, *pix2, *pix3;
257 pixa1 = pixaCreate(4);
260 pix1 = pixCreate(size, size, 32);
262 pix2 = pixCreate(size, size, 1);
263 pixSetPixel(pix2, 1, 1, 1);
264 pixSetPixel(pix2, size - 2, size - 2, 1);
266 pixDilateBrick(pix2, pix2, dilation, dilation);
267 pixSetMasked(pix1, pix2, 0x00ff0000);
268 pix3 = pixRotate90(pix2, 1);
269 pixSetMasked(pix1, pix3, 0xff000000);
270 pixSetRGBPixel(pix1, size / 2, size / 2, 128, 128, 128);
274 pix1 = pixCreate(size, size, 32);
276 pixSetMasked(pix1, pix2, 0xff000000);
277 pixSetMasked(pix1, pix3, 0x00ff0000);
278 pixSetRGBPixel(pix1, size / 2, size / 2, 128, 128, 128);
287 pix1 = pixCreate(size, size, 32);
289 pix2 = pixCreate(size, size, 1);
290 pixSetPixel(pix2, size / 2, 1, 1);
291 pixSetPixel(pix2, size / 2, size - 2, 1);
293 pixDilateBrick(pix2, pix2, dilation, dilation);
294 pixSetMasked(pix1, pix2, 0x00ff0000);
295 pix3 = pixRotate90(pix2, 1);
296 pixSetMasked(pix1, pix3, 0xff000000);
297 pixSetRGBPixel(pix1, size / 2, size / 2, 128, 128, 128);
301 pix1 = pixCreate(size, size, 32);
303 pixSetMasked(pix1, pix3, 0x00ff0000);
304 pixSetMasked(pix1, pix2, 0xff000000);
305 pixSetRGBPixel(pix1, size / 2, size / 2, 128, 128, 128);