Fix Hardsubx OCR (#1741)

* fix: hardsubx segmentation fault

* fix: hardsubx garbage output

* chore: enable hardsubx on test builds
This commit is contained in:
Hridesh MG
2025-09-02 13:58:02 +05:30
committed by GitHub
parent f09b6ff446
commit 3f441150b4
4 changed files with 20 additions and 16 deletions

View File

@@ -26,10 +26,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo apt update && sudo apt-get install libgpac-dev libtesseract-dev
run: sudo apt update && sudo apt-get install libgpac-dev libtesseract-dev libavcodec-dev libavdevice-dev libx11-dev libxcb1-dev libxcb-shm0-dev
- uses: actions/checkout@v4
- name: build
run: ./build
run: ./build -hardsubx
working-directory: ./linux
- name: Display version information
run: ./ccextractor --version

View File

@@ -1,5 +1,6 @@
1.0 (to be released)
-----------------
- Fix: HardSubX OCR on Rust
- Removed the Share Module
- Fix: Regression failures on DVD files
- Fix: Segmentation faults on MP4 files with CEA-708 captions

View File

@@ -40,22 +40,25 @@ pub unsafe fn dispatch_classifier_functions(ctx: *mut lib_hardsubx_ctx, im: *mut
// function that calls the classifier functions
match (*ctx).ocr_mode {
0 => {
let ret_char_arr = get_ocr_text_wordwise_threshold(ctx, im, (*ctx).conf_thresh);
ffi::CStr::from_ptr(ret_char_arr)
.to_string_lossy()
.into_owned()
}
1 => {
let ret_char_arr = get_ocr_text_letterwise_threshold(ctx, im, (*ctx).conf_thresh);
let ret_char_arr = get_ocr_text_simple_threshold(ctx, im, (*ctx).conf_thresh);
let text_out_result = ffi::CString::from_raw(ret_char_arr).into_string();
match text_out_result {
Ok(T) => T,
Err(_E) => "".to_string(),
}
}
1 => {
let ret_char_arr = get_ocr_text_wordwise_threshold(ctx, im, (*ctx).conf_thresh);
if ret_char_arr.is_null() {
"".to_string()
} else {
ffi::CStr::from_ptr(ret_char_arr)
.to_string_lossy()
.into_owned()
}
}
2 => {
let ret_char_arr = get_ocr_text_simple_threshold(ctx, im, (*ctx).conf_thresh);
let ret_char_arr = get_ocr_text_letterwise_threshold(ctx, im, (*ctx).conf_thresh);
let text_out_result = ffi::CString::from_raw(ret_char_arr).into_string();
match text_out_result {
Ok(T) => T,
@@ -66,7 +69,6 @@ pub unsafe fn dispatch_classifier_functions(ctx: *mut lib_hardsubx_ctx, im: *mut
_ => {
eprintln!("Invalid OCR Mode");
exit(EXIT_MALFORMED_PARAMETER);
// "".to_string()
}
}
}
@@ -113,7 +115,7 @@ pub unsafe extern "C" fn _process_frame_white_basic(
let mut gray_im: *mut Pix = pixConvertRGBToGray(im, 0.0, 0.0, 0.0);
let mut sobel_edge_im: *mut Pix =
pixSobelEdgeFilter(gray_im, L_VERTICAL_EDGES.try_into().unwrap());
let mut dilate_gray_im: *mut Pix = pixDilateGray(sobel_edge_im, 21, 1);
let mut dilate_gray_im: *mut Pix = pixDilateGray(sobel_edge_im, 21, 11);
let mut edge_im: *mut Pix = pixThresholdToBinary(dilate_gray_im, 50);
let mut feat_im: *mut Pix = pixCreate(width, height, 32);

View File

@@ -13,10 +13,11 @@ pub extern "C" fn rgb_to_hsv(R: f32, G: f32, B: f32, H: &mut f32, S: &mut f32, V
#[no_mangle]
pub extern "C" fn rgb_to_lab(R: f32, G: f32, B: f32, L: &mut f32, a: &mut f32, b: &mut f32) {
let rgb = Srgb::new(R, G, B);
// Normalize input RGB from 0-255 to 0.0-1.0
let rgb = Srgb::new(R / 255.0, G / 255.0, B / 255.0);
// This declaration sets the white-point as per the D65 standard
let lab_rep = Lab::<palette::white_point::D65, f32>::from_color(rgb);
// Convert from sRGB to Lab (D65 white point is default)
let lab_rep = Lab::from_color(rgb);
*L = lab_rep.l;
*a = lab_rep.a;