Skip to content

Commit 426285b

Browse files
MagicalTuxclaude
andcommitted
test: add locdebug example + real EAN-13 scene fixture
Real captured frame region (native res) where detect::locate fails: the EAN-13 at (250,205)-(790,405) decodes fine when cropped, but locate() swallows it into a Matrix (0,0)-(900,416) mega-region and emits no linear candidate there. Fixture + examples/locdebug.rs pin this for the locator fix. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 664d327 commit 426285b

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎Cargo.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ required-features = ["cli"]
5050
[[example]]
5151
name = "degrade"
5252
required-features = ["cli"]
53+
54+
[[example]]
55+
name = "locdebug"
56+
required-features = ["cli"]

‎examples/locdebug.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Diagnostic: what does detect::locate find on a real photo?
2+
use anyd::detect::{locate, LocateOptions};
3+
fn main() {
4+
let path = std::env::args().nth(1).expect("usage: locdebug <png>");
5+
let rgba = oxideav_png::decode_png_to_rgba(&std::fs::read(&path).unwrap()).unwrap();
6+
let (w, h) = (rgba.width as usize, rgba.height as usize);
7+
let luma: Vec<u8> = rgba.data.chunks_exact(4)
8+
.map(|p| ((p[0] as u32 * 299 + p[1] as u32 * 587 + p[2] as u32 * 114) / 1000) as u8).collect();
9+
let frame = anyd::GrayFrame::new(&luma, w, h).unwrap();
10+
let cands = locate(&frame, &LocateOptions::default());
11+
println!("frame {w}x{h}: {} candidates", cands.len());
12+
for c in &cands {
13+
let cr = c.location.outline.corners;
14+
let (xs, ys): (Vec<f32>, Vec<f32>) = (cr.iter().map(|p| p.x).collect(), cr.iter().map(|p| p.y).collect());
15+
let (x0, y0) = (xs.iter().cloned().fold(f32::MAX, f32::min), ys.iter().cloned().fold(f32::MAX, f32::min));
16+
let (x1, y1) = (xs.iter().cloned().fold(0.0, f32::max), ys.iter().cloned().fold(0.0, f32::max));
17+
let fam = c.symbology.map(|s| format!("{:?}", s.dimension())).unwrap_or("?".into());
18+
println!(" {fam:8} ({:.0},{:.0})-({:.0},{:.0}) {:.0}x{:.0}", x0, y0, x1, y1, x1 - x0, y1 - y0);
19+
}
20+
}

‎testdata/real_scene_ean.png‎

646 KB
Loading

0 commit comments

Comments
 (0)