use assert_cmd::Command;
use oximedia_compat_cv2::{image_io::imwrite, mat::Mat};
use tempfile::TempDir;
fn cmd() -> Command {
Command::cargo_bin("oximedia-cv2").expect("oximedia-cv2 binary not found")
}
#[test]
fn orb_detect_help_exits_zero() {
cmd().args(["orb-detect", "--help"]).assert().success();
}
#[test]
fn orb_detect_synth_image_returns_keypoints() {
let dir = TempDir::new().expect("tempdir");
let h = 64usize;
let w = 64usize;
let mut data = vec![20u8; h * w];
let centres: [(usize, usize); 9] = [
(12, 12),
(32, 12),
(52, 12),
(12, 32),
(32, 32),
(52, 32),
(12, 52),
(32, 52),
(52, 52),
];
for (cx, cy) in centres {
for dy in -1i32..=1 {
for dx in -1i32..=1 {
let x = cx as i32 + dx;
let y = cy as i32 + dy;
if x >= 0 && y >= 0 && (x as usize) < w && (y as usize) < h {
data[y as usize * w + x as usize] = 240;
}
}
}
}
let input = dir.path().join("orb_in.png");
imwrite(&input, &Mat::from_gray_bytes(data, h, w)).expect("write orb input");
let out = cmd()
.args([
"orb-detect",
input.to_str().expect("input path utf8"),
"--num-features",
"200",
])
.output()
.expect("run orb-detect");
assert!(
out.status.success(),
"orb-detect failed: stderr={}",
String::from_utf8_lossy(&out.stderr)
);
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(
stdout.contains("orb keypoints="),
"stdout missing 'orb keypoints=' line: {stdout}"
);
let keypoint_line = stdout
.lines()
.find(|l| l.starts_with("orb keypoints="))
.expect("keypoints line present");
assert!(
keypoint_line.contains("descriptors_rows="),
"keypoint line missing descriptor row count: {keypoint_line}"
);
}