我正在尝试使用 ndarray_image 从图像中获取 Array3:
pub fn from_png(path: &str) -> Result<Self, &str> {
return match ndarray_image::open_image(path, Colors::Rgba) {
Ok(data) => { ;
let size = Size {
x: data.shape()[0],
y: data.shape()[1]
};
Ok( Self { data, size } )
}
Err(_) => {
Err("Unable to open image!")
}
}
}
Self.data 类型是 Array3,open_image 返回一个 Array3。这很奇怪,但错误类型也相同:
error[E0308]: mismatched types
|
| Ok( Self { data, size } )
| ^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
|
= note: expected struct `ArrayBase<OwnedRepr<u8>, Dim<[usize; 3]>>`
found struct `ndarray::ArrayBase<ndarray::data_repr::OwnedRepr<u8>, ndarray::dimension::dim::Dim<[usize; 3]>>`
= note: perhaps two different versions of crate `ndarray` are being used?
关于版本:我对所有 ndarray-* crate 使用版本“0”。
Cargo.toml 中的依赖项:
[dependencies]
bytes = "1.1.0"
font-kit = "0.10.1"
pathfinder_geometry = "0.5.1"
image = "0.23.14"
rayon = "1.5.1"
ndarray = { version="0", features=["rayon", "serde"]}
serde = "1.0.133"
serde_json = "1.0.74"
ndarray-stats = "0"
ndarray-image = "0"