SqueezeBrains SDK 1.18
surface_detect.c
Go to the documentation of this file.
1
48#include "../common/common.h"
49
53int main(void)
54{
56 sb_t_info* sb_info = NULL;
57 SB_HANDLE project = NULL;
58 sb_t_roi* roi = NULL;
59 sb_t_image* image = NULL;
60 sb_t_res* res = NULL;
61 sb_t_par* par = NULL;
62 sb_t_solution_info* solution = NULL;
63
65 printf("Initialize the SqueezeBrains library\n");
66 CHECK_FN_GOTO(sb_init("../sb.lic"))
67
68 // Print library version.
69 CHECK_FN_GOTO(sb_get_info(&sb_info, 0))
70 printf("sb ver. %s, compiled on %s %s\n", sb_info->version_str, sb_info->compile_date, sb_info->compile_time);
71
73 printf("wait for license...\n");
75
76
77 CHECK_FN_GOTO(sb_solution_get_info("solution/surface_tutorial." SB_SOLUTION_EXT, &solution));
79 CHECK_FN_GOTO(sb_project_load(&project, "solution/surface_tutorial." SB_SOLUTION_EXT, solution->projects.info[solution->current_project].uuid, SB_PROJECT_MODE_DETECTION_ONLY))
81 CHECK_FN_GOTO(sb_image_load(&image, "dataset/surface_001.png"))
83 CHECK_FN_GOTO(sb_roi_create(&roi, image->width, image->height))
84 // Set a rectangular roi equal to image dimensions.
85 CHECK_FN_GOTO(sb_roi_set_rect(roi, 255, sb_rect(0, 0, image->width, image->height), 0))
86 // Set the blob analysis par
87 CHECK_FN_GOTO(sb_project_get_par(project, &par))
88 par->surface_blob_analysis = 1;
89 par->blob_par.area.min = 10;
90 par->blob_par.merge_area.min = 20;
91 par->blob_par.blob_rle = 1;
92 par->blob_par.blob_contour = 1;
93 par->blob_par.merge_distance = 10;
96 CHECK_FN_GOTO(sb_project_detection(project, image, roi, NULL, NULL))
98 CHECK_FN_GOTO(sb_project_get_res(project, &res, 0))
99 // Print the results
100 printf("%d defect blobs found:\n", res->global.surface->blobs->size);
101 for (int j = 0; j < res->global.surface->blobs->size; ++j)
102 printf(" ul=(%d,%d), size=(%d,%d), area=%d\n", res->global.surface->blobs->blob[j].rect.x, res->global.surface->blobs->blob[j].rect.y, res->global.surface->blobs->blob[j].rect.width, res->global.surface->blobs->blob[j].rect.height, res->global.surface->blobs->blob[j].area);
103
104FnExit:
106 sb_destroy_info(&sb_info);
107 sb_project_destroy(&project);
108 sb_image_destroy(&image);
109 sb_roi_destroy(&roi);
110 sb_par_destroy(&par);
111 sb_res_destroy(&res);
112 sb_solution_destroy_info(&solution);
113
115 printf("Release SqueezeBrains library\n");
116 sb_release();
117
118 printf("Press ENTER to terminate\n");
119 getchar();
120 return (int)err;
121}
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_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_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_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 blob_contour
Set to 1 if you want the contour of each blob.
Definition: sb.h:9378
sb_t_range area
Range of area, value in pixel.
Definition: sb.h:9365
sb_t_range merge_area
Range of area after merge, value in pixel. Used only if sb_t_blob_par::merge_distance is greater than...
Definition: sb.h:9395
int blob_rle
Set to 1 if you want the rle of each blob.
Definition: sb.h:9373
int merge_distance
Blobs with a distance inferior or equal to the value are merged together.
Definition: sb.h:9394
sb_t_rect rect
Bounding box of the blob.
Definition: sb.h:9447
int area
Area of the blob, number of the pixel.
Definition: sb.h:9444
sb_t_blob * blob
Array of the blobs.
Definition: sb.h:9515
int size
Number of blobs, ie number of elements of the array sb_t_blobs::blob .
Definition: sb.h:9514
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 surface_blob_analysis
Enables the blob analysis.
Definition: sb.h:11901
sb_t_blob_par blob_par
Surface blob analysis parameters.
Definition: sb.h:11857
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
int min
minimum value
Definition: sb.h:6516
int y
y coordinate of the upper left corner of the rectangle
Definition: sb.h:6535
int x
x coordinate of the upper left corner of the rectangle
Definition: sb.h:6534
int width
width of the rectangle
Definition: sb.h:6536
int height
height of the rectangle
Definition: sb.h:6537
sb_t_surface_res * surface
Surface model analysis result.
Definition: sb.h:12529
Results of detection.
Definition: sb.h:12672
sb_t_res_model global
Global results.
Definition: sb.h:12707
Defines a roi.
Definition: sb.h:8520
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_blobs * blobs
Defects blobs extracted.
Definition: sb.h:12414
int main(void)