SqueezeBrains SDK 1.18
RetinaDetect.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using sb_cs;
7using Tutorials_Common;
8
10{
40 {
41 static SbError execute()
42 {
43 SbProject prj = null;
44 SbImage img = null;
45 SbRoi roi = null;
46 SbRes res = null;
47 SbError err = SbError.SB_ERR_NONE;
48
50 Console.WriteLine("Sb Init");
51 err = Sb.Init("../../../sb.lic");
52 if (err != SbError.SB_ERR_NONE)
53 {
54 Console.WriteLine("Sb.Init failed with error " + err);
55 return err;
56 }
57
59 Console.WriteLine("Wait for license...");
60 err = Common.WaitLicense();
61 if (err != SbError.SB_ERR_NONE)
62 {
63 Console.WriteLine("SbLicense.WaitLicense failed with error " + err);
64 goto FnExit;
65 }
66
68 String project_file = "../../../images/wheels." + SbDefines.SbSolutionExt;
69 SbSolutionInfo solutionInfo = SbSolution.GetInfo(project_file);
70 if (solutionInfo == null || solutionInfo.Error() != SbError.SB_ERR_NONE)
71 {
72 err = solutionInfo == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : solutionInfo.Error();
73 Console.WriteLine("SbSolution.GetInfo failed");
74 goto FnExit;
75 }
76 else if (solutionInfo.projects.Length == 0)
77 {
78 err = SbError.SB_ERR_PROJECT_NOT_FOUND;
79 Console.WriteLine("SbSolution.GetInfo no projects found");
80 goto FnExit;
81 }
82 Console.WriteLine("GetProjectsInfo, found " + solutionInfo.projects.Length + " projects");
83
85 prj = SbProject.Load(project_file, solutionInfo.projects[0].uuid, SbProjectMode.SB_PROJECT_MODE_DETECTION_ONLY);
86 if (prj == null || prj.Error() != SbError.SB_ERR_NONE)
87 {
88 err = prj == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : prj.Error();
89 Console.WriteLine("SbProject.Load failed with error " + err);
90 goto FnExit;
91 }
92
93 SbFolder folder = SbFolder.Load("../../../images", "ppm", true, 0);
94 if (folder != null)
95 {
96 for (int i = 0; i < folder.files.Length; i++)
97 {
98 SbRect rect = new SbRect();
99
101 img = SbImage.Load(folder.files[i]);
102 if (img == null || img.Error() != SbError.SB_ERR_NONE)
103 {
104 Console.WriteLine("SbImage.Load " + folder.files[i] + " failed");
105 err = img == null ? SbError.SB_ERR_INTERNAL : img.Error();
106 break;
107 }
108
110 roi = SbRoi.Create(img.Width(), img.Height());
111 if (roi == null || roi.Error() != SbError.SB_ERR_NONE)
112 {
113 Console.WriteLine("SbRoi.Create failed");
114 err = roi == null ? SbError.SB_ERR_INTERNAL : roi.Error();
115 break;
116 }
117
119 err = roi.SetRect(255, new SbRect(0, 0, img.Width(), img.Height()), false);
120 if (err != SbError.SB_ERR_NONE)
121 {
122 Console.WriteLine("SbRoi.SetRect failed with error " + err);
123 break;
124 }
125
127 err = prj.Detection(img, roi);
128 if (err != SbError.SB_ERR_NONE)
129 {
130 Console.WriteLine("SbProject.Detection failed with error " + err);
131 break;
132 }
133
135 res = prj.GetRes(false);
136 if (res == null || prj.Error() != SbError.SB_ERR_NONE)
137 {
138 err = res == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : prj.Error();
139 Console.WriteLine("SbProject.GetRes failed with error " + err);
140 break;
141 }
142
144 Console.WriteLine("image: ", folder.files[i]);
145 for (int j = 0; j < res.samples.Length; ++j)
146 Console.WriteLine(" centre=(" + res.samples[j].centre.x + "," + res.samples[j].centre.y + ") weight=" + res.samples[j].weight);
147
148 if (img != null)
149 {
150 img.Dispose();
151 img = null;
152 }
153 if (roi != null)
154 {
155 roi.Dispose();
156 roi = null;
157 }
158 if (res != null)
159 {
160 res.Dispose();
161 res = null;
162 }
163 }
164 }
165
166 FnExit:
168 if (prj != null)
169 prj.Dispose();
170 if (img != null)
171 img.Dispose();
172 if (roi != null)
173 roi.Dispose();
174 if (res != null)
175 res.Dispose();
176
177 Console.WriteLine("Release SqueezeBrains library");
178 Sb.Release();
179
180 Console.WriteLine("Press ENTER to terminate");
181 Console.ReadKey();
182
183 return err;
184 }
185
186 static void Main(string[] args)
187 {
188 execute();
189 }
190 }
191}
Tutorial 3 - Retina - How to elaborate images
Definition: RetinaDetect.cs:40
SbError Error()
Returns the error code of the last operation. If no error SbError.SB_ERR_NONE is returned.
Defines class
Definition: cs_common.h:309
static const String SbSolutionExt
Solution file extension
Definition: cs_common.h:315
Folder Class that wraps the sb_t_folder structure
Definition: cs_folder.h:16
static SbFolder Load(String^ path, String ^ext, bool sort, int verbosity)
Creates the list of the name of the files in a specified folder.
array< String^> files
Array of files.
Definition: cs_folder.h:22
Sb Main Class
Definition: cs_sb.h:401
static SbError Release()
Releases all the resources allocated in the library
static SbError Init(String ^ license_file)
Init the SB Library. The function initializes all the functionalities of the library including the li...
SbImage class that wraps the sb_t_image structure. You must call the Dispose() method to free all the...
Definition: cs_image.h:66
int Height()
Height, in pixel, of the image.
static SbImage Load(String^ filename)
Loads an image from file.
int Width()
Width, in pixel, of the image.
Project Class You must call the Dispose() method to free all the resources of the returned instance.
Definition: cs_project.h:51
static SbProject Load(String^ solution_file, String^ project_uuid, SbProjectMode mode)
Loads an existing project from file.
SbRes GetRes(bool details)
Retrieves the results of the last processed image
SbError Detection(SbImage ^img, SbRoi ^roi)
The function elaborates the image inside the ROI. For Surface projects the function computes also the...
Rectangle class that wraps the sb_t_rect structure
Definition: cs_sb.h:214
Class of the results of the image elaboration with the SbProject::Detection method....
Definition: cs_res.h:229
array< SbSample^> samples
Samples results. Only Retina projects
Definition: cs_res.h:250
ROI Class that wraps the sb_t_roi structure. You must call the Dispose() method to free all the resou...
Definition: cs_roi.h:18
static SbRoi Create(int width, int height)
Creates a ROI.
SbError SetRect(int gl, SbRect^ rect, bool reset_roi)
Sets a rectangular ROI.
Solution class
Definition: cs_solution.h:44
static SbSolutionInfo GetInfo(String^ solution_file)
Returns the information contained in the solution_file.
Solution Info Class that wraps the sb_t_solution_info structure
Definition: cs_solution.h:17
array< SbProjectInfo^> projects
Array of the projects information of the solution. sb_t_solution_info.projects
Definition: cs_solution.h:23
SbError
Enum error codes
Definition: cs_common.h:13
SbProjectMode
Project loading or saving mode that wraps the sb_t_project_mode enum
Definition: cs_project.h:18
SB Namespace
Definition: cs_common.h:3