Example #1
0
        public void FeatureMatchTest(double ratio, int threshold, FeatureMatchType type)
        {
            var imageFolder = Path.GetFullPath(@".\_TestResources\CvMatchTest");
            var sourceImage = Path.Combine(imageFolder, "source.png");
            var testImage1  = Path.Combine(imageFolder, "test1.png");

            //Îļþ²âÊÔ
            var matchResult = CvMatch.FeatureMatch(sourceImage, testImage1, type, new FeatureMatchArgument()
            {
                Ratio           = ratio,
                RansacThreshold = (uint)threshold,
                ExtensionConfig = new Dictionary <string, object>()
                {
                    { MatchArgument.ConsoleOutput, true },
                    { MatchArgument.PreviewMatchResult, true }
                }
            });

            Assert.IsTrue(matchResult.Success && matchResult.MatchItems.Any());

            //Bitmap²âÊÔ
            using var sourceBitmap = new Bitmap(sourceImage);
            using var testBitmap1  = new Bitmap(testImage1);
            matchResult            = CvMatch.FeatureMatch(sourceImage, testImage1, type, new FeatureMatchArgument()
            {
                Ratio           = ratio,
                RansacThreshold = (uint)threshold,
                ExtensionConfig = new Dictionary <string, object>()
                {
                    { MatchArgument.ConsoleOutput, true },
                    { MatchArgument.PreviewMatchResult, true }
                }
            });
            Assert.IsTrue(matchResult.Success && matchResult.MatchItems.Any());
        }
Example #2
0
        /// <summary>
        ///     搜索控件
        /// </summary>
        /// <param name="matchResult"></param>
        /// <returns></returns>
        public bool Search(out FeatureMatchResult matchResult)
        {
            matchResult = null;
            var captor = CaptorFactory.GetCaptor();

            using var captureWindow = IsSearchScreen ? captor.CaptureScreen() : captor.CaptureWindow(_windowHandle);

            foreach (var searchMat in _searchMats)
            {
                matchResult = CvMatch.FeatureMatch(captureWindow, searchMat, FeatureMatchType.Sift, MatchArgument);
                if (matchResult.Success)
                {
                    return(true);
                }
            }

            return(false);
        }