Exemplo n.º 1
0
 public bool SetSetting(int id)
 {
     var db = new FacesDBDataContext(_connectionString);
     var temp = db.DetectionSettings.Where(x => x.SettingID == id).SingleOrDefault();
     if (temp != null) _currentSetting = temp;
     return temp != null;
 }
Exemplo n.º 2
0
 public void InitCaches()
 {
     var db = new FacesDBDataContext(_connectionString);
     _faceUKeyLookup = db.Faces.ToDictionary(x => x.FaceUKey, x => (api.Face) new FaceImpl(x, _m, null));
     var query =  (from f in db.Faces join p in db.Persons on f.PersonID equals p.PersonID select new { f, p });
     _Faces = new Dictionary<api.Face,api.Person>();
     Dictionary<int, api.Person> persons = new Dictionary<int,api.Person>();
     foreach (var x in query) {
         // todo; build pers dic at same time...
         api.Person person = null;
         if (!persons.TryGetValue(x.p.PersonID, out person))
         {
             person = (api.Person)new PersonImpl(x.p.FirstName, x.p.LastName, x.p.PersonID);
             persons.Add(person.Id, person);
         }
         api.Face thisFace = _faceUKeyLookup[x.f.FaceUKey];
         thisFace.Person = person;
         _Faces.Add(thisFace, person);
     }
     _Persons = _Faces.GroupBy(x => x.Value).ToDictionary(x => x.Key, x => x.Select(y=>y.Key).ToList());
     _allPersonsLookup = persons;
     foreach (var pers in db.Persons) // add in other persons that don't have faces.
     {
         if (!_allPersonsLookup.ContainsKey(pers.PersonID))
             _allPersonsLookup.Add(pers.PersonID, (api.Person)new PersonImpl(pers.FirstName, pers.LastName, pers.PersonID));
     }
     _PicturesToFaces = db.Faces
         .ToLookup(x => x.PictureID, x => _faceUKeyLookup[x.FaceUKey]);
 }
Exemplo n.º 3
0
 public DBManager(String connectionString, Manager m)
 {
     _connectionString = connectionString;
     _m = m;
     var db = new FacesDBDataContext(_connectionString);
     var currentSettingID = db.DetectionSettings.Max(x => x.SettingID);
     CurrentSetting = db.DetectionSettings.Where(x => x.SettingID == currentSettingID).Single();
 }
Exemplo n.º 4
0
 public void UpdateFace(int faceUKey, bool check)
 {
     var db = new FacesDBDataContext(_connectionString);
     var face = db.Faces.Where(x => x.FaceUKey == faceUKey).Single();
     face.Selected = check;
     db.SubmitChanges();
     _faceUKeyLookup[faceUKey].Selected = check;
 }
Exemplo n.º 5
0
        public Dictionary<int, String> GetPicturePaths(bool showMarkup, bool showPicsWithFaces, bool showPicsWithoutFaces)
        {
            var db = new FacesDBDataContext(_connectionString);
            var pIds = db.Pictures.Select(x => x.PictureID).ToList();

            HashSet<int> faceLookup = new HashSet<int>(db.Faces.Select(x => x.PictureID).Distinct().ToList());

            var paths = pIds.Where(pid => (!faceLookup.Contains(pid) && showPicsWithoutFaces) ||
                                       (faceLookup.Contains(pid) && showPicsWithFaces))
                            .ToDictionary(pid => pid, pid => _m.GetPicturePath(pid, showMarkup));

            return paths;
        }
Exemplo n.º 6
0
 internal void SaveMatchResults(List<MatchRun> results)
 {
     var db = new FacesDBDataContext(_connectionString);
     foreach (var res in results)
     {
         res.MatchRunID = db.GetID("MatchRuns", 1);
         db.MatchRuns.InsertOnSubmit(res);
     }
     db.SubmitChanges();
     System.Diagnostics.Debug.WriteLine("Inserting " + results.Count() + " records.");
 }
Exemplo n.º 7
0
 public Dictionary<String, int> GetMethodologyNames()
 {
     var db = new FacesDBDataContext(_connectionString);
     return db.MatchingMethodologies.OrderBy(x => x.MatchingMethodologyID)
                 .ToDictionary(x => x.Description, x => x.MatchingMethodologyID);
 }
Exemplo n.º 8
0
 public List<String> GetAvailableFaceSetNames()
 {
     var db = new FacesDBDataContext(_connectionString);
     return db.FaceSets.OrderBy(x => x.Date).Select(x => x.Name).ToList();
 }
Exemplo n.º 9
0
 public List<String> GetDetectionSetNames()
 {
     var db = new FacesDBDataContext(_connectionString);
     return db.DetectionSettings.OrderBy(x => x.TimeStamp).Select(x => x.Description).ToList();
 }
Exemplo n.º 10
0
        public void Import(List<Person> newPersons, List<Face> newFaces, String name)
        {
            var db = new FacesDBDataContext(_connectionString);

            db.Persons.InsertAllOnSubmit(newPersons);
            db.Faces.InsertAllOnSubmit(newFaces);
            CreateFaceSet(db, name, newFaces);
            db.SubmitChanges();
            InitCaches();
        }
Exemplo n.º 11
0
        public int CreateTrainingRun
            (String name, String trainingDropZone, int numDimensions, double threshhold, String faceSet,
            string detectionSettingName, int rows, int cols, Manager.ImageMode mode, Manager.Model model)
        {
            var db = new FacesDBDataContext(_connectionString);
            int faceSetID = db.FaceSets.Where(x => x.Name.Equals(faceSet)).Single().FaceSetID;
            int detectionSettingID = db.DetectionSettings.Where(x => x.Description.Equals(detectionSettingName)).Single().SettingID;
            List<Face> tFaces = (from fsm in db.FaceSetMappings
                                 join f in db.Faces on fsm.FaceUKey equals f.FaceUKey
                                 where fsm.FaceSetID == faceSetID
                                 select f).ToList();

            String fileNameRoot = trainingDropZone + "\\" + name;
            String csvFilePath = fileNameRoot + ".csv";
            String firstFacePath = null;
            using (StreamWriter writer = new StreamWriter(csvFilePath))
            {
                foreach (var f in tFaces)
                {
                    String facePath = _m.GetFacePath(f.PictureID, f.FaceID, false, (api.FaceState)f.FaceStateID);
                    if (firstFacePath == null)
                        firstFacePath = facePath;
                    int? personId = f.PersonID;
                    if (personId == null) personId = -1;
                    String line = facePath + ";" + personId;
                    writer.WriteLine(line);
                }
                writer.Flush(); writer.Close();
            }
            if (rows == 0)
            {
                var img = System.Drawing.Image.FromFile(firstFacePath);
                rows = img.Height; cols = img.Width;
            }

            System.Diagnostics.Debug.WriteLine("CSV file written to " + csvFilePath);
            int realNComponents = CAPI.TrainModel(fileNameRoot, false, numDimensions, rows, cols, (int) mode, (int) model);

            int nextId = db.GetID("TrainingRuns", 1);
            db.TrainingRuns.InsertOnSubmit(new TrainingRun()
            {
                Date = DateTime.Now,
                Name = name,
                TrainingRunID = nextId,
                NumDimensions = realNComponents,
                Threshold = threshhold,
                ImageModeID = (int)mode,
                FaceSetID = faceSetID,
                ScannerSettingID = detectionSettingID,
                Rows = rows,
                Cols = cols,
                ModelID = (int)model
            });
            db.SubmitChanges();
            return tFaces.Count();
        }
Exemplo n.º 12
0
 public List<int> GetFaceSet(String name)
 {
     var db = new FacesDBDataContext(_connectionString);
     int faceSetID = db.FaceSets.Where(x => x.Name.Equals(name)).Single().FaceSetID;
     List<Face> tFaces = (from fsm in db.FaceSetMappings
                          join f in db.Faces on fsm.FaceUKey equals f.FaceUKey
                          where fsm.FaceSetID == faceSetID
                          select f).ToList();
     return tFaces.Select(x => x.FaceUKey).ToList();
 }
Exemplo n.º 13
0
 public void AssignPersonToFace(int personId, int pictureId, int faceId)
 {
     var db = new FacesDBDataContext(_connectionString);
     var face = db.Faces.Where(x => x.PictureID == pictureId &&
         x.FaceID == faceId).Single();
     face.PersonID = personId;
     db.SubmitChanges();
     InitCaches();       // todo: don't be so lazy.
 }
Exemplo n.º 14
0
        private void CreateFaceSet(FacesDBDataContext db, String name, List<int> faces)
        {
            int nextId = db.GetID("FaceSets", 1);
            int nextMappingId = db.GetID("FaceSetMappings", faces.Count());
            db.FaceSets.InsertOnSubmit(new FaceSet() { Date = DateTime.Now, FaceSetID = nextId, Name = name });
            foreach (var f in faces)
                db.FaceSetMappings.InsertOnSubmit(
                    new FaceSetMapping() { FaceSetID = nextId, FaceSetMappingID = nextMappingId++, FaceUKey = f});

        }
Exemplo n.º 15
0
 private void CreateFaceSet(FacesDBDataContext db, String name, List<Face> faces)
 {
     CreateFaceSet(db, name, faces.Select(x => x.FaceUKey).ToList());
 }
Exemplo n.º 16
0
 public void CreateFaceSet(String name, List<int> fukeys)
 {
     var db = new FacesDBDataContext(_connectionString);
     CreateFaceSet(db, name, fukeys);
     db.SubmitChanges();
     InitCaches();
 }
Exemplo n.º 17
0
 public TrainingRunInfo LoadSavedTrainingRun(String name)
 {
     var db = new FacesDBDataContext(_connectionString);
     var rec = (from tr in db.TrainingRuns 
                join fs in db.FaceSets on tr.FaceSetID equals fs.FaceSetID
                join ds in db.DetectionSettings on tr.ScannerSettingID equals ds.SettingID
                where tr.Name == name
                select new { tr, fs, ds}).SingleOrDefault();
     return rec == null ? null : new TrainingRunInfo() { 
         ID = rec.tr.TrainingRunID,
         Rows = rec.tr.Rows, Cols = rec.tr.Cols, NumDimensions = rec.tr.NumDimensions, Threshold = rec.tr.Threshold,
         Name = name, DetectionSettingsName = rec.ds.Description, FaceSetName=rec.fs.Name,
         ImageModeID = rec.tr.ImageModeID
     };
 }
Exemplo n.º 18
0
 // TODO: Cache and refresh these...
 public List<String> GetTrainingRunNames()
 {
     var db = new FacesDBDataContext(_connectionString);
     return db.TrainingRuns.OrderBy(x => x.Date).Select(x => x.Name).ToList();
 }
Exemplo n.º 19
0
        public int AddPerson(String firstName, String lastName) { 
            var db = new FacesDBDataContext(_connectionString);

            if (db.Persons
                    .Where(x => x.FirstName.ToUpper() == firstName.ToUpper() && x.LastName.ToUpper() == lastName.ToUpper())
                    .Count() > 0)
                throw new ApplicationException("That name already exists.");

            int id = db.GetID("Persons", 1);
            var person = new Person()
            {
                PersonID = id,
                FirstName = firstName.Trim(),
                LastName = lastName.Trim()
            };
            db.Persons.InsertOnSubmit(person);
            db.SubmitChanges();
            _Persons.Add((api.Person) new PersonImpl(firstName.Trim(), lastName.Trim(), id), new List<api.Face>());
            return id;
        }
Exemplo n.º 20
0
        public int GetID(String table)
        {
            Tuple<int /* last */, int /* remaining */> innerDic = null;
            int id = 0; int remaining = 0;
            if (_idCache.TryGetValue(table, out innerDic))
            {
                id = innerDic.Item1; remaining = innerDic.Item2;
            }
            else
                innerDic = new Tuple<int, int>(0, 0);

            if (innerDic.Item2 == 0)
            {
                var db = new FacesDBDataContext(_connectionString);
                id = db.GetID(table, 20);
                remaining = 20;
            }
            _idCache[table] = new Tuple<int, int>(id+1, remaining-1);
            return id;
        }