InsightFace

Struct InsightFace 

Source
pub struct InsightFace { /* private fields */ }
Expand description

InsightFace is a struct which handle the internal pointers to compare two faces and returns the cosine value

Implementations§

Source§

impl InsightFace

Source

pub fn new<S: AsRef<str>>( model: S, chunk_size: Option<usize>, ) -> Result<Self, Box<dyn Error>>

Create a new InsightFace handler. It needs to be only call once as it build a model. Therefore it’s recommended to use it within an Arc<Mutex<InsightFace>> to ensure thread safety. Chunk size is used in order to split the image data into smaller chunks for processing.

§Arguments
  • model - S
  • chunk_size - u8
§Examples
use std::sync::Arc;
use std::sync::Mutex;
use baklava::InsightFace;

let insight_face = Arc::new(Mutex::new(InsightFace::new("./Megatron", None).unwrap()));
Source

pub fn prepare_images<S: AsRef<str> + Clone + Send + Sync + Copy>( &mut self, sources: &[S], ) -> Result<&mut Self, Box<dyn Error>>

Prepare a slice of a images to be compared toward the target

§Arguments
  • sources - &[S]
Source

pub fn prepare_target_image<S: AsRef<str>>( &mut self, target_img_path: S, ) -> Result<&mut Self, Box<dyn Error>>

Prepare the target image that will be compared against the sources images

§Arguments
  • target_img_path - S
Source

pub fn compare_images( &self, methodology: Methodology, ) -> Result<(f32, f64), Box<dyn Error>>

Compare the images and return the cosine similary which can range from 1 to -1

§Arguments
  • methodology - Methodology
Source

pub fn is_similar(cosine: f32, threshold: Option<f64>) -> bool

Return whether the two faces are similar based on the cosine

§Arguments
  • cosine - f32
  • threshold - Option<f64>

Trait Implementations§

Source§

impl Drop for InsightFace

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for InsightFace

Source§

impl Sync for InsightFace

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.