I'm trying to open an image, converting it into gray, and drawing a rectangle, then save it under another name, so, I'm using image and imageproc, and wrote the below code:
use image::{GenericImageView, FilterType, Rgb};
use imageproc::drawing::draw_hollow_rect_mut;
use imageproc::rect::Rect;
fn main() {
let img = image::open("self.jpg").unwrap();
let mut gray = img.grayscale();
let white = Rgb([255u8, 255u8, 255u8]);
draw_hollow_rect_mut(&mut gray, Rect::at(60, 10).of_size(20, 20), white);
gray.save("gray.png").unwrap();
}
But I got the below error:
error[E0277]: the trait bound `image::dynimage::DynamicImage: image::image::GenericImage` is not satisfied
--> src/main.rs:34:5
|
34 | draw_hollow_rect_mut(&mut gray, Rect::at(60, 10).of_size(20, 20), white);
| ^^^^^^^^^^^^^^^^^^^^ the trait `image::image::GenericImage` is not implemented for `image::dynimage::DynamicImage`
= note: required by `imageproc::drawing::rect::draw_hollow_rect_mut`
Seems to be a version issue: imageproc:0.18.0 pulls in image:0.21.3, whereas the latest version of image is 0.22.1. You can fix this by putting compatible versions in your Cargo.toml:
[dependencies]
image = "0.21.3"
imageproc = "0.18.0"
(The way you can figure out this sort of thing is to see that the docs say DynamicImage does implement GenericImage, suggesting a version mismatch, and then use cargo-tree to figure out exactly what the mismatch is.)
@HeroicKatora we should probably figure out a way to make sure that the latest versions of image and imageproc remain compatible so people don't keep running into this.
I've just published imageproc 0.19, which references image 0.22.1
Most helpful comment
I've just published imageproc 0.19, which references image 0.22.1