From 86217da183a59ab12942ffbaca445c1ef932cf11 Mon Sep 17 00:00:00 2001 From: Pradeep Garigipati Date: Sat, 12 Feb 2022 21:23:15 +0530 Subject: [PATCH] Report error for unsupported matching types in Match Template fn Signed-off-by: Pradeep Garigipati --- src/vision/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/vision/mod.rs b/src/vision/mod.rs index 6c6840a0..671a2e4c 100644 --- a/src/vision/mod.rs +++ b/src/vision/mod.rs @@ -501,6 +501,10 @@ where T: HasAfEnum + ImageFilterType, T::AbsOutType: HasAfEnum, { + match mtype { + MatchType::NCC | MatchType::ZNCC | MatchType::SHD => HANDLE_ERROR(AfError::ERR_ARG), + _ => (), // Do nothing valid matching type + }; unsafe { let mut temp: af_array = std::ptr::null_mut(); let err_val = af_match_template( @@ -670,3 +674,19 @@ where (temp.into(), inliers) } } + +#[cfg(test)] +mod tests { + use crate::randu; + + #[test] + #[should_panic] + fn check_invalid_matchtype() { + crate::core::set_device(0); + let a = randu!(f32; 10, 10); + let b = randu!(f32; 2, 2); + super::match_template(&a, &b, crate::MatchType::NCC); + super::match_template(&a, &b, crate::MatchType::ZNCC); + super::match_template(&a, &b, crate::MatchType::SHD); + } +}