Esempio n. 1
0
 // Yes singleton anti-pattern
 internal static ImageCache getImageCache(String tempPathRoot)
 {
     if (_imageCache == null)
     {
         _imageCache = new ImageCache(tempPathRoot);
         _imageCachePathRoot = tempPathRoot;
     }
     if (_imageCachePathRoot != tempPathRoot)
         throw new ApplicationException("Programming Error");
     return _imageCache;
 }
Esempio n. 2
0
        public FacesLite(String modelName, String connectionString, String imageCachePath, StorageSystem storageSystem)
        {
            if (_firstCall) throw new ApplicationException("Programming Error: 2 instances of FacesLite!");
            _firstCall = true;

            _imageCache = ImageCache.getImageCache(imageCachePath);
            _storageSystem = storageSystem;

            _modelName = modelName;
            _connectionString = connectionString;
        }
Esempio n. 3
0
        public void SaveCoordinates(String modelPath, String imageStorage)
        {
            // loads from disk, saves to DB.
            var db = new DataClasses1DataContext(_connectionString);
            var aModel = db.TrainingRuns.Where(x => x.Name.Equals(_modelName)).Single();

            _dimensions = CAPI.TrainModel(modelPath + _modelName, true, -1, aModel.Rows, aModel.Cols, (int)CAPI.ImageMode.Undefined, (int)_modelType);
            if (aModel.Dimensions != _dimensions) throw new ApplicationException("Number of dimensions in db dont match number of dimensions in model flat file.");

            var faceCoords = new Dictionary<int, List<double>>();
            double[] coords = new double[_dimensions];
            System.Diagnostics.Debug.WriteLine("Start saving coords");
            var ic = new ImageCache(imageStorage);      // non S3 version
            foreach (String file in Directory.GetFiles(imageStorage, "*.jpg"))
            {
                CAPI.GetCoordinates(file, coords, aModel.Rows, aModel.Cols, (int) CAPI.ImageMode.Histogram);
                int ukey = int.Parse(Path.GetFileNameWithoutExtension(file));

                // store the greyscale for later upload to S3 and display in the carousel
                String histFacePath = ic.GetNormFacePath(ukey, aModel.Rows*2, aModel.Cols*2);     // TODO: maybe we can store larger versions?

                for (int i = 0; i < _dimensions; i++)
                {
                    db.Coordinates.InsertOnSubmit(new Coordinate()
                    {
                        TrainingRunID = aModel.TrainingRunID,
                        Dimension = i,
                        FaceUKey = ukey,
                        Coordinate1 = coords[i]
                    });
                }
                db.SubmitChanges();
                System.Diagnostics.Debug.WriteLine("Storing " + ukey);
            }
            System.Diagnostics.Debug.WriteLine("Done saving coords");

        }