Example #1
0
        public static FindMatchResult FindMatchInSource(MatchInput matchInput)
        {
            FindMatchResult matchResult = new FindMatchResult();
            long            matchTime; int inLiers, outLiers;
            string          MatchFolderPath, MatchFile, MatchAbsolutePath, MatchedFaceFile;

            MatchFolderPath = MatchFile = MatchedFaceFile = MatchAbsolutePath = "";

            //file folders assignment
            MatchFolderPath   = matchInput.WebFolderPath;
            MatchAbsolutePath = matchInput.FindInFile.DirectoryName + "\\" + "MatchFiles";


            using (Image <Gray, Byte> modelImage = new Image <Gray, byte>(matchInput.MatchFile.FullName))
                using (Image <Gray, Byte> observedImage = new Image <Gray, byte>(matchInput.FindInFile.FullName))
                {
                    Image <Bgr, byte> result = BruteForceMatcher.Draw(modelImage, observedImage, out matchTime, out inLiers, out outLiers);
                    //ImageViewer.Show(result, String.Format("Matched using {0} in {1} milliseconds", GpuInvoke.HasCuda ? "GPU" : "CPU", matchTime));
                    if (inLiers > matchInput.InlierThreshold)
                    {
                        matchResult.Matched = true;
                        MatchedFaceFile     = Guid.NewGuid().ToString();

                        bool exists = System.IO.Directory.Exists(MatchAbsolutePath);
                        if (!exists)
                        {
                            System.IO.Directory.CreateDirectory(MatchAbsolutePath);
                        }

                        result.Save(MatchAbsolutePath + "\\" + MatchedFaceFile + matchInput.FindInFile.Extension);
                    }
                    matchResult.Inliers         = inLiers;
                    matchResult.Outliers        = outLiers;
                    matchResult.FolderPath      = MatchFolderPath;
                    matchResult.AbsolutePath    = MatchAbsolutePath + "\\";
                    matchResult.MatchedFaceFile = MatchedFaceFile;
                }
            return(matchResult);
        }
Example #2
0
        static void Run(string[] args, bool verboseShow)
        {
            // Dependency Injection to reuse all stuff developed so far
            IKernel kernel = new StandardKernel();

            DependencyInjection(kernel);

            // service initializatons
            var _albumInstanceDetailSvc = kernel.Get <IAlbumInstanceDetailService>();
            var _albumInstanceSvc       = kernel.Get <IAlbumInstanceService>();
            var _memberSvc = kernel.Get <IMemberService>();

            //class variable intializations

            string MatchFolderPath, MatchFile;

            IEnumerable <UserAlbumInstanceDetail> batchPhotos = _albumInstanceDetailSvc.GetPhotosForBatchProcssing();

            Console.WriteLine("About to process {0} records", batchPhotos.Count().ToString());

            if (batchPhotos.Count() > 0)
            {
                if (verboseShow)
                {
                    Console.WriteLine("Total records retrieved for processing : {0}", batchPhotos.Count().ToString());
                }

                foreach (UserAlbumInstanceDetail batchPhoto in batchPhotos)
                {
                    long ticks = DateTime.Now.Ticks;
                    if (verboseShow)
                    {
                        Console.WriteLine("Ticks-{0} : Processig record AlbumInstanceKey : {1}, MmeberKey : {2}, FaceToFind : {3}....", ticks.ToString(), batchPhoto.UserAlbumInstanceKey, batchPhoto.MemberKey, batchPhoto.FaceImage);
                    }
                    UserAlbumInstance photoImage      = null;
                    Member            member          = null;
                    FindMatchResult   findMatchResult = null;

                    MatchFolderPath = MatchFile = "";
                    photoImage      = _albumInstanceSvc.FindAlbumInstance(batchPhoto.UserAlbumInstanceKey);
                    member          = _memberSvc.FindMember(batchPhoto.MemberKey);

                    MatchInput matchInput = new MatchInput();
                    matchInput.FindInFile    = new FileInfo(photoImage.AbsolutePath);
                    matchInput.MatchFile     = new FileInfo(member.AbsoultePath + batchPhoto.FaceImage);
                    matchInput.WebFolderPath = photoImage.FolderPath + "MatchFiles";

                    if (verboseShow)
                    {
                        Console.WriteLine(JsonConvert.SerializeObject(matchInput, Formatting.Indented));
                    }
                    try
                    {
                        findMatchResult = BruteForceMatcher.FindMatchInSource(matchInput);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error processing AlbumInstanceKey : {0}", batchPhoto.UserAlbumInstanceKey);
                        Console.Error.WriteLine("Exception");
                        Console.Error.WriteLine(e.Message);
                        Console.Error.WriteLine("Inner Exception");
                        Console.Error.WriteLine(e.InnerException.ToString());
                    }
                    finally
                    {
                        if (findMatchResult != null)
                        {
                            if (findMatchResult.Matched)
                            {
                                batchPhoto.FaceMatchFile = findMatchResult.MatchedFaceFile;
                            }
                            batchPhoto.Inliers      = findMatchResult.Inliers;
                            batchPhoto.OpenCVMethod = findMatchResult.OpenCvMethod;
                            batchPhoto.FaceFound    = findMatchResult.Matched;
                            batchPhoto.FolderPath   = findMatchResult.FolderPath;
                            batchPhoto.AbsolutePath = findMatchResult.AbsolutePath;
                            batchPhoto.ProcessedOn  = DateTime.Now;
                            batchPhoto.Processed    = true;

                            _albumInstanceDetailSvc.Update(batchPhoto);

                            if (verboseShow)
                            {
                                Console.WriteLine("Ticks-{0} : Processed successfully AlbumInstanceKey : {1}, MmeberKey : {2}, FaceToFind : {3}....", ticks.ToString(), batchPhoto.UserAlbumInstanceKey, batchPhoto.MemberKey, batchPhoto.FaceImage);
                            }
                        }
                    }
                }
            }
        }