Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HELP | How to use imgproc::match_template #643

Open
Aryxst opened this issue Dec 21, 2024 · 0 comments
Open

HELP | How to use imgproc::match_template #643

Aryxst opened this issue Dec 21, 2024 · 0 comments

Comments

@Aryxst
Copy link

Aryxst commented Dec 21, 2024

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.

MY REPO

  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):
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant