ArrayFire match_template 之后如何获得像素坐标 X,Y?

How can I have the pixel coordinate X,Y after ArrayFire match_template?

我正在尝试使用 ArrayFire 库中的 matching_template 函数,但我不知道如何找到最佳匹配值的 X 和 Y 坐标。 我正在使用 imageproc 库来执行这个功能,它有 find_extremes 函数,returns 坐标给我。你会如何使用 ArrayFire lib 做同样的事情?

我使用 imageproc 的例子

    let template = image::open("connect.png").unwrap().to_luma8();
    let screenshot = image::open("screenshot.png").unwrap().to_luma8();

   let matching_probability= imageproc::template_matching::match_template(&screenshot, &template, MatchTemplateMethod::CrossCorrelationNormalized);
   let positions = find_extremes(&matching_probability);

 println!("{:?}", positions);

Extremes { max_value: 0.9998113, min_value: 0.42247093, max_value_location: (843, 696), min_value_location: (657, 832) }

我使用 ArrayFire 的例子

   let template: Array<u8> = arrayfire::load_image(String::from("connect.png"), true);
   let screenshot: Array<u8> = arrayfire::load_image(String::from("screenshot.png"), true);

   let template_gray = rgb2gray(&template, 0.2126, 0.7152, 0.0722);
   let screen_gray =  rgb2gray(&screenshot, 0.2126, 0.7152, 0.0722);
   let matching_probability = arrayfire::match_template(&screen_gray, &template_gray, arrayfire::MatchType::LSAD);

af_print!("{:?}", matching_probability);

139569.0469 140099.2500 139869.8594 140015.7969 140680.9844 141952.5781 142602.7344 142870.7188...

从这里我不知道如何获得最匹配的像素坐标。

Arrayfire 不提供“极值”函数,但将最小和最大函数族分开。

提供索引信息的前缀为i

imin_allimax_all returns 最小值和最大值索引分别包含在一个元组中。

知道 arrayfire 是主要列,您可以从值索引和数组维度中得出像素位置。

let template: Array<u8> = arrayfire::load_image(String::from("connect.png"), true);
let screenshot: Array<u8> = arrayfire::load_image(String::from("screenshot.png"), true);

let template_gray = rgb2gray(&template, 0.2126, 0.7152, 0.0722);
let screen_gray = rgb2gray(&screenshot, 0.2126, 0.7152, 0.0722);
let matching_probability = arrayfire::match_template(&screen_gray, &template_gray, arrayfire::MatchType::LSAD);

let (min, _, min_idx) = imin_all(&matching_probability);
let (max, _, max_idx) = imax_all(&matching_probability);

let dims = matching_probability.dims();
let [_, height, _, _] = dims.get();

let px_x_min = min_idx as u64 / height;
let px_y_min = min_idx as u64 % height;

let px_x_max = max_idx as u64 / height;
let px_y_max = max_idx as u64 % height;

af_print!("{:?}", matching_probability);
println!("Minimum value: {} is at pixel ({},{}).",min, px_x_min, px_y_min);
println!("Maximum value: {} is at pixel ({},{}).", max, px_x_max, px_y_max);