import ocr ares
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use image::RgbaImage;
|
||||
use image::{GenericImageView, Rgba, RgbaImage};
|
||||
use ort::session::{Session, builder::GraphOptimizationLevel};
|
||||
use ort::value::Value;
|
||||
use std::path::Path;
|
||||
@@ -31,7 +31,26 @@ pub fn run_ocr_detection(
|
||||
// And usually resized to multiple of 32. Limit max size for speed.
|
||||
let max_side = 1600; // Increase resolution limit
|
||||
let (orig_w, orig_h) = input_image.dimensions();
|
||||
|
||||
// --- CROP to top 5% and bottom 5% ---
|
||||
let crop_height = (orig_h as f64 * 0.05).ceil() as u32;
|
||||
let mut masked_image = RgbaImage::from_pixel(orig_w, orig_h, Rgba([0, 0, 0, 255]));
|
||||
|
||||
if crop_height > 0 {
|
||||
// Copy top part
|
||||
let top_view = input_image.view(0, 0, orig_w, crop_height).to_image();
|
||||
image::imageops::replace(&mut masked_image, &top_view, 0, 0);
|
||||
|
||||
// Copy bottom part
|
||||
let bottom_y = orig_h.saturating_sub(crop_height);
|
||||
let bottom_view = input_image.view(0, bottom_y, orig_w, crop_height).to_image();
|
||||
image::imageops::replace(&mut masked_image, &bottom_view, 0, bottom_y as i64);
|
||||
} else {
|
||||
// If image is very short, just use the original
|
||||
masked_image = input_image.clone();
|
||||
}
|
||||
// --- End CROP ---
|
||||
|
||||
let mut resize_w = orig_w;
|
||||
let mut resize_h = orig_h;
|
||||
|
||||
@@ -50,7 +69,7 @@ pub fn run_ocr_detection(
|
||||
resize_w = resize_w.max(32);
|
||||
resize_h = resize_h.max(32);
|
||||
|
||||
let resized = image::imageops::resize(input_image, resize_w, resize_h, image::imageops::FilterType::Triangle);
|
||||
let resized = image::imageops::resize(&masked_image, resize_w, resize_h, image::imageops::FilterType::Triangle);
|
||||
|
||||
let channel_stride = (resize_w * resize_h) as usize;
|
||||
let mut input_data = Vec::with_capacity(1 * 3 * channel_stride);
|
||||
|
||||
Reference in New Issue
Block a user