Beispiel #1
0
        public static void testCall(string checkImage, string SearchInImage)
        {
            long matchTime;
            int  InlierThreshold = 10;
            int  outlier;

            using (Image <Gray, Byte> modelImage = new Image <Gray, byte>(checkImage))
                using (Image <Gray, Byte> observedImage = new Image <Gray, byte>(SearchInImage))
                //using (Image<Gray, Byte> observedImage = new Image<Gray, byte>("NoBoy3.jpg"))
                {
                    //Image<Bgr, byte> result = DrawMatches.Draw(modelImage, observedImage, out matchTime);
                    Image <Bgr, byte> result = BruteForceMatcher.Draw(modelImage, observedImage, out matchTime, out InlierThreshold, out outlier);
                    //ImageViewer.Show(result, String.Format("Matched using {0} in {1} milliseconds", GpuInvoke.HasCuda ? "GPU" : "CPU", matchTime));
                    Console.WriteLine("Matched using {0} in {1} milliseconds", GpuInvoke.HasCuda ? "GPU" : "CPU", matchTime);
                }
        }
        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);
        }