Open
Description
After I get the result Mat how do i determine if the template has matched with a threshold? I get an immense Vector of floats, how do I use it?
I took a look at issues #131 and #168 but I couldn't determine how after they got the Mat they processed it.
use opencv::{
core::{ToInputArray, CV_32FC1},
imgcodecs::{imread, IMREAD_GRAYSCALE},
imgproc::{self, TM_CCORR_NORMED},
prelude::*,
};
fn detect_image(haystack: &Mat) -> Mat {
let needle = imread("./src/needle_spawn_sign.png", IMREAD_GRAYSCALE)
.expect("Failed to read needle image");
let zero = Mat::zeros(
haystack.rows() - needle.rows() + 1,
haystack.cols() - needle.cols() + 1,
CV_32FC1,
)
.unwrap();
let mut result = zero.to_mat().unwrap();
imgproc::match_template(
&haystack.input_array().unwrap(),
&needle.input_array().unwrap(),
&mut result,
TM_CCORR_NORMED,
&Mat::default(),
)
.expect("Failed to match template");
result
}
// ...
let result = detect_image(&img);
println!("{:?}", &result.data_typed::<f32>().unwrap());
// ...
Results in(#131):
Metadata
Metadata
Assignees
Labels
No labels