Skip to content

Commit d2f3731

Browse files
committed
Merge branch 'sjbeskur-unit/feature2d-bfmatcher'
* sjbeskur-unit/feature2d-bfmatcher: Switch back to jobserver to drop the transitive syn dependency updated unit test/example unit: a failing unit test to feature2d::BFMatcher
2 parents 59a4a13 + 2590227 commit d2f3731

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

tests/features2d.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg(ocvrs_has_module_features2d)]
22

3-
use opencv::core::{Size, Vector};
3+
use opencv::core::{no_array, Size, Vector, NORM_HAMMING};
44
use opencv::prelude::*;
55
use opencv::{features2d, imgcodecs, Result};
66

@@ -18,3 +18,32 @@ fn orb() -> Result<()> {
1818
assert_eq!(Size::new(32, i32::try_from(size)?), des.size()?);
1919
Ok(())
2020
}
21+
22+
#[test]
23+
fn orb_bruteforce_match() -> Result<()> {
24+
let img_a = imgcodecs::imdecode(&BLOX, imgcodecs::IMREAD_GRAYSCALE)?;
25+
let img_b = img_a.clone(); // yep this is the same
26+
27+
let mut orb = features2d::ORB::create_def()?;
28+
let mut kp_a = Vector::new();
29+
let mut des_a = Mat::default();
30+
orb.detect_and_compute(&img_a, &Mat::default(), &mut kp_a, &mut des_a, false)?;
31+
32+
let mut kp_b = Vector::new();
33+
let mut des_b = Mat::default();
34+
orb.detect_and_compute(&img_b, &Mat::default(), &mut kp_b, &mut des_b, false)?;
35+
36+
let size = 290;
37+
assert_eq!(size, kp_a.len());
38+
assert_eq!(Size::new(32, size as i32), des_a.size()?);
39+
assert_eq!(size, kp_b.len());
40+
assert_eq!(Size::new(32, size as i32), des_b.size()?);
41+
42+
let bf_matcher = features2d::BFMatcher::create(NORM_HAMMING, true).unwrap();
43+
44+
let mut matches = opencv::types::VectorOfDMatch::new();
45+
bf_matcher.train_match(&des_a, &des_b, &mut matches, &no_array()).unwrap();
46+
47+
assert_ne!(matches.len(), 0); // expected many matches since images are equal
48+
Ok(())
49+
}

0 commit comments

Comments
 (0)