【发布时间】:2022-11-22 04:51:03
【问题描述】:
我只想从imageproc crate 调用this function。现在我这样做:
let mut contours = find_contours_with_threshold(&src_image.to_luma8(), 10);
而且我不断收到此错误:
error[E0283]: type annotations needed
--> src/main.rs:77:24
|
77 | let mut contours = find_contours_with_threshold(&src_image.to_luma8(), 10);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `find_contours_with_threshold`
|
= note: cannot satisfy `_: Num`
note: required by a bound in `find_contours_with_threshold`
--> /home/mike/.cargo/registry/src/github.com-1ecc6299db9ec823/imageproc-0.23.0/src/contours.rs:61:8
|
61 | T: Num + NumCast + Copy + PartialEq + Eq,
| ^^^ required by this bound in `find_contours_with_threshold`
help: consider specifying the type argument in the function call
|
77 | let mut contours = find_contours_with_threshold::<T>(&src_image.to_luma8(), 10);
| +++++
我知道 Rust 无法弄清楚该函数调用的结果是什么。在文档中它应该返回 Vec<Contour<T>> where T: Num + NumCast + Copy + PartialEq + Eq 但我不知道如何在我的代码中转置它。
我试过这样做:let mut contours: Vec<Contour<dyn Num + NumCast + Copy + PartialEq + Eq>> = find_contours_with_threshold(&src_image.to_luma8(), 10); 但我仍然不明白我在做什么所以任何帮助都会很棒。
在 python 中解压是不是有太多的值?我应该做类似let x, y, z = find_contours..()的事情吗?
【问题讨论】:
-
如果您使用
let mut contours = find_contours_with_threshold::<i32>(&src_image.to_luma8(), 10);(或其他一些适当的整数类型)会发生什么?那样有用吗?我不熟悉那个图书馆,但它要求具体的输入Contour不受限制。 -
@KevinAnderson 它确实有效。谢谢!该特定类型不应该来自
Num, NumCast, Copy, PartialEq, Eq吗? -
@Mike
Num,NumCast,Copy, ... 是特质。绑定T: Num + NumCast + ...意味着类型T必须具有这些特征的实现。满足这种界限的一种类型是i32,但是,它不是唯一的。编译器消息意味着它无法推断哪个输入你想要的。 -
@BlackBeans 感谢您的解释,帮助很大!
标签: image-processing rust