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; }
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."); }
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}); }
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(); }
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; }