MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
NormalizedBBox.cs
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.IO;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8
9namespace MyCaffe.basecode
10{
18 [Serializable]
19 public class NormalizedBBox
20 {
21 float m_fxmin = 0; // [0]
22 float m_fymin = 0; // [1]
23 float m_fxmax = 0; // [2]
24 float m_fymax = 0; // [3]
25 int m_nLabel = -1;
26 bool m_bDifficult = false;
27 float m_fScore = 0;
28 float m_fSize = 0;
29
41 public NormalizedBBox(float fxmin, float fymin, float fxmax, float fymax, int nLabel = 0, bool bDifficult = false, float fScore = 0, float fSize = 0)
42 {
43 Set(fxmin, fymin, fxmax, fymax, nLabel, bDifficult, fScore, fSize);
44 }
45
57 public void Set(float fxmin, float fymin, float fxmax, float fymax, int? nLabel = null, bool? bDifficult = null, float? fScore = null, float? fSize = null)
58 {
59 m_fxmin = fxmin;
60 m_fxmax = fxmax;
61 m_fymin = fymin;
62 m_fymax = fymax;
63
64 if (nLabel.HasValue)
65 m_nLabel = nLabel.Value;
66
67 if (bDifficult.HasValue)
68 m_bDifficult = bDifficult.Value;
69
70 if (fScore.HasValue)
71 m_fScore = fScore.Value;
72
73 if (fSize.HasValue)
74 m_fSize = fSize.Value;
75 }
76
82 {
83 return new NormalizedBBox(m_fxmin, m_fymin, m_fxmax, m_fymax, m_nLabel, m_bDifficult, m_fScore, m_fSize);
84 }
85
89 public float xmin
90 {
91 get { return m_fxmin; }
92 set { m_fxmin = value; }
93 }
94
98 public float xmax
99 {
100 get { return m_fxmax; }
101 set { m_fxmax = value; }
102 }
103
107 public float ymin
108 {
109 get { return m_fymin; }
110 set { m_fymin = value; }
111 }
112
116 public float ymax
117 {
118 get { return m_fymax; }
119 set { m_fymax = value; }
120 }
121
125 public int label
126 {
127 get { return m_nLabel; }
128 set { m_nLabel = value; }
129 }
130
134 public bool difficult
135 {
136 get { return m_bDifficult; }
137 set { m_bDifficult = value; }
138 }
139
143 public float score
144 {
145 get { return m_fScore; }
146 set { m_fScore = value; }
147 }
148
152 public float size
153 {
154 get { return m_fSize; }
155 set { m_fSize = value; }
156 }
157
162 public void Save(BinaryWriter bw)
163 {
164 bw.Write(m_fxmin);
165 bw.Write(m_fxmax);
166 bw.Write(m_fymin);
167 bw.Write(m_fymax);
168 bw.Write(m_nLabel);
169 bw.Write(m_bDifficult);
170 bw.Write(m_fScore);
171 bw.Write(m_fSize);
172 }
173
179 public static NormalizedBBox Load(BinaryReader br)
180 {
181 float fXmin = br.ReadSingle();
182 float fXmax = br.ReadSingle();
183 float fYmin = br.ReadSingle();
184 float fYmax = br.ReadSingle();
185 int nLabel = br.ReadInt32();
186 bool bDifficult = br.ReadBoolean();
187 float fScore = br.ReadSingle();
188 float fSize = br.ReadSingle();
189
190 return new NormalizedBBox(fXmin, fYmin, fXmax, fYmax, nLabel, bDifficult, fScore, fSize);
191 }
192
197 public override string ToString()
198 {
199 string strOut = "(" + m_nLabel.ToString() + ") { ";
200
201 strOut += m_fxmin.ToString() + ", ";
202 strOut += m_fymin.ToString() + ", ";
203 strOut += m_fxmax.ToString() + ", ";
204 strOut += m_fymax.ToString() + " } -> ";
205 strOut += m_fScore.ToString();
206 strOut += " size = " + m_fSize.ToString();
207 strOut += " difficult = " + m_bDifficult.ToString();
208
209 return strOut;
210 }
211
218 public RectangleF GetBounds(int nWidth, int nHeight)
219 {
220 float fX1 = m_fxmin * nWidth;
221 float fX2 = m_fxmax * nWidth;
222 float fY1 = m_fymin * nHeight;
223 float fY2 = m_fymax * nHeight;
224
225 return new RectangleF(fX1, fY1, fX2 - fX1, fY2 - fY1);
226 }
227 }
228}
The NormalizedBBox manages a bounding box used in SSD.
float ymax
Get/set the y maximum.
float xmax
Get/set the x maximum.
NormalizedBBox Clone()
Return a copy of the object.
float xmin
Get/set the x minimum.
RectangleF GetBounds(int nWidth, int nHeight)
Calculates and returns the non-normalized bounding rectangle based in the specified width and height.
bool difficult
Get/set the difficulty.
float size
Get/set the size.
static NormalizedBBox Load(BinaryReader br)
Load and return a new NormalizedBbox.
float ymin
Get/set the y minimum.
void Set(float fxmin, float fymin, float fxmax, float fymax, int? nLabel=null, bool? bDifficult=null, float? fScore=null, float? fSize=null)
Set the values of the NormalizedBbox.
void Save(BinaryWriter bw)
Save the NormalizedBbox using the binary writer.
override string ToString()
Returns a string representation of the NormalizedBBox.
float score
Get/set the score.
NormalizedBBox(float fxmin, float fymin, float fxmax, float fymax, int nLabel=0, bool bDifficult=false, float fScore=0, float fSize=0)
The constructor.
int label
Get/set the label.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12