Struct find_subimage::SubImageFinderState [−][src]
pub struct SubImageFinderState { /* fields omitted */ }Expand description
The main context struct. This stores the necessary buffers for the search, eters.
u8 buffers are used if conversion to grayscale is necessary, and f32 buffers for the backends that require them.
There is also a Vec<(usize, usize, f32)> used to store results.
Implementations
Create a SubImageFinderState
This uses the Scalar backend by default, unless the “simdeez-default-new” e is enabled (It is currently enabled by default).
See the backend and with_backend methods to change the backend.
Like Self::new but uses Backend::OpenCV
Set the currently configured backend.
See also Self::with_backend
Set the currently configured prune width/height scaling.
For more information see Self::with_pruning
Return a new state with the given backend
use find_subimage::{Backend, SubImageFinderState};
let state = SubImageFinderState::new().with_backend(Backend::Scalar {
threshold: 0.5,
step_x: 2,
step_y: 1,
});Return a new state with the given pruning width/height scaling parameters.
These default to 0.5
Finds positions where the subimage is found within the search image. These positions represent the top-right corner of the subimage.
You can tweak the likelyhood of positions found with the backend’s threshold. Note that the threshold is backend-dependant.
The channel_count argument should be the number of channels for both input images (For
example, 3 for an RGB image or 1 for grayscale).
The input image can optionally be converted to grayscale before applying the algorithm, see Self::find_subimage_positions_as_grayscale.
The third field of the tuples in the returned slice is the matching/distance value. Values closer to 1 mean a fuzzier match, and closer to 0 a more exact match. These values are returned sorted by distance, with the best matches first.
Like Self::find_subimage_positions_as_grayscale but lets you use a different backend than the currently configured one.
Like Self::find_subimage_positions, but before finding positions it converts the images to grayscale. This can speed up runtime, but depending on the images it can be harmful to results.
This is done using internal buffers. If you reuse a SubImageFinderState for multiple images of the same size, it should only need to allocate once.
If channel_count_subimage is None, channel_count_search is used in its place.
Like Self::find_subimage_positions_as_grayscale but lets you use a different backend than the currently configured one.
This returns the same as the last value returned from Self::find_subimage_positions, as long as you haven’t modified them by calling Self::most_recent_results_mut
Gives a mutable reference to the most recent results. Calling this after Self::find_subimage_positions gives you the same slice, but with mutable access. This can be useful if you want to sort the results without allocating a new Vec.
For example, if you need to sort by y and then by x position:
use find_subimage::{Image, SubImageFinderState};
let (w, h) = (128, 128);
let mut rgb_image = vec![0u8; w * h * 3];
let (sub_w, sub_h) = (16, 16);
let mut rgb_subimage = vec![0u8; sub_w * sub_h * 3];
let mut finder = SubImageFinderState::new();
finder.find_subimage_positions((&rgb_image, w, h), (&rgb_subimage, sub_w, sub_h), 3);
let results = finder.most_recent_results_mut();
results.sort_unstable_by(|a, b| a.1.cmp(&b.1).then(a.0.cmp(&b.0)));