Skip to content

Commit

Permalink
Add test case for allowed_chars option
Browse files Browse the repository at this point in the history
  • Loading branch information
robertknight committed Oct 3, 2024
1 parent fa6c0c6 commit 1401ec3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions ocrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,41 @@ mod tests {

Ok(())
}

#[test]
fn test_ocr_engine_filter_chars() -> Result<(), Box<dyn Error>> {
let mut image = NdTensor::zeros([1, 64, 32]);

// Set the probability of "0" to 0.7 and "1" to 0.3.
image.slice_mut::<2, _>((.., 2, ..)).fill(0.7);
image.slice_mut::<2, _>((.., 3, ..)).fill(0.3);

let (rec_model, alphabet) = fake_recognition_model();
test_recognition(
OcrEngineParams {
detection_model: None,
recognition_model: Some(rec_model),
alphabet: Some(alphabet),
..Default::default()
},
image.view(),
"0",
)?;

// Run recognition again but exclude "0" from the output.
let (rec_model, alphabet) = fake_recognition_model();
test_recognition(
OcrEngineParams {
detection_model: None,
recognition_model: Some(rec_model),
alphabet: Some(alphabet),
allowed_chars: Some("123456789".into()),
..Default::default()
},
image.view(),
"1",
)?;

Ok(())
}
}

0 comments on commit 1401ec3

Please sign in to comment.