char *get_ocr_text_simple_threshold(struct lib_hardsubx_ctx *ctx, PIX *image, float threshold) { char *text_out=NULL; TessBaseAPISetImage2(ctx->tess_handle, image); if(TessBaseAPIRecognize(ctx->tess_handle, NULL) != 0) { mprint("Error in Tesseract recognition, skipping frame\n"); return NULL; } if((text_out = TessBaseAPIGetUTF8Text(ctx->tess_handle)) == NULL) { mprint("Error getting text, skipping frame\n"); } int conf = TessBaseAPIMeanTextConf(ctx->tess_handle); if(conf < threshold) return NULL; ctx->cur_conf = (float)conf; return text_out; }
char* ocr_bitmap(void* arg, png_color *palette,png_byte *alpha, unsigned char* indata,int w, int h) { PIX *pix = NULL; PIX *cpix = NULL; char*text_out= NULL; int i,j,index; unsigned int wpl; unsigned int *data,*ppixel; BOOL tess_ret = FALSE; struct ocrCtx* ctx = arg; pix = pixCreate(w, h, 32); if(pix == NULL) { return NULL; } wpl = pixGetWpl(pix); data = pixGetData(pix); #if LEPTONICA_VERSION > 69 pixSetSpp(pix, 4); #endif for (i = 0; i < h; i++) { ppixel = data + i * wpl; for (j = 0; j < w; j++) { index = indata[i * w + (j)]; composeRGBPixel(palette[index].red, palette[index].green,palette[index].blue, ppixel); SET_DATA_BYTE(ppixel, L_ALPHA_CHANNEL,alpha[index]); ppixel++; } } ignore_alpha_at_edge(alpha, indata, w, h, pix, &cpix); #ifdef OCR_DEBUG { char str[128] = ""; static int i = 0; sprintf(str,"temp/file_c_%d.png",i); pixWrite(str, cpix, IFF_PNG); i++; } #endif TessBaseAPISetImage2(ctx->api, cpix); tess_ret = TessBaseAPIRecognize(ctx->api, NULL); if( tess_ret != 0) printf("\nsomething messy\n"); text_out = TessBaseAPIGetUTF8Text(ctx->api); pixDestroy(&pix); pixDestroy(&cpix); return text_out; }
char *get_ocr_text_simple(struct lib_hardsubx_ctx *ctx, PIX *image) { char *text_out=NULL; TessBaseAPISetImage2(ctx->tess_handle, image); if(TessBaseAPIRecognize(ctx->tess_handle, NULL) != 0) { mprint("Error in Tesseract recognition, skipping frame\n"); return NULL; } if((text_out = TessBaseAPIGetUTF8Text(ctx->tess_handle)) == NULL) { mprint("Error getting text, skipping frame\n"); } return text_out; }