pub trait FaceRecognizerTraitConst: AlgorithmTraitConst {
// Required method
fn as_raw_FaceRecognizer(&self) -> *const c_void;
// Provided methods
fn predict_label(&self, src: &impl ToInputArray) -> Result<i32> { ... }
fn predict(
&self,
src: &impl ToInputArray,
label: &mut i32,
confidence: &mut f64,
) -> Result<()> { ... }
fn predict_collect(
&self,
src: &impl ToInputArray,
collector: Ptr<PredictCollector>,
) -> Result<()> { ... }
fn write(&self, filename: &str) -> Result<()> { ... }
fn write_1(&self, fs: &mut impl FileStorageTrait) -> Result<()> { ... }
fn empty(&self) -> Result<bool> { ... }
fn get_label_info(&self, label: i32) -> Result<String> { ... }
fn get_labels_by_string(&self, str: &str) -> Result<Vector<i32>> { ... }
fn get_threshold(&self) -> Result<f64> { ... }
}
Expand description
Constant methods for crate::face::FaceRecognizer
Required Methods§
fn as_raw_FaceRecognizer(&self) -> *const c_void
Provided Methods§
Sourcefn predict_label(&self, src: &impl ToInputArray) -> Result<i32>
fn predict_label(&self, src: &impl ToInputArray) -> Result<i32>
Predicts a label and associated confidence (e.g. distance) for a given input image.
§Parameters
- src: Sample image to get a prediction from.
- label: The predicted label for the given image.
- confidence: Associated confidence (e.g. distance) for the predicted label.
The suffix const means that prediction does not affect the internal model state, so the method can be safely called from within different threads.
The following example shows how to get a prediction from a trained model:
using namespace cv;
// Do your initialization here (create the cv::FaceRecognizer model) ...
// ...
// Read in a sample image:
Mat img = imread("person1/3.jpg", IMREAD_GRAYSCALE);
// And get a prediction from the cv::FaceRecognizer:
int predicted = model->predict(img);
Or to get a prediction and the associated confidence (e.g. distance):
using namespace cv;
// Do your initialization here (create the cv::FaceRecognizer model) ...
// ...
Mat img = imread("person1/3.jpg", IMREAD_GRAYSCALE);
// Some variables for the predicted label and associated confidence (e.g. distance):
int predicted_label = -1;
double predicted_confidence = 0.0;
// Get the prediction and associated confidence from the model
model->predict(img, predicted_label, predicted_confidence);
§Overloaded parameters
Sourcefn predict(
&self,
src: &impl ToInputArray,
label: &mut i32,
confidence: &mut f64,
) -> Result<()>
fn predict( &self, src: &impl ToInputArray, label: &mut i32, confidence: &mut f64, ) -> Result<()>
Predicts a label and associated confidence (e.g. distance) for a given input image.
§Parameters
- src: Sample image to get a prediction from.
- label: The predicted label for the given image.
- confidence: Associated confidence (e.g. distance) for the predicted label.
The suffix const means that prediction does not affect the internal model state, so the method can be safely called from within different threads.
The following example shows how to get a prediction from a trained model:
using namespace cv;
// Do your initialization here (create the cv::FaceRecognizer model) ...
// ...
// Read in a sample image:
Mat img = imread("person1/3.jpg", IMREAD_GRAYSCALE);
// And get a prediction from the cv::FaceRecognizer:
int predicted = model->predict(img);
Or to get a prediction and the associated confidence (e.g. distance):
using namespace cv;
// Do your initialization here (create the cv::FaceRecognizer model) ...
// ...
Mat img = imread("person1/3.jpg", IMREAD_GRAYSCALE);
// Some variables for the predicted label and associated confidence (e.g. distance):
int predicted_label = -1;
double predicted_confidence = 0.0;
// Get the prediction and associated confidence from the model
model->predict(img, predicted_label, predicted_confidence);
Sourcefn predict_collect(
&self,
src: &impl ToInputArray,
collector: Ptr<PredictCollector>,
) -> Result<()>
fn predict_collect( &self, src: &impl ToInputArray, collector: Ptr<PredictCollector>, ) -> Result<()>
- if implemented - send all result of prediction to collector that can be used for somehow custom result handling
§Parameters
- src: Sample image to get a prediction from.
- collector: User-defined collector object that accepts all results
To implement this method u just have to do same internal cycle as in predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) but not try to get “best@ result, just resend it to caller side with given collector
Sourcefn write(&self, filename: &str) -> Result<()>
fn write(&self, filename: &str) -> Result<()>
Saves a FaceRecognizer and its model state.
Saves this model to a given filename, either as XML or YAML.
§Parameters
- filename: The filename to store this FaceRecognizer to (either XML/YAML).
Every FaceRecognizer overwrites FaceRecognizer::save(FileStorage& fs) to save the internal model state. FaceRecognizer::save(const String& filename) saves the state of a model to the given filename.
The suffix const means that prediction does not affect the internal model state, so the method can be safely called from within different threads.
Sourcefn write_1(&self, fs: &mut impl FileStorageTrait) -> Result<()>
fn write_1(&self, fs: &mut impl FileStorageTrait) -> Result<()>
Saves a FaceRecognizer and its model state.
Saves this model to a given filename, either as XML or YAML.
§Parameters
- filename: The filename to store this FaceRecognizer to (either XML/YAML).
Every FaceRecognizer overwrites FaceRecognizer::save(FileStorage& fs) to save the internal model state. FaceRecognizer::save(const String& filename) saves the state of a model to the given filename.
The suffix const means that prediction does not affect the internal model state, so the method can be safely called from within different threads.
§Overloaded parameters
Saves this model to a given FileStorage.
- fs: The FileStorage to store this FaceRecognizer to.
Sourcefn empty(&self) -> Result<bool>
fn empty(&self) -> Result<bool>
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sourcefn get_label_info(&self, label: i32) -> Result<String>
fn get_label_info(&self, label: i32) -> Result<String>
Gets string information by label.
If an unknown label id is provided or there is no label information associated with the specified label id the method returns an empty string.
Sourcefn get_labels_by_string(&self, str: &str) -> Result<Vector<i32>>
fn get_labels_by_string(&self, str: &str) -> Result<Vector<i32>>
Gets vector of labels by string.
The function searches for the labels containing the specified sub-string in the associated string info.
Sourcefn get_threshold(&self) -> Result<f64>
fn get_threshold(&self) -> Result<f64>
threshold parameter accessor - required for default BestMinDist collector
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.