API C++#
-
namespace dvi#
Functions
-
std::string getLibVersion()#
Get the library version. Always provide this value when asking for support.
- Returns:
String with information about current library version.
-
class DVI#
Public Types
-
enum class Result#
enum
with possible DVI methods outcomes.Values:
-
enumerator OK#
Success.
-
enumerator ERROR_GENERIC#
Generic internal error. Please get in touch with DVI team for troubleshooting.
-
enumerator ERROR_THREHSOLD_REFERENCE_NOT_AVAILABLE#
The reference threshold could not be extracted. Check that train or load methods has been called succesfully.
-
enumerator ERROR_NOT_SETUP_YET#
setup must be called before calling the method that returned this
Result
-
enumerator ERROR_NOT_TRAINED_OR_LOADED_YET#
DVI must be trained or loaded before calling the method that returned this
Result
. Call train or load with appropriate arguments.
-
enumerator ERROR_ALREADY_TRAINED_OR_LOADED#
DVI already trained or loaded, can’t call twice the method that returned this
Result
.
-
enumerator ERROR_INVALID_IMAGE_SIZE#
An image provided to train or test has a different size than the one provided during setup.
-
enumerator ERROR_WRONG_SETUP_SIZE_FOR_MULTIPLE_MODELS#
setup is launched with different image size from already setup models
-
enumerator ERROR_INVALID_IMAGES#
At least one of the provided images is not valid.
-
enumerator ERROR_INVALID_PRIVATES#
Provided privates string is invalid, please check for correctness or contact DVI team.
-
enumerator ERROR_CANNOT_READ_MODEL_FILE#
Model file cannot be found at provided path.
-
enumerator ERROR_CANNOT_PARSE_MODEL_FILE#
Model file cannot be loaded, please check for correctness or contact DVI team.
-
enumerator ERROR_ULA_NOT_ACCEPTED#
U.L.A. (User License Agreeement) has not been accepted yet. Run the program
dvi_accept_ula
.
-
enumerator OK#
Public Functions
-
virtual Result setup(const cv::Size &imageSize) = 0#
Setup DVI instance, must be called after creating the instance (with create) and before any other method.
Setup
can also be used for changingimageSize
of an already setup DVI Instance.If this method fails, DVI instance reverts to creation state and must be setup again with success.
- Parameters:
imageSize – [in] Size (width, height) of images that DVI instance will process.
- Returns:
DVI::Result of the operation. If OK, DVI instance is ready to be trained or loaded. Any other value indicates an error in usage.
-
virtual Result setup(const cv::Size &imageSize, const std::string &privates) = 0#
Alternative method, use only if suggested by DVI team
-
virtual Result train(const std::vector<cv::Mat> &goodTrainImages) = 0#
Train the model with nominal/good images provided. This can be called only after a successful setup. The images must be all of the same size, in grayscale or BGR. Images size must coincide with
imageSize
specified when calling setup method.- Parameters:
goodTrainImages – [in] vector of nominal/good images.
- Returns:
DVI::Result of the operation. If OK,
train
is ready to be used for test or saved. Any other value indicates an error.
-
virtual Result getThresholdReference(double &threshold_reference) const = 0#
Extract the computed reference threshold. This can be called only after a successful train or load.
- Parameters:
threshold_reference – [out] computed reference threshold computed on trained/loaded DVI Model.
- Returns:
DVI::Result of the operation. If OK,
getThresholdReference
is completed with success. Any other value indicates an error.
-
virtual Result test(const std::vector<cv::Mat> &testImages, std::vector<double> &scores, std::vector<cv::Mat1d> &scores_maps) const = 0#
Test the model on images, providing
scores
andscores_maps
in output.This method can be called only after a successful train or load. The images must be all of the same size, in grayscale or BGR. Images size must coincide with
imageSize
specified when calling setup method.Output vectors will be cleared before populating them, so it’s best to provide them empty. Output
scores
can be compared with a threshold afterwards (specified by user or obtained by getThresholdReference) for assigning a nominal/anomalous label to image.- Parameters:
testImages – [in] vector of test images.
scores – [out] vector of image scores. Each of these scores represents information for the entirety of a test image.
scores_map – [out] vector of image scores_maps. Each of these scores_map represents local information for a test image.
- Returns:
DVI::Result of the operation. If OK,
test
is completed with success. Any other value indicates an error.
-
virtual Result save(const std::string &modelPath) const = 0#
Save the trained model to a file at the provided path.
This method can be called only after a successful train or load.
Make sure that the path is writable by the process.
- Parameters:
modelPath – [in] path where to save the model.
- Returns:
DVI::Result of the operation. If OK,
save
is completed with success. Any other value indicates an error.
-
virtual Result load(const std::string &modelPath) = 0#
Load a trained model from a file.
This method can be called only after a successful setup. Make sure that the path is a readable file for the process.
modelPath
must coincide with a path previously used in save of a valid DVI model.- Parameters:
modelPath – [in] path from which model will be loaded.
- Returns:
DVI::Result of the operation. If OK,
load
is completed with success. Any other value indicates an error.
-
enum class Result#
-
std::string getLibVersion()#