SqueezeBrains SDK 1.18
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 = NULL;
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 sb_par_destroy(&par);
122 return err;
123}
124
126{
127 sb_t_err err = SB_ERR_NONE;
128 SB_HANDLE image_info = NULL;
129 sb_t_roi *defects = NULL;
130 sb_t_roi *roi = NULL;
131 sb_t_image *img = NULL;
132
133 // Erase the rtn to begin from zero
134 remove("dataset/surface_001.rtn");
135
140 // load image and create image info
141 CHECK_FN_GOTO(sb_image_load(&img, "dataset/surface_001.png"))
142 CHECK_FN_GOTO(sb_image_info_load(&image_info, "dataset/surface_001.png", surface))
143 // Reset the image info
146 // Get the roi
147 CHECK_FN_GOTO(sb_image_info_get_roi(image_info, &roi, img->width, img->height, 0))
148 // Set a ellipse ROI
149 CHECK_FN_GOTO(sb_roi_set_ellipse(roi, 255, roi->img->width / 2, roi->img->height / 2, 250, 150, 1))
150 CHECK_FN_GOTO(sb_image_info_set_roi(image_info, roi))
151 // Get the defects roi
152 CHECK_FN_GOTO(sb_image_info_get_roi_defects(image_info, &defects, img->width, img->height, 0))
153 // Set a circle defect area
154 CHECK_FN_GOTO(sb_roi_set_circle(defects, 255, 478, 156, 12, 1))
155 CHECK_FN_GOTO(sb_image_info_set_roi_defects(image_info, defects))
157FnExit:
158 sb_image_info_destroy(&image_info);
159 sb_image_destroy(&img);
160 sb_roi_destroy(&roi);
161 sb_roi_destroy(&defects);
162 return err;
163}
164
166{
167 sb_t_err err = SB_ERR_NONE;
168 SB_HANDLE svl = NULL;
169 sb_t_svl_res* svl_res = NULL;
170 sb_t_par* par = NULL;
171 sb_t_solution_info* solution = NULL;
172
174 CHECK_FN_GOTO(sb_solution_get_info("dataset/surface." SB_SOLUTION_EXT, &solution));
182 strcpy(par->svl.project_path, "dataset/");
183 par->svl.sl.goodness_target = 0.5f;
186 printf("Training is running, please wait . . .\n");
189 CHECK_FN_GOTO(sb_svl_get_res(svl, &svl_res))
190 printf("goodness=%f\n", svl_res->global.goodness);
191 printf("time=%1.3fs\n", svl_res->time_ms / 1000.0f);
194FnExit:
196 sb_svl_destroy_res(&svl_res);
197 sb_par_destroy(&par);
198 sb_project_destroy(&svl);
199 sb_solution_destroy_info(&solution);
200 return err;
201}
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:6230
@ SB_ERR_NONE
No errors.
Definition: sb.h:6231
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.
Definition: sb.h:6766
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:13377
#define SB_IMAGE_FILE_EXTENSIONS
List of the possible extensions of the image.
Definition: sb.h:8033
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_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_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_AND_SVL
Load/save all the module information.
Definition: sb.h:9823
@ SB_PROJECT_TYPE_SURFACE
Project Surface.
Definition: sb.h:9671
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:9721
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:8100
int width
Width, in pixel, of the image.
Definition: sb.h:8104
int height
Height, in pixel, of the image.
Definition: sb.h:8105
General information about sb library and computing devices like CPU and GPUs.
Definition: sb.h:6946
char compile_time[32]
String with the compilation time of the sb library.
Definition: sb.h:6950
char compile_date[32]
String with the compilation date of the sb library.
Definition: sb.h:6949
char version_str[16]
String with the version of the sb library.
Definition: sb.h:6948
Project parameters.
Definition: sb.h:11797
sb_t_svl_par svl
SVL parameters.
Definition: sb.h:11913
char uuid[SB_PROJECT_UUID_LEN]
Project UUID.
Definition: sb.h:9697
sb_t_project_info * info
Array of solution project information.
Definition: sb.h:9707
Defines a roi.
Definition: sb.h:8520
sb_t_image * img
8bit BW image.
Definition: sb.h:8524
Solution info structure.
Definition: sb.h:9727
sb_t_projects_info projects
Array of the projects info.
Definition: sb.h:9728
int current_project
Index of the current project in the projects array.
Definition: sb.h:9729
sb_t_svl_sl_par sl
Shallow Learning SVL parameters.
Definition: sb.h:11342
char project_path[512]
Path of the project, where the SVL will find the images.
Definition: sb.h:11289
char image_ext[64]
Extensions of the images.
Definition: sb.h:11297
float goodness
Goodness of the training.
Definition: sb.h:14396
Defines the results of SVL.
Definition: sb.h:14638
sb_t_svl_res_level global
Cumulative results of all levels of all models.
Definition: sb.h:14681
long long time_ms
Execution time, in ms, of SVL.
Definition: sb.h:14740
float goodness_target
Goodness target of the training.
Definition: sb.h:11184
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.