SqueezeBrains SDK 1.13
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 SbError err = SbError.SB_ERR_NONE;
47
49 Console.WriteLine("Sb Init");
50 err = Sb.Init("../../../sb.lic");
51 if (err != SbError.SB_ERR_NONE)
52 {
53 Console.WriteLine("Sb.Init failed with error " + err);
54 return err;
55 }
56
58 Console.WriteLine("Wait for license...");
59 err = Common.WaitLicense();
60 if (err != SbError.SB_ERR_NONE)
61 {
62 Console.WriteLine("SbLicense.WaitLicense failed with error " + err);
63 goto FnExit;
64 }
65
67 String project_file = "../../../images/wheels." + SbDefines.SbSolutionExt;
68 SbSolutionInfo solutionInfo = SbSolution.GetInfo(project_file);
69 if (solutionInfo == null || solutionInfo.Error() != SbError.SB_ERR_NONE)
70 {
71 err = solutionInfo == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : solutionInfo.Error();
72 Console.WriteLine("SbSolution.GetInfo failed");
73 goto FnExit;
74 }
75 else if (solutionInfo.projects.Length == 0)
76 {
77 err = SbError.SB_ERR_PROJECT_NOT_FOUND;
78 Console.WriteLine("SbSolution.GetInfo no projects found");
79 goto FnExit;
80 }
81 Console.WriteLine("GetProjectsInfo, found " + solutionInfo.projects.Length + " projects");
82
84 prj = SbProject.Load(project_file, solutionInfo.projects[0].uuid, SbProjectMode.SB_PROJECT_MODE_DETECTION_ONLY);
85 if (prj == null || prj.Error() != SbError.SB_ERR_NONE)
86 {
87 err = prj == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : prj.Error();
88 Console.WriteLine("SbProject.Load failed with error " + err);
89 goto FnExit;
90 }
91
92 SbFolder folder = SbFolder.Load("../../../images", "ppm", true, 0);
93 if (folder != null)
94 {
95 for (int i = 0; i < folder.files.Length; i++)
96 {
97 SbRect rect = new SbRect();
98
100 img = SbImage.Load(folder.files[i]);
101 if (img == null || img.Error() != SbError.SB_ERR_NONE)
102 {
103 Console.WriteLine("SbImage.Load " + folder.files[i] + " failed");
104 err = img == null ? SbError.SB_ERR_INTERNAL : img.Error();
105 break;
106 }
107
109 roi = SbRoi.Create(img.Width(), img.Height());
110 if (roi == null || roi.Error() != SbError.SB_ERR_NONE)
111 {
112 Console.WriteLine("SbRoi.Create failed");
113 err = roi == null ? SbError.SB_ERR_INTERNAL : roi.Error();
114 break;
115 }
116
118 err = roi.SetRect(255, new SbRect(0, 0, img.Width(), img.Height()), false);
119 if (err != SbError.SB_ERR_NONE)
120 {
121 Console.WriteLine("SbRoi.SetRect failed with error " + err);
122 break;
123 }
124
126 err = prj.Detection(img, roi);
127 if (err != SbError.SB_ERR_NONE)
128 {
129 Console.WriteLine("SbProject.Detection failed with error " + err);
130 break;
131 }
132
134 SbRes res = prj.GetRes(false);
135 if (res == null || prj.Error() != SbError.SB_ERR_NONE)
136 {
137 err = res == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : prj.Error();
138 Console.WriteLine("SbProject.GetRes failed with error " + err);
139 break;
140 }
141
143 Console.WriteLine("image: ", folder.files[i]);
144 for (int j = 0; j < res.samples.Length; ++j)
145 Console.WriteLine(" centre=(" + res.samples[j].centre.x + "," + res.samples[j].centre.y + ") weight=" + res.samples[j].weight);
146
147 if (img != null)
148 {
149 img.Dispose();
150 img = null;
151 }
152 if (roi != null)
153 {
154 roi.Dispose();
155 roi = null;
156 }
157 }
158 }
159
160 FnExit:
162 if (prj != null)
163 prj.Dispose();
164 if (img != null)
165 img.Dispose();
166 if (roi != null)
167 roi.Dispose();
168
169 Console.WriteLine("Release SqueezeBrains library");
170 Sb.Release();
171
172 Console.WriteLine("Press ENTER to terminate");
173 Console.ReadKey();
174
175 return err;
176 }
177
178 static void Main(string[] args)
179 {
180 execute();
181 }
182 }
183}
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:258
static const String SbSolutionExt
Solution file extension
Definition: cs_common.h:264
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:374
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:44
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:224
Class of the results of the image elaboration with the SbProject::Detection method....
Definition: cs_res.h:225
array< SbSample^> samples
Samples results. Only Retina projects
Definition: cs_res.h:246
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