本文整理汇总了C++中pixaGetCount函数的典型用法代码示例。如果您正苦于以下问题:C++ pixaGetCount函数的具体用法?C++ pixaGetCount怎么用?C++ pixaGetCount使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pixaGetCount函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pixaWriteFiles
/*!
* pixaWriteFiles()
*
* Input: rootname
* pixa
* format (defined in imageio.h; see notes for default)
* Return: 0 if OK; 1 on error
*
* Notes:
* (1) Use @format = IFF_DEFAULT to decide the output format
* individually for each pix.
*/
l_int32
pixaWriteFiles(const char *rootname, PIXA *pixa, l_int32 format)
{
PIX *pix;
l_int32 i, n, pixformat;
char bigbuf[L_BUF_SIZE];
PROCNAME("pixaWriteFiles");
if (!rootname)
return ERROR_INT("rootname not defined", procName, 1);
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
if (format < 0 || format == IFF_UNKNOWN ||
format >= NumImageFileFormatExtensions)
return ERROR_INT("invalid format", procName, 1);
n = pixaGetCount(pixa);
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixa, i, L_CLONE);
if (format == IFF_DEFAULT)
pixformat = pixChooseOutputFormat(pix);
else
pixformat = format;
snprintf(bigbuf, L_BUF_SIZE, "%s%03d.%s", rootname, i,
ImageFileFormatExtensions[pixformat]);
pixWrite(bigbuf, pix, pixformat);
pixDestroy(&pix);
}
return 0;
}
示例2: pixConnCompTransform
/*!
* \brief pixConnCompTransform()
*
* \param[in] pixs 1 bpp
* \param[in] connect connectivity: 4 or 8
* \param[in] depth of pixd: 8 or 16 bpp; use 0 for auto determination
* \return pixd 8, 16 or 32 bpp, or NULL on error
*
* <pre>
* Notes:
* (1) pixd is 8, 16 or 32 bpp, and the pixel values label the
* fg component, starting with 1. Pixels in the bg are labelled 0.
* (2) If %depth = 0, the depth of pixd is 8 if the number of c.c.
* is less than 254, 16 if the number of c.c is less than 0xfffe,
* and 32 otherwise.
* (3) If %depth = 8, the assigned label for the n-th component is
* 1 + n % 254. We use mod 254 because 0 is uniquely assigned
* to black: e.g., see pixcmapCreateRandom(). Likewise,
* if %depth = 16, the assigned label uses mod(2^16 - 2), and
* if %depth = 32, no mod is taken.
* </pre>
*/
PIX *
pixConnCompTransform(PIX *pixs,
l_int32 connect,
l_int32 depth)
{
l_int32 i, n, index, w, h, xb, yb, wb, hb;
BOXA *boxa;
PIX *pix1, *pix2, *pixd;
PIXA *pixa;
PROCNAME("pixConnCompTransform");
if (!pixs || pixGetDepth(pixs) != 1)
return (PIX *)ERROR_PTR("pixs undefined or not 1 bpp", procName, NULL);
if (connect != 4 && connect != 8)
return (PIX *)ERROR_PTR("connectivity must be 4 or 8", procName, NULL);
if (depth != 0 && depth != 8 && depth != 16 && depth != 32)
return (PIX *)ERROR_PTR("depth must be 0, 8, 16 or 32", procName, NULL);
boxa = pixConnComp(pixs, &pixa, connect);
n = pixaGetCount(pixa);
boxaDestroy(&boxa);
pixGetDimensions(pixs, &w, &h, NULL);
if (depth == 0) {
if (n < 254)
depth = 8;
else if (n < 0xfffe)
depth = 16;
else
depth = 32;
}
pixd = pixCreate(w, h, depth);
pixSetSpp(pixd, 1);
if (n == 0) { /* no fg */
pixaDestroy(&pixa);
return pixd;
}
/* Label each component and blit it in */
for (i = 0; i < n; i++) {
pixaGetBoxGeometry(pixa, i, &xb, &yb, &wb, &hb);
pix1 = pixaGetPix(pixa, i, L_CLONE);
if (depth == 8) {
index = 1 + (i % 254);
pix2 = pixConvert1To8(NULL, pix1, 0, index);
} else if (depth == 16) {
index = 1 + (i % 0xfffe);
pix2 = pixConvert1To16(NULL, pix1, 0, index);
} else { /* depth == 32 */
index = 1 + i;
pix2 = pixConvert1To32(NULL, pix1, 0, index);
}
pixRasterop(pixd, xb, yb, wb, hb, PIX_PAINT, pix2, 0, 0);
pixDestroy(&pix1);
pixDestroy(&pix2);
}
pixaDestroy(&pixa);
return pixd;
}
示例3: pixaAnyColormaps
/*!
* pixaAnyColormaps()
*
* Input: pixa
* &hascmap (<return> 1 if any pix has a colormap; 0 otherwise)
* Return: 0 if OK; 1 on error
*/
l_int32
pixaAnyColormaps(PIXA *pixa,
l_int32 *phascmap)
{
l_int32 i, n;
PIX *pix;
PIXCMAP *cmap;
PROCNAME("pixaAnyColormaps");
if (!phascmap)
return ERROR_INT("&hascmap not defined", procName, 1);
*phascmap = 0;
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
n = pixaGetCount(pixa);
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixa, i, L_CLONE);
cmap = pixGetColormap(pix);
pixDestroy(&pix);
if (cmap) {
*phascmap = 1;
return 0;
}
}
return 0;
}
示例4: recogAddCharstrLabels
/*!
* \brief recogAddCharstrLabels()
*
* \param[in] recog
* \return 0 if OK, 1 on error
*/
static l_int32
recogAddCharstrLabels(L_RECOG *recog)
{
char *text;
l_int32 i, j, n1, n2;
PIX *pix;
PIXA *pixa;
PIXAA *paa;
PROCNAME("recogAddCharstrLabels");
if (!recog)
return ERROR_INT("recog not defined", procName, 1);
/* Add the labels to each unscaled pix */
paa = recog->pixaa_u;
n1 = pixaaGetCount(paa, NULL);
for (i = 0; i < n1; i++) {
pixa = pixaaGetPixa(paa, i, L_CLONE);
text = sarrayGetString(recog->sa_text, i, L_NOCOPY);
n2 = pixaGetCount(pixa);
for (j = 0; j < n2; j++) {
pix = pixaGetPix(pixa, j, L_CLONE);
pixSetText(pix, text);
pixDestroy(&pix);
}
pixaDestroy(&pixa);
}
return 0;
}
示例5: pixAddWithIndicator
/*!
* pixAddWithIndicator()
*
* Input: pixs (1 bpp pix from which components are added; in-place)
* pixa (of connected components, some of which will be put
* into pixs)
* na (numa indicator: add components corresponding to 1s)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) This complements pixRemoveWithIndicator(). Here, the selected
* components are added to pixs.
*/
l_int32
pixAddWithIndicator(PIX *pixs,
PIXA *pixa,
NUMA *na)
{
l_int32 i, n, ival, x, y, w, h;
BOX *box;
PIX *pix;
PROCNAME("pixAddWithIndicator");
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
if (!na)
return ERROR_INT("na not defined", procName, 1);
n = pixaGetCount(pixa);
if (n != numaGetCount(na))
return ERROR_INT("pixa and na sizes not equal", procName, 1);
for (i = 0; i < n; i++) {
numaGetIValue(na, i, &ival);
if (ival == 1) {
pix = pixaGetPix(pixa, i, L_CLONE);
box = pixaGetBox(pixa, i, L_CLONE);
boxGetGeometry(box, &x, &y, &w, &h);
pixRasterop(pixs, x, y, w, h, PIX_SRC | PIX_DST, pix, 0, 0);
boxDestroy(&box);
pixDestroy(&pix);
}
}
return 0;
}
示例6: jbCorrelation
/*!
* jbCorrelation()
*
* Input: dirin (directory of input images)
* thresh (typically ~0.8)
* weight (typically ~0.6)
* components (JB_CONN_COMPS, JB_CHARACTERS, JB_WORDS)
* rootname (for output files)
* firstpage (0-based)
* npages (use 0 for all pages in dirin)
* renderflag (1 to render from templates; 0 to skip)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) The images must be 1 bpp. If they are not, you can convert
* them using convertFilesTo1bpp().
* (2) See prog/jbcorrelation for generating more output (e.g.,
* for debugging)
*/
l_int32
jbCorrelation(const char *dirin,
l_float32 thresh,
l_float32 weight,
l_int32 components,
const char *rootname,
l_int32 firstpage,
l_int32 npages,
l_int32 renderflag) {
char filename[L_BUF_SIZE];
l_int32 nfiles, i, numpages;
JBDATA *data;
JBCLASSER *classer;
PIX *pix;
PIXA *pixa;
SARRAY *safiles;
PROCNAME("jbCorrelation");
if (!dirin)
return ERROR_INT("dirin not defined", procName, 1);
if (!rootname)
return ERROR_INT("rootname not defined", procName, 1);
if (components != JB_CONN_COMPS && components != JB_CHARACTERS &&
components != JB_WORDS)
return ERROR_INT("components invalid", procName, 1);
safiles = getSortedPathnamesInDirectory(dirin, NULL, firstpage, npages);
nfiles = sarrayGetCount(safiles);
/* Classify components */
classer = jbCorrelationInit(components, 0, 0, thresh, weight);
jbAddPages(classer, safiles);
/* Save data */
data = jbDataSave(classer);
jbDataWrite(rootname, data);
/* Optionally, render pages using class templates */
if (renderflag) {
pixa = jbDataRender(data, FALSE);
numpages = pixaGetCount(pixa);
if (numpages != nfiles)
fprintf(stderr, "numpages = %d, nfiles = %d, not equal!\n",
numpages, nfiles);
for (i = 0; i < numpages; i++) {
pix = pixaGetPix(pixa, i, L_CLONE);
snprintf(filename, L_BUF_SIZE, "%s.%05d", rootname, i);
fprintf(stderr, "filename: %s\n", filename);
pixWrite(filename, pix, IFF_PNG);
pixDestroy(&pix);
}
pixaDestroy(&pixa);
}
sarrayDestroy(&safiles);
jbClasserDestroy(&classer);
jbDataDestroy(&data);
return 0;
}
示例7: pixaFindStrokeWidth
/*!
* \brief pixaFindStrokeWidth()
*
* \param[in] pixa of 1 bpp images
* \param[in] thresh fractional count threshold relative to distance 1
* \param[in] tab8 [optional] table for counting fg pixels; can be NULL
* \param[in] debug 1 for debug output; 0 to skip
* \return na array of stroke widths for each pix in %pixa; NULL on error
*
* <pre>
* Notes:
* (1) See pixFindStrokeWidth() for details.
* </pre>
*/
NUMA *
pixaFindStrokeWidth(PIXA *pixa,
l_float32 thresh,
l_int32 *tab8,
l_int32 debug)
{
l_int32 i, n, same, maxd;
l_int32 *tab;
l_float32 width;
NUMA *na;
PIX *pix;
PROCNAME("pixaFindStrokeWidth");
if (!pixa)
return (NUMA *)ERROR_PTR("pixa not defined", procName, NULL);
pixaVerifyDepth(pixa, &same, &maxd);
if (maxd > 1)
return (NUMA *)ERROR_PTR("pix not all 1 bpp", procName, NULL);
tab = (tab8) ? tab8 : makePixelSumTab8();
n = pixaGetCount(pixa);
na = numaCreate(n);
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixa, i, L_CLONE);
pixFindStrokeWidth(pix, thresh, tab8, &width, NULL);
numaAddNumber(na, width);
pixDestroy(&pix);
}
if (!tab8) LEPT_FREE(tab);
return na;
}
示例8: pixaClipToPix
/*!
* pixaClipToPix()
*
* Input: pixas
* pixs
* Return: pixad, or null on error
*
* Notes:
* (1) This is intended for use in situations where pixas
* was originally generated from the input pixs.
* (2) Returns a pixad where each pix in pixas is ANDed
* with its associated region of the input pixs. This
* region is specified by the the box that is associated
* with the pix.
* (3) In a typical application of this function, pixas has
* a set of region masks, so this generates a pixa of
* the parts of pixs that correspond to each region
* mask component, along with the bounding box for
* the region.
*/
PIXA *
pixaClipToPix(PIXA *pixas,
PIX *pixs)
{
l_int32 i, n;
BOX *box;
PIX *pix, *pixc;
PIXA *pixad;
PROCNAME("pixaClipToPix");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (!pixs)
return (PIXA *)ERROR_PTR("pixs not defined", procName, NULL);
n = pixaGetCount(pixas);
if ((pixad = pixaCreate(n)) == NULL)
return (PIXA *)ERROR_PTR("pixad not made", procName, NULL);
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixas, i, L_CLONE);
box = pixaGetBox(pixas, i, L_COPY);
pixc = pixClipRectangle(pixs, box, NULL);
pixAnd(pixc, pixc, pix);
pixaAddPix(pixad, pixc, L_INSERT);
pixaAddBox(pixad, box, L_INSERT);
pixDestroy(&pix);
}
return pixad;
}
示例9: pixaModifyStrokeWidth
/*!
* \brief pixaModifyStrokeWidth()
*
* \param[in] pixas of 1 bpp pix
* \param[out] targetw desired width for strokes in each pix
* \return pixa with modified stroke widths, or NULL on error
*/
PIXA *
pixaModifyStrokeWidth(PIXA *pixas,
l_float32 targetw)
{
l_int32 i, n, same, maxd;
l_float32 width;
NUMA *na;
PIX *pix1, *pix2;
PIXA *pixad;
PROCNAME("pixaModifyStrokeWidth");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (targetw < 1)
return (PIXA *)ERROR_PTR("target width < 1", procName, NULL);
pixaVerifyDepth(pixas, &same, &maxd);
if (maxd > 1)
return (PIXA *)ERROR_PTR("pix not all 1 bpp", procName, NULL);
na = pixaFindStrokeWidth(pixas, 0.1, NULL, 0);
n = pixaGetCount(pixas);
pixad = pixaCreate(n);
for (i = 0; i < n; i++) {
pix1 = pixaGetPix(pixas, i, L_CLONE);
numaGetFValue(na, i, &width);
pix2 = pixModifyStrokeWidth(pix1, width, targetw);
pixaAddPix(pixad, pix2, L_INSERT);
pixDestroy(&pix1);
}
numaDestroy(&na);
return pixad;
}
示例10: pixaSortByIndex
/*!
* pixaSortByIndex()
*
* Input: pixas
* naindex (na that maps from the new pixa to the input pixa)
* copyflag (L_COPY, L_CLONE)
* Return: pixad (sorted), or null on error
*/
PIXA *
pixaSortByIndex(PIXA *pixas,
NUMA *naindex,
l_int32 copyflag)
{
l_int32 i, n, index;
BOX *box;
PIX *pix;
PIXA *pixad;
PROCNAME("pixaSortByIndex");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (!naindex)
return (PIXA *)ERROR_PTR("naindex not defined", procName, NULL);
if (copyflag != L_CLONE && copyflag != L_COPY)
return (PIXA *)ERROR_PTR("invalid copyflag", procName, NULL);
n = pixaGetCount(pixas);
pixad = pixaCreate(n);
for (i = 0; i < n; i++) {
numaGetIValue(naindex, i, &index);
pix = pixaGetPix(pixas, index, copyflag);
box = pixaGetBox(pixas, index, copyflag);
pixaAddPix(pixad, pix, L_INSERT);
pixaAddBox(pixad, box, L_INSERT);
}
return pixad;
}
示例11: pixaSetStrokeWidth
/*!
* \brief pixaSetStrokeWidth()
*
* \param[in] pixas of 1 bpp pix
* \param[in] width set stroke width to this value, in [1 ... 100].
* \param[in] thinfirst 1 to thin all pix to a skeleton first; 0 to skip
* \param[in] connectivity 4 or 8, to be used if %thinfirst == 1
* \return pixa with all stroke widths being %width, or NULL on error
*
* <pre>
* Notes:
* (1) If %thinfirst == 1, thin to a skeleton using the specified
* %connectivity. Use %thinfirst == 0 if all pix in pixas
* have already been thinned as far as possible.
* (2) The image is dilated to the required %width. This dilation
* is not connectivity preserving, so this is typically
* used in a situation where merging of c.c. in the individual
* pix is not a problem; e.g., where each pix is a single c.c.
* </pre>
*/
PIXA *
pixaSetStrokeWidth(PIXA *pixas,
l_int32 width,
l_int32 thinfirst,
l_int32 connectivity)
{
l_int32 i, n, maxd, same;
PIX *pix1, *pix2;
PIXA *pixad;
PROCNAME("pixaSetStrokeWidth");
if (!pixas)
return (PIXA *)ERROR_PTR("pixas not defined", procName, NULL);
if (width < 1 || width > 100)
return (PIXA *)ERROR_PTR("width not in [1 ... 100]", procName, NULL);
if (connectivity != 4 && connectivity != 8)
return (PIXA *)ERROR_PTR("connectivity not 4 or 8", procName, NULL);
pixaVerifyDepth(pixas, &same, &maxd);
if (maxd > 1)
return (PIXA *)ERROR_PTR("pix are not all 1 bpp", procName, NULL);
n = pixaGetCount(pixas);
pixad = pixaCreate(n);
for (i = 0; i < n; i++) {
pix1 = pixaGetPix(pixas, i, L_CLONE);
pix2 = pixSetStrokeWidth(pix1, width, thinfirst, connectivity);
pixaAddPix(pixad, pix2, L_INSERT);
pixDestroy(&pix1);
}
return pixad;
}
示例12: MakePtrasFromPixa
static void
MakePtrasFromPixa(PIXA *pixa,
L_PTRA **ppapix,
L_PTRA **ppabox,
l_int32 copyflag)
{
l_int32 i, n;
BOX *box;
PIX *pix;
L_PTRA *papix, *pabox;
n = pixaGetCount(pixa);
papix = ptraCreate(n);
pabox = ptraCreate(n);
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixa, i, copyflag);
box = pixaGetBox(pixa, i, copyflag);
ptraAdd(papix, pix);
ptraAdd(pabox, box);
}
*ppapix = papix;
*ppabox = pabox;
return;
}
示例13: Java_com_example_ocr_Pixa_nativeWriteToFileRandomCmap
jboolean Java_com_example_ocr_Pixa_nativeWriteToFileRandomCmap(JNIEnv *env,
jclass clazz,
jint nativePixa,
jstring fileName,
jint width,
jint height) {
PIX *pixtemp;
PIXA *pixa = (PIXA *) nativePixa;
const char *c_fileName = env->GetStringUTFChars(fileName, NULL);
if (c_fileName == NULL) {
LOGE("could not extract fileName string!");
return JNI_FALSE;
}
if (pixaGetCount(pixa) > 0) {
pixtemp = pixaDisplayRandomCmap(pixa, (l_int32) width, (l_int32) height);
} else {
pixtemp = pixCreate((l_int32) width, (l_int32) height, 1);
}
pixWrite(c_fileName, pixtemp, IFF_BMP);
pixDestroy(&pixtemp);
env->ReleaseStringUTFChars(fileName, c_fileName);
return JNI_TRUE;
}
示例14: pixaWriteFiles
/*!
* pixaWriteFiles()
*
* Input: rootname
* pixa
* format (defined in imageio.h)
* Return: 0 if OK; 1 on error
*/
l_int32
pixaWriteFiles(const char *rootname,
PIXA *pixa,
l_int32 format)
{
char bigbuf[L_BUF_SIZE];
l_int32 i, n;
PIX *pix;
PROCNAME("pixaWriteFiles");
if (!rootname)
return ERROR_INT("rootname not defined", procName, 1);
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
if (format < 0 || format >= NumImageFileFormatExtensions)
return ERROR_INT("invalid format", procName, 1);
n = pixaGetCount(pixa);
for (i = 0; i < n; i++) {
snprintf(bigbuf, L_BUF_SIZE, "%s%03d.%s", rootname, i,
ImageFileFormatExtensions[format]);
pix = pixaGetPix(pixa, i, L_CLONE);
pixWrite(bigbuf, pix, format);
pixDestroy(&pix);
}
return 0;
}
示例15: pixaSaveFont
/*!
* pixaSaveFont()
*
* Input: indir (directory holding image of character set)
* outdir (directory into which the output pixa file
* will be written)
* size (in pts, at 300 ppi)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) This saves a font of a particular size.
* (2) prog/genfonts calls this function for each of the
* nine font sizes, to generate all the font pixa files.
*/
l_int32
pixaSaveFont(const char *indir,
const char *outdir,
l_int32 size)
{
char *pathname;
l_int32 bl1, bl2, bl3;
PIXA *pixa;
PROCNAME("pixaSaveFont");
if (size < 4 || size > 20 || (size % 2))
return ERROR_INT("size must be in {4, 6, ..., 20}", procName, 1);
if ((pixa = pixaGenerateFont(indir, size, &bl1, &bl2, &bl3)) == NULL)
return ERROR_INT("pixa not made", procName, 1);
pathname = genPathname(outdir, outputfonts[(size - 4) / 2]);
pixaWrite(pathname, pixa);
#if DEBUG_FONT_GEN
fprintf(stderr, "Found %d chars in font size %d\n",
pixaGetCount(pixa), size);
fprintf(stderr, "Baselines are at: %d, %d, %d\n", bl1, bl2, bl3);
#endif /* DEBUG_FONT_GEN */
FREE(pathname);
pixaDestroy(&pixa);
return 0;
}