public void SaveImage(ImageModelBase image, int personId)
        {
            var imageId       = PrepareNewId();
            var imageFileName = $"{LocalStorageUtility.PrepareImageName(imageId, personId)}" +
                                $".{RecognizerConfig.DefaultImageExtension}";

            using (var imageToSave = Image.FromStream(new MemoryStream(image.Data)))
            {
                imageToSave.Save(Path.Combine(RecognizerConfig.ImagesPath, imageFileName),
                                 ImageFormat.Jpeg);
            }
        }
示例#2
0
        public static double CalculateRatioResizingOfImage(ImageModelBase model)
        {
            double ratio = 1.0;

            // Figure out the ratio
            double ratioX = (double)model.ThumbnailWidth / (double)model.MasterFileWidth;
            double ratioY = (double)model.ThumbnailHeight / (double)model.MasterFileHeight;

            // Use whichever multiplier is smaller
            ratio = ratioX < ratioY ? ratioX : ratioY;

            return(ratio);
        }
示例#3
0
        public Image AddImage(ImageModelBase image, int personId)
        {
            image.PersonId = personId;
            var newImage = Context.Images.Add(new Image
            {
                Id          = image.Id,
                Data        = image.Data,
                PersonId    = image.PersonId,
                AddDateTime = DateTime.Now
            });

            Context.SaveChanges();

            return(newImage);
        }
        public ImageModelBase GetImage(int id)
        {
            var files        = Directory.GetFiles(RecognizerConfig.ImagesPath);
            var imageName    = files.SingleOrDefault(x => x.Contains($"i{id}_"));
            var imageNameTmp = imageName.Replace($"i{id}_p", "")
                               .Replace(RecognizerConfig.DefaultImageExtension, "")
                               .Replace(RecognizerConfig.ImagesPath, "");
            var resultString = Regex.Match(imageNameTmp, @"\d+").Value;
            var personId     = Convert.ToInt32(resultString);
            var data         = File.Open(imageName, FileMode.Open);
            var imageModel   = new ImageModelBase
            {
                Id       = id,
                PersonId = personId,
                Data     = ReadFully(data)
            };

            return(imageModel);
        }
示例#5
0
        public void SaveFace(PersonModelBase person, ImageModelBase image)
        {
            var possiblePerson = _personRepository.GetPerson(person.Name);
            int personId;

            if (possiblePerson != null)
            {
                personId  = possiblePerson.Id;
                person.Id = personId;
                _personRepository.EditPerson(possiblePerson.Id, new PersonModel(person));
            }
            else
            {
                var newPerson = _personRepository.AddPerson(person);
                personId = newPerson.Id;
            }

            _imageRepository.AddImage(image, personId);
        }
        public void SaveDetected()
        {
            var person = new PersonModelBase()
            {
                Name    = _controls.Name,
                Age     = Convert.ToInt32(_controls.Age),
                Address = _controls.Address,
                Details = _controls.Details
            };

            var image = new ImageModelBase()
            {
                Data = BitmapUtility.BitmapToByteArray(_controls.TheNewestFace)
            };

            try
            {
                if (_parameters.UseExplorer)
                {
                    _localStorageService.SaveFace(person, image);
                }
                else
                {
                    _databaseService.SaveFace(new PersonModel(person), new ImageModel(image));
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Wystąpił błąd podczas zapisu do bazy danych\r\n\r\n" + e);
            }

            _controls.KnownPeople = _parameters.UseExplorer
                ? _localStorageService.GetPeopleNames()
                : _databaseService.GetPeopleNames();
            _controls.StatusText  = StatusTypes.SaveCompleted.GetDesciption();
            _controls.IsNewUpdate = true;

            StatusBarUtility.ResestStatus(_controls);
        }
 public void SaveFace(PersonModelBase person, ImageModelBase image)
 {
     _personRepositoryLs.SavePerson(person, out var id);
     _imageRepositoryLs.SaveImage(image, id);
 }