本文整理汇总了C++中pixConvertTo8函数的典型用法代码示例。如果您正苦于以下问题:C++ pixConvertTo8函数的具体用法?C++ pixConvertTo8怎么用?C++ pixConvertTo8使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pixConvertTo8函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: MakeWordBoxes2
void
MakeWordBoxes2(PIX *pixs,
l_int32 reduction,
L_REGPARAMS *rp)
{
l_int32 default_minwidth = 10;
l_int32 default_minheight = 10;
l_int32 default_maxwidth = 400;
l_int32 default_maxheight = 70;
l_int32 minwidth, minheight, maxwidth, maxheight;
BOXA *boxa1, *boxa2;
NUMA *na;
PIX *pixd1, *pixd2;
PIXA *pixa;
minwidth = default_minwidth / reduction;
minheight = default_minheight / reduction;
maxwidth = default_maxwidth / reduction;
maxheight = default_maxheight / reduction;
/* Get the word boxes */
pixGetWordsInTextlines(pixs, reduction, minwidth, minheight,
maxwidth, maxheight, &boxa1, &pixa, &na);
pixaDestroy(&pixa);
numaDestroy(&na);
if (reduction == 1)
boxa2 = boxaCopy(boxa1, L_CLONE);
else
boxa2 = boxaTransform(boxa1, 0, 0, 2.0, 2.0);
pixd1 = pixConvertTo8(pixs, 1);
pixRenderBoxaArb(pixd1, boxa2, 2, 255, 0, 0);
regTestWritePixAndCheck(rp, pixd1, IFF_PNG);
pixDisplayWithTitle(pixd1, 800, 100, NULL, rp->display);
boxaDestroy(&boxa1);
boxaDestroy(&boxa2);
/* Do it again with this interface. The result should be the same. */
pixGetWordBoxesInTextlines(pixs, reduction, minwidth, minheight,
maxwidth, maxheight, &boxa1, NULL);
if (reduction == 1)
boxa2 = boxaCopy(boxa1, L_CLONE);
else
boxa2 = boxaTransform(boxa1, 0, 0, 2.0, 2.0);
pixd2 = pixConvertTo8(pixs, 1);
pixRenderBoxaArb(pixd2, boxa2, 2, 255, 0, 0);
if (regTestComparePix(rp, pixd1, pixd2)) {
L_ERROR("pix not the same", "MakeWordBoxes2");
pixDisplayWithTitle(pixd2, 800, 100, NULL, rp->display);
}
pixDestroy(&pixd1);
pixDestroy(&pixd2);
boxaDestroy(&boxa1);
boxaDestroy(&boxa2);
return;
}
开发者ID:0ximDigital,项目名称:appsScanner,代码行数:55,代码来源:wordboxes_reg.c
示例2: pixGetDepth
/* static */
void Input::PreparePixInput(const StaticShape& shape, const Pix* pix,
TRand* randomizer, NetworkIO* input) {
bool color = shape.depth() == 3;
Pix* var_pix = const_cast<Pix*>(pix);
int depth = pixGetDepth(var_pix);
Pix* normed_pix = nullptr;
// On input to BaseAPI, an image is forced to be 1, 8 or 24 bit, without
// colormap, so we just have to deal with depth conversion here.
if (color) {
// Force RGB.
if (depth == 32)
normed_pix = pixClone(var_pix);
else
normed_pix = pixConvertTo32(var_pix);
} else {
// Convert non-8-bit images to 8 bit.
if (depth == 8)
normed_pix = pixClone(var_pix);
else
normed_pix = pixConvertTo8(var_pix, false);
}
int height = pixGetHeight(normed_pix);
int target_height = shape.height();
if (target_height == 1) target_height = shape.depth();
if (target_height != 0 && target_height != height) {
// Get the scaled image.
float im_factor = static_cast<float>(target_height) / height;
Pix* scaled_pix = pixScale(normed_pix, im_factor, im_factor);
pixDestroy(&normed_pix);
normed_pix = scaled_pix;
}
input->FromPix(shape, normed_pix, randomizer);
pixDestroy(&normed_pix);
}
开发者ID:vmlobanov78,项目名称:tesseract,代码行数:35,代码来源:input.cpp
示例3: pixRotateBinaryNice
/*!
* pixRotateBinaryNice()
*
* Input: pixs (1 bpp)
* angle (radians; clockwise is positive; about the center)
* incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK)
* Return: pixd, or null on error
*
* Notes:
* (1) For very small rotations, just return a clone.
* (2) This does a computationally expensive rotation of 1 bpp images.
* The fastest rotators (using shears or subsampling) leave
* visible horizontal and vertical shear lines across which
* the image shear changes by one pixel. To ameliorate the
* visual effect one can introduce random dithering. One
* way to do this in a not-too-random fashion is given here.
* We convert to 8 bpp, do a very small blur, rotate using
* linear interpolation (same as area mapping), do a
* small amount of sharpening to compensate for the initial
* blur, and threshold back to binary. The shear lines
* are magically removed.
* (3) This operation is about 5x slower than rotation by sampling.
*/
PIX *
pixRotateBinaryNice(PIX *pixs,
l_float32 angle,
l_int32 incolor)
{
PIX *pixt1, *pixt2, *pixt3, *pixt4, *pixd;
PROCNAME("pixRotateBinaryNice");
if (!pixs || pixGetDepth(pixs) != 1)
return (PIX *)ERROR_PTR("pixs undefined or not 1 bpp", procName, NULL);
if (incolor != L_BRING_IN_WHITE && incolor != L_BRING_IN_BLACK)
return (PIX *)ERROR_PTR("invalid incolor", procName, NULL);
pixt1 = pixConvertTo8(pixs, 0);
pixt2 = pixBlockconv(pixt1, 1, 1); /* smallest blur allowed */
pixt3 = pixRotateAM(pixt2, angle, incolor);
pixt4 = pixUnsharpMasking(pixt3, 1, 1.0); /* sharpen a bit */
pixd = pixThresholdToBinary(pixt4, 128);
pixDestroy(&pixt1);
pixDestroy(&pixt2);
pixDestroy(&pixt3);
pixDestroy(&pixt4);
return pixd;
}
开发者ID:0ximDigital,项目名称:appsScanner,代码行数:48,代码来源:rotate.c
示例4: dewarpSinglePageInit
/*!
* dewarpSinglePageInit()
*
* Input: pixs (with text, any depth)
* thresh (for global thresholding to 1 bpp; ignored otherwise)
* adaptive (1 for adaptive thresholding; 0 for global threshold)
* use_both (1 for horizontal and vertical; 0 for vertical only)
* &pixb (<return> 1 bpp image)
* &dewa (<return> initialized dewa)
* Return: 0 if OK, 1 on error (list of page numbers), or null on error
*
* Notes:
* (1) This binarizes the input pixs if necessary, returning the
* binarized image. It also initializes the dewa to default values
* for the model parameters.
* (2) If pixs is 1 bpp, the parameters @adaptive and @thresh are ignored.
* (3) To change the model parameters, call dewarpaSetCurvatures()
* before running dewarpSinglePageRun(). For DC:
* dewarpSinglePageInit(pixs, 0, 1, 1, &pixb, &dewa);
* dewarpaSetCurvatures(dewa, 250, -1, -1, 80, 70, 150);
* dewarpSinglePageRun(pixs, pixb, dewa, &pixd, 0);
* dewarpaDestroy(&dewa);
* pixDestroy(&pixb);
*/
l_int32
dewarpSinglePageInit(PIX *pixs,
l_int32 thresh,
l_int32 adaptive,
l_int32 use_both,
PIX **ppixb,
L_DEWARPA **pdewa)
{
PIX *pix1;
PROCNAME("dewarpSinglePageInit");
if (ppixb) *ppixb = NULL;
if (pdewa) *pdewa = NULL;
if (!ppixb || !pdewa)
return ERROR_INT("&pixb and &dewa not both defined", procName, 1);
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
*pdewa = dewarpaCreate(1, 0, 1, 0, -1);
dewarpaUseBothArrays(*pdewa, use_both);
/* Generate a binary image, if necessary */
if (pixGetDepth(pixs) > 1) {
pix1 = pixConvertTo8(pixs, 0);
if (adaptive)
*ppixb = pixAdaptThresholdToBinary(pix1, NULL, 1.0);
else
*ppixb = pixThresholdToBinary(pix1, thresh);
pixDestroy(&pix1);
} else {
*ppixb = pixClone(pixs);
}
return 0;
}
开发者ID:Dhavalc2012,项目名称:Opticial-Character-Recognisation,代码行数:59,代码来源:dewarp4.c
示例5: Java_com_googlecode_leptonica_android_Convert_nativeConvertTo8
jint Java_com_googlecode_leptonica_android_Convert_nativeConvertTo8(JNIEnv *env, jclass clazz,
jint nativePix) {
PIX *pixs = (PIX *) nativePix;
PIX *pixd = pixConvertTo8(pixs, FALSE);
return (jint) pixd;
}
开发者ID:slohman,项目名称:October2012Workspace,代码行数:7,代码来源:utilities.cpp
示例6: if
// Helper gets the image of a rectangle, using the block.re_rotation() if
// needed to get to the image, and rotating the result back to horizontal
// layout. (CJK characters will be on their left sides) The vertical text flag
// is set in the returned ImageData if the text was originally vertical, which
// can be used to invoke a different CJK recognition engine. The revised_box
// is also returned to enable calculation of output bounding boxes.
ImageData* Tesseract::GetRectImage(const TBOX& box, const BLOCK& block,
int padding, TBOX* revised_box) const {
TBOX wbox = box;
wbox.pad(padding, padding);
*revised_box = wbox;
// Number of clockwise 90 degree rotations needed to get back to tesseract
// coords from the clipped image.
int num_rotations = 0;
if (block.re_rotation().y() > 0.0f)
num_rotations = 1;
else if (block.re_rotation().x() < 0.0f)
num_rotations = 2;
else if (block.re_rotation().y() < 0.0f)
num_rotations = 3;
// Handle two cases automatically: 1 the box came from the block, 2 the box
// came from a box file, and refers to the image, which the block may not.
if (block.bounding_box().major_overlap(*revised_box))
revised_box->rotate(block.re_rotation());
// Now revised_box always refers to the image.
// BestPix is never colormapped, but may be of any depth.
Pix* pix = BestPix();
int width = pixGetWidth(pix);
int height = pixGetHeight(pix);
TBOX image_box(0, 0, width, height);
// Clip to image bounds;
*revised_box &= image_box;
if (revised_box->null_box()) return NULL;
Box* clip_box = boxCreate(revised_box->left(), height - revised_box->top(),
revised_box->width(), revised_box->height());
Pix* box_pix = pixClipRectangle(pix, clip_box, NULL);
if (box_pix == NULL) return NULL;
boxDestroy(&clip_box);
if (num_rotations > 0) {
Pix* rot_pix = pixRotateOrth(box_pix, num_rotations);
pixDestroy(&box_pix);
box_pix = rot_pix;
}
// Convert sub-8-bit images to 8 bit.
int depth = pixGetDepth(box_pix);
if (depth < 8) {
Pix* grey;
grey = pixConvertTo8(box_pix, false);
pixDestroy(&box_pix);
box_pix = grey;
}
bool vertical_text = false;
if (num_rotations > 0) {
// Rotated the clipped revised box back to internal coordinates.
FCOORD rotation(block.re_rotation().x(), -block.re_rotation().y());
revised_box->rotate(rotation);
if (num_rotations != 2)
vertical_text = true;
}
return new ImageData(vertical_text, box_pix);
}
开发者ID:hoiqs,项目名称:tesseract-ocr,代码行数:61,代码来源:linerec.cpp
示例7: main
l_int32 main(int argc,
char **argv)
{
l_uint32 *colors;
l_int32 ncolors;
PIX *pix1, *pix2, *pix3;
L_REGPARAMS *rp;
if (regTestSetup(argc, argv, &rp))
return 1;
/* Find the most populated colors */
pix1 = pixRead("fish24.jpg");
pixGetMostPopulatedColors(pix1, 2, 3, 10, &colors, NULL);
pix2 = pixDisplayColorArray(colors, 10, 190, 5, 1);
pixDisplayWithTitle(pix2, 0, 0, NULL, rp->display);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 0 */
lept_free(colors);
pixDestroy(&pix2);
/* Do a simple color quantization with sigbits = 2 */
pix2 = pixSimpleColorQuantize(pix1, 2, 3, 10);
pixDisplayWithTitle(pix2, 0, 400, NULL, rp->display);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 1 */
pix3 = pixRemoveColormap(pix2, REMOVE_CMAP_TO_FULL_COLOR);
regTestComparePix(rp, pix2, pix3); /* 2 */
pixNumColors(pix3, 1, &ncolors);
regTestCompareValues(rp, ncolors, 10, 0.0); /* 3 */
pixDestroy(&pix1);
pixDestroy(&pix2);
pixDestroy(&pix3);
/* Do a simple color quantization with sigbits = 3 */
pix1 = pixRead("wyom.jpg");
pixNumColors(pix1, 1, &ncolors); /* >255, so should give 0 */
regTestCompareValues(rp, ncolors, 0, 0.0); /* 4 */
pix2 = pixSimpleColorQuantize(pix1, 3, 3, 20);
pixDisplayWithTitle(pix2, 1000, 0, NULL, rp->display);
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 5 */
ncolors = pixcmapGetCount(pixGetColormap(pix2));
regTestCompareValues(rp, ncolors, 20, 0.0); /* 6 */
pixDestroy(&pix1);
pixDestroy(&pix2);
/* Find the number of perceptually significant gray intensities */
pix1 = pixRead("marge.jpg");
pix2 = pixConvertTo8(pix1, 0);
pixNumSignificantGrayColors(pix2, 20, 236, 0.0001, 1, &ncolors);
regTestCompareValues(rp, ncolors, 219, 0.0); /* 7 */
pixDestroy(&pix1);
pixDestroy(&pix2);
return regTestCleanup(rp);
}
开发者ID:BruceWoR,项目名称:tess-two-master,代码行数:54,代码来源:colorcontent_reg.c
示例8: pixProjectivePta
/*!
* pixProjectivePta()
*
* Input: pixs (all depths; colormap ok)
* ptad (4 pts of final coordinate space)
* ptas (4 pts of initial coordinate space)
* incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK)
* Return: pixd, or null on error
*
* Notes:
* (1) Brings in either black or white pixels from the boundary
* (2) Removes any existing colormap, if necessary, before transforming
*/
PIX *
pixProjectivePta(PIX *pixs,
PTA *ptad,
PTA *ptas,
l_int32 incolor)
{
l_int32 d;
l_uint32 colorval;
PIX *pixt1, *pixt2, *pixd;
PROCNAME("pixProjectivePta");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (!ptas)
return (PIX *)ERROR_PTR("ptas not defined", procName, NULL);
if (!ptad)
return (PIX *)ERROR_PTR("ptad not defined", procName, NULL);
if (incolor != L_BRING_IN_WHITE && incolor != L_BRING_IN_BLACK)
return (PIX *)ERROR_PTR("invalid incolor", procName, NULL);
if (ptaGetCount(ptas) != 4)
return (PIX *)ERROR_PTR("ptas count not 4", procName, NULL);
if (ptaGetCount(ptad) != 4)
return (PIX *)ERROR_PTR("ptad count not 4", procName, NULL);
if (pixGetDepth(pixs) == 1)
return pixProjectiveSampledPta(pixs, ptad, ptas, incolor);
/* Remove cmap if it exists, and unpack to 8 bpp if necessary */
pixt1 = pixRemoveColormap(pixs, REMOVE_CMAP_BASED_ON_SRC);
d = pixGetDepth(pixt1);
if (d < 8)
pixt2 = pixConvertTo8(pixt1, FALSE);
else
pixt2 = pixClone(pixt1);
d = pixGetDepth(pixt2);
/* Compute actual color to bring in from edges */
colorval = 0;
if (incolor == L_BRING_IN_WHITE) {
if (d == 8)
colorval = 255;
else /* d == 32 */
colorval = 0xffffff00;
}
if (d == 8)
pixd = pixProjectivePtaGray(pixt2, ptad, ptas, colorval);
else /* d == 32 */
pixd = pixProjectivePtaColor(pixt2, ptad, ptas, colorval);
pixDestroy(&pixt1);
pixDestroy(&pixt2);
return pixd;
}
开发者ID:0xkasun,项目名称:Dummy_Tes,代码行数:67,代码来源:projective.c
示例9: GetPixRect
// Get a clone/copy of the source image rectangle, reduced to greyscale.
// The returned Pix must be pixDestroyed.
// This function will be used in the future by the page layout analysis, and
// the layout analysis that uses it will only be available with Leptonica,
// so there is no raw equivalent.
Pix* ImageThresholder::GetPixRectGrey() {
Pix* pix = GetPixRect(); // May have to be reduced to grey.
int depth = pixGetDepth(pix);
if (depth != 8) {
Pix* result = depth < 8 ? pixConvertTo8(pix, false)
: pixConvertRGBToLuminance(pix);
pixDestroy(&pix);
return result;
}
return pix;
}
开发者ID:ErfanHasmin,项目名称:scope-ocr,代码行数:16,代码来源:thresholder.cpp
示例10: main
l_int32 main(int argc,
char **argv)
{
l_int32 pageno;
L_DEWARP *dew1;
L_DEWARPA *dewa;
PIX *pixs, *pixn, *pixg, *pixb;
static char mainName[] = "dewarptest2";
if (argc != 1 && argc != 3)
return ERROR_INT("Syntax: dewarptest2 [image pageno]", mainName, 1);
if (argc == 1) {
pixs = pixRead("cat-35.jpg");
pageno = 35;
}
else {
pixs = pixRead(argv[1]);
pageno = atoi(argv[2]);
}
if (!pixs)
return ERROR_INT("image not read", mainName, 1);
dewa = dewarpaCreate(40, 30, 1, 6, 50);
#if NORMALIZE
/* Normalize for varying background and binarize */
pixn = pixBackgroundNormSimple(pixs, NULL, NULL);
pixg = pixConvertRGBToGray(pixn, 0.5, 0.3, 0.2);
pixb = pixThresholdToBinary(pixg, 130);
pixDestroy(&pixn);
#else
/* Don't normalize; just threshold and clean edges */
pixg = pixConvertTo8(pixs, 0);
pixb = pixThresholdToBinary(pixg, 100);
pixSetOrClearBorder(pixb, 30, 30, 40, 40, PIX_CLR);
#endif
/* Run the basic functions */
dew1 = dewarpCreate(pixb, pageno);
dewarpaInsertDewarp(dewa, dew1);
dewarpBuildModel(dew1, "/tmp/dewarp_model1.pdf");
dewarpaApplyDisparity(dewa, pageno, pixg, "/tmp/dewarp_apply1.pdf");
dewarpaDestroy(&dewa);
pixDestroy(&pixs);
pixDestroy(&pixg);
pixDestroy(&pixb);
return 0;
}
开发者ID:ErfanHasmin,项目名称:scope-ocr,代码行数:50,代码来源:dewarptest2.c
示例11: QuantizeNonImageRegion
static PIX *
QuantizeNonImageRegion(PIX *pixs,
PIX *pixm,
l_int32 levels) {
PIX *pix1, *pix2, *pixd;
pix1 = pixConvertTo8(pixs, 0);
pix2 = pixThresholdOn8bpp(pix1, levels, 1);
pixd = pixConvertTo32(pix2); /* save in rgb */
pixCombineMasked(pixd, pixs, pixm); /* rgb result */
pixDestroy(&pix1);
pixDestroy(&pix2);
return pixd;
}
开发者ID:mehulsbhatt,项目名称:MyOCRTEST,代码行数:14,代码来源:pdfiotest.c
示例12: pixRotateAM
/*!
* pixRotateAM()
*
* Input: pixs (2, 4, 8 bpp gray or colormapped, or 32 bpp RGB)
* angle (radians; clockwise is positive)
* incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK)
* Return: pixd, or null on error
*
* Notes:
* (1) Rotates about image center.
* (2) A positive angle gives a clockwise rotation.
* (3) Brings in either black or white pixels from the boundary.
*/
PIX *
pixRotateAM(PIX *pixs,
l_float32 angle,
l_int32 incolor)
{
l_int32 d;
l_uint32 fillval;
PIX *pixt1, *pixt2, *pixd;
PROCNAME("pixRotateAM");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (pixGetDepth(pixs) == 1)
return (PIX *)ERROR_PTR("pixs is 1 bpp", procName, NULL);
if (L_ABS(angle) < MIN_ANGLE_TO_ROTATE)
return pixClone(pixs);
/* Remove cmap if it exists, and unpack to 8 bpp if necessary */
pixt1 = pixRemoveColormap(pixs, REMOVE_CMAP_BASED_ON_SRC);
d = pixGetDepth(pixt1);
if (d < 8)
pixt2 = pixConvertTo8(pixt1, FALSE);
else
pixt2 = pixClone(pixt1);
d = pixGetDepth(pixt2);
/* Compute actual incoming color */
fillval = 0;
if (incolor == L_BRING_IN_WHITE) {
if (d == 8)
fillval = 255;
else /* d == 32 */
fillval = 0xffffff00;
}
if (d == 8)
pixd = pixRotateAMGray(pixt2, angle, fillval);
else /* d == 32 */
pixd = pixRotateAMColor(pixt2, angle, fillval);
pixDestroy(&pixt1);
pixDestroy(&pixt2);
return pixd;
}
开发者ID:xmarston,项目名称:BillRecognizer,代码行数:59,代码来源:rotateam.c
示例13: pixProjective
/*!
* pixProjective()
*
* Input: pixs (all depths; colormap ok)
* vc (vector of 8 coefficients for projective transformation)
* incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK)
* Return: pixd, or null on error
*
* Notes:
* (1) Brings in either black or white pixels from the boundary
* (2) Removes any existing colormap, if necessary, before transforming
*/
PIX *
pixProjective(PIX *pixs,
l_float32 *vc,
l_int32 incolor)
{
l_int32 d;
l_uint32 colorval;
PIX *pixt1, *pixt2, *pixd;
PROCNAME("pixProjective");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (!vc)
return (PIX *)ERROR_PTR("vc not defined", procName, NULL);
if (pixGetDepth(pixs) == 1)
return pixProjectiveSampled(pixs, vc, incolor);
/* Remove cmap if it exists, and unpack to 8 bpp if necessary */
pixt1 = pixRemoveColormap(pixs, REMOVE_CMAP_BASED_ON_SRC);
d = pixGetDepth(pixt1);
if (d < 8)
pixt2 = pixConvertTo8(pixt1, FALSE);
else
pixt2 = pixClone(pixt1);
d = pixGetDepth(pixt2);
/* Compute actual color to bring in from edges */
colorval = 0;
if (incolor == L_BRING_IN_WHITE) {
if (d == 8)
colorval = 255;
else /* d == 32 */
colorval = 0xffffff00;
}
if (d == 8)
pixd = pixProjectiveGray(pixt2, vc, colorval);
else /* d == 32 */
pixd = pixProjectiveColor(pixt2, vc, colorval);
pixDestroy(&pixt1);
pixDestroy(&pixt2);
return pixd;
}
开发者ID:0xkasun,项目名称:Dummy_Tes,代码行数:57,代码来源:projective.c
示例14: pixColorGrayCmap
/*!
* pixColorGrayCmap()
*
* Input: pixs (2, 4 or 8 bpp, with colormap)
* box (<optional> region to set color; can be NULL)
* type (L_PAINT_LIGHT, L_PAINT_DARK)
* rval, gval, bval (target color)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) This is an in-place operation.
* (2) If type == L_PAINT_LIGHT, it colorizes non-black pixels,
* preserving antialiasing.
* If type == L_PAINT_DARK, it colorizes non-white pixels,
* preserving antialiasing.
* (3) box gives the region to apply color; if NULL, this
* colorizes the entire image.
* (4) If the cmap is only 2 or 4 bpp, pixs is converted in-place
* to an 8 bpp cmap. A 1 bpp cmap is not a valid input pix.
* (5) This can also be called through pixColorGray().
* (6) This operation increases the colormap size by the number of
* different gray (non-black or non-white) colors in the
* input colormap. If there is not enough room in the colormap
* for this expansion, it returns 1 (error), and the caller
* should check the return value.
* (7) Using the darkness of each original pixel in the rect,
* it generates a new color (based on the input rgb values).
* If type == L_PAINT_LIGHT, the new color is a (generally)
* darken-to-black version of the input rgb color, where the
* amount of darkening increases with the darkness of the
* original pixel color.
* If type == L_PAINT_DARK, the new color is a (generally)
* faded-to-white version of the input rgb color, where the
* amount of fading increases with the brightness of the
* original pixel color.
*/
l_int32
pixColorGrayCmap(PIX *pixs,
BOX *box,
l_int32 type,
l_int32 rval,
l_int32 gval,
l_int32 bval)
{
l_int32 w, h, d, ret;
PIX *pixt;
BOXA *boxa;
PIXCMAP *cmap;
PROCNAME("pixColorGrayCmap");
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
if ((cmap = pixGetColormap(pixs)) == NULL)
return ERROR_INT("no colormap", procName, 1);
pixGetDimensions(pixs, &w, &h, &d);
if (d != 2 && d != 4 && d != 8)
return ERROR_INT("depth not in {2, 4, 8}", procName, 1);
if (type != L_PAINT_DARK && type != L_PAINT_LIGHT)
return ERROR_INT("invalid type", procName, 1);
/* If 2 bpp or 4 bpp, convert in-place to 8 bpp. */
if (d == 2 || d == 4) {
pixt = pixConvertTo8(pixs, 1);
pixTransferAllData(pixs, &pixt, 0, 0);
}
/* If box == NULL, color the entire image */
boxa = boxaCreate(1);
if (box) {
boxaAddBox(boxa, box, L_COPY);
} else {
box = boxCreate(0, 0, w, h);
boxaAddBox(boxa, box, L_INSERT);
}
ret = pixColorGrayRegionsCmap(pixs, boxa, type, rval, gval, bval);
boxaDestroy(&boxa);
return ret;
}
开发者ID:Dhavalc2012,项目名称:Opticial-Character-Recognisation,代码行数:80,代码来源:paintcmap.c
示例15: MakeWordBoxes1
void
MakeWordBoxes1(PIX *pixs,
l_int32 maxdil,
L_REGPARAMS *rp) {
BOXA *boxa;
PIX *pix1, *pixd;
pixWordMaskByDilation(pixs, maxdil, &pix1, NULL);
pixd = NULL;
if (pix1) {
boxa = pixConnComp(pix1, NULL, 8);
pixd = pixConvertTo8(pixs, 1);
pixRenderBoxaArb(pixd, boxa, 2, 255, 0, 0);
boxaDestroy(&boxa);
}
regTestWritePixAndCheck(rp, pixd, IFF_PNG);
pixDisplayWithTitle(pixd, 0, 100, NULL, rp->display);
pixDestroy(&pix1);
pixDestroy(&pixd);
return;
}
开发者ID:mehulsbhatt,项目名称:MyOCRTEST,代码行数:21,代码来源:wordboxes_reg.c
示例16: pixDestroy
// NOTE: Opposite to SetImage for raw images, SetImage for Pix clones its
// input, so the source pix may be pixDestroyed immediately after.
void ImageThresholder::SetImage(const Pix* pix) {
image_data_ = NULL;
if (pix_ != NULL)
pixDestroy(&pix_);
Pix* src = const_cast<Pix*>(pix);
int depth;
pixGetDimensions(src, &image_width_, &image_height_, &depth);
// Convert the image as necessary so it is one of binary, plain RGB, or
// 8 bit with no colormap.
if (depth > 1 && depth < 8) {
pix_ = pixConvertTo8(src, false);
} else if (pixGetColormap(src)) {
pix_ = pixRemoveColormap(src, REMOVE_CMAP_BASED_ON_SRC);
} else {
pix_ = pixClone(src);
}
depth = pixGetDepth(pix_);
image_bytespp_ = depth / 8;
image_bytespl_ = pixGetWpl(pix_) * sizeof(l_uint32);
scale_ = 1;
estimated_res_ = yres_ = pixGetYRes(src);
Init();
}
开发者ID:ErfanHasmin,项目名称:scope-ocr,代码行数:25,代码来源:thresholder.cpp
示例17: main
main(int argc,
char **argv)
{
PIX *pixs, *pixg1, *pixg2;
L_REGPARAMS *rp;
if (regTestSetup(argc, argv, &rp))
return 1;
/* Use for input two different images */
pixs = pixRead("projectionstats.jpg");
pixg1 = pixConvertTo8(pixs, 0);
pixDestroy(&pixs);
pixs = pixRead("feyn.tif");
pixg2 = pixScaleToGray4(pixs);
pixDestroy(&pixs);
TestProjection(rp, pixg1);
TestProjection(rp, pixg2);
pixDestroy(&pixg1);
pixDestroy(&pixg2);
regTestCleanup(rp);
return 0;
}
开发者ID:0359xiaodong,项目名称:tess-two,代码行数:24,代码来源:projection_reg.c
示例18: main
main(int argc,
char **argv)
{
char *errorstr;
l_int32 same, error;
PIX *pixs1, *pixs2, *pixs4, *pixs8, *pixs16, *pixs32, *pixd;
PIX *pixc2, *pixc4, *pixc8;
PIX *pixt1, *pixt2, *pixt3, *pixt4, *pixt5, *pixt6;
PIXCMAP *cmap;
SARRAY *sa;
static char mainName[] = "convert_reg";
if (argc != 1)
exit(ERROR_INT(" Syntax: convert_rt", mainName, 1));
if ((pixs1 = pixRead("test1.png")) == NULL)
exit(ERROR_INT("pixs1 not made", mainName, 1));
if ((pixs2 = pixRead("dreyfus2.png")) == NULL)
exit(ERROR_INT("pixs2 not made", mainName, 1));
if ((pixc2 = pixRead("weasel2.4c.png")) == NULL)
exit(ERROR_INT("pixc2 not made", mainName, 1));
if ((pixs4 = pixRead("weasel4.16g.png")) == NULL)
exit(ERROR_INT("pixs4 not made", mainName, 1));
if ((pixc4 = pixRead("weasel4.11c.png")) == NULL)
exit(ERROR_INT("pixc4 not made", mainName, 1));
if ((pixs8 = pixRead("karen8.jpg")) == NULL)
exit(ERROR_INT("pixs8 not made", mainName, 1));
if ((pixc8 = pixRead("weasel8.240c.png")) == NULL)
exit(ERROR_INT("pixc8 not made", mainName, 1));
if ((pixs16 = pixRead("test16.tif")) == NULL)
exit(ERROR_INT("pixs16 not made", mainName, 1));
if ((pixs32 = pixRead("marge.jpg")) == NULL)
exit(ERROR_INT("pixs32 not made", mainName, 1));
error = FALSE;
sa = sarrayCreate(0);
/* Conversion: 1 bpp --> 8 bpp --> 1 bpp */
pixt1 = pixConvertTo8(pixs1, FALSE);
pixt2 = pixThreshold8(pixt1, 1, 0, 0);
pixEqual(pixs1, pixt2, &same);
if (!same) {
pixDisplayWithTitle(pixs1, 100, 100, "1 bpp, no cmap", DFLAG);
pixDisplayWithTitle(pixt2, 500, 100, "1 bpp, no cmap", DFLAG);
error = TRUE;
sarrayAddString(sa, (char *)"conversion 1 bpp <==> 8 bpp", L_COPY);
} else
fprintf(stderr, "OK: conversion 1 bpp <==> 8 bpp\n");
pixDestroy(&pixt1);
pixDestroy(&pixt2);
/* Conversion: 2 bpp --> 8 bpp --> 2 bpp */
/* Conversion: 2 bpp cmap --> 8 bpp cmap --> 2 bpp cmap */
pixt1 = pixRemoveColormap(pixs2, REMOVE_CMAP_TO_GRAYSCALE);
pixt2 = pixThreshold8(pixt1, 2, 4, 0);
pixt3 = pixConvertTo8(pixt2, FALSE);
pixt4 = pixThreshold8(pixt3, 2, 4, 0);
pixEqual(pixt2, pixt4, &same);
if (!same) {
pixDisplayWithTitle(pixt2, 100, 100, "2 bpp, no cmap", DFLAG);
pixDisplayWithTitle(pixt4, 500, 100, "2 bpp, no cmap", DFLAG);
error = TRUE;
sarrayAddString(sa, (char *)"conversion 2 bpp <==> 8 bpp", L_COPY);
} else
fprintf(stderr, "OK: conversion 2 bpp <==> 8 bpp\n");
pixt5 = pixConvertTo8(pixs2, TRUE);
pixt6 = pixThreshold8(pixt5, 2, 4, 1);
pixEqual(pixs2, pixt6, &same);
if (!same) {
pixDisplayWithTitle(pixs2, 100, 100, "2 bpp, cmap", DFLAG);
pixDisplayWithTitle(pixt6, 500, 100, "2 bpp, cmap", DFLAG);
error = TRUE;
sarrayAddString(sa, (char *)"conversion 2 bpp <==> 8 bpp; cmap",
L_COPY);
} else
fprintf(stderr, "OK: conversion 2 bpp <==> 8 bpp; cmap\n");
pixDestroy(&pixt1);
pixDestroy(&pixt2);
pixDestroy(&pixt3);
pixDestroy(&pixt4);
pixDestroy(&pixt5);
pixDestroy(&pixt6);
/* Conversion: 4 bpp --> 8 bpp --> 4 bpp */
/* Conversion: 4 bpp cmap --> 8 bpp cmap --> 4 bpp cmap */
pixt1 = pixRemoveColormap(pixs4, REMOVE_CMAP_TO_GRAYSCALE);
pixt2 = pixThreshold8(pixt1, 4, 16, 0);
pixt3 = pixConvertTo8(pixt2, FALSE);
pixt4 = pixThreshold8(pixt3, 4, 16, 0);
pixEqual(pixt2, pixt4, &same);
if (!same) {
pixDisplayWithTitle(pixt2, 100, 100, "4 bpp, no cmap", DFLAG);
pixDisplayWithTitle(pixt4, 500, 100, "4 bpp, no cmap", DFLAG);
error = TRUE;
sarrayAddString(sa, (char *)"conversion 4 bpp <==> 8 bpp", L_COPY);
} else
fprintf(stderr, "OK: conversion 4 bpp <==> 8 bpp\n");
pixt5 = pixConvertTo8(pixs4, TRUE);
pixt6 = pixThreshold8(pixt5, 4, 16, 1);
pixEqual(pixs4, pixt6, &same);
if (!same) {
//.........这里部分代码省略.........
开发者ID:0xkasun,项目名称:Dummy_Tes,代码行数:101,代码来源:conversion_reg.c
示例19: pixSaveTiledOutline
/*!
* pixSaveTiledOutline()
*
* Input: pixs (1, 2, 4, 8, 32 bpp)
* pixa (the pix are accumulated here)
* scalefactor (0.0 to disable; otherwise this is a scale factor)
* newrow (0 if placed on the same row as previous; 1 otherwise)
* space (horizontal and vertical spacing, in pixels)
* linewidth (width of added outline for image; 0 for no outline)
* dp (depth of pixa; 8 or 32 bpp; only used on first call)
* Return: 0 if OK, 1 on error.
*
* Notes:
* (1) Before calling this function for the first time, use
* pixaCreate() to make the @pixa that will accumulate the pix.
* This is passed in each time pixSaveTiled() is called.
* (2) @scalefactor scales the input image. After scaling and
* possible depth conversion, the image is saved in the input
* pixa, along with a box that specifies the location to
* place it when tiled later. Disable saving the pix by
* setting @scalefactor == 0.0.
* (3) @newrow and @space specify the location of the new pix
* with respect to the last one(s) that were entered.
* (4) @dp specifies the depth at which all pix are saved. It can
* be only 8 or 32 bpp. Any colormap is removed. This is only
* used at the first invocation.
* (5) This function uses two variables from call to call.
* If they were static, the function would not be .so or thread
* safe, and furthermore, there would be interference with two or
* more pixa accumulating images at a time. Consequently,
* we use the first pix in the pixa to store and obtain both
* the depth and the current position of the bottom (one pixel
* below the lowest image raster line when laid out using
* the boxa). The bottom variable is stored in the input format
* field, which is the only field available for storing an int.
*/
l_int32
pixSaveTiledOutline(PIX *pixs,
PIXA *pixa,
l_float32 scalefactor,
l_int32 newrow,
l_int32 space,
l_int32 linewidth,
l_int32 dp)
{
l_int32 n, top, left, bx, by, bw, w, h, depth, bottom;
BOX *box;
PIX *pix1, *pix2, *pix3, *pix4;
PROCNAME("pixSaveTiledOutline");
if (scalefactor == 0.0) return 0;
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
if (!pixa)
return ERROR_INT("pixa not defined", procName, 1);
n = pixaGetCount(pixa);
if (n == 0) {
bottom = 0;
if (dp != 8 && dp != 32) {
L_WARNING("dp not 8 or 32 bpp; using 32\n", procName);
depth = 32;
} else {
depth = dp;
}
} else { /* extract the depth and bottom params from the first pix */
pix1 = pixaGetPix(pixa, 0, L_CLONE);
depth = pixGetDepth(pix1);
bottom = pixGetInputFormat(pix1); /* not typical usage! */
pixDestroy(&pix1);
}
/* Remove colormap if it exists; otherwise a copy. This
* guarantees that pix4 is not a clone of pixs. */
pix1 = pixRemoveColormapGeneral(pixs, REMOVE_CMAP_BASED_ON_SRC, L_COPY);
/* Scale and convert to output depth */
if (scalefactor == 1.0) {
pix2 = pixClone(pix1);
} else if (scalefactor > 1.0) {
pix2 = pixScale(pix1, scalefactor, scalefactor);
} else if (scalefactor < 1.0) {
if (pixGetDepth(pix1) == 1)
pix2 = pixScaleToGray(pix1, scalefactor);
else
pix2 = pixScale(pix1, scalefactor, scalefactor);
}
pixDestroy(&pix1);
if (depth == 8)
pix3 = pixConvertTo8(pix2, 0);
else
pix3 = pixConvertTo32(pix2);
pixDestroy(&pix2);
/* Add black outline */
if (linewidth > 0)
pix4 = pixAddBorder(pix3, linewidth, 0);
else
//.........这里部分代码省略.........
开发者ID:KevinSantos,项目名称:openalpr-windows,代码行数:101,代码来源:writefile.c
示例20: DegradeImage
// Degrade the pix as if by a print/copy/scan cycle with exposure > 0
// corresponding to darkening on the copier and <0 lighter and 0 not copied.
// Exposures in [-2,2] are most useful, with -3 and 3 being extreme.
// If rotation is nullptr, rotation is skipped. If *rotation is non-zero, the
// pix
// is rotated by *rotation else it is randomly rotated and *rotation is
// modified.
//
// HOW IT WORKS:
// Most of the process is really dictated by the fact that the minimum
// available convolution is 3X3, which is too big really to simulate a
// good quality print/scan process. (2X2 would be better.)
// 1 pixel wide inputs are heavily smeared by the 3X3 convolution, making the
// images generally biased to being too light, so most of the work is to make
// them darker. 3 levels of thickening/darkening are achieved with 2 dilations,
// (using a greyscale erosion) one heavy (by being before convolution) and one
// light (after convolution).
// With no dilation, after covolution, the images are so light that a heavy
// constant offset is required to make the 0 image look reasonable. A simple
// constant offset multiple of exposure to undo this value is enough to achieve
// all the required lightening. This gives the advantage that exposure level 1
// with a single dilation gives a good impression of the broken-yet-too-dark
// problem that is often seen in scans.
// A small random rotation gives some varying greyscale values on the edges,
// and some random salt and pepper noise on top helps to realistically jaggy-up
// the edges.
// Finally a greyscale ramp provides a continuum of effects between exposure
// levels.
Pix* DegradeImage(Pix* input, int exposure, TRand* randomizer,
float* rotation) {
Pix* pix = pixConvertTo8(input, false);
pixDestroy(&input);
input = pix;
int width = pixGetWidth(input);
int height = pixGetHeight(input);
if (exposure >= 2) {
// An erosion simulates the spreading darkening of a dark copy.
// This is backwards to binary morphology,
// see http://www.leptonica.com/grayscale-morphology.html
pix = input;
input = pixErodeGray(pix, 3, 3);
pixDestroy(&pix);
}
// A convolution is essential to any mode as no scanner produces an
// image as sharp as the electronic image.
pix = pix
|
请发表评论