Skip to content

Commit

Permalink
fix: missing comments/whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
remy barranco committed Aug 26, 2024
1 parent 30090ac commit bcb6550
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
6 changes: 2 additions & 4 deletions ocrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub use preprocess::{DimOrder, ImagePixels, ImageSource, ImageSourceError};
pub use recognition::DecodeMethod;
pub use text_items::{TextChar, TextItem, TextLine, TextWord};


// nb. The "E" before "ABCDE" should be the EUR symbol.
const DEFAULT_ALPHABET: &str = " 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~EABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";


Expand Down Expand Up @@ -87,7 +87,7 @@ impl OcrEngine {
recognizer,
debug: params.debug,
decode_method: params.decode_method,
alphabet: params.alphabet.unwrap_or_else(|| DEFAULT_ALPHABET.to_string()), // Use the default alphabet if none is provided
alphabet: params.alphabet.unwrap_or_else(|| DEFAULT_ALPHABET.to_string()),
})
}

Expand Down Expand Up @@ -166,8 +166,6 @@ impl OcrEngine {
}
}



/// Prepare an image for input into the text line recognition model.
///
/// This method exists to help with debugging recognition issues by exposing
Expand Down
11 changes: 5 additions & 6 deletions ocrs/src/recognition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ pub struct RecognitionOpt {
pub alphabet: String,
}


/// Input and output from recognition for a single text line.
struct LineRecResult {
/// Input to the recognition model.
Expand Down Expand Up @@ -275,9 +274,11 @@ fn text_lines_from_recognition_results(results: &[LineRecResult], alphabet: &str
} else {
result.line.resized_width
};

// Map X coords to those of the input image.
let [start_x, end_x] = [start_x, end_x]
.map(|x| line_rect.left() + (x as f32 * x_scale_factor) as i32);

// Since the recognition input is padded, it is possible to
// get predicted characters in the output with positions
// that correspond to the padding region, and thus are
Expand All @@ -286,7 +287,7 @@ fn text_lines_from_recognition_results(results: &[LineRecResult], alphabet: &str
return None;
}

let char = alphabet // Use the provided alphabet
let char = alphabet
.chars()
.nth((step.label - 1) as usize)
.unwrap_or('?');
Expand All @@ -297,8 +298,7 @@ fn text_lines_from_recognition_results(results: &[LineRecResult], alphabet: &str
result.line.region.borrow(),
start_x,
end_x,
)
.expect("invalid X coords"),
).expect("invalid X coords"),
})
})
.collect();
Expand All @@ -312,7 +312,6 @@ fn text_lines_from_recognition_results(results: &[LineRecResult], alphabet: &str
.collect()
}


/// Extracts character sequences and coordinates from text lines detected in
/// an image.
pub struct TextRecognizer {
Expand Down Expand Up @@ -534,7 +533,7 @@ impl TextRecognizer {
// batching and parallel processing. Re-sort them into input order.
line_rec_results.sort_by_key(|result| result.line.index);

let text_lines = text_lines_from_recognition_results(&line_rec_results, &alphabet); // Pass the alphabet
let text_lines = text_lines_from_recognition_results(&line_rec_results, &alphabet);

Ok(text_lines)
}
Expand Down

0 comments on commit bcb6550

Please sign in to comment.