Exemple #1
0
        public void TestWrite()
        {
            using (AnnotationRecordOperator annotationRecordOperator =
                       new AnnotationRecordOperator("res1.mat", DesiredAccess.Both, CreationDisposition.CreateAlways))
            {
                ulong n = 5;

                int    id_ = 1, x_ = 1, y_ = 1, w_ = 1, h_ = 1;
                bool   isLabeled_ = true, occlusion_ = false, outOfView_ = false;
                string path_ = "0001.jpg";

                annotationRecordOperator.Resize(n);
                for (ulong index = 0; index < n; ++index)
                {
                    annotationRecordOperator.Update(index, id_, isLabeled_, x_, y_, w_, h_, occlusion_, outOfView_, path_);
                }

                ulong numberOfRecords = annotationRecordOperator.GetNumberOfRecords();
                for (ulong index = 0; index < numberOfRecords; ++index)
                {
                    int    id, x, y, w, h;
                    bool   isLabeled, occlusion, outOfView;
                    string path;
                    Assert.IsTrue(annotationRecordOperator.Get(index, out id, out isLabeled, out x, out y, out w, out h,
                                                               out occlusion, out outOfView, out path));
                }
            }
        }
        private static (IList <AnnotationRecord>, IList <bool>) LoadRecordsFromMatFile(string matPath)
        {
            IList <AnnotationRecord> recordList         = new List <AnnotationRecord>();
            IList <bool>             recordValidityList = new List <bool>();

            try
            {
                using (AnnotationRecordOperator annotationRecordOperator
                           = new AnnotationRecordOperator(matPath, AnnotationRecordOperator.DesiredAccess.Read,
                                                          AnnotationRecordOperator.CreationDisposition.OpenAlways))
                {
                    var numberOfRecordsULong = annotationRecordOperator.Length();
                    if (numberOfRecordsULong >= int.MaxValue)
                    {
                        throw new Exception("Too many records");
                    }
                    int numberOfRecords = Convert.ToInt32(numberOfRecordsULong);

                    for (int index = 0; index < numberOfRecords; ++index)
                    {
                        AnnotationRecord record = null;
                        bool             isRecordValid;
                        try
                        {
                            (record, isRecordValid) = annotationRecordOperator.Get(Convert.ToUInt64(index));
                        }
                        catch (Exception)
                        {
                            isRecordValid = false;
                        }

                        if (record == null)
                        {
                            record = new AnnotationRecord(false, 0, 0, 0, 0, false, false, null);
                        }

                        recordList.Add(record);
                        recordValidityList.Add(isRecordValid);
                    }
                }
            }
            catch (Exception)
            {
                return(recordList, recordValidityList);
            }

            return(recordList, recordValidityList);
        }
Exemple #3
0
 public void TestRead()
 {
     using (AnnotationRecordOperator annotationRecordOperator =
                new AnnotationRecordOperator("res.mat", DesiredAccess.Read, CreationDisposition.OpenAlways))
     {
         UInt64 numberOfRecords = annotationRecordOperator.GetNumberOfRecords();
         for (UInt64 index = 0; index < numberOfRecords; ++index)
         {
             int    id, x, y, w, h;
             bool   isLabeled, occlusion, outOfView;
             string path;
             Assert.IsTrue(annotationRecordOperator.Get(index, out id, out isLabeled, out x, out y, out w, out h,
                                                        out occlusion, out outOfView, out path));
         }
     }
 }
        private static void GenerateMatlabFile(IList <AnnotationRecord> records, string filePath)
        {
            using (AnnotationRecordOperator annotationRecordOperator
                       = new AnnotationRecordOperator(filePath, AnnotationRecordOperator.DesiredAccess.Write, AnnotationRecordOperator.CreationDisposition.CreateAlways))
            {
                int count = records.Count;
                annotationRecordOperator.Resize(Convert.ToUInt64(count));

                for (int index = 0; index < count; ++index)
                {
                    var record = records[index];

                    annotationRecordOperator.Set(Convert.ToUInt64(index), record);
                }
            }
        }
        public void UpdateMatlabFile()
        {
            if (_pendingUpdates.Count == 0)
            {
                return;
            }

            using (AnnotationRecordOperator annotationRecordOperator =
                       new AnnotationRecordOperator(GetMatFilePath(), AnnotationRecordOperator.DesiredAccess.Write,
                                                    AnnotationRecordOperator.CreationDisposition.OpenAlways))
            {
                foreach (var index in _pendingUpdates)
                {
                    var record = _annotationRecords[index];

                    annotationRecordOperator.Set(Convert.ToUInt32(index), record);
                }
            }

            _pendingUpdates.Clear();
        }