3using System.Collections.Generic;
 
    8using System.Threading.Tasks;
 
    9using System.Xml.Serialization;
 
   23        int m_nInstanceId = 0;
 
   34            m_nInstanceId = nInstanceId;
 
   56            get { 
return m_nInstanceId; }
 
   57            set { m_nInstanceId = value; }
 
   65            get { 
return m_bbox; }
 
   66            set { m_bbox = value; }
 
   80            if (m_bbox.
xmin > rc.Left)
 
   81                fxmin = (m_bbox.
xmin - rc.Left) / rc.Width;
 
   83            if (m_bbox.
ymin > rc.Top)
 
   84                fymin = (m_bbox.
ymin - rc.Top) / rc.Height;
 
   86            if (m_bbox.
xmax < rc.Right)
 
   87                fxmax = (m_bbox.
xmax - rc.Left) / rc.Width;
 
   89            if (m_bbox.
ymax < rc.Bottom)
 
   90                fymax = (m_bbox.
ymax - rc.Top) / rc.Height;
 
   92            m_bbox.
Set(fxmin, fymin, fxmax, fymax);
 
   99        public void Save(BinaryWriter bw)
 
  101            bw.Write(m_nInstanceId);
 
  112            int nInstanceId = br.ReadInt32();
 
  125        int m_nGroupLabel = 0;
 
  126        List<Annotation> m_rgAnnotations = 
new List<Annotation>();
 
  135            if (rgAnnotations != 
null && rgAnnotations.Count > 0)
 
  136                m_rgAnnotations.AddRange(rgAnnotations);
 
  138            m_nGroupLabel = nGroupLabel;
 
  147            List<Annotation> rg = 
null;
 
  149            if (m_rgAnnotations != 
null)
 
  151                rg = 
new List<Annotation>();
 
  171            for (
int i = 0; i < m_rgAnnotations.Count; i++)
 
  173                if (m_rgAnnotations[i].bbox.score >= fMaxScore)
 
  176                    fMaxScore = m_rgAnnotations[i].
bbox.
score;
 
  183            return m_rgAnnotations[nMaxIdx];
 
  203            get { 
return m_rgAnnotations; }
 
  204            set { m_rgAnnotations = value; }
 
  212            get { 
return m_nGroupLabel; }
 
  213            set { m_nGroupLabel = value; }
 
  220        public void Save(BinaryWriter bw)
 
  222            bw.Write(m_nGroupLabel);
 
  223            bw.Write(m_rgAnnotations.Count);
 
  225            for (
int i = 0; i < m_rgAnnotations.Count; i++)
 
  227                m_rgAnnotations[i].Save(bw);
 
  238            int nGroupLabel = br.ReadInt32();
 
  239            int nCount = br.ReadInt32();
 
  240            List<Annotation> rgAnnotations = 
new List<Annotation>();
 
  242            for (
int i = 0; i < nCount; i++)
 
  257        List<AnnotationGroup> m_rgItems = 
new List<AnnotationGroup>();
 
  258        Dictionary<int, string> m_rgLabels = 
new Dictionary<int, string>();
 
  261        int m_nCreatorID = 0;
 
  262        int m_nDatasetID = 0;
 
  264        bool m_bHasDataCriteria = 
false;
 
  265        bool m_bHasDebugData = 
false;
 
  279            get { 
return m_bHasDataCriteria; }
 
  280            set { m_bHasDataCriteria = value; }
 
  288            get { 
return m_bHasDebugData; }
 
  289            set { m_bHasDebugData = value; }
 
  297            get { 
return m_nImageID; }
 
  298            set { m_nImageID = value; }
 
  306            get { 
return m_nImageIdx; }
 
  307            set { m_nImageIdx = value; }
 
  315            get { 
return m_nCreatorID; }
 
  316            set { m_nCreatorID = value; }
 
  324            get { 
return m_nDatasetID; }
 
  325            set { m_nDatasetID = value; }
 
  333            get { 
return m_nSourceID; }
 
  334            set { m_nSourceID = value; }
 
  342            get { 
return m_rgLabels; }
 
  343            set { m_rgLabels = value; }
 
  351            get { 
return m_rgItems.Count; }
 
  361            get { 
return m_rgItems[nIdx]; }
 
  362            set { m_rgItems[nIdx] = value; }
 
  393            return m_rgItems.Remove(g);
 
  402            m_rgItems.RemoveAt(nIdx);
 
  419            return m_rgItems.GetEnumerator();
 
  426        IEnumerator IEnumerable.GetEnumerator()
 
  428            return m_rgItems.GetEnumerator();
 
  444                if (a != 
null && a.
bbox.
score >= fMaxScore)
 
  451            return bestAnnotation;
 
  483            foreach (KeyValuePair<int, string> kv 
in m_rgLabels)
 
  485                col.m_rgLabels.Add(kv.Key, kv.Value);
 
  488            col.ImageID = m_nImageID;
 
  489            col.ImageIdx = m_nImageIdx;
 
  490            col.CreatorID = m_nCreatorID;
 
  491            col.DatasetID = m_nDatasetID;
 
  492            col.SourceID = m_nSourceID;
 
  493            col.HasDataCriteria = m_bHasDataCriteria;
 
  494            col.HasDebugData = m_bHasDebugData;
 
  505            int nMin = 
int.MaxValue;
 
  506            int nMax = -
int.MaxValue;
 
  508            for (
int i = 0; i < m_rgItems.Count; i++)
 
  510                nMin = Math.Min(nMin, m_rgItems[i].group_label);
 
  511                nMax = Math.Max(nMax, m_rgItems[i].group_label);
 
  514            return new Tuple<int, int>(nMin, nMax);
 
  543            bw.Write(rg.ImageID);
 
  544            bw.Write(rg.ImageIdx);
 
  545            bw.Write(rg.CreatorID);
 
  546            bw.Write(rg.DatasetID);
 
  547            bw.Write(rg.SourceID);
 
  548            bw.Write(rg.HasDataCriteria);
 
  549            bw.Write(rg.HasDebugData);
 
  559            bw.Write(rg.
Labels.Count);
 
  560            foreach (KeyValuePair<int, string> kv 
in rg.Labels)
 
  575            int nCount = br.ReadInt32();
 
  577            for (
int i = 0; i < nCount; i++)
 
  598        public static Dictionary<int, string> 
LoadLabels(BinaryReader br)
 
  600            Dictionary<int, string> rg = 
new Dictionary<int, string>();
 
  602            int nCount = br.ReadInt32();
 
  603            for (
int i = 0; i < nCount; i++)
 
  605                int nKey = br.ReadInt32();
 
  606                string strVal = br.ReadString();
 
  608                rg.Add(nKey, strVal);
 
  622            using (MemoryStream ms = 
new MemoryStream())
 
  623            using (BinaryWriter bw = 
new BinaryWriter(ms))
 
  627                bw.Write(bIncludeLabels);
 
  651            using (MemoryStream ms = 
new MemoryStream(rg))
 
  652            using (BinaryReader br = 
new BinaryReader(ms))
 
  656                if (br.ReadBoolean())
 
Defines a collection of AnnotationGroups.
Dictionary< int, string > Labels
Get/set the label name mappings.
IEnumerator< AnnotationGroup > GetEnumerator()
Returns the enumerator for the collection.
static void SaveList(BinaryWriter bw, AnnotationGroupCollection rg)
Save an AnnotationGroupCollection to a binary writer.
int SourceID
Specifies the Data Source ID.
void Add(AnnotationGroupCollection col)
Add another AnnotationGroupCollection to this one.
int ImageIdx
Specifies the Image Index.
int ImageID
Specifies the ImageID.
bool HasDataCriteria
Get/set whether or not the image has a data criteria associated with it.
void Clear()
Clear all items from the collection.
static void SaveLabels(BinaryWriter bw, AnnotationGroupCollection rg)
Save the labels to a binary writer.
static AnnotationGroupCollection FromByteArray(byte[] rg)
Returns an AnnotationGroupCollection from a byte array.
int Count
Specifies the number of items in the collection.
Annotation GetMaxScoringAnnotation()
Returns the maximum scoring annotation within a collection of groups.
void RemoveAt(int nIdx)
Remove an item at a given index.
AnnotationGroup Find(int nLabel)
Find the annotation group with the given label.
bool HasDebugData
Get/set whether or not the image has debug data associated with it.
static Dictionary< int, string > LoadLabels(BinaryReader br)
Load the labels from a binary reader.
static byte[] ToByteArray(AnnotationGroupCollection rg, bool bIncludeLabels=false)
Saves a AnnotationGroupCollection to a byte array.
AnnotationGroupCollection Clone()
Return a copy of the collection.
AnnotationGroupCollection()
The constructor.
static AnnotationGroupCollection LoadList(BinaryReader br)
Load an AnnotationGroupCollection from a binary stream.
int CreatorID
Specifies the Dataset Creator ID.
void Normalize(Rectangle rc)
Normalize all annotations to the given rectangle.
bool Remove(AnnotationGroup g)
Remove an AnnotationGroup from the collection if it exists.
int DatasetID
Specifies the Dataset ID.
Tuple< int, int > GetMinMaxLabels()
Return the min/max labels found int the collection.
void Add(AnnotationGroup g)
Add a new AnnotationGroup to the collection.
The AnnoationGroup class manages a group of annotations.
Annotation GetMaxScoringAnnotation()
Returns the maximum scoring annotation within a group.
AnnotationGroup Clone()
Create a copy of the annotation group.
int group_label
Get/set the group label.
void Normalize(Rectangle rc)
Normalize all annotations to the given rectangle.
AnnotationGroup(List< Annotation > rgAnnotations=null, int nGroupLabel=0)
The constructor.
static AnnotationGroup Load(BinaryReader br)
Load an annotation group using the binary reader.
List< Annotation > annotations
Get/set the group annoations.
void Save(BinaryWriter bw)
Save the annotation group to the binary writer.
The Annotation class is used by annotations attached to SimpleDatum's and used in SSD.
Annotation Clone()
Returns a copy of the Annotation.
Annotation(NormalizedBBox bbox, int nInstanceId=0)
The constructor.
void Normalize(Rectangle rc)
Normalize all annotations to the given rectangle.
int instance_id
Get/set the instance ID.
void Save(BinaryWriter bw)
Save the annotation data using the binary writer.
static Annotation Load(BinaryReader br)
Load the annotation using a binary reader.
NormalizedBBox bbox
Get/set the bounding box.
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.
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.
float score
Get/set the score.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.