mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-07-08 18:06:30 +00:00
Add -quant (OCR quantization function)
This commit is contained in:
@@ -68,6 +68,7 @@ void init_options (struct ccx_s_options *options)
|
||||
options->dvblang = NULL; // By default, autodetect DVB language
|
||||
options->ocrlang = NULL; // By default, autodetect .traineddata file
|
||||
options->ocr_oem = 0; // By default, set Tesseract OEM mode OEM_TESSERACT_ONLY (0)
|
||||
options->ocr_quantmode = 1; // CCExtractor's internal
|
||||
options->mkvlang = NULL; // By default, all the languages are extracted
|
||||
options->ignore_pts_jumps = 1;
|
||||
options->analyze_video_stream = 0;
|
||||
|
||||
@@ -138,6 +138,7 @@ struct ccx_s_options // Options from user parameters
|
||||
char *dvblang; // The name of the language stream for DVB
|
||||
char *ocrlang; // The name of the .traineddata file to be loaded with tesseract
|
||||
int ocr_oem; // The Tesseract OEM mode, could be 0 (default), 1 or 2
|
||||
int ocr_quantmode; // How to quantize the bitmap before passing to to tesseract (0=no quantization at all, 1=CCExtractor's internal)
|
||||
char *mkvlang; // The name of the language stream for MKV
|
||||
int analyze_video_stream; // If 1, the video stream will be processed even if we're using a different one for subtitles.
|
||||
|
||||
|
||||
@@ -366,6 +366,7 @@ struct lib_cc_decode* init_cc_decode (struct ccx_decoders_common_settings_t *set
|
||||
ctx->xds_ctx = ccx_decoders_xds_init_library(ctx->timing, setting->xds_write_to_file);
|
||||
|
||||
ctx->vbi_decoder = NULL;
|
||||
ctx->ocr_quantmode = setting->ocr_quantmode;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ struct ccx_decoders_common_settings_t
|
||||
enum ccx_code_type codec;
|
||||
int xds_write_to_file;
|
||||
void *private_data;
|
||||
int ocr_quantmode;
|
||||
};
|
||||
|
||||
struct lib_cc_decode
|
||||
@@ -199,6 +200,7 @@ struct lib_cc_decode
|
||||
int (*writedata)(const unsigned char *data, int length, void *private_data, struct cc_subtitle *sub);
|
||||
|
||||
//dvb subtitle related
|
||||
int ocr_quantmode;
|
||||
struct lib_cc_decode *prev;
|
||||
};
|
||||
|
||||
|
||||
@@ -1643,7 +1643,7 @@ static int write_dvb_sub(struct lib_cc_decode *dec_ctx, struct cc_subtitle *sub)
|
||||
#ifdef ENABLE_OCR
|
||||
char *ocr_str = NULL;
|
||||
if (ctx->ocr_ctx) {
|
||||
ret = ocr_rect(ctx->ocr_ctx, rect, &ocr_str, region->bgcolor);
|
||||
ret = ocr_rect(ctx->ocr_ctx, rect, &ocr_str, region->bgcolor, dec_ctx->ocr_quantmode);
|
||||
if (ret >= 0)
|
||||
rect->ocr_text = ocr_str;
|
||||
else
|
||||
|
||||
@@ -351,7 +351,7 @@ int write_dvd_sub(struct lib_cc_decode *dec_ctx, struct DVD_Ctx *ctx, struct cc_
|
||||
|
||||
#ifdef ENABLE_OCR
|
||||
char *ocr_str = NULL;
|
||||
ret = ocr_rect(ctx->ocr_ctx, rect, &ocr_str, 0);
|
||||
ret = ocr_rect(ctx->ocr_ctx, rect, &ocr_str, 0, dec_ctx->ocr_quantmode);
|
||||
if(ret >= 0)
|
||||
rect->ocr_text = ocr_str;
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,7 @@ static struct ccx_decoders_common_settings_t *init_decoder_setting(
|
||||
setting->send_to_srv = opt->send_to_srv;
|
||||
setting->hauppauge_mode = opt->hauppauge_mode;
|
||||
setting->xds_write_to_file = opt->transcript_settings.xds;
|
||||
setting->ocr_quantmode = opt->ocr_quantmode;
|
||||
|
||||
return setting;
|
||||
}
|
||||
|
||||
@@ -733,7 +733,7 @@ static int quantize_map(png_byte *alpha, png_color *palette,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ocr_rect(void* arg, struct cc_bitmap *rect, char **str, int bgcolor)
|
||||
int ocr_rect(void* arg, struct cc_bitmap *rect, char **str, int bgcolor, int ocr_quantmode)
|
||||
{
|
||||
int ret = 0;
|
||||
png_color *palette = NULL;
|
||||
@@ -769,8 +769,12 @@ int ocr_rect(void* arg, struct cc_bitmap *rect, char **str, int bgcolor)
|
||||
copy->data[i] = rect->data[0][i];
|
||||
}
|
||||
|
||||
|
||||
quantize_map(alpha, palette, rect->data[0], size, 3, rect->nb_colors);
|
||||
switch (ocr_quantmode)
|
||||
{
|
||||
case 1:
|
||||
quantize_map(alpha, palette, rect->data[0], size, 3, rect->nb_colors);
|
||||
break;
|
||||
}
|
||||
*str = ocr_bitmap(arg, palette, alpha, rect->data[0], rect->w, rect->h, copy);
|
||||
|
||||
end:
|
||||
|
||||
@@ -14,7 +14,7 @@ struct image_copy //A copy of the original OCR image, used for color detection
|
||||
void delete_ocr (void** arg);
|
||||
void* init_ocr(int lang_index);
|
||||
char* ocr_bitmap(void* arg, png_color *palette,png_byte *alpha, unsigned char* indata,int w, int h, struct image_copy *copy);
|
||||
int ocr_rect(void* arg, struct cc_bitmap *rect, char **str, int bgcolor);
|
||||
int ocr_rect(void* arg, struct cc_bitmap *rect, char **str, int bgcolor, int ocr_quantmode);
|
||||
char *paraof_ocrtext(struct cc_subtitle *sub, const char *crlf, unsigned crlf_length);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -618,6 +618,10 @@ void print_usage (void)
|
||||
mprint (" using the Chinese (Traditional) trained data\n");
|
||||
mprint (" This option is also helpful when the traineddata file\n");
|
||||
mprint (" has non standard names that don't follow ISO specs\n");
|
||||
mprint (" -quant mode: How to quantize the bitmap before passing it to tesseract");
|
||||
mprint (" for OCR'ing.");
|
||||
mprint (" 0 = Don't quantize at all.");
|
||||
mprint (" 1 = Use CCExtractor's internal function (default).");
|
||||
mprint (" -oem: Select the OEM mode for Tesseract, could be 0, 1 or 2.\n");
|
||||
mprint (" 0: OEM_TESSERACT_ONLY - default value, the fastest mode.\n");
|
||||
mprint (" 1: OEM_LSTM_ONLY - use LSTM algorithm for recognition.\n");
|
||||
@@ -1485,6 +1489,12 @@ int parse_parameters (struct ccx_s_options *opt, int argc, char *argv[])
|
||||
opt->ocrlang[char_index] = cctolower(opt->ocrlang[char_index]);
|
||||
continue;
|
||||
}
|
||||
if (strcmp(argv[i], "-quant") == 0 && i < argc - 1)
|
||||
{
|
||||
i++;
|
||||
opt->ocr_quantmode = atoi(argv[i]);
|
||||
continue;
|
||||
}
|
||||
if (strcmp(argv[i], "-nospupngocr") == 0)
|
||||
{
|
||||
opt->enc_cfg.nospupngocr = 1;
|
||||
|
||||
Reference in New Issue
Block a user