From d22ab6f9a1ac2872162615e5a33dbfa478887b79 Mon Sep 17 00:00:00 2001 From: Anshul Maheshwari Date: Mon, 5 Nov 2018 14:51:15 +0530 Subject: [PATCH 1/2] remove multiple RGB to grey conversion while OCR --- docs/CHANGES.TXT | 1 + src/lib_ccx/ocr.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/CHANGES.TXT b/docs/CHANGES.TXT index 30579f4c..c002c940 100644 --- a/docs/CHANGES.TXT +++ b/docs/CHANGES.TXT @@ -1,5 +1,6 @@ 0.88(2018-10-24) (unreleased) ----------------- +- Optimize: Remove multiple RGB to grey conversion in OCR. - Fix: Update UTF8Proc to 2.2.0 - Fix: Warn instead of fatal when a 0xFF marker is missing diff --git a/src/lib_ccx/ocr.c b/src/lib_ccx/ocr.c index d30f1f2e..7e51fcc9 100644 --- a/src/lib_ccx/ocr.c +++ b/src/lib_ccx/ocr.c @@ -244,20 +244,21 @@ char* ocr_bitmap(void* arg, png_color *palette,png_byte *alpha, unsigned char* i ppixel++; } } - + BOX *crop_points = ignore_alpha_at_edge(copy->alpha, copy->data, w, h, color_pix, &color_pix_out); + //Converting image to grayscale for OCR to avoid issues with transparency + cpix_gs = pixConvertRGBToGray(cpix, 0.0, 0.0, 0.0); #ifdef OCR_DEBUG { char str[128] = ""; static int i = 0; sprintf(str,"temp/file_c_%d.jpg",i); printf("Writing file_c_%d.jpg\n", i); - pixWrite(str, pixConvertRGBToGray(cpix, 0.0, 0.0, 0.0), IFF_JFIF_JPEG); + pixWrite(str, cpix_gs, IFF_JFIF_JPEG); i++; } #endif - cpix_gs = pixConvertRGBToGray(cpix, 0.0, 0.0, 0.0); // Abhinav95: Converting image to grayscale for OCR to avoid issues with transparency if (cpix_gs==NULL) tess_ret=-1; else @@ -273,7 +274,7 @@ char* ocr_bitmap(void* arg, png_color *palette,png_byte *alpha, unsigned char* i pixDestroy(&cpix_gs); pixDestroy(&color_pix); pixDestroy(&color_pix_out); - + return NULL; } } From ef3d25c25b69453284f66551fea7bff370c9489d Mon Sep 17 00:00:00 2001 From: Anshul Maheshwari Date: Mon, 5 Nov 2018 15:09:08 +0530 Subject: [PATCH 2/2] Indentocr. Some Space and Indentation --- src/lib_ccx/ocr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_ccx/ocr.c b/src/lib_ccx/ocr.c index 7e51fcc9..daea418d 100644 --- a/src/lib_ccx/ocr.c +++ b/src/lib_ccx/ocr.c @@ -192,7 +192,7 @@ BOX* ignore_alpha_at_edge(png_byte *alpha, unsigned char* indata, int w, int h, char* ocr_bitmap(void* arg, png_color *palette,png_byte *alpha, unsigned char* indata,int w, int h, struct image_copy *copy) { // uncomment the below lines to output raw image as debug.png iteratively - //save_spupng("debug.png", indata, w, h, palette, alpha, 16); + // save_spupng("debug.png", indata, w, h, palette, alpha, 16); PIX *pix = NULL; PIX *cpix = NULL; @@ -246,7 +246,7 @@ char* ocr_bitmap(void* arg, png_color *palette,png_byte *alpha, unsigned char* i } BOX *crop_points = ignore_alpha_at_edge(copy->alpha, copy->data, w, h, color_pix, &color_pix_out); - //Converting image to grayscale for OCR to avoid issues with transparency + // Converting image to grayscale for OCR to avoid issues with transparency cpix_gs = pixConvertRGBToGray(cpix, 0.0, 0.0, 0.0); #ifdef OCR_DEBUG {