Skip to content

Commit

Permalink
Merge branch 'sjbeskur-unit/feature2d-bfmatcher'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
twistedfall committed Apr 20, 2024
2 parents 59a4a13 + 2590227 commit d2f3731
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/features2d.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(ocvrs_has_module_features2d)]

use opencv::core::{Size, Vector};
use opencv::core::{no_array, Size, Vector, NORM_HAMMING};
use opencv::prelude::*;
use opencv::{features2d, imgcodecs, Result};

Expand All @@ -18,3 +18,32 @@ fn orb() -> Result<()> {
assert_eq!(Size::new(32, i32::try_from(size)?), des.size()?);
Ok(())
}

#[test]
fn orb_bruteforce_match() -> Result<()> {
let img_a = imgcodecs::imdecode(&BLOX, imgcodecs::IMREAD_GRAYSCALE)?;
let img_b = img_a.clone(); // yep this is the same

let mut orb = features2d::ORB::create_def()?;
let mut kp_a = Vector::new();
let mut des_a = Mat::default();
orb.detect_and_compute(&img_a, &Mat::default(), &mut kp_a, &mut des_a, false)?;

let mut kp_b = Vector::new();
let mut des_b = Mat::default();
orb.detect_and_compute(&img_b, &Mat::default(), &mut kp_b, &mut des_b, false)?;

let size = 290;
assert_eq!(size, kp_a.len());
assert_eq!(Size::new(32, size as i32), des_a.size()?);
assert_eq!(size, kp_b.len());
assert_eq!(Size::new(32, size as i32), des_b.size()?);

let bf_matcher = features2d::BFMatcher::create(NORM_HAMMING, true).unwrap();

let mut matches = opencv::types::VectorOfDMatch::new();
bf_matcher.train_match(&des_a, &des_b, &mut matches, &no_array()).unwrap();

assert_ne!(matches.len(), 0); // expected many matches since images are equal
Ok(())
}

0 comments on commit d2f3731

Please sign in to comment.