rust image找图
[dependencies]
image = "0.24.6"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | use image::{GenericImageView, ImageBuffer, Rgb}; fn main() { let img_a = image::open( "2.png" ).unwrap().to_rgb8(); let img_b = image::open( "1.png" ).unwrap().to_rgb8(); if is_image_a_in_image_b(&img_a, &img_b) { println!( "Image A is in Image B." ); } else { println!( "Image A is not in Image B." ); } } fn is_image_a_in_image_b(img_a: &ImageBuffer<Rgb<u8>, Vec<u8>>, img_b: &ImageBuffer<Rgb<u8>, Vec<u8>>) -> bool { let (width_a, height_a) = img_a.dimensions(); let (width_b, height_b) = img_b.dimensions(); if width_a > width_b || height_a > height_b { // Image A is larger than Image B, cannot be contained in Image B. return false ; } for y in 0..height_b - height_a { for x in 0..width_b - width_a { if is_image_a_at_position_in_image_b(img_a, img_b, x, y) { return true ; } } } false } fn is_image_a_at_position_in_image_b(img_a: &ImageBuffer<Rgb<u8>, Vec<u8>>, img_b: &ImageBuffer<Rgb<u8>, Vec<u8>>, x: u32, y: u32) -> bool { let (width_a, height_a) = img_a.dimensions(); for dy in 0..height_a { for dx in 0..width_a { let pixel_a = img_a.get_pixel(dx, dy); let pixel_b = img_b.get_pixel(x + dx, y + dy); if pixel_a != pixel_b { return false ; } } } true } |
找色
1 2 3 4 5 6 7 8 9 10 11 | [dependencies] image = "0.23.14" use image::GenericImageView; fn main() { let img = image::open( "path/to/image.png" ).unwrap(); let pixel_color = img.get_pixel(10, 20); println!( "Color at (10, 20): {:?}" , pixel_color); } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
2019-03-28 关于 stream, InheritedWidget, bloc 的一些看法, 比较重要
2019-03-28 Vertical viewport was given unbounded height
2019-03-28 Flutter之MaterialApp使用详解