SqueezeBrains SDK 1.13
surface_svl_simple.c
Go to the documentation of this file.
1
38#include "../common/common.h"
39
44
49
54
55#define MODEL_NAME "w"
56
60int main(void)
61{
63 sb_t_info* sb_info = NULL;
64 SB_HANDLE project = NULL;
65
67 printf("Initialize the SqueezeBrains library\n");
68 CHECK_FN_GOTO(sb_init("../sb.lic"))
69
70 // Print library version.
71 CHECK_FN_GOTO(sb_get_info(&sb_info, 0))
72 printf("sb ver. %s, compiled on %s %s\n", sb_info->version_str, sb_info->compile_date, sb_info->compile_time);
73
75 printf("wait for license...\n");
77
78
80
81
83
84
86
87FnExit:
89 sb_destroy_info(&sb_info);
90 sb_project_destroy(&project);
91
93 printf("Release SqueezeBrains library\n");
94 sb_release();
95
96 printf("Press ENTER to terminate\n");
97 getchar();
98 return (int)err;
99}
100
102{
103 sb_t_err err = SB_ERR_NONE;
104 sb_t_par par;
105
106 // Erase the project file to begin from zero
107 remove("dataset/surface." SB_SOLUTION_EXT);
108
109 // Create the project file
111 CHECK_FN_GOTO(sb_project_get_par(*surface, &par))
114 CHECK_FN_GOTO(sb_par_add_model(&par, MODEL_NAME))
116 CHECK_FN_GOTO(sb_par_add_level(&par, MODEL_NAME, 1.0f))
117 CHECK_FN_GOTO(sb_project_set_par(*surface, &par))
120FnExit:
121 return err;
122}
123
125{
126 sb_t_err err = SB_ERR_NONE;
127 SB_HANDLE image_info = NULL;
128 sb_t_roi *defects = NULL;
129 sb_t_roi *roi = NULL;
130 sb_t_image *img = NULL;
131
132 // Erase the rtn to begin from zero
133 remove("dataset/surface_001.rtn");
134
139 // load image and create image info
140 CHECK_FN_GOTO(sb_image_load(&img, "dataset/surface_001.png"))
141 CHECK_FN_GOTO(sb_image_info_load(&image_info, "dataset/surface_001.png", surface))
142 // Reset the image info
145 // Get the roi
146 CHECK_FN_GOTO(sb_image_info_get_roi(image_info, &roi, img->width, img->height, 0))
147 // Set a ellipse ROI
148 CHECK_FN_GOTO(sb_roi_set_ellipse(roi, 255, roi->img->width / 2, roi->img->height / 2, 250, 150, 1))
149 CHECK_FN_GOTO(sb_image_info_set_roi(image_info, roi))
150 // Get the defects roi
151 CHECK_FN_GOTO(sb_image_info_get_roi_defects(image_info, &defects, img->width, img->height, 0))
152 // Set a circle defect area
153 CHECK_FN_GOTO(sb_roi_set_circle(defects, 255, 478, 156, 12, 1))
154 CHECK_FN_GOTO(sb_image_info_set_roi_defects(image_info, defects))
156FnExit:
157 sb_image_info_destroy(&image_info);
158 sb_image_destroy(&img);
159 sb_roi_destroy(&roi);
160 sb_roi_destroy(&defects);
161 return err;
162}
163
165{
166 sb_t_err err = SB_ERR_NONE;
167 SB_HANDLE svl = NULL;
168 sb_t_svl_res* svl_res = NULL;
169 sb_t_par par;
170 sb_t_solution_info* solution = NULL;
171
173 CHECK_FN_GOTO(sb_solution_get_info("dataset/surface." SB_SOLUTION_EXT, &solution));
181 strcpy(par.svl.project_path, "dataset/");
182 par.svl.sl.goodness_target = 0.5f;
185 printf("Training is running, please wait . . .\n");
188 CHECK_FN_GOTO(sb_svl_get_res(svl, &svl_res))
189 printf("goodness=%f\n", svl_res->global.goodness);
190 printf("time=%1.3fs\n", svl_res->time_ms / 1000.0f);
193FnExit:
195 sb_svl_destroy_res(&svl_res);
196 sb_project_destroy(&svl);
197 sb_solution_destroy_info(&solution);
198 return err;
199}
EXTERN_C sb_t_err wait_license(void)
The functions wait until the license status is active.
Definition: common.c:11
#define CHECK_FN_GOTO(function)
Definition: common.h:34
sb_t_err
Errors code enum.
Definition: sb.h:5541
@ SB_ERR_NONE
No errors.
Definition: sb.h:5542
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_init(const char *const license_file)
Initializes the SB library.
void * SB_HANDLE
HANDLE definition.
Definition: sb.h:6042
sb_t_err sb_get_info(sb_t_info **const info, int gpu_info)
The function gets information about the sb library and the available computational devices.
sb_t_err sb_image_info_set_roi(SB_HANDLE image_info, const sb_t_roi *const roi)
Sets the ROI in a SqueezeBrains image info handle.
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_get_roi(SB_HANDLE image_info, sb_t_roi **const roi, int width, int height, int compressed)
Gets the ROI from a SqueezeBrains image info handle.
sb_t_err sb_image_info_get_roi_defects(SB_HANDLE image_info, sb_t_roi **const defects, int width, int height, int compressed)
Gets the surface defects ROI from a 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_set_roi_defects(SB_HANDLE image_info, const sb_t_roi *const defects)
Sets the surface defects ROI on 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.
Definition: sb.h:11931
#define SB_IMAGE_FILE_EXTENSIONS
List of the possible extensions of the image.
Definition: sb.h:7243
sb_t_err sb_image_destroy(sb_t_image **const pimg)
Destroys 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_par_add_level(sb_t_par *const par, const char *const model_name, float scale)
Adds the level to the parameter structure.
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_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_get_par(SB_HANDLE handle, sb_t_par *const par)
Retrieves the project parameters structure.
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 file.
sb_t_err sb_project_destroy(SB_HANDLE *phandle)
Frees all the resources of the project handle.
@ SB_PROJECT_MODE_DETECTION_AND_SVL
Load/save all the module information.
Definition: sb.h:9027
@ SB_PROJECT_TYPE_SURFACE
Project Surface.
Definition: sb.h:8876
sb_t_err sb_roi_set_circle(sb_t_roi *const roi, unsigned char gl, int center_x, int center_y, int radius, int reset_roi)
Sets a circular ROI.
sb_t_err sb_roi_set_ellipse(sb_t_roi *const roi, unsigned char gl, int center_x, int center_y, int radius_x, int radius_y, int reset_roi)
Sets an elliptical ROI.
sb_t_err sb_roi_destroy(sb_t_roi **const roi)
Destroys the ROI.
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.
Definition: sb.h:8925
sb_t_err sb_solution_destroy_info(sb_t_solution_info **const solution)
Destroys the structure of the solution information.
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.
Defines an image.
Definition: sb.h:7310
int width
Width, in pixel, of the image.
Definition: sb.h:7314
int height
Height, in pixel, of the image.
Definition: sb.h:7315
General information about sb library and computing devices like CPU and GPUs.
Definition: sb.h:6180
char compile_time[32]
String with the compilation time of the sb library.
Definition: sb.h:6184
char compile_date[32]
String with the compilation date of the sb library.
Definition: sb.h:6183
char version_str[16]
String with the version of the sb library.
Definition: sb.h:6182
Project parameters.
Definition: sb.h:10647
sb_t_svl_par svl
SVL parameters.
Definition: sb.h:10763
char uuid[SB_PROJECT_UUID_LEN]
Project UUID.
Definition: sb.h:8901
sb_t_project_info * info
Array of solution project information.
Definition: sb.h:8911
Defines a roi.
Definition: sb.h:7730
sb_t_image * img
8bit BW image.
Definition: sb.h:7734
Solution info structure.
Definition: sb.h:8931
sb_t_projects_info projects
Array of the projects info.
Definition: sb.h:8932
int current_project
Index of the current project in the projects array.
Definition: sb.h:8933
sb_t_svl_sl_par sl
Shallow Learning SVL parameters.
Definition: sb.h:10198
char project_path[512]
Path of the project, where the SVL will find the images.
Definition: sb.h:10145
char image_ext[64]
Extensions of the images.
Definition: sb.h:10153
float goodness
Goodness of the training.
Definition: sb.h:12701
Defines the results of SVL.
Definition: sb.h:12877
sb_t_svl_res_level global
Cumulative results of all levels of all models.
Definition: sb.h:12920
long long time_ms
Execution time, in ms, of SVL.
Definition: sb.h:12973
float goodness_target
Goodness target of the training.
Definition: sb.h:10046
int main(void)
sb_t_err execute_training(void)
Execute training.
sb_t_err set_labeling(SB_HANDLE surface)
Set labeling.
sb_t_err create_surface_project_file(SB_HANDLE *surface)
Create a surface project file.