SqueezeBrains SDK 1.18
retina_multi_project.c
Go to the documentation of this file.
1
79#include "../common/common.h"
80
84int main(int argc, char* argv[])
85{
87 sb_t_info* sb_info = NULL;
88 char path[256] = "";
89 SB_HANDLE slice = NULL;
90 SB_HANDLE hole = NULL;
91 sb_t_folder* folder = NULL;
92 sb_t_roi* roi = NULL;
93 sb_t_image* image = NULL;
94 sb_t_res* res_slice = NULL;
95 sb_t_res* res_hole = NULL;
96 sb_t_par* par_slice = NULL;
97 sb_t_par* par_hole = NULL;
98 sb_t_solution_info* solution = NULL;
99 const char solution_file[] = "solution/tutorial_7_retina_multi_project." SB_SOLUTION_EXT;
100 char str[8192];
101 int i;
102
104 printf("Initialize the SqueezeBrains library\n");
105 CHECK_FN_GOTO(sb_init("../sb.lic"))
106
107 // Print library version.
108 CHECK_FN_GOTO(sb_get_info(&sb_info, 0))
109 printf("sb ver. %s, compiled on %s %s\n", sb_info->version_str, sb_info->compile_date, sb_info->compile_time);
110
112 printf("wait for license...\n");
114
115
117 CHECK_FN_GOTO(sb_solution_get_info(solution_file, &solution));
120 CHECK_FN_GOTO(sb_project_get_par(slice, &par_slice))
121 CHECK_FN_GOTO(sb_par_format(par_slice, str, sizeof(str)))
122 printf(str);
124 CHECK_FN_GOTO(sb_project_get_par(hole, &par_hole))
125 CHECK_FN_GOTO(sb_par_format(par_hole, str, sizeof(str)))
126 printf(str);
127
131 CHECK_FN_GOTO(sb_folder_load(&folder, "dataset", "png", 1, 0))
132 for (i = 0; i < folder->n; ++i)
133 {
134 int j;
135 // Find the slices of gruyere.
136 printf("\nimage=\"%s\"\n", folder->file[i].fname);
137 CHECK_FN_GOTO(sb_image_load(&image, folder->file[i].name))
138 // Create the roi
139 if (roi && roi->img && (roi->img->width != image->width || roi->img->height != image->height))
140 sb_roi_destroy(&roi);
141 if (!roi)
142 {
143 CHECK_FN_GOTO(sb_roi_create(&roi, image->width, image->height))
144 }
145 // Set a rectangular roi equal to image dimensions.
146 CHECK_FN_GOTO(sb_roi_set_rect(roi, 255, sb_rect(0, 0, image->width, image->height), 1))
147 // Elaborate the image.
148 CHECK_FN_GOTO(sb_project_detection(slice, image, roi, NULL, NULL))
149 // Get the results.
150 CHECK_FN_GOTO(sb_project_get_res(slice, &res_slice, 0))
151 printf(" slice detection time=%1.3fms, %d slices found\n", res_slice->time_us / 1000.0f, res_slice->samples.size);
152 for (j = 0; j < res_slice->samples.size; ++j)
153 {
154 // Find the holes in the slice.
155 int k;
156 // Reset the previous ROI and set a rectangular ROI 230x130 center on the slice.
157 CHECK_FN_GOTO(sb_roi_set_rect(roi, 255, sb_rect(res_slice->samples.sample[j].centre.x - 115, res_slice->samples.sample[j].centre.y - 65, 230, 130), 1))
158 // Elaborate the image
159 CHECK_FN_GOTO(sb_project_detection(hole, image, roi, NULL, NULL))
160 // Get the results.
161 CHECK_FN_GOTO(sb_project_get_res(hole, &res_hole, 0))
162 printf(" slice %d hole detection time=%1.3fms, %d holes found\n", j, res_hole->time_us/1000.0f, res_hole->samples.size);
163 // Print the results
164 for (k = 0; k < res_hole->samples.size; ++k)
165 printf(" centre=(%d,%d), weight=%1.3f\n", res_hole->samples.sample[k].centre.x, res_hole->samples.sample[k].centre.y, res_hole->samples.sample[k].weight);
166 CHECK_FN_GOTO(sb_res_destroy(&res_hole))
167 }
168 // Destroy the handles.
170 CHECK_FN_GOTO(sb_res_destroy(&res_slice))
171 }
172
173FnExit:
175 sb_destroy_info(&sb_info);
176 sb_project_destroy(&slice);
177 sb_project_destroy(&hole);
178 sb_image_destroy(&image);
179 sb_roi_destroy(&roi);
180 sb_par_destroy(&par_slice);
181 sb_par_destroy(&par_hole);
182 sb_res_destroy(&res_slice);
183 sb_res_destroy(&res_hole);
184 sb_folder_destroy(&folder);
185 sb_solution_destroy_info(&solution);
186
188 printf("Release SqueezeBrains library\n");
189 sb_release();
190
191 printf("Press ENTER to terminate\n");
192 getchar();
193 return (int)err;
194}
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_folder_destroy(sb_t_folder **folder)
Frees all the resources of the sb_t_folder structure.
sb_t_err sb_folder_load(sb_t_folder **const f, const char *const path, const char *const ext, int sort, int verbosity)
Creates the list of the name of the files in a specified folder.
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_INLINE sb_t_rect sb_rect(int x, int y, int width, int height)
Inline constructor of structure sb_t_rect.
Definition: sb.h:6632
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_format(const sb_t_par *const par, char *const str, int str_size)
Formats the project parameters structure.
sb_t_err sb_par_destroy(sb_t_par **const par)
Destroys the project parameters structure.
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.
Definition: sb.h:9822
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_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.
int main(int argc, char *argv[])
char name[256]
Name of the file included of path.
Definition: sb.h:7359
char * fname
Name of file excluded the path.
Definition: sb.h:7360
defines the list of the file in a folder.
Definition: sb.h:7367
sb_t_file * file
Array of files.
Definition: sb.h:7368
int n
Number of elements of the array file.
Definition: sb.h:7369
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
int x
abscissa of the point
Definition: sb.h:6480
int y
ordinate of the point
Definition: sb.h:6481
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
Results of detection.
Definition: sb.h:12672
sb_t_samples samples
Samples found in the image.
Definition: sb.h:12692
long long time_us
Elaboration time of the image, in us.
Definition: sb.h:12719
Defines a roi.
Definition: sb.h:8520
sb_t_image * img
8bit BW image.
Definition: sb.h:8524
sb_t_point centre
Coordinates of the centre of the sample.
Definition: sb.h:8916
float weight
Weight of classification.
Definition: sb.h:9013
int size
Number of samples that is number of elements of the array sb_t_samples::sample .
Definition: sb.h:9169
sb_t_sample * sample
Pointer to the array of sample. The number of element is sb_t_samples::size .
Definition: sb.h:9168
Solution info structure.
Definition: sb.h:9727
sb_t_projects_info projects
Array of the projects info.
Definition: sb.h:9728