51#include "../common/common.h"
78 long long last_time_ms;
93 if (!user_data || !image_file || !pe)
95 printf(
"NULL pointer\n");
99 memset(pe, 0,
sizeof(*pe));
119 for (
int y = 0; y < pe->image->height; ++y)
124 raw[x].
y = (int)lrintf(y / SCALE);
125 if (raw[x].y >= image->height)
126 raw[x].
y = image->height - 1;
128 raw[x].
x = (int)lrintf(x / SCALE);
129 if (raw[x].x >= image->width)
130 raw[x].
x = image->width - 1;
149 if (ud->last_time_ms < res->
time_ms || force)
151 ud->last_time_ms = res->
time_ms + 500;
152 printf(
"\rsvl_progress[%d] time=%lldms, tp=%d, fp=%d, fn=%d, goodness=%f ", force, res->
time_ms, res->
global.
tp, res->
global.
fp, res->
global.
fn, res->
global.
goodness);
160 printf(
"SVL CALLBACK ACTION: stop_reason=%d, msg=%s\n", res->
stop_reason, msg);
176 printf(
"Initialize the SqueezeBrains library\n");
184 printf(
"wait for license...\n");
207 printf(
"Release SqueezeBrains library\n");
210 printf(
"Press ENTER to terminate\n");
252 memset(&sample, 0,
sizeof(sample));
328 memset(&user_data, 0,
sizeof(user_data));
343 printf(
"time=%1.3fs\n", svl_res->
time_ms / 1000.0f);
370 for (
int i = 1; i <= 3; i++)
373 snprintf(name,
sizeof(name) - 1,
"../images/%03d.ppm", i);
388 printf(
"image: %s\n", name);
EXTERN_C sb_t_err wait_license(void)
The functions wait until the license status is active.
#define CHECK_FN_GOTO(function)
sb_t_err
Errors code enum.
@ SB_ERR_NULL_POINTER
Function has been called with a NULL pointer.
sb_t_err sb_destroy_info(sb_t_info **const info)
Destroys the structure.
sb_t_err sb_release(void)
Releases all the resources allocates in the library.
sb_t_err sb_get_info(sb_t_info **const info, int dl_devices_info)
The function gets information about the sb library and the available computational devices.
sb_t_err sb_init(const char *const license_file)
Initializes the SB library.
void * SB_HANDLE
HANDLE definition.
sb_t_err sb_get_uuid(char *const str, size_t size)
Creates a new uuid.
SB_INLINE sb_t_point sb_point(int x, int y)
Inline constructor of structure sb_t_point.
SB_INLINE sb_t_size sb_size(int width, int height)
Inline constructor of structure sb_t_size.
SB_INLINE sb_t_rect sb_rect(int x, int y, int width, int height)
Inline constructor of structure sb_t_rect.
sb_t_err sb_image_info_set_type(SB_HANDLE image_info, sb_t_image_info_type type)
Sets the type of the SqueezeBrains image info.
sb_t_err sb_image_info_set_notes(SB_HANDLE image_info, const char *const str)
Set a note into SqueezeBrains image info handle.
sb_t_err sb_image_info_add_sample(SB_HANDLE image_info, const sb_t_sample *const sample)
Adds a sample into the SqueezeBrains image info handle.
sb_t_err sb_image_info_load(SB_HANDLE *image_info, const char *const image_file, SB_HANDLE module_handle)
Creates a SqueezeBrains image info handle.
sb_t_err sb_image_info_reset(SB_HANDLE image_info)
Erases all the data from the SqueezeBrains image info handle.
sb_t_err sb_image_info_destroy(SB_HANDLE *image_info)
Destroys the SqueezeBrains image info handle.
sb_t_err sb_image_info_save(SB_HANDLE image_info)
Saves the SqueezeBrains image info handle into the image file.
@ SB_IMAGE_INFO_TYPE_SVL
Image is used for SVL and not used for training.
sb_t_err sb_image_create(sb_t_image **const pimg, int width, int height, sb_t_image_format format)
Creates an image.
#define SB_IMAGE_FILE_EXTENSIONS
List of the possible extensions of the image.
sb_t_err sb_image_destroy(sb_t_image **const pimg)
Destroys the image.
sb_t_err sb_image_resize(const sb_t_image *const src, sb_t_rect rect, float scale, sb_t_interpolation_mode interpolation_mode, sb_t_image *const dst)
Resizes the image.
sb_t_err sb_image_load(sb_t_image **const img, const char *const file)
Loads an image from a file.
sb_t_err sb_lut_destroy(SB_HANDLE *phandle)
Destroys the handle of the lut.
sb_t_err sb_lut_create(SB_HANDLE *phandle, int width, int height)
Creates the handle of the lut.
sb_t_err sb_lut_get_ptr(SB_HANDLE phandle, sb_t_lut_point **const ptr)
Retrieves, in the parameter ptr, the pointer to internal array of the lut.
sb_t_err sb_par_add_model(sb_t_par *const par, const char *const model_name)
Adds the model to the parameter structure.
sb_t_err sb_par_destroy(sb_t_par **const par)
Destroys the project parameters structure.
sb_t_err sb_project_set_par(SB_HANDLE handle, const sb_t_par *const par)
Sets the parameters structure into the project handle.
sb_t_err sb_project_create(SB_HANDLE *phandle, const char *const project_name, sb_t_project_type project_type)
Creates a new project of the specifed type.
sb_t_err sb_project_save(SB_HANDLE handle, const char *const solution_file, sb_t_project_mode mode)
Saves the project to file.
sb_t_err sb_project_load(SB_HANDLE *phandle, const char *const solution_file, const char *const project_uuid, sb_t_project_mode mode)
Loads an existing project from a solution file.
sb_t_err sb_project_detection(SB_HANDLE handle, const sb_t_image *const img, const sb_t_roi *const roi, const sb_t_roi *const roi_defects, const sb_t_samples *const samples)
Detection function.
sb_t_err sb_project_get_res(SB_HANDLE handle, sb_t_res **const res, int details)
Retrieves the results of the last elaborated image.
sb_t_err sb_project_destroy(SB_HANDLE *phandle)
Frees all the resources of the project handle.
sb_t_err sb_project_get_par(SB_HANDLE handle, sb_t_par **const par)
Retrieves the project parameters structure.
@ SB_PROJECT_MODE_DETECTION_ONLY
Load/save the minimum module information to allow detection.
@ SB_PROJECT_MODE_DETECTION_AND_SVL
Load/save all the module information.
@ SB_PROJECT_TYPE_RETINA
Project Retina.
sb_t_err sb_res_destroy(sb_t_res **const res)
Destroys the module results structure.
sb_t_err sb_roi_set_rect(sb_t_roi *const roi, unsigned char gl, sb_t_rect rect, int reset_roi)
Sets a rectangular ROI.
sb_t_err sb_roi_create(sb_t_roi **const roi, int width, int height)
Creates a ROI.
sb_t_err sb_roi_destroy(sb_t_roi **const roi)
Destroys the ROI.
@ SB_OBJ_TEST
Object is not used for learning.
sb_t_err sb_solution_get_info(const char *const solution_file, sb_t_solution_info **const solution)
Returns the information contained in the solution_file.
#define SB_SOLUTION_EXT
Extension of the SqueezeBrains solution file.
sb_t_err sb_solution_destroy_info(sb_t_solution_info **const solution)
Destroys the structure of the solution information.
sb_t_svl_command
Enumerates the actions that SVL has to do after a stop.
sb_t_err sb_svl_destroy_res(sb_t_svl_res **const res)
Destroys the structure of the results of SVL.
sb_t_err sb_svl_reset(SB_HANDLE handle)
Resets the history of previous executions of the SVL.
sb_t_err sb_svl_run(SB_HANDLE handle)
Runs the SVL.
sb_t_err sb_svl_get_res(SB_HANDLE handle, sb_t_svl_res **const res)
Retrieves the results of SVL.
@ SB_SVL_COMMAND_CONTINUE
The SVL continues and, if necessary, resets the training.
sb_t_err detection(void)
Detection on resized images.
sb_t_err set_samples(SB_HANDLE retina)
Set samples.
sb_t_err execute_svl(void)
Execute svl.
sb_t_err create_retina_project_file(SB_HANDLE *retina)
Create a retina project file.
int width
Width, in pixel, of the image.
sb_t_image_format format
Format of the image pixel.
int height
Height, in pixel, of the image.
General information about sb library and computing devices like CPU and GPUs.
char compile_time[32]
String with the compilation time of the sb library.
char compile_date[32]
String with the compilation date of the sb library.
char version_str[16]
String with the version of the sb library.
Struct that defines the coordinates of a point of a lut.
unsigned short y
ordinate of the point.
unsigned short x
abscissa of the point.
sb_t_par_perturbations perturbations
Perturbations of the samples.
sb_t_size obj_size
Model size.
sb_t_size obj_stride_coarse
Coarse search step.
sb_t_size obj_stride_fine
Fine search step.
sb_t_size obj_min_distance
Minimum distance between two samples.
sb_t_par_model model[SB_PAR_MODELS_NUM]
Array of models.
int flip_vertical
Flip around vertical axis. 3th operation.
int num_synthetic_samples
Number of synthetic sample to generated with a random angle in the range sb_t_par_perturbation::angle...
sb_t_par_perturbation perturbation[SB_PAR_PERTURBATIONS_NUM]
Array of the perturbations.
int size
Number of used elements of the array perturbation.
sb_t_par_models models
Models parameters.
sb_t_svl_par svl
SVL parameters.
int x
abscissa of the point
int y
ordinate of the point
char uuid[SB_PROJECT_UUID_LEN]
Project UUID.
sb_t_project_info * info
Array of solution project information.
sb_t_samples samples
Samples found in the image.
sb_t_point centre
Coordinates of the centre of the sample.
char model_name[SB_PAR_STRING_LEN]
Name of the model.
char uuid[36]
uuid of the sample.
sb_t_sample_classify_mode classify_mode
Classification mode.
sb_t_obj_type type
Sample type.
float weight
Weight of classification.
int size
Number of samples that is number of elements of the array sb_t_samples::sample .
sb_t_sample * sample
Pointer to the array of sample. The number of element is sb_t_samples::size .
sb_t_projects_info projects
Array of the projects info.
int current_project
Index of the current project in the projects array.
sb_fp_svl_progress fp_progress
The SVL calls this callback to notify the user the results of SVL.
sb_t_svl_sl_par sl
Shallow Learning SVL parameters.
sb_fp_svl_pre_elaboration fp_pre_elaboration
Callback to execute an image pre elaboration.
sb_fp_svl_command fp_command
Callback called by SVL to allow the user to decide how to continue when particular situations happen,...
char project_path[512]
Path of the project, where the SVL will find the images.
void * user_data
Pointer to data which is passed to the callbacks.
char image_ext[64]
Extensions of the images.
Contains the results of the image pre-processing.
sb_t_image * image
Pre processed image, that is the warped image.
SB_HANDLE warped2ori
lut of the samples coordinates from warped image to the original one.
sb_t_roi * roi
Image elaboration ROI.
float goodness
Goodness of the training.
int fn
Number of FALSE NEGATIVE samples.
int tp
Number of TRUE POSITIVE samples.
int fp
Number of FALSE POSITIVE samples.
Defines the results of SVL.
sb_t_svl_res_level global
Cumulative results of all levels of all models.
long long time_ms
Execution time, in ms, of SVL.
sb_t_svl_stop_reason stop_reason
It describes the reason why the SVL is finished.
float goodness_target
Goodness target of the training.