Exemplo n.º 1
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);
                            }
                        }
                    }
                }
            }
        }