コード例 #1
0
        private bool IsEqualFaceDescriptros(FaceEncoding uploadedImageEncoding, PhotoFaceDescriptor databasePhoto)
        {
            bool result = false;
            // определяем порог допустимой точности
            const double precision = 0.6d;

            if (databasePhoto != null)
            {
                FaceEncoding imageEncodingToCompare =
                    JsonConvert.DeserializeObject <FaceEncoding>(databasePhoto.Descriptor);
                result = FaceRecognition.CompareFace(
                    uploadedImageEncoding, imageEncodingToCompare, precision);
            }

            return(result);
        }
コード例 #2
0
        public async Task PopulateDescriptors()
        {
            var wantedPhotosFolderPath = String.Concat(
                _appEnvironment.WebRootPath, "\\WantedFacePhotos\\", "photoCollection");

            if (!Directory.Exists(wantedPhotosFolderPath))
            {
                Directory.CreateDirectory(wantedPhotosFolderPath);
            }

            var    wantedFacePhotos = _context.LoadPhotoFilesTest();
            string filePath         = "";

            foreach (var photo in wantedFacePhotos)
            {
                string photoName = string.Concat("\\photo.", photo.Mime);
                filePath = string.Concat(wantedPhotosFolderPath, photoName);
                await System.IO.File.WriteAllBytesAsync(filePath, photo.Photo);

                Image photoImage = FaceRecognition.LoadImageFile(filePath);
                IEnumerable <Location> faceLocations = _fr.FaceLocations(photoImage);
                FaceEncoding           faceEncoding  = CreateImageDescriptor(filePath);
                string encodingSerialized            = faceEncoding != null
                    ? JsonConvert.SerializeObject(faceEncoding)
                    : "";

                PhotoFaceDescriptor desc;

                if (!string.IsNullOrEmpty(encodingSerialized))
                {
                    desc = new PhotoFaceDescriptor()
                    {
                        Id          = Guid.NewGuid(),
                        PhotoFaceId = photo.PhotoId,
                        Descriptor  = encodingSerialized
                    };

                    _context.PhotoFaceDescriptors.Add(desc);
                    _context.SaveChanges();
                }

                System.IO.File.Delete(filePath);
            }
        }