Crates.io | spectrust |
lib.rs | spectrust |
version | 0.2.0 |
source | src |
created_at | 2023-07-17 21:42:14.978978 |
updated_at | 2023-07-19 18:33:23.778638 |
description | A fast, Rust-based computer vision library for locating images on the screen. |
homepage | |
repository | https://github.com/Bullesta/SpectRust |
max_upload_size | |
id | 918867 |
size | 13,073 |
A Rust-based Computer visioner for locating images on screen
It can search the entire screen a over 3x faster than pyautogui and does not require OpenCV for options like Confidence. I've also added an option called Tolerance that allows for leniency with pixel colors that are close to the original image's. Written in pure Rust.
locate_img_center(img: &DynamicImage, region: Option<(u16, u16, u16, u16)>, min_confidence: Option<f32>, tolerance: Option<u8>) -> Option<(u32, u32, f32)>)
locate_img(img: &DynamicImage, region: Option<(u16, u16, u16, u16)>, min_confidence: Option<f32>, tolerance: Option<u8>)
img: required borrowed DynamicImage
region: requires tuple BoundingBox (x, y, width, height) (Default Entire Screen)
min_confidence: 0.1 - 1.0, percentage of how many of the pixels need to match (Default 0.95)
tolerance: 0 - 255, range of pixels to accept from image's pixels. So if an image has a pixel of 234, 52, 245 with a tolerance of 10, then the locator will accept values ranging from 224, 42, 235 - 244, 62, 255. (Default 5)
All of these requires (except img) are optional and require either a Some() or None
Examples:
use spectrust::*;
fn main () {
let img = image::open("images.png").expect("Unable to locate file.");
let region = None;
let min_confidence = Some(0.8);
let tolerance = Some(5);
match locate_center_of_image(&img, region, min_confidence, tolerance) {
Some((x, y, confidence)) => {
println!("Image center found at {}, {} with confidence {}", x, y, confidence);
},
None => println!("Image not found"),
}
}
fn main() {
let img = image::open("images.png").expect("Unable to locate file.");
match locate_image(&img, None, None, None) {
Some((x, y, img_width, img_height, _confidence)) => {
println!("x: {}, y: {}, width: {}, height: {}",x, y, img_width, img_height)
},
None => println!("Image not found")
}
}
If you are having trouble with finding an image. Try lowering the confidence or increasing the tolerance.
Python: 150ms Rust: 53ms (Both finding the Rust icon with a size of 225x225px on a 1920x1080 screen)
Useful for Bot Creating
Commit count: 21