本文整理汇总了C++中pixThresholdToBinary函数的典型用法代码示例。如果您正苦于以下问题:C++ pixThresholdToBinary函数的具体用法?C++ pixThresholdToBinary怎么用?C++ pixThresholdToBinary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pixThresholdToBinary函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: AddTestSet
void
AddTestSet(PIXA *pixa,
PIX *pixs,
l_int32 filtertype,
l_int32 edgethresh,
l_int32 smoothx,
l_int32 smoothy,
l_float32 gamma,
l_int32 minval,
l_int32 maxval,
l_int32 targetthresh)
{
PIX *pixb, *pixd, *pixth;
pixThresholdSpreadNorm(pixs, filtertype, edgethresh,
smoothx, smoothy, gamma, minval,
maxval, targetthresh, &pixth, NULL, &pixd);
pixSaveTiled(pixth, pixa, 1.0, 1, 20, 0);
pixSaveTiled(pixd, pixa, 1.0, 0, 20, 0);
pixb = pixThresholdToBinary(pixd, targetthresh - 20);
pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0);
pixDestroy(&pixb);
pixb = pixThresholdToBinary(pixd, targetthresh);
pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0);
pixDestroy(&pixb);
pixb = pixThresholdToBinary(pixd, targetthresh + 20);
pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0);
pixDestroy(&pixb);
pixb = pixThresholdToBinary(pixd, targetthresh + 40);
pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0);
pixDestroy(&pixb);
pixDestroy(&pixth);
pixDestroy(&pixd);
return;
}
开发者ID:0ximDigital,项目名称:appsScanner,代码行数:35,代码来源:threshnorm_reg.c
示例2: main
main(int argc,
char **argv)
{
l_int32 i, w, h, d;
l_float32 time;
PIX *pixs, *pixf, *pixd;
PIXA *pixa;
char *filein, *fileout;
static char mainName[] = "edgetest";
if (argc != 3)
exit(ERROR_INT(" Syntax: edgetest filein fileout", mainName, 1));
filein = argv[1];
fileout = argv[2];
if ((pixs = pixRead(filein)) == NULL)
exit(ERROR_INT("pix not made", mainName, 1));
pixGetDimensions(pixs, &w, &h, &d);
if (d != 8)
exit(ERROR_INT("pix not 8 bpp", mainName, 1));
/* Speed: about 12 Mpix/GHz/sec */
startTimer();
pixf = pixSobelEdgeFilter(pixs, L_HORIZONTAL_EDGES);
pixd = pixThresholdToBinary(pixf, 60);
pixInvert(pixd, pixd);
time = stopTimer();
fprintf(stderr, "Time = %7.3f sec\n", time);
fprintf(stderr, "MPix/sec: %7.3f\n", 0.000001 * w * h / time);
pixDisplay(pixs, 0, 0);
pixInvert(pixf, pixf);
pixDisplay(pixf, 480, 0);
pixDisplay(pixd, 960, 0);
pixWrite(fileout, pixf, IFF_PNG);
pixDestroy(&pixd);
/* Threshold at different values */
pixInvert(pixf, pixf);
for (i = 10; i <= 120; i += 10) {
pixd = pixThresholdToBinary(pixf, i);
pixInvert(pixd, pixd);
pixDisplayWrite(pixd, 1);
pixDestroy(&pixd);
}
pixDestroy(&pixf);
/* Display tiled */
pixa = pixaReadFiles("/tmp", "junk_write_display");
pixd = pixaDisplayTiledAndScaled(pixa, 8, 400, 3, 0, 25, 2);
pixWrite("/tmp/junktiles.jpg", pixd, IFF_JFIF_JPEG);
pixDestroy(&pixd);
pixaDestroy(&pixa);
pixDestroy(&pixs);
exit(0);
}
开发者ID:0359xiaodong,项目名称:tess-two,代码行数:57,代码来源:edgetest.c
示例3: 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
示例4: Java_com_googlecode_leptonica_android_GrayQuant_nativePixThresholdToBinary
jlong Java_com_googlecode_leptonica_android_GrayQuant_nativePixThresholdToBinary(JNIEnv *env, jclass clazz,
jlong nativePix, jint thresh) {
PIX *pixs = (PIX *) nativePix;
PIX *pixd = pixThresholdToBinary(pixs, (l_int32) thresh);
return (jlong) pixd;
}
开发者ID:0ximDigital,项目名称:appsScanner,代码行数:7,代码来源:utilities.cpp
示例5: dfprintf
/* load PNG, TIFF, JPG, GIF or BMP to PIX datastructure. The actual supported
* formats depends on how the leptonica was compiled */
PIX *loadimage(char *filename){
PIX *pix, *pixt;
int format, bpp;
format=fileformat(filename);
// In later versions of leptonica you will have to do this
// pixReadHeader(filename, format,NULL,NULL,NULL,bpp,NULL);
if(format!=IFF_PNG && format!=IFF_JFIF_JPEG && format!=IFF_TIFF && format!=
IFF_GIF && format!=7 && format!=8){
dfprintf(stderr,"Not recognised file format %i", format);
return NULL;
}
if ((pix = pixRead(filename)) == NULL) return NULL;
/* TODO: convert image to 1-bpp 300dpi regardless of scan */
bpp=pixGetDepth(pix);
if(bpp>1){
/*
printf("Bits per pixel=%i",bpp);
exit(1); */
//pixThresholdForFgBg(pix,5,100,NULL,NULL);
//pixContrastTRC(pix, pix, 1000);
pixt = pixContrastNorm(NULL, pix, 10, 10, 40, 2, 2);
pixDestroy(&pix);
pix = pixGammaTRC(NULL, pixt, 1.5, 50, 235);
pixt=pixThresholdToBinary(pix, 200);
//pixt=pixThreshold8(pix,1,1,0);
pixDestroy(&pix);
pix=pixt;
}
return pix;
}
开发者ID:samop,项目名称:havoc-ochi,代码行数:33,代码来源:imageio.c
示例6: 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
示例7: main
main(int argc,
char **argv)
{
char *infile, *outfile;
l_int32 d;
PIX *pixs, *pixgr, *pixb;
static char mainName[] = "showedges";
if (argc != 3)
exit(ERROR_INT(" Syntax: showedges infile outfile", mainName, 1));
infile = argv[1];
outfile = argv[2];
pixs = pixRead(infile);
d = pixGetDepth(pixs);
if (d != 8 && d != 32)
exit(ERROR_INT("d not 8 or 32 bpp", mainName, 1));
pixgr = pixHalfEdgeByBandpass(pixs, SMOOTH_WIDTH_1, SMOOTH_WIDTH_1,
SMOOTH_WIDTH_2, SMOOTH_WIDTH_2);
pixb = pixThresholdToBinary(pixgr, THRESHOLD);
pixInvert(pixb, pixb);
/* pixWrite("junkpixgr", pixgr, IFF_JFIF_JPEG); */
pixWrite(outfile, pixb, IFF_PNG);
return 0;
}
开发者ID:0xkasun,项目名称:Dummy_Tes,代码行数:28,代码来源:showedges.c
示例8: 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
示例9: Pix
// threshold the image -- warning, operates ONLY on grayscale pixmaps
// original image is unchanged - a new modified image at raster's end
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
Pix Pix::ThresholdToBinary(int threshold)
{
if(IsEmpty())
return Pix();
PIX *dPix = pixThresholdToBinary(pix, threshold);
if(!dPix)
return Pix();
return Pix(&dPix);
} // END Pix::ThresholdToBinary()
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:13,代码来源:Lept-Threshold.cpp
示例10: Java_com_googlecode_leptonica_android_Dewarp_nativeDewarp
jint Java_com_googlecode_leptonica_android_Dewarp_nativeDewarp(JNIEnv *env, jclass clazz, jint nativePix) {
LOGV("%s",__FUNCTION__);
PIX* pixd=NULL;
PIX *pixs = (PIX *) nativePix;
PIX* pixb = pixThresholdToBinary(pixs, 130);
// Basic functioning:
L_Dewarp *dew = dewarpCreate(pixb,0,60,5,1);
int buildresult=dewarpBuildModel(dew, 0);
if(buildresult==0){
int applyresult=dewarpApplyDisparity(dew, pixs, 0);
if(applyresult==0){
pixd = pixClone(dew->pixd);
}
}
pixDestroy(&pixb);
dewarpDestroy(&dew);
if(pixd!=NULL){
return (jint) pixd;
} else {
return (jint) 0;
}
}
开发者ID:ArunPandiyan,项目名称:textfairy,代码行数:23,代码来源:utilities.cpp
示例11: _process_frame_tickertext
char* _process_frame_tickertext(struct lib_hardsubx_ctx *ctx, AVFrame *frame, int width, int height, int index)
{
PIX *im;
PIX *edge_im;
PIX *lum_im;
PIX *feat_im;
char *subtitle_text=NULL;
im = pixCreate(width,height,32);
lum_im = pixCreate(width,height,32);
feat_im = pixCreate(width,height,32);
int i,j;
for(i=(92*height)/100;i<height;i++)
{
for(j=0;j<width;j++)
{
int p=j*3+i*frame->linesize[0];
int r=frame->data[0][p];
int g=frame->data[0][p+1];
int b=frame->data[0][p+2];
pixSetRGBPixel(im,j,i,r,g,b);
float L,A,B;
rgb_to_lab((float)r,(float)g,(float)b,&L,&A,&B);
if(L > ctx->lum_thresh)
pixSetRGBPixel(lum_im,j,i,255,255,255);
else
pixSetRGBPixel(lum_im,j,i,0,0,0);
}
}
//Handle the edge image
edge_im = pixCreate(width,height,8);
edge_im = pixConvertRGBToGray(im,0.0,0.0,0.0);
edge_im = pixSobelEdgeFilter(edge_im, L_VERTICAL_EDGES);
edge_im = pixDilateGray(edge_im, 21, 11);
edge_im = pixThresholdToBinary(edge_im,50);
for(i=92*(height/100);i<height;i++)
{
for(j=0;j<width;j++)
{
unsigned int p1,p2,p3;
pixGetPixel(edge_im,j,i,&p1);
// pixGetPixel(pixd,j,i,&p2);
pixGetPixel(lum_im,j,i,&p3);
if(p1==0&&p3>0)
pixSetRGBPixel(feat_im,j,i,255,255,255);
else
pixSetRGBPixel(feat_im,j,i,0,0,0);
}
}
// Tesseract OCR for the ticker text here
subtitle_text = get_ocr_text_simple(ctx, lum_im);
char write_path[100];
sprintf(write_path,"./lum_im%04d.jpg",index);
pixWrite(write_path,lum_im,IFF_JFIF_JPEG);
sprintf(write_path,"./im%04d.jpg",index);
pixWrite(write_path,im,IFF_JFIF_JPEG);
pixDestroy(&lum_im);
pixDestroy(&im);
pixDestroy(&edge_im);
pixDestroy(&feat_im);
return subtitle_text;
}
开发者ID:Abhinav95,项目名称:ccextractor,代码行数:66,代码来源:hardsubx_decoder.c
示例12: _display_frame
void _display_frame(struct lib_hardsubx_ctx *ctx, AVFrame *frame, int width, int height, int timestamp)
{
// Debug: Display the frame after processing
PIX *im;
im = pixCreate(width,height,32);
PIX *hue_im = pixCreate(width,height,32);
int i,j;
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
int p=j*3+i*frame->linesize[0];
int r=frame->data[0][p];
int g=frame->data[0][p+1];
int b=frame->data[0][p+2];
pixSetRGBPixel(im,j,i,r,g,b);
float H,S,V;
rgb_to_hsv((float)r,(float)g,(float)b,&H,&S,&V);
if(abs(H-ctx->hue)<20)
{
pixSetRGBPixel(hue_im,j,i,r,g,b);
}
}
}
PIX *edge_im = pixCreate(width,height,8),*edge_im_2 = pixCreate(width,height,8);
edge_im = pixConvertRGBToGray(im,0.0,0.0,0.0);
edge_im = pixSobelEdgeFilter(edge_im, L_VERTICAL_EDGES);
edge_im = pixDilateGray(edge_im, 21, 1);
edge_im = pixThresholdToBinary(edge_im,50);
PIX *pixd = pixCreate(width,height,1);
pixSauvolaBinarize(pixConvertRGBToGray(hue_im,0.0,0.0,0.0), 15, 0.3, 1, NULL, NULL, NULL, &pixd);
edge_im_2 = pixConvertRGBToGray(hue_im,0.0,0.0,0.0);
edge_im_2 = pixDilateGray(edge_im_2, 5, 5);
PIX *feat_im = pixCreate(width,height,32);
for(i=3*(height/4);i<height;i++)
{
for(j=0;j<width;j++)
{
unsigned int p1,p2,p3,p4;
pixGetPixel(edge_im,j,i,&p1);
pixGetPixel(pixd,j,i,&p2);
// pixGetPixel(hue_im,j,i,&p3);
pixGetPixel(edge_im_2,j,i,&p4);
if(p1==0&&p2==0&&p4>0)//if(p4>0&&p1==0)//if(p2==0&&p1==0&&p3>0)
{
pixSetRGBPixel(feat_im,j,i,255,255,255);
}
}
}
char *txt=NULL;
// txt = get_ocr_text_simple(ctx, feat_im);
// txt=get_ocr_text_wordwise_threshold(ctx, feat_im, ctx->conf_thresh);
// if(txt != NULL)printf("%s\n", txt);
pixDestroy(&im);
pixDestroy(&edge_im);
pixDestroy(&feat_im);
pixDestroy(&edge_im_2);
pixDestroy(&pixd);
}
开发者ID:Abhinav95,项目名称:ccextractor,代码行数:65,代码来源:hardsubx_decoder.c
示例13: _process_frame_white_basic
char* _process_frame_white_basic(struct lib_hardsubx_ctx *ctx, AVFrame *frame, int width, int height, int index)
{
//printf("frame : %04d\n", index);
PIX *im;
PIX *edge_im;
PIX *lum_im;
PIX *feat_im;
char *subtitle_text=NULL;
im = pixCreate(width,height,32);
lum_im = pixCreate(width,height,32);
feat_im = pixCreate(width,height,32);
int i,j;
for(i=(3*height)/4;i<height;i++)
{
for(j=0;j<width;j++)
{
int p=j*3+i*frame->linesize[0];
int r=frame->data[0][p];
int g=frame->data[0][p+1];
int b=frame->data[0][p+2];
pixSetRGBPixel(im,j,i,r,g,b);
float L,A,B;
rgb_to_lab((float)r,(float)g,(float)b,&L,&A,&B);
if(L > ctx->lum_thresh)
pixSetRGBPixel(lum_im,j,i,255,255,255);
else
pixSetRGBPixel(lum_im,j,i,0,0,0);
}
}
//Handle the edge image
edge_im = pixCreate(width,height,8);
edge_im = pixConvertRGBToGray(im,0.0,0.0,0.0);
edge_im = pixSobelEdgeFilter(edge_im, L_VERTICAL_EDGES);
edge_im = pixDilateGray(edge_im, 21, 11);
edge_im = pixThresholdToBinary(edge_im,50);
for(i=3*(height/4);i<height;i++)
{
for(j=0;j<width;j++)
{
unsigned int p1,p2,p3;
pixGetPixel(edge_im,j,i,&p1);
// pixGetPixel(pixd,j,i,&p2);
pixGetPixel(lum_im,j,i,&p3);
if(p1==0&&p3>0)
pixSetRGBPixel(feat_im,j,i,255,255,255);
else
pixSetRGBPixel(feat_im,j,i,0,0,0);
}
}
if(ctx->detect_italics)
{
ctx->ocr_mode = HARDSUBX_OCRMODE_WORD;
}
// TESSERACT OCR FOR THE FRAME HERE
switch(ctx->ocr_mode)
{
case HARDSUBX_OCRMODE_WORD:
if(ctx->conf_thresh > 0)
subtitle_text = get_ocr_text_wordwise_threshold(ctx, lum_im, ctx->conf_thresh);
else
subtitle_text = get_ocr_text_wordwise(ctx, lum_im);
break;
case HARDSUBX_OCRMODE_LETTER:
if(ctx->conf_thresh > 0)
subtitle_text = get_ocr_text_letterwise_threshold(ctx, lum_im, ctx->conf_thresh);
else
subtitle_text = get_ocr_text_letterwise(ctx, lum_im);
break;
case HARDSUBX_OCRMODE_FRAME:
if(ctx->conf_thresh > 0)
subtitle_text = get_ocr_text_simple_threshold(ctx, lum_im, ctx->conf_thresh);
else
subtitle_text = get_ocr_text_simple(ctx, lum_im);
break;
default:
fatal(EXIT_MALFORMED_PARAMETER,"Invalid OCR Mode");
}
pixDestroy(&lum_im);
pixDestroy(&im);
pixDestroy(&edge_im);
pixDestroy(&feat_im);
return subtitle_text;
}
开发者ID:Abhinav95,项目名称:ccextractor,代码行数:89,代码来源:hardsubx_decoder.c
示例14: main
l_int32 main(int argc,
char **argv) {
l_int32 i, n;
l_float32 a, b, c, d, e;
NUMA *nax, *nafit;
PIX *pixs, *pixn, *pixg, *pixb, *pixt1, *pixt2;
PIXA *pixa;
PTA *pta, *ptad;
PTAA *ptaa1, *ptaa2;
pixs = pixRead("cat-35.jpg");
/* pixs = pixRead("zanotti-78.jpg"); */
/* 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);
pixDestroy(&pixg);
/* Get the textline centers */
pixa = pixaCreate(6);
ptaa1 = dewarpGetTextlineCenters(pixb, 0);
pixt1 = pixCreateTemplate(pixs);
pixSetAll(pixt1);
pixt2 = pixDisplayPtaa(pixt1, ptaa1);
pixWrite("/tmp/textline1.png", pixt2, IFF_PNG);
pixDisplayWithTitle(pixt2, 0, 100, "textline centers 1", 1);
pixaAddPix(pixa, pixt2, L_INSERT);
pixDestroy(&pixt1);
/* Remove short lines */
fprintf(stderr, "Num all lines = %d\n", ptaaGetCount(ptaa1));
ptaa2 = dewarpRemoveShortLines(pixb, ptaa1, 0.8, 0);
pixt1 = pixCreateTemplate(pixs);
pixSetAll(pixt1);
pixt2 = pixDisplayPtaa(pixt1, ptaa2);
pixWrite("/tmp/textline2.png", pixt2, IFF_PNG);
pixDisplayWithTitle(pixt2, 300, 100, "textline centers 2", 1);
pixaAddPix(pixa, pixt2, L_INSERT);
pixDestroy(&pixt1);
n = ptaaGetCount(ptaa2);
fprintf(stderr, "Num long lines = %d\n", n);
ptaaDestroy(&ptaa1);
pixDestroy(&pixb);
/* Long lines over input image */
pixt1 = pixCopy(NULL, pixs);
pixt2 = pixDisplayPtaa(pixt1, ptaa2);
pixWrite("/tmp/textline3.png", pixt2, IFF_PNG);
pixDisplayWithTitle(pixt2, 600, 100, "textline centers 3", 1);
pixaAddPix(pixa, pixt2, L_INSERT);
pixDestroy(&pixt1);
/* Quadratic fit to curve */
pixt1 = pixCopy(NULL, pixs);
for (i = 0; i < n; i++) {
pta = ptaaGetPta(ptaa2, i, L_CLONE);
ptaGetArrays(pta, &nax, NULL);
ptaGetQuadraticLSF(pta, &a, &b, &c, &nafit);
fprintf(stderr, "Quadratic: a = %10.6f, b = %7.3f, c = %7.3f\n",
a, b, c);
ptad = ptaCreateFromNuma(nax, nafit);
pixDisplayPta(pixt1, pixt1, ptad);
ptaDestroy(&pta);
ptaDestroy(&ptad);
numaDestroy(&nax);
numaDestroy(&nafit);
}
pixWrite("/tmp/textline4.png", pixt1, IFF_PNG);
pixDisplayWithTitle(pixt1, 900, 100, "textline centers 4", 1);
pixaAddPix(pixa, pixt1, L_INSERT);
/* Cubic fit to curve */
pixt1 = pixCopy(NULL, pixs);
for (i = 0; i < n; i++) {
pta = ptaaGetPta(ptaa2, i, L_CLONE);
ptaGetArrays(pta, &nax, NULL);
ptaGetCubicLSF(pta, &a, &b, &c, &d, &nafit);
fprintf(stderr, "Cubic: a = %10.6f, b = %10.6f, c = %7.3f, d = %7.3f\n",
a, b, c, d);
ptad = ptaCreateFromNuma(nax, nafit);
pixDisplayPta(pixt1, pixt1, ptad);
ptaDestroy(&pta);
ptaDestroy(&ptad);
numaDestroy(&nax);
numaDestroy(&nafit);
}
pixWrite("/tmp/textline5.png", pixt1, IFF_PNG);
pixDisplayWithTitle(pixt1, 1200, 100, "textline centers 5", 1);
pixaAddPix(pixa, pixt1, L_INSERT);
/* Quartic fit to curve */
pixt1 = pixCopy(NULL, pixs);
for (i = 0; i < n; i++) {
pta = ptaaGetPta(ptaa2, i, L_CLONE);
ptaGetArrays(pta, &nax, NULL);
ptaGetQuarticLSF(pta, &a, &b, &c, &d, &e, &nafit);
fprintf(stderr,
"Quartic: a = %7.3f, b = %7.3f, c = %9.5f, d = %7.3f, e = %7.3f\n",
//.........这里部分代码省略.........
开发者ID:mehulsbhatt,项目名称:MyOCRTEST,代码行数:101,代码来源:dewarptest3.c
示例15: main
int main(int argc,
char **argv) {
char *infile;
l_int32 w, d, threshval, ival, newval;
l_uint32 val;
PIX *pixs, *pixg, *pixg2;
PIX *pix1, *pix2;
PIXA *pixa;
static char mainName[] = "binarize_set";
if (argc != 2)
return ERROR_INT(" Syntax: binarize_set infile", mainName, 1);
infile = argv[1];
pixa = pixaCreate(5);
pixs = pixRead(infile);
pixGetDimensions(pixs, &w, NULL, &d);
pixSaveTiled(pixs, pixa, 1.0, 1, 50, 32);
pixDisplay(pixs, 100, 0);
#if ALL
/* 1. Standard background normalization with a global threshold. */
pixg = pixConvertTo8(pixs, 0);
pix1 = pixBackgroundNorm(pixg, NULL, NULL, 10, 15, 100, 50, 255, 2, 2);
pix2 = pixThresholdToBinary(pix1, 160);
pixWrite("/tmp/binar1.png", pix2, IFF_PNG);
pixDisplay(pix2, 100, 0);
pixSaveTiled(pix2, pixa, 1.0, 1, 50, 32);
pixDestroy(&pixg);
pixDestroy(&pix1);
pixDestroy(&pix2);
#endif
#if ALL
/* 2. Background normalization followed by Otsu thresholding. Otsu
* binarization attempts to split the image into two roughly equal
* sets of pixels, and it does a very poor job when there are large
* amounts of dark background. By doing a background normalization
* first (to get the background near 255), we remove this problem.
* Then we use a modified Otsu to estimate the best global
* threshold on the normalized image. */
pixg = pixConvertTo8(pixs, 0);
pix1 = pixOtsuThreshOnBackgroundNorm(pixg, NULL, 10, 15, 100,
50, 255, 2, 2, 0.10, &threshval);
fprintf(stderr, "thresh val = %d\n", threshval);
pixSaveTiled(pix1, pixa, 1.0, 1, 50, 32);
pixWrite("/tmp/binar2.png", pix1, IFF_PNG);
pixDisplay(pix1, 100, 200);
pixDestroy(&pixg);
pixDestroy(&pix1);
#endif
#if ALL
/* 3. Background normalization with Otsu threshold estimation and
* masking for threshold selection. */
pixg = pixConvertTo8(pixs, 0);
pix1 = pixMaskedThreshOnBackgroundNorm(pixg, NULL, 10, 15, 100,
50, 2, 2, 0.10, &threshval);
fprintf(stderr, "thresh val = %d\n", threshval);
pixSaveTiled(pix1, pixa, 1.0, 1, 50, 32);
pixWrite("/tmp/binar3.png", pix1, IFF_PNG);
pixDisplay(pix1, 100, 400);
pixDestroy(&pixg);
pixDestroy(&pix1);
#endif
#if ALL
/* 4. Background normalization followed by Sauvola binarization */
if (d == 32)
pixg = pixConvertRGBToGray(pixs, 0.2, 0.7, 0.1);
else
pixg = pixConvertTo8(pixs, 0);
pixg2 = pixContrastNorm(NULL, pixg, 20, 20, 130, 2, 2);
pixSauvolaBinarizeTiled(pixg2, 25, 0.40, 1, 1, NULL, &pix1);
pixSaveTiled(pix1, pixa, 1.0, 1, 50, 32);
pixWrite("/tmp/binar4.png", pix1, IFF_PNG);
pixDisplay(pix1, 100, 600);
pixDestroy(&pixg);
pixDestroy(&pixg2);
pixDestroy(&pix1);
#endif
#if ALL
/* 5. Contrast normalization followed by background normalization, and
* thresholding. */
if (d == 32)
pixg = pixConvertRGBToGray(pixs, 0.2, 0.7, 0.1);
else
pixg = pixConvertTo8(pixs, 0);
pixOtsuAdaptiveThreshold(pixg, 5000, 5000, 0, 0, 0.1, &pix1, NULL);
pixGetPixel(pix1, 0, 0, &val);
ival = (l_int32) val;
newval = ival + (l_int32)(0.6 * (110 - ival));
fprintf(stderr, "th1 = %d, th2 = %d\n", ival, newval);
pixDestroy(&pix1);
pixContrastNorm(pixg, pixg, 50, 50, 130, 2, 2);
pixg2 = pixBackgroundNorm(pixg, NULL, NULL, 20, 20, 70, 40, 200, 2, 2);
//.........这里部分代码省略.........
开发者ID:mehulsbhatt,项目名称:MyOCRTEST,代码行数:101,代码来源:binarize_set.c
示例16: main
l_int32 main(int argc,
char **argv)
{
l_int32 method, pageno;
L_DEWARP *dew1;
L_DEWARPA *dewa;
PIX *pixs, *pixn, *pixg, *pixb, *pixd;
static char mainName[] = "dewarptest2";
if (argc != 2 && argc != 4)
return ERROR_INT("Syntax: dewarptest2 method [image pageno]",
mainName, 1);
if (argc == 2) {
pixs = pixRead("cat-35.jpg");
pageno = 35;
}
else {
pixs = pixRead(argv[2]);
pageno = atoi(argv[3]);
}
if (!pixs)
return ERROR_INT("image not read", mainName, 1);
method = atoi(argv[1]);
lept_mkdir("lept");
if (method == 1) { /* Use single page dewarp function */
dewarpSinglePage(pixs, 1, 100, 1, &pixd, NULL, 1);
pixDisplay(pixd, 100, 100);
} else { /* Break down into multiple steps; require min of only 6 lines */
dewa = dewarpaCreate(40, 30, 1, 6, 50);
dewarpaUseBothArrays(dewa, 1);
#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);
dewarpBuildPageModel(dew1, "/tmp/lept/test2_model.pdf");
dewarpaApplyDisparity(dewa, pageno, pixg, -1, 0, 0, &pixd,
"/tmp/lept/test2_apply.pdf");
dewarpaInfo(stderr, dewa);
dewarpaDestroy(&dewa);
pixDestroy(&pixg);
pixDestroy(&pixb);
}
pixDestroy(&pixs);
pixDestroy(&pixd);
return 0;
}
开发者ID:xmarston,项目名称:BillRecognizer,代码行数:63,代码来源:dewarptest2.c
示例17: main
int main(int argc,
char **argv)
{
l_int32 index;
l_uint32 val32;
BOX *box, *box1, *box2, *box3, *box4, *box5;
BOXA *boxa;
L_KERNEL *kel;
PIX *pixs, *pixg, *pixb, *pixd, *pixt, *pix1, *pix2, *pix3, *pix4;
PIXA *pixa;
PIXCMAP *cmap;
L_REGPARAMS *rp;
if (regTestSetup(argc, argv, &rp))
return 1;
pixa = pixaCreate(0);
/* Color non-white pixels on RGB */
pixs = pixRead("lucasta-frag.jpg");
pixt = pixConvert8To32(pixs);
box = boxCreate(120, 30, 200, 200);
pixColorGray(pixt, box, L_PAINT_DARK, 220, 0, 0, 255);
regTestWritePixAndCheck(rp, pixt, IFF_JFIF_JPEG); /* 0 */
pixaAddPix(pixa, pixt, L_COPY);
pixColorGray(pixt, NULL, L_PAINT_DARK, 220, 255, 100, 100);
regTestWritePixAndCheck(rp, pixt, IFF_JFIF_JPEG); /* 1 */
pixaAddPix(pixa, pixt, L_INSERT);
boxDestroy(&box);
/* Color non-white pixels on colormap */
pixt = pixThresholdTo4bpp(pixs, 6, 1);
box = boxCreate(120, 30, 200, 200);
pixColorGray(pixt, box, L_PAINT_DARK, 220, 0, 0, 255);
regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 2 */
pixaAddPix(pixa, pixt, L_COPY);
pixColorGray(pixt, NULL, L_PAINT_DARK, 220, 255, 100, 100);
regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 3 */
pixaAddPix(pixa, pixt, L_INSERT);
boxDestroy(&box);
/* Color non-black pixels on RGB */
pixt = pixConvert8To32(pixs);
box = boxCreate(120, 30, 200, 200);
pixColorGray(pixt, box, L_PAINT_LIGHT, 20, 0, 0, 255);
regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 4 */
pixaAddPix(pixa, pixt, L_COPY);
pixColorGray(pixt, NULL, L_PAINT_LIGHT, 80, 255, 100, 100);
regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 5 */
pixaAddPix(pixa, pixt, L_INSERT);
boxDestroy(&box);
/* Color non-black pixels on colormap */
pixt = pixThresholdTo4bpp(pixs, 6, 1);
box = boxCreate(120, 30, 200, 200);
pixColorGray(pixt, box, L_PAINT_LIGHT, 20, 0, 0, 255);
regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 6 */
pixaAddPix(pixa, pixt, L_COPY);
pixColorGray(pixt, NULL, L_PAINT_LIGHT, 20, 255, 100, 100);
regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 7 */
pixaAddPix(pixa, pixt, L_INSERT);
boxDestroy(&box);
/* Add highlight color to RGB */
pixt = pixConvert8To32(pixs);
box = boxCreate(507, 5, 385, 45);
pixg = pixClipRectangle(pixs, box, NULL);
pixb = pixThresholdToBinary(pixg, 180);
pixInvert(pixb, pixb);
pixDisplayWrite(pixb, 1);
composeRGBPixel(50, 0, 250, &val32);
pixPaintThroughMask(pixt, pixb, box->x, box->y, val32);
boxDestroy(&box);
pixDestroy(&pixg);
pixDestroy(&pixb);
box = boxCreate(236, 107, 262, 40);
pixg = pixClipRectangle(pixs, box, NULL);
pixb = pixThresholdToBinary(pixg, 180);
pixInvert(pixb, pixb);
composeRGBPixel(250, 0, 50, &val32);
pixPaintThroughMask(pixt, pixb, box->x, box->y, val32);
boxDestroy(&box);
pixDestroy(&pixg);
pixDestroy(&pixb);
box = boxCreate(222, 208, 247, 43);
pixg = pixClipRectangle(pixs, box, NULL);
pixb = pixThresholdToBinary(pixg, 180);
pixInvert(pixb, pixb);
composeRGBPixel(60, 250, 60, &val32);
pixPaintThroughMask(pixt, pixb, box->x, box->y, val32);
regTestWritePixAndCheck(rp, pixt, IFF_PNG); /* 8 */
pixaAddPix(pixa, pixt, L_INSERT);
boxDestroy(&box);
pixDestroy(&pixg);
pixDestroy(&pixb);
/* Add highlight color to colormap */
pixt = pixThresholdTo4bpp(pixs, 5, 1);
cmap = pixGetColormap(pixt);
pixcmapGetIndex(cmap, 255, 255, 255, &index);
//.........这里部分代码省略.........
开发者ID:AAAyag,项目名称:tess-two,代码行数:101,代码来源:paint_reg.c
示例18: main
//.........这里部分代码省略.........
pixt5 = fpixConvertToPix(fpixt1, 8, L_CLIP_TO_ZERO, 0);
regTestWritePixAndCheck(rp, pixt5, IFF_JFIF_JPEG); /* 16 */
pixSaveTiled(pixt5, pixa, 1, 1, 20, 32);
fpixt2 = fpixConvolveSep(fpixg, kelx, kely, 1);
pixt6 = fpixConvertToPix(fpixt2, 8, L_CLIP_TO_ZERO, 0);
regTestWritePixAndCheck(rp, pixt6, IFF_JFIF_JPEG); /* 17 */
pixSaveTiled(pixt2, pixa, 1, 0, 20, 32);
regTestCompareSimilarPix(rp, pixt1, pixt5, 2, 0.00, 0); /* 18 */
regTestCompareSimilarPix(rp, pixt2, pixt6, 2, 0.00, 0); /* 19 */
pixDestroy(&pixt1);
pixDestroy(&pixt2);
pixDestroy(&pixt3);
pixDestroy(&pixt4);
pixDestroy(&pixt5);
pixDestroy(&pixt6);
fpixDestroy(&fpixg);
fpixDestroy(&fpixt1);
fpixDestroy(&fpixt2);
pixd = pixaDisplay(pixa, 0, 0);
regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG); /* 20 */
pixDisplayWithTitle(pixd, 600, 100, NULL, rp->display);
pixDestroy(&pixs);
pixDestroy(&pixg);
pixDestroy(&pixd);
pixaDestroy(&pixa);
/* Test extension (continued and slope).
* First, build a smooth vertical disparity array;
* then extend and show the contours. */
pixs = pixRead("cat-35.jpg");
pixn = pixBackgroundNormSimple(pixs, NULL, NULL);
pixg = pixConvertRGBToGray(pixn, 0.5, 0.3, 0.2);
pixb = pixThresholdToBinary(pixg, 130);
dewa = dewarpaCreate(1, 30, 1, 15, 0);
dew = dewarpCreate(pixb, 35);
dewarpaInsertDewarp(dewa, dew);
dewarpBuildModel(dew, NULL);
dewarpPopulateFullRes(dew, NULL);
fpixs = dew->fullvdispar;
fpixs2 = fpixAddContinuedBorder(fpixs, 200, 200, 100, 300);
fpixs3 = fpixAddSlopeBorder(fpixs, 200, 200, 100, 300);
dpix = fpixConvertToDPix(fpixs3);
fpixs4 = dpixConvertToFPix(dpix);
pixt1 = fpixRenderContours(fpixs, 2.0, 0.2);
pixt2 = fpixRenderContours(fpixs2, 2.0, 0.2);
pixt3 = fpixRenderContours(fpixs3, 2.0, 0.2);
pixt4 = fpixRenderContours(fpixs4, 2.0, 0.2);
pixt5 = pixRead("karen8.jpg");
dpix2 = pixConvertToDPix(pixt5, 1);
pixt6 = dpixConvertToPix(dpix2, 8, L_CLIP_TO_ZERO, 0);
regTestWritePixAndCheck(rp, pixt1, IFF_PNG); /* 21 */
pixDisplayWithTitle(pixt1, 0, 100, NULL, rp->display);
regTestWritePixAndCheck(rp, pixt2, IFF_PNG); /* 22 */
pixDisplayWithTitle(pixt2, 470, 100, NULL, rp->display);
regTestWritePixAndCheck(rp, pixt3, IFF_PNG); /* 23 */
pixDisplayWithTitle(pixt3, 1035, 100, NULL, rp->display);
regTestComparePix(rp, pixt3, pixt4); /* 24 */
regTestComparePix(rp, pixt5, pixt6); /* 25 */
pixDestroy(&pixs);
pixDestroy(&pixn);
pixDestroy(&pixg);
pixDestroy(&pixb);
pixDestroy(&pixt1);
pixDestroy(&pixt2);
pixDestroy(&pixt3);
开发者ID:ErfanHasmin,项目名称:scope-ocr,代码行数:67,代码来源:fpix_reg.c
示例19: deskew
/*!
* deskew()
*
* Input: pixs
* redsearch (for binary search: reduction factor = 1, 2 or 4)
* Return: deskewed pix, or NULL on error
*/
PIX *
deskew(PIX *pixs,
l_int32 redsearch)
{
l_float32 angle, conf, deg2rad;
PIX *pixg; /* gray version */
PIX *pixb; /* binary version */
PIX *pixd; /* destination image */
PROCNAME("deskew");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
/* Calculate a skew angle. We may need to make a binary version of the
* image for this calculation.
*/
if (pixGetDepth(pixs) != 1) {
/* FIX ME: We should probably pick a threshold value with more care. */
/* Create a grayscale image if we need one. */
if (pixGetDepth(pixs) >= 24) {
pixg = pixConvertRGBToGray(pixs, 0.0, 0.0, 0.0);
} else {
pixg = pixs;
}
pixb = pixThresholdToBinary(pixg, 127);
if (pixg != pixs) {
pixDestroy(&pixg);
}
/* Assert: We are done with any gray image. */
} else {
pixb = pixs;
}
/* Assert: We have a valid binary image. */
if (redsearch != 1 && redsearch != 2 && redsearch != 4)
return (PIX *)ERROR_PTR("redsearch not in {1,2,4}", procName, NULL);
deg2rad = 3.1415926535 / 180.;
if (pixFindSkewSweepAndSearch(pixb, &angle, &conf,
DEFAULT_SWEEP_REDUCTION, redsearch,
DEFAULT_SWEEP_RANGE, DEFAULT_SWEEP_DELTA,
DEFAULT_MINBS_DELTA)) {
pixd = pixClone(pixs);
goto finish;
}
if (L_ABS(angle) < MIN_DESKEW_ANGLE || conf < MIN_ALLOWED_CONFIDENCE) {
pixd = pixClone(pixs);
goto finish;
}
/* If the pixel depth of pixs is 1, we need to use a bit-depth
* independent rotate instead of the more accurate area mapping rotate.
*/
if (pixGetDepth(pixs) == 1) {
if ((pixd = pixRotateShear(pixs, 0, 0, deg2rad * angle, 0xffffff00)) == NULL) {
pixd = pixClone(pixs);
}
} else {
#if defined(COLOR_ROTATE)
if ((pixd = pixRotateAMColorFast(pixs, deg2rad * angle)) == NULL) {
pixd = pixClone(pixs);
}
#else
if ((pixd = pixRotateAM(pixs, deg2rad * angle, 0xffffff00)) == NULL) {
pixd = pixClone(pixs);
}
#endif
}
finish:
if (pixb != pixs) {
pixDestroy(&pixb);
}
return pixd;
}
开发者ID:chronomex,项目名称:ess-ocr,代码行数:84,代码来源:deskew.c
|
请发表评论