Esempio n. 1
0
    public RGBChannels ApplyFeatureDetection(RGBChannels image, HarrisCornerDetection type, double threshold = 0.0000000002)
    {
        if (featureDetector == null)
        {
            featureDetector = FeatureDetector.Instance();
        }
        RGBChannels       output = image;
        List <HarrisNode> maximas;

        switch (type)
        {
        case HarrisCornerDetection.fValues:
            output = featureDetector.HarrisCornerDetection(image);
            break;

        case HarrisCornerDetection.LokalMaxima9x9:
            output  = featureDetector.HarrisCornerDetection(image);
            maximas = featureDetector.GetMaximas(9, 9, output);
            output  = featureDetector.GetColorFromFValue(output, maximas);
            break;

        case HarrisCornerDetection.fValues4bin:
            output  = featureDetector.HarrisCornerDetection(image);
            maximas = featureDetector.GetMaximas(9, 9, output);
            maximas = featureDetector.ThresholdMaximas(maximas, threshold);
            RGBChannels orientation = filterManipulator.GradientOrientation(image);
            maximas = featureDetector.GetOrientationBin(orientation, maximas);
            output  = featureDetector.GetColorFromOrientation(output, maximas);

            break;
        }

        return(output);
    }
        // Use this for initialization
        void Start()
        {
            Texture2D imgTexture = Resources.Load("detect_blob") as Texture2D;

            Mat imgMat = new Mat(imgTexture.height, imgTexture.width, CvType.CV_8UC1);

            Utils.texture2DToMat(imgTexture, imgMat);
            Debug.Log("imgMat dst ToString " + imgMat.ToString());

            Mat outImgMat = new Mat();

            FeatureDetector blobDetector = FeatureDetector.create(FeatureDetector.SIMPLEBLOB);

            blobDetector.read(Utils.getFilePath("blobparams.yml"));


            MatOfKeyPoint keypoints = new MatOfKeyPoint();

            blobDetector.detect(imgMat, keypoints);
            Features2d.drawKeypoints(imgMat, keypoints, outImgMat);


            Texture2D texture = new Texture2D(outImgMat.cols(), outImgMat.rows(), TextureFormat.RGBA32, false);

            Utils.matToTexture2D(outImgMat, texture);

            gameObject.GetComponent <Renderer> ().material.mainTexture = texture;
        }
Esempio n. 3
0
        public static ProcessStartInfo Create(
            string name,
            string args,
            string?workingDirectory = null,
            bool captureOutput      = true,
            string?windowsName      = null,
            string?windowsArgs      = null,
            Action <IDictionary <string, string> >?configureEnvironment = null)
        {
            var isWindows = FeatureDetector.IsWindows();

            var startInfo = new ProcessStartInfo
            {
                FileName               = isWindows ? (windowsName ?? name) : name,
                Arguments              = isWindows ? (windowsArgs ?? args) : args,
                WorkingDirectory       = workingDirectory ?? Environment.CurrentDirectory,
                UseShellExecute        = false,
                RedirectStandardError  = captureOutput,
                RedirectStandardOutput = captureOutput,
                //On windows dotnet core seams to set the codepage to 850
                //see: https://github.com/dotnet/runtime/issues/17849#issuecomment-353612399
                StandardOutputEncoding = isWindows
                    ? Encoding.GetEncoding(850) //DOS-Latin-1
                    : Encoding.Default,
            };

            configureEnvironment?.Invoke(startInfo.Environment);

            return(startInfo);
        }
    void InitBlobDetector()
    {
        // Try to create the blob detector.
        blobDetector = FeatureDetector.create(
            FeatureDetector.SIMPLEBLOB);
        if (blobDetector == null)
        {
            Debug.LogError(
                "Unable to create blob detector");
            Destroy(this);
            return;
        }

        // The blob detector parameters must be put inta a yaml file for unity
        string blobDetectorParams = @"%YAML:1.0
thresholdStep: 10.0
minThreshold: 50.0
maxThreshold: 220.0
minRepeatability: 2
minDistBetweenBlobs: 10.0
filterByColor: False
blobColor: 0
filterByArea: True
minArea: 50.0
maxArea: 5000.0
filterByCircularity: True
minCircularity: 0.8
maxCircularity: 3.4028234663852886e+38
filterByInertia: False
minInertiaRatio: 0.1
maxInertiaRatio: 3.4028234663852886e+38
filterByConvexity: False
minConvexity: 0.95
maxConvexity: 3.4028234663852886e+38
";

        // Try to write the blob detector's parameters
        // to a temporary file.
        string path = Application.persistentDataPath +
                      "/blobDetectorParams.yaml";

        File.WriteAllText(path, blobDetectorParams);
        if (!File.Exists(path))
        {
            Debug.LogError(
                "Unable to write blob " +
                "detector's parameters to " +
                path);
            Destroy(this);
            return;
        }

        // Read the blob detector's parameters from the
        // temporary file.
        blobDetector.read(path);

        // Delete the temporary file.
        File.Delete(path);
    }
Esempio n. 5
0
        // Use this for initialization
        void Start()
        {
            Texture2D imgTexture = Resources.Load("lena") as Texture2D;

            Mat img1Mat = new Mat(imgTexture.height, imgTexture.width, CvType.CV_8UC3);

            Utils.texture2DToMat(imgTexture, img1Mat);
            Debug.Log("img1Mat dst ToString " + img1Mat.ToString());

            Mat img2Mat = new Mat(imgTexture.height, imgTexture.width, CvType.CV_8UC3);

            Utils.texture2DToMat(imgTexture, img2Mat);
            Debug.Log("img2Mat dst ToString " + img2Mat.ToString());



            float angle = UnityEngine.Random.Range(0, 360), scale = 1.0f;

            Point center = new Point(img2Mat.cols() * 0.5f, img2Mat.rows() * 0.5f);

            Mat affine_matrix = Imgproc.getRotationMatrix2D(center, angle, scale);

            Imgproc.warpAffine(img1Mat, img2Mat, affine_matrix, img2Mat.size());


            FeatureDetector     detector  = FeatureDetector.create(FeatureDetector.ORB);
            DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);

            MatOfKeyPoint keypoints1   = new MatOfKeyPoint();
            Mat           descriptors1 = new Mat();

            detector.detect(img1Mat, keypoints1);
            extractor.compute(img1Mat, keypoints1, descriptors1);

            MatOfKeyPoint keypoints2   = new MatOfKeyPoint();
            Mat           descriptors2 = new Mat();

            detector.detect(img2Mat, keypoints2);
            extractor.compute(img2Mat, keypoints2, descriptors2);


            DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);
            MatOfDMatch       matches = new MatOfDMatch();

            matcher.match(descriptors1, descriptors2, matches);


            Mat resultImg = new Mat();

            Features2d.drawMatches(img1Mat, keypoints1, img2Mat, keypoints2, matches, resultImg);



            Texture2D texture = new Texture2D(resultImg.cols(), resultImg.rows(), TextureFormat.RGBA32, false);

            Utils.matToTexture2D(resultImg, texture);

            gameObject.GetComponent <Renderer> ().material.mainTexture = texture;
        }
Esempio n. 6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            adapter = new TabsAdapter(this, SupportFragmentManager);
            pager   = FindViewById <ViewPager>(Resource.Id.viewpager);
            var tabs = FindViewById <TabLayout>(Resource.Id.tabs);

            pager.Adapter = adapter;
            tabs.SetupWithViewPager(pager);
            pager.OffscreenPageLimit = 3;

            pager.PageSelected += (sender, args) =>
            {
                var fragment = adapter.InstantiateItem(pager, args.Position) as IFragmentVisible;

                fragment?.BecameVisible();
            };

            Toolbar.MenuItemClick += (sender, e) =>
            {
                var intent = new Intent(this, typeof(AddItemActivity));;
                StartActivity(intent);
            };

            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);

            var src         = new Mat[2];
            var dst         = new Mat[2];
            var keyPoints1  = new MatOfKeyPoint();
            var keyPoints2  = new MatOfKeyPoint();
            var descripter1 = new Mat();
            var descripter2 = new Mat();
            var dmatch      = new MatOfDMatch();
            var output      = new Mat();

            src[0] = Imgcodecs.Imread("path/to/source/1.png");
            src[1] = Imgcodecs.Imread("path/to/source/2.png");
            dst[0] = new Mat();
            dst[1] = new Mat();
            Imgproc.CvtColor(src[0], dst[0], Imgproc.COLORBayerGR2GRAY);
            Imgproc.CvtColor(src[1], dst[1], Imgproc.COLORBayerGR2GRAY);

            var akaze    = FeatureDetector.Create(FeatureDetector.Akaze);
            var executor = DescriptorExtractor.Create(DescriptorExtractor.Akaze);

            akaze.Detect(dst[0], keyPoints1);
            akaze.Detect(dst[1], keyPoints2);

            executor.Compute(dst[0], keyPoints1, descripter1);
            executor.Compute(dst[1], keyPoints2, descripter2);

            var matcher = DescriptorMatcher.Create(DescriptorMatcher.BruteforceHamming);

            matcher.Match(descripter1, descripter2, dmatch);

            Features2d.DrawMatches(src[0], keyPoints1, src[1], keyPoints2, dmatch, output);
        }
Esempio n. 7
0
        public void LoadFeaturesFromAssemblyMetadata_Does_Not_Load_Feature_If_Feature_Does_Not_Exist_In_Assembly()
        {
            var featureDetector    = new FeatureDetector(ParsedFeatureConfigSetupFixture.FeatureConfigWithNonexistentFeature);
            var loadedFeatureNames = featureDetector.LoadedFeatureSet.AllFeatures.Select(feature => feature.Name).ToList();

            CollectionAssert.DoesNotContain(loadedFeatureNames, "NonExistentFeature");
            CollectionAssert.Contains(loadedFeatureNames, "AspNetWebApiFeature");
        }
Esempio n. 8
0
        public void FeatureDetector_Loads_Features_In_Specified_Config()
        {
            var featureConfig    = Path.Combine(TestProjectDirectory, "Examples", "Input", "EntityFramework_config_features.json");
            var featureDetector  = new FeatureDetector(featureConfig);
            var loadedFeatureSet = featureDetector.LoadedFeatureSet;

            Assert.IsEmpty(loadedFeatureSet.CompiledFeatures);
            Assert.True(loadedFeatureSet.ConfiguredFeatures.Count == 9);
        }
Esempio n. 9
0
        public void DownloadTestProjects()
        {
            _tempDirName = Path.Combine("Projects", "TempFD");
            _tempBaseDir = Path.Combine(TestUtils.GetTstPath(), _tempDirName);
            var tempDownloadDir = Path.Combine(_tempBaseDir, "d");

            // Download test solutions
            DownloadTestProjects(tempDownloadDir);

            // Get directory of each solution
            var tempCoreMvcSolutionDir                 = GetSolutionDir(tempDownloadDir, CoreMvcSolutionName);
            var tempCoreWebApiSolutionDir              = GetSolutionDir(tempDownloadDir, CoreWebApiSolutionName);
            var tempEfSolutionDir                      = GetSolutionDir(tempDownloadDir, EfSolutionName);
            var tempMvcSolutionDir                     = GetSolutionDir(tempDownloadDir, MvcSolutionName);
            var tempWebApiSolutionDir                  = GetSolutionDir(tempDownloadDir, WebApiSolutionName);
            var tempWebClassLibrarySolutionDir         = GetSolutionDir(tempDownloadDir, WebClassLibrarySolutionName);
            var tempWindowsAuthenticationSolutionDir   = GetSolutionDir(tempDownloadDir, WindowsAuthenticationSolutionName);
            var tempFormsAuthenticationSolutionDir     = GetSolutionDir(tempDownloadDir, FormsAuthenticationSolutionName);
            var tempFederatedAuthenticationSolutionDir = GetSolutionDir(tempDownloadDir, FederatedAuthenticationSolutionName);

            // Copy solutions to a directory with a shorter path
            var destDir = "dest";

            _targetDir = Path.Combine(_tempBaseDir, destDir);
            TestUtils.CopyDirectory(tempCoreMvcSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _coreMvcDir)));
            TestUtils.CopyDirectory(tempCoreWebApiSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _coreWebApiDir)));
            TestUtils.CopyDirectory(tempEfSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _efDir)));
            TestUtils.CopyDirectory(tempMvcSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _mvcDir)));
            TestUtils.CopyDirectory(tempWebApiSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _webApiDir)));
            TestUtils.CopyDirectory(tempWebClassLibrarySolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _webClassLibraryDir)));
            TestUtils.CopyDirectory(tempWindowsAuthenticationSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _windowsAuthenticationDir)));
            TestUtils.CopyDirectory(tempFormsAuthenticationSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _formsAuthenticationDir)));
            TestUtils.CopyDirectory(tempFederatedAuthenticationSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _federatedAuthenticationDir)));

            // Run source code analysis
            CoreMvcAnalyzerResults                 = AnalyzerResultsFactory.GetAnalyzerResults(CoreMvcSolutionPath);
            CoreWebApiAnalyzerResults              = AnalyzerResultsFactory.GetAnalyzerResults(CoreWebApiSolutionPath);
            EfAnalyzerResults                      = AnalyzerResultsFactory.GetAnalyzerResults(EfSolutionPath);
            MvcAnalyzerResults                     = AnalyzerResultsFactory.GetAnalyzerResults(MvcSolutionPath);
            WebApiAnalyzerResults                  = AnalyzerResultsFactory.GetAnalyzerResults(WebApiSolutionPath);
            WebClassLibraryAnalyzerResults         = AnalyzerResultsFactory.GetAnalyzerResults(WebClassLibrarySolutionPath);
            WindowsAuthenticationAnalyzerResults   = AnalyzerResultsFactory.GetAnalyzerResults(WindowsAuthenticationSolutionPath);
            FormsAuthenticationAnalyzerResults     = AnalyzerResultsFactory.GetAnalyzerResults(FormsAuthenticationSolutionPath);
            FederatedAuthenticationAnalyzerResults = AnalyzerResultsFactory.GetAnalyzerResults(FederatedAuthenticationSolutionPath);

            // Detect features in each solution
            FeatureDetector = new FeatureDetector(ConfigFile);
            CoreMvcFeatureDetectionResult                 = FeatureDetector.DetectFeaturesInProjects(CoreMvcAnalyzerResults)[CoreMvcProjectPath];
            CoreWebApiFeatureDetectionResult              = FeatureDetector.DetectFeaturesInProjects(CoreWebApiAnalyzerResults)[CoreWebApiProjectPath];
            Ef6FeatureDetectionResult                     = FeatureDetector.DetectFeaturesInProjects(EfAnalyzerResults)[Ef6ProjectPath];
            MvcFeatureDetectionResult                     = FeatureDetector.DetectFeaturesInProjects(MvcAnalyzerResults)[MvcProjectPath];
            WebApiFeatureDetectionResult                  = FeatureDetector.DetectFeaturesInProjects(WebApiAnalyzerResults)[WebApiProjectPath];
            WebClassLibraryFeatureDetectionResult         = FeatureDetector.DetectFeaturesInProjects(WebClassLibraryAnalyzerResults)[WebClassLibraryProjectPath];
            WindowsAuthenticationFeatureDetectionResult   = FeatureDetector.DetectFeaturesInProjects(WindowsAuthenticationAnalyzerResults)[WindowsAuthenticationProjectPath];
            FormsAuthenticationFeatureDetectionResult     = FeatureDetector.DetectFeaturesInProjects(FormsAuthenticationAnalyzerResults)[FormsAuthenticationProjectPath];
            FederatedAuthenticationFeatureDetectionResult = FeatureDetector.DetectFeaturesInProjects(FederatedAuthenticationAnalyzerResults)[FederatedAuthenticationProjectPath];
        }
Esempio n. 10
0
        public void FeatureDetector_Loads_Features_In_Specified_Config()
        {
            var featureConfig    = Path.Combine(TestProjectDirectory, "Examples", "Templates", "ProjectType_code_features.json");
            var featureDetector  = new FeatureDetector(featureConfig);
            var loadedFeatureSet = featureDetector.LoadedFeatureSet;

            Assert.IsEmpty(loadedFeatureSet.ConfiguredFeatures);
            Assert.True(loadedFeatureSet.CompiledFeatures.Count == 3);
        }
        public void SetUp()
        {
            var analyzerResult = TestProjectsSetupFixture.EfAnalyzerResults.First(a =>
                                                                                  a.ProjectResult.ProjectFilePath == TestProjectsSetupFixture.Ef6ProjectPath);

            var featureDetector = new FeatureDetector(ConfigFile);

            _featureDetectionResult = featureDetector.DetectFeaturesInProject(analyzerResult);
        }
Esempio n. 12
0
        private void InitRules(List <PortCoreConfiguration> solutionConfiguration, List <AnalyzerResult> analyzerResults)
        {
            using var projectTypeFeatureDetector = new FeatureDetector();

            // sync up passed in configuration with analyze results
            solutionConfiguration      = solutionConfiguration.Where(s => analyzerResults.Select(a => a.ProjectResult?.ProjectFilePath).Contains(s.ProjectPath)).ToList();
            analyzerResults            = analyzerResults.Where(a => solutionConfiguration.Select(s => s.ProjectPath).Contains(a.ProjectResult?.ProjectFilePath)).ToList();
            _projectTypeFeatureResults = projectTypeFeatureDetector.DetectFeaturesInProjects(analyzerResults);

            var allReferences = new HashSet <string>();

            foreach (var projectConfiguration in solutionConfiguration)
            {
                var projectTypeFeatureResult = _projectTypeFeatureResults[projectConfiguration.ProjectPath];
                projectConfiguration.ProjectType = GetProjectType(projectTypeFeatureResult);
                if (projectConfiguration.UseDefaultRules)
                {
                    //If a rules dir was provided, copy files from that dir into the rules folder
                    if (!string.IsNullOrEmpty(projectConfiguration.RulesDir))
                    {
                        CopyOverrideRules(projectConfiguration.RulesDir);
                    }
                    projectConfiguration.RulesDir = Constants.RulesDefaultPath;
                    var projectResult = analyzerResults
                                        .FirstOrDefault(a => a.ProjectResult?.ProjectFilePath == projectConfiguration.ProjectPath)
                                        .ProjectResult;

                    projectResult?.SourceFileResults?.SelectMany(s => s.References)?.Select(r => r.Namespace).Distinct().ToList().ForEach(currentReference => {
                        if (currentReference != null && !allReferences.Contains(currentReference))
                        {
                            allReferences.Add(currentReference);
                        }
                    });

                    projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType <UsingDirective>())?.Select(u => u.Identifier).Distinct().ToList().ForEach(currentReference => {
                        if (currentReference != null && !allReferences.Contains(currentReference))
                        {
                            allReferences.Add(currentReference);
                        }
                    });
                }
                AddWCFReferences(projectConfiguration);

                projectConfiguration.AdditionalReferences.Add(Constants.ProjectRecommendationFile);

                allReferences.UnionWith(projectConfiguration.AdditionalReferences);
            }

            _portSolutionResult.References = allReferences.ToHashSet <string>();

            DownloadRecommendationFiles(allReferences);
        }
Esempio n. 13
0
        private static async Task <Stream> CreateStream(Uri connectionString, CancellationToken token = default)
        {
            _ = connectionString ?? throw new ArgumentNullException(nameof(connectionString));

            var serverName = FeatureDetector.IsWindows() ? connectionString.Host : ".";

            // TODO: write a connection string parser once we introduce the next transport
            var connectionId = connectionString.Segments[1];
            var stream       = new NamedPipeClientStream(serverName, connectionId, PipeDirection.InOut, PipeOptions.Asynchronous);
            await stream.ConnectAsync(token).ConfigureAwait(false);

            return(stream);
        }
Esempio n. 14
0
        public void FeatureDetector_Default_Constructor_Loads_All_ProjectType_Features()
        {
            var defaultFeatureDetector = new FeatureDetector();
            var defaultFeatureSet      = FeatureSetLoader.LoadDefaultFeatureSet();

            var loadedFeatureNames  = defaultFeatureDetector.LoadedFeatureSet.CompiledFeatures.Select(f => f.Name);
            var defaultFeatureNames = defaultFeatureSet.CompiledFeatures.Select(f => f.Name);

            var difference = defaultFeatureNames.Except(loadedFeatureNames);

            Assert.IsNotEmpty(defaultFeatureNames);
            Assert.IsNotEmpty(loadedFeatureNames);
            Assert.IsEmpty(difference);
        }
Esempio n. 15
0
        public void DetectFeaturesInProject_Detects_Features_In_Specified_Project()
        {
            const string mvcFeature               = "AspNetMvcFeature";
            const string webApiFeature            = "AspNetWebApiFeature";
            const string sqlServerProviderFeature = "SqlServerProviderFeature";
            const string postgresProviderFeature  = "PostgresProviderFeature";

            var results = FeatureDetector.DetectFeaturesInProject(TestProjectsSetupFixture.MvcProjectPath);

            Assert.True(results.FeatureStatus[mvcFeature]);
            Assert.False(results.FeatureStatus[webApiFeature]);
            Assert.False(results.FeatureStatus[sqlServerProviderFeature]);
            Assert.False(results.FeatureStatus[postgresProviderFeature]);
        }
Esempio n. 16
0
 public static FeatureDetector Instance()
 {
     if (_instance == null)
     {
         lock (instancelock)
         {
             if (_instance == null)
             {
                 _instance = new FeatureDetector();
             }
         }
     }
     return(_instance);
 }
Esempio n. 17
0
        private void InitRules(List<PortCoreConfiguration> solutionConfiguration, List<AnalyzerResult> analyzerResults)
        {
            var projectTypeFeatureDetector = new FeatureDetector();
            var projectTypeFeatureResults = projectTypeFeatureDetector.DetectFeaturesInProjects(analyzerResults);

            foreach (var projectConfiguration in solutionConfiguration)
            {
                var projectTypeFeatureResult = projectTypeFeatureResults[projectConfiguration.ProjectPath];
                projectConfiguration.ProjectType = GetProjectType(projectTypeFeatureResult);
                if (projectConfiguration.UseDefaultRules)
                {
                    DownloadRecommendationFiles(analyzerResults);
                    projectConfiguration.RulesPath = Constants.RulesDefaultPath;
                }
            }
        }
Esempio n. 18
0
        public void FeatureDetector_Loads_Features_In_Specified_Configs()
        {
            var featureConfig1 = Path.Combine(TestProjectDirectory, "Examples", "Templates", "feature_config.json");
            var featureConfig2 = Path.Combine(TestProjectDirectory, "Examples", "Templates", "ProjectType_code_features.json");
            var featureConfigs = new List <string>
            {
                featureConfig1,
                featureConfig2
            };
            var featureDetector  = new FeatureDetector(featureConfigs);
            var loadedFeatureSet = featureDetector.LoadedFeatureSet;

            CollectionAssert.IsNotEmpty(loadedFeatureSet.ConfiguredFeatures);
            CollectionAssert.IsNotEmpty(loadedFeatureSet.CompiledFeatures);
            Assert.True(loadedFeatureSet.ConfiguredFeatures.Count == 9);
            Assert.True(loadedFeatureSet.CompiledFeatures.Count == 18);
        }
Esempio n. 19
0
        private void InitRules(PortCoreConfiguration projectConfiguration, AnalyzerResult analyzerResult)
        {
            using var projectTypeFeatureDetector = new FeatureDetector();

            ProjectTypeFeatureResults = projectTypeFeatureDetector.DetectFeaturesInProject(analyzerResult);

            projectConfiguration.ProjectType = _solutionPort.GetProjectType(ProjectTypeFeatureResults);
            if (projectConfiguration.UseDefaultRules)
            {
                //If a rules dir was provided, copy files from that dir into the rules folder
                if (!string.IsNullOrEmpty(projectConfiguration.RulesDir))
                {
                    _solutionPort.CopyOverrideRules(projectConfiguration.RulesDir);
                }
                projectConfiguration.RulesDir = Constants.RulesDefaultPath;
                var projectResult = analyzerResult.ProjectResult;

                projectResult?.SourceFileResults?.SelectMany(s => s.References)?.Select(r => r.Namespace).Distinct().ToList().ForEach(currentReference =>
                {
                    if (currentReference != null && !ProjectReferences.Contains(currentReference))
                    {
                        ProjectReferences.Add(currentReference);
                    }
                });

                projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType <UsingDirective>())?.Select(u => u.Identifier).Distinct().ToList().ForEach(currentReference =>
                {
                    if (currentReference != null && !ProjectReferences.Contains(currentReference))
                    {
                        ProjectReferences.Add(currentReference);
                    }
                });
                ProjectReferences.Add(Constants.ProjectRecommendationFile);
            }

            _solutionPort.DownloadRecommendationFiles(ProjectReferences);
        }
        private void CalibrateBlacklevel()
        {
            Bitmap capture        = settings.CaptureImage();
            int    tempBlacklevel = FeatureDetector.GetBlackLevel(ref capture);

            if (tempBlacklevel != -1 && tempBlacklevel < settings.cmpBlackLevel)
            {
                settings.cmpBlackLevel = tempBlacklevel;
            }
            FeatureDetector.ClearBackground(ref capture, settings.cmpBlackLevel);

            BitmapToPixConverter btp = new BitmapToPixConverter();
            Pix    img        = btp.Convert(capture);
            string ResultText = "";

            using (var page = engine.Process(img, PageSegMode.SingleChar))
            {
                ResultText = page.GetText();
            }
            int counter = 0;

            if (settings.platform == "ENG/PS2" || settings.platform == "ENG/XBOX&GC")
            {
                foreach (char c in expectedResultEng)
                {
                    if (ResultText.Contains(c))
                    {
                        counter++;
                    }
                }
                if (counter > 5 && ResultText.Length == 8)
                {
                    isCmpFinished = true;
                }
            }
            else if (settings.platform == "JPN/PS2")
            {
                foreach (char c in expectedResultJpn)
                {
                    if (ResultText.Contains(c))
                    {
                        counter++;
                    }
                }
                if (counter > 3)
                {
                    isCmpFinished = true;
                }
            }
            else
            {
                foreach (char c in expectedResultKrn)
                {
                    if (ResultText.Contains(c))
                    {
                        counter++;
                    }
                }
                if (counter > 2)
                {
                    isCmpFinished = true;
                }
            }
            if (isCmpFinished)
            {
                settings.blacklevel = settings.cmpBlackLevel;
                isCmpFinished       = false;
                settings.isCalibratingBlacklevel = false;
                settings.cmpBlackLevel           = 100;
                Console.WriteLine("BLACKLEVEL: {0}", settings.blacklevel);
                settings.UpdateBlacklevelLabel();
                settings.Refresh();
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Finds centers in the grid of circles.
        /// </summary>
        /// <param name="image">grid view of input circles; it must be an 8-bit grayscale or color image.</param>
        /// <param name="patternSize">number of circles per row and column ( patternSize = Size(points_per_row, points_per_colum) ).</param>
        /// <param name="centers">output array of detected centers.</param>
        /// <param name="flags">various operation flags that can be one of the FindCirclesGridFlag values</param>
        /// <param name="blobDetector">feature detector that finds blobs like dark circles on light background.</param>
        /// <returns></returns>
        public static bool FindCirclesGrid(
            InputArray image,
            Size patternSize,
            out Point2f[] centers,
            FindCirclesGridFlags flags = FindCirclesGridFlags.SymmetricGrid,
            FeatureDetector blobDetector = null)
        {
            if (image == null)
                throw new ArgumentNullException("image");
            image.ThrowIfDisposed();

            using (var centersVec = new VectorOfPoint2f())
            {
                int ret = NativeMethods.calib3d_findCirclesGrid_vector(
                image.CvPtr, patternSize, centersVec.CvPtr, (int)flags, ToPtr(blobDetector));
                centers = centersVec.ToArray();
                return ret != 0;
            }
        }
Esempio n. 22
0
    public bool descriptorsORB_Old(Mat RGB, Mat cameraFeed, string targetName)//找出特徵的顏色方法三(可運行但效率不佳放棄)
    {
        if (RGB == null)
        {
            Debug.Log("RGB Mat is Null");
            return(false);
        }
        //將傳入的RGB存入Src
        Mat SrcMat = new Mat();

        RGB.copyTo(SrcMat);
        //比對樣本
        Texture2D imgTexture = Resources.Load(targetName) as Texture2D;
        //  Texture2D imgTexture2 = Resources.Load("lenaK") as Texture2D;

        //Texture2D轉Mat
        Mat img1Mat = new Mat(imgTexture.height, imgTexture.width, CvType.CV_8UC3);

        Utils.texture2DToMat(imgTexture, img1Mat);

        //創建 ORB的特徵點裝置
        FeatureDetector     detector  = FeatureDetector.create(FeatureDetector.ORB);
        DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
        //產生存放特徵點Mat
        MatOfKeyPoint keypoints1     = new MatOfKeyPoint();
        Mat           descriptors1   = new Mat();
        MatOfKeyPoint keypointsSrc   = new MatOfKeyPoint();
        Mat           descriptorsSrc = new Mat();

        //找特徵點圖1
        detector.detect(img1Mat, keypoints1);
        extractor.compute(img1Mat, keypoints1, descriptors1);
        //找特徵點圖Src
        detector.detect(SrcMat, keypointsSrc);
        extractor.compute(SrcMat, keypointsSrc, descriptorsSrc);

        DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);
        MatOfDMatch       matches = new MatOfDMatch();

        matcher.match(descriptors1, descriptorsSrc, matches);
        DMatch[] arrayDmatch = matches.toArray();

        for (int i = arrayDmatch.Length - 1; i >= 0; i--)
        {
            //   Debug.Log("match " + i + ": " + arrayDmatch[i].distance);
        }
        //做篩選
        double max_dist = 0;
        double min_dist = 100;
        //-- Quick calculation of max and min distances between keypoints
        double dist = new double();

        for (int i = 0; i < matches.rows(); i++)
        {
            dist = arrayDmatch[i].distance;
            if (dist < min_dist)
            {
                min_dist = dist;
            }
            if (dist > max_dist)
            {
                max_dist = dist;
            }
        }
        Debug.Log("Max dist :" + max_dist);
        Debug.Log("Min dist :" + min_dist);
        //只畫好的點

        List <DMatch> matchesGoodList = new List <DMatch>();

        for (int i = 0; i < matches.rows(); i++)
        {
            //if (arrayDmatch[i].distance < RateDist.value * min_dist)
            //{
            //    //Debug.Log("match " + i + ": " + arrayDmatch[i].distance);
            //    matchesGoodList.Add(arrayDmatch[i]);
            //}
        }
        MatOfDMatch matchesGood = new MatOfDMatch();

        matchesGood.fromList(matchesGoodList);

        //Draw Keypoints
        Features2d.drawKeypoints(SrcMat, keypointsSrc, SrcMat);

        //做輸出的轉換予宣告

        Mat resultImg = new Mat();
        // Features2d.drawMatches(img1Mat, keypoints1, SrcMat, keypointsSrc, matchesGood, resultImg);

        List <Point> P1 = new List <Point>();
        // List<Point> P2 = new List<Point>();
        List <Point> pSrc = new List <Point>();

        Debug.Log("MatchCount" + matchesGoodList.Count);
        for (int i = 0; i < matchesGoodList.Count; i++)
        {
            P1.Add(new Point(keypoints1.toArray()[matchesGoodList[i].queryIdx].pt.x, keypoints1.toArray()[matchesGoodList[i].queryIdx].pt.y));
            pSrc.Add(new Point(keypointsSrc.toArray()[matchesGoodList[i].trainIdx].pt.x, keypointsSrc.toArray()[matchesGoodList[i].trainIdx].pt.y));
            //Debug.Log("ID = " + matchesGoodList[i].queryIdx );
            //Debug.Log("x,y =" + (int)keypoints1.toArray()[matchesGoodList[i].queryIdx].pt.x + "," + (int)keypoints1.toArray()[matchesGoodList[i].queryIdx].pt.y);
            //Debug.Log("x,y =" + (int)keypoints2.toArray()[matchesGoodList[i].trainIdx].pt.x + "," + (int)keypoints2.toArray()[matchesGoodList[i].trainIdx].pt.y);
        }

        MatOfPoint2f p2fTarget = new MatOfPoint2f(P1.ToArray());
        MatOfPoint2f p2fSrc    = new MatOfPoint2f(pSrc.ToArray());

        Mat          matrixH         = Calib3d.findHomography(p2fTarget, p2fSrc, Calib3d.RANSAC, 3);
        List <Point> srcPointCorners = new List <Point>();

        srcPointCorners.Add(new Point(0, 0));
        srcPointCorners.Add(new Point(img1Mat.width(), 0));
        srcPointCorners.Add(new Point(img1Mat.width(), img1Mat.height()));
        srcPointCorners.Add(new Point(0, img1Mat.height()));

        Mat          originalRect       = Converters.vector_Point2f_to_Mat(srcPointCorners);
        List <Point> srcPointCornersEnd = new List <Point>();

        srcPointCornersEnd.Add(new Point(0, img1Mat.height()));
        srcPointCornersEnd.Add(new Point(0, 0));
        srcPointCornersEnd.Add(new Point(img1Mat.width(), 0));
        srcPointCornersEnd.Add(new Point(img1Mat.width(), img1Mat.height()));

        Mat changeRect = Converters.vector_Point2f_to_Mat(srcPointCornersEnd);

        Core.perspectiveTransform(originalRect, changeRect, matrixH);
        List <Point> srcPointCornersSave = new List <Point>();

        Converters.Mat_to_vector_Point(changeRect, srcPointCornersSave);

        if ((srcPointCornersSave[2].x - srcPointCornersSave[0].x) < 5 || (srcPointCornersSave[2].y - srcPointCornersSave[0].y) < 5)
        {
            Debug.Log("Match Out Put image is to small");
            SrcMat.copyTo(cameraFeed);
            SrcMat.release();
            Imgproc.putText(cameraFeed, "X-S", new Point(10, 50), 0, 1, new Scalar(255, 255, 255), 2);
            return(false);
        }
        //    Features2d.drawMatches(img1Mat, keypoints1, SrcMat, keypointsSrc, matchesGood, resultImg);
        Imgproc.line(SrcMat, srcPointCornersSave[0], srcPointCornersSave[1], new Scalar(255, 0, 0), 3);
        Imgproc.line(SrcMat, srcPointCornersSave[1], srcPointCornersSave[2], new Scalar(255, 0, 0), 3);
        Imgproc.line(SrcMat, srcPointCornersSave[2], srcPointCornersSave[3], new Scalar(255, 0, 0), 3);
        Imgproc.line(SrcMat, srcPointCornersSave[3], srcPointCornersSave[0], new Scalar(255, 0, 0), 3);

        SrcMat.copyTo(cameraFeed);
        keypoints1.release();
        img1Mat.release();
        SrcMat.release();
        return(true);
    }
Esempio n. 23
0
//============================================================
//=================以下為沒有再使用的函式=====================
//============================================================

    //找出特徵的顏色方法三(ORB特徵點比對)
    public bool descriptorsORB(Mat RGB, Mat cameraFeed, string targetName)
    {
        if (RGB == null)
        {
            Debug.Log("RGB Mat is Null");
            return(false);
        }
        //將傳入的RGB存入Src
        Mat SrcMat = new Mat();

        RGB.copyTo(SrcMat);
        //比對樣本載入
        Texture2D imgTexture = Resources.Load(targetName) as Texture2D;

        //Texture2D轉Mat
        Mat targetMat = new Mat(imgTexture.height, imgTexture.width, CvType.CV_8UC3);

        Utils.texture2DToMat(imgTexture, targetMat);

        //創建 ORB的特徵點裝置
        FeatureDetector     detector  = FeatureDetector.create(FeatureDetector.ORB);
        DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);

        //產生存放特徵點Mat
        MatOfKeyPoint keypointsTarget   = new MatOfKeyPoint();
        Mat           descriptorsTarget = new Mat();
        MatOfKeyPoint keypointsSrc      = new MatOfKeyPoint();
        Mat           descriptorsSrc    = new Mat();

        //找特徵點圖Target
        detector.detect(targetMat, keypointsTarget);
        extractor.compute(targetMat, keypointsTarget, descriptorsTarget);

        //找特徵點圖Src
        detector.detect(SrcMat, keypointsSrc);
        extractor.compute(SrcMat, keypointsSrc, descriptorsSrc);

        //創建特徵點比對物件
        DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);
        MatOfDMatch       matches = new MatOfDMatch();

        //丟入兩影像的特徵點
        matcher.match(descriptorsTarget, descriptorsSrc, matches);
        DMatch[] arrayDmatch = matches.toArray();

        //做篩選
        double max_dist = 0;
        double min_dist = 100;
        //-- Quick calculation of max and min distances between keypoints
        double dist = new double();

        for (int i = 0; i < matches.rows(); i++)
        {
            dist = arrayDmatch[i].distance;
            if (dist < min_dist)
            {
                min_dist = dist;
            }
            if (dist > max_dist)
            {
                max_dist = dist;
            }
        }
        Debug.Log("Max dist :" + max_dist);
        Debug.Log("Min dist :" + min_dist);

        List <DMatch> matchesGoodList = new List <DMatch>();

        MatOfDMatch matchesGood = new MatOfDMatch();

        matchesGood.fromList(matchesGoodList);

        //Draw Keypoints
        Features2d.drawKeypoints(SrcMat, keypointsSrc, SrcMat);

        List <Point> pTarget = new List <Point>();
        List <Point> pSrc    = new List <Point>();

        Debug.Log("MatchCount" + matchesGoodList.Count);
        for (int i = 0; i < matchesGoodList.Count; i++)
        {
            pTarget.Add(new Point(keypointsTarget.toArray()[matchesGoodList[i].queryIdx].pt.x, keypointsTarget.toArray()[matchesGoodList[i].queryIdx].pt.y));
            pSrc.Add(new Point(keypointsSrc.toArray()[matchesGoodList[i].trainIdx].pt.x, keypointsSrc.toArray()[matchesGoodList[i].trainIdx].pt.y));
        }

        MatOfPoint2f p2fTarget = new MatOfPoint2f(pTarget.ToArray());
        MatOfPoint2f p2fSrc    = new MatOfPoint2f(pSrc.ToArray());

        Mat matrixH = Calib3d.findHomography(p2fTarget, p2fSrc, Calib3d.RANSAC, 3);

        List <Point> srcPointCorners = new List <Point>();

        srcPointCorners.Add(new Point(0, 0));
        srcPointCorners.Add(new Point(targetMat.width(), 0));
        srcPointCorners.Add(new Point(targetMat.width(), targetMat.height()));
        srcPointCorners.Add(new Point(0, targetMat.height()));
        Mat originalRect = Converters.vector_Point2f_to_Mat(srcPointCorners);

        List <Point> srcPointCornersEnd = new List <Point>();

        srcPointCornersEnd.Add(new Point(0, targetMat.height()));
        srcPointCornersEnd.Add(new Point(0, 0));
        srcPointCornersEnd.Add(new Point(targetMat.width(), 0));
        srcPointCornersEnd.Add(new Point(targetMat.width(), targetMat.height()));
        Mat changeRect = Converters.vector_Point2f_to_Mat(srcPointCornersEnd);

        Core.perspectiveTransform(originalRect, changeRect, matrixH);
        List <Point> srcPointCornersSave = new List <Point>();

        Converters.Mat_to_vector_Point(changeRect, srcPointCornersSave);

        if ((srcPointCornersSave[2].x - srcPointCornersSave[0].x) < 5 || (srcPointCornersSave[2].y - srcPointCornersSave[0].y) < 5)
        {
            Debug.Log("Match Out Put image is to small");
            SrcMat.copyTo(cameraFeed);
            SrcMat.release();
            Imgproc.putText(cameraFeed, targetName, srcPointCornersSave[0], 0, 1, new Scalar(255, 255, 255), 2);
            return(false);
        }
        //畫出框框
        Imgproc.line(SrcMat, srcPointCornersSave[0], srcPointCornersSave[1], new Scalar(255, 0, 0), 3);
        Imgproc.line(SrcMat, srcPointCornersSave[1], srcPointCornersSave[2], new Scalar(255, 0, 0), 3);
        Imgproc.line(SrcMat, srcPointCornersSave[2], srcPointCornersSave[3], new Scalar(255, 0, 0), 3);
        Imgproc.line(SrcMat, srcPointCornersSave[3], srcPointCornersSave[0], new Scalar(255, 0, 0), 3);
        //畫中心
        Point middlePoint = new Point((srcPointCornersSave[0].x + srcPointCornersSave[2].x) / 2, (srcPointCornersSave[0].y + srcPointCornersSave[2].y) / 2);

        Imgproc.line(SrcMat, middlePoint, middlePoint, new Scalar(0, 0, 255), 10);


        SrcMat.copyTo(cameraFeed);
        keypointsTarget.release();
        targetMat.release();
        SrcMat.release();
        return(true);
    }
        private bool CaptureLoadsPS2()
        {
            bool isLoad = false;

            framesSinceLastManualSplit++;
            //Console.WriteLine("TIME NOW: {0}", DateTime.Now - lastTime);13
            //Console.WriteLine("TIME DIFF START: {0}", DateTime.Now - lastTime);
            lastTime = DateTime.Now;

            //Capture image using the settings defined for the component
            Bitmap capture = settings.CaptureImage();

            wasBlackScreen = isBlackScreen;
            isBlackScreen  = FeatureDetector.IsBlackScreen(ref capture, settings.blacklevel);
            //BitmapToPixConverter btp = new BitmapToPixConverter();
            //if (!testSaved)
            //{
            //    Bitmap jpntestbmp = new Bitmap("cutout.bmp");
            //    FeatureDetector.GetBlackLevel(ref jpntestbmp);
            //    FeatureDetector.ClearBackground(ref jpntestbmp);
            //    jpntestbmp.Save("jpntest.bmp");
            //    Pix jpntest = btp.Convert(jpntestbmp);
            //    using (var page = engine.Process(jpntest, PageSegMode.SingleChar))
            //    {
            //        Console.WriteLine(page.GetText());
            //    }
            //    testSaved = true;
            //}


            if (!isBlackScreen && waitOnLoad)
            {
                FeatureDetector.ClearBackground(ref capture, settings.blacklevel);

                BitmapToPixConverter btp = new BitmapToPixConverter();
                Pix    img        = btp.Convert(capture);
                string ResultText = "";
                using (var page = engine.Process(img, PageSegMode.SingleChar))
                {
                    ResultText = page.GetText();
                    //Console.WriteLine(ResultText);
                }
                int counter = 0;
                if (settings.platform == "ENG/PS2")
                {
                    foreach (char c in expectedResultEng)
                    {
                        if (ResultText.Contains(c))
                        {
                            counter++;
                        }
                    }
                    if (counter > 5 && ResultText.Length == 8)
                    {
                        isLoading = true;
                        isLoad    = true;
                    }
                    else
                    {
                        waitFrames++;
                        if (waitFrames == WAIT_ON_LOAD_FRAMES)
                        {
                            waitOnLoad = false;
                            waitFrames = 0;
                        }
                    }
                }
                else if (settings.platform == "JPN/PS2")
                {
                    foreach (char c in expectedResultJpn)
                    {
                        if (ResultText.Contains(c))
                        {
                            counter++;
                        }
                    }
                    if (counter > 3)
                    {
                        isLoading = true;
                        isLoad    = true;
                    }
                    else
                    {
                        waitFrames++;
                        if (waitFrames == WAIT_ON_LOAD_FRAMES)
                        {
                            waitOnLoad = false;
                            waitFrames = 0;
                        }
                    }
                }
                //TODO: add korean
                else
                {
                    foreach (char c in expectedResultKrn)
                    {
                        if (ResultText.Contains(c))
                        {
                            counter++;
                        }
                    }
                    if (counter > 1)
                    {
                        isLoading = true;
                        isLoad    = true;
                    }
                    else
                    {
                        waitFrames++;
                        if (waitFrames == WAIT_ON_LOAD_FRAMES)
                        {
                            waitOnLoad = false;
                            waitFrames = 0;
                        }
                    }
                }
            }

            timer.CurrentState.IsGameTimePaused = isLoading || isBlackScreen;

            if (waitOnFadeIn && isBlackScreen)
            {
                waitOnFadeIn = false;
                isLoading    = false;
            }


            if (wasBlackScreen && !isBlackScreen)
            {
                //This could be a pre-load transition, start timing it
                transitionStart = DateTime.Now;
                waitOnLoad      = true;
                waitFrames      = 0;
            }



            if (isLoading && waitOnLoad)
            {
                // This was a pre-load transition, subtract the gametime
                TimeSpan delta = (DateTime.Now - transitionStart);
                timer.CurrentState.SetGameTime(timer.CurrentState.GameTimePauseTime - delta);
                waitOnLoad   = false;
                waitFrames   = 0;
                waitOnFadeIn = true;
            }
            return(isLoad);
        }
Esempio n. 25
0
 private static bool ShouldCheckMap(TypeMap typeMap)
 {
     return(typeMap.CustomMapper == null && !FeatureDetector.IsIDataRecordType(typeMap.SourceType));
 }
Esempio n. 26
0
        public void Instantiating_An_Invalid_Feature_Does_Not_Load_It()
        {
            var featureDetector = new FeatureDetector(ParsedFeatureConfigSetupFixture.FeatureConfigWithInvalidFeature);

            Assert.False(featureDetector.LoadedFeatureSet.AllFeatures.Any());
        }
Esempio n. 27
0
        /// <summary>
        /// Finds centers in the grid of circles.
        /// </summary>
        /// <param name="image">grid view of input circles; it must be an 8-bit grayscale or color image.</param>
        /// <param name="patternSize">number of circles per row and column ( patternSize = Size(points_per_row, points_per_colum) ).</param>
        /// <param name="centers">output array of detected centers.</param>
        /// <param name="flags">various operation flags that can be one of the FindCirclesGridFlag values</param>
        /// <param name="blobDetector">feature detector that finds blobs like dark circles on light background.</param>
        /// <returns></returns>
        public static bool FindCirclesGrid(
            InputArray image,
            Size patternSize,
            OutputArray centers,
            FindCirclesGridFlags flags = FindCirclesGridFlags.SymmetricGrid,
            FeatureDetector blobDetector = null)
        {
            if (image == null)
                throw new ArgumentNullException("image");
            if (centers == null)
                throw new ArgumentNullException("centers");
            image.ThrowIfDisposed();
            centers.ThrowIfNotReady();

            int ret = NativeMethods.calib3d_findCirclesGrid_InputArray(
                image.CvPtr, patternSize, centers.CvPtr, (int)flags, ToPtr(blobDetector));
            centers.Fix();
            return ret != 0;
        }
Esempio n. 28
0
        private void CaptureLoads()
        {
            try
            {
                if (timerStarted)
                {
                    framesSinceLastManualSplit++;
                    //Console.WriteLine("TIME NOW: {0}", DateTime.Now - lastTime);
                    //Console.WriteLine("TIME DIFF START: {0}", DateTime.Now - lastTime);
                    lastTime = DateTime.Now;

                    //Capture image using the settings defined for the component
                    Bitmap capture = settings.CaptureImage(Crash4State);
                    isLoading = false;

                    try
                    {
                        // CSV Test code.

                        /*
                         * FeatureDetector.compareImageCaptureCrash4(capture, test_hsv_ranges, test_gradient_ranges, achieved_hsv_ranges, achieved_gradient_thresholds, average_thresholded_gradients);
                         *
                         * string csv_out = timer.CurrentState.CurrentTime.RealTime.ToString();
                         *
                         * for (int i = 0; i < achieved_hsv_ranges.Count; i++)
                         * {
                         * csv_out += ";" + achieved_hsv_ranges[i];
                         * }
                         *
                         * for (int i = 0; i < achieved_gradient_thresholds.Count; i++)
                         * {
                         * csv_out += ";" + achieved_gradient_thresholds[i];
                         * csv_out += ";" + average_thresholded_gradients[i];
                         * }
                         *
                         * Console.WriteLine(csv_out);*/
                        // ...


                        //DateTime current_time = DateTime.Now;
                        //isLoading = FeatureDetector.compareFeatureVector(features.ToArray(), FeatureDetector.listOfFeatureVectorsEng, out tempMatchingBins, -1.0f, false);
                        //Console.WriteLine("Timing for detection: {0}", (DateTime.Now - current_time).TotalSeconds);

                        if (Crash4State == Crash4LoadState.WAITING_FOR_LOAD1 || Crash4State == Crash4LoadState.LOAD1 || Crash4State == Crash4LoadState.WAITING_FOR_LOAD2)
                        {
                            // Do HSV comparison on the raw image, without any features
                            //float achieved_threshold = 0.0f;
                            //float achieved_threshold_2 = 0.0f;

                            //isLoading = FeatureDetector.compareImageCaptureHSVCrash4(capture, 0.3f, out achieved_threshold, 5, 55, 50, 101, 75, 101);

                            //isLoading &= FeatureDetector.compareImageCaptureHSVCrash4(capture, 0.08f, out achieved_threshold_2, -1, 361, 30, 101, -1, 30);

                            FeatureDetector.compareImageCaptureCrash4(capture, hsv_ranges_load_1, gradient_thresholds_load_1, achieved_hsv_ranges, achieved_gradient_thresholds, average_thresholded_gradients, 2);

                            isLoading = (achieved_hsv_ranges[0] > 0.03) && (achieved_gradient_thresholds[0] > 0.09) && (average_thresholded_gradients[1] > 40);

                            if (output_first_load_debug && settings.DetailedDetectionLog)
                            {
                                string csv_out = "first_load;" + timer.CurrentState.CurrentTime.RealTime.ToString();
                                csv_out += ";" + achieved_hsv_ranges[0];

                                csv_out += ";" + achieved_gradient_thresholds[0];
                                csv_out += ";" + average_thresholded_gradients[1];


                                Console.WriteLine(csv_out);
                            }

                            //Console.WriteLine("Loading 1: " + isLoading.ToString() + ", achieved Threshold 1: " + achieved_threshold.ToString() + ", achieved Threshold 2: " + achieved_threshold_2.ToString());

                            if (Crash4State == Crash4LoadState.LOAD1 && (Single.IsNaN(average_thresholded_gradients[1]) || (average_thresholded_gradients[1] < 20 && achieved_gradient_thresholds[0] <= 0.04 && achieved_hsv_ranges[0] <= 0.02)))
                            {
                                if (output_state_info && settings.DetailedDetectionLog)
                                {
                                    Console.WriteLine("Weird black screen thing during LOAD1, setting isLoading to true manually, tolerance frames: " + load1_tolerance_frames);
                                }
                                //settings.StoreCaptureImage(GameName, GameCategory, capture);

                                load1_tolerance_frames--;

                                if (load1_tolerance_frames > 0)
                                {
                                    isLoading = true;
                                }
                            }

                            if (isLoading && Crash4State == Crash4LoadState.WAITING_FOR_LOAD1)
                            {
                                load1_tolerance_frames = LOAD1_BLACK_SCREEN_TOLERANCE_FRAMES;
                                // Store current time - this is the start of our load!
                                Crash4State       = Crash4LoadState.LOAD1;
                                load1_phase_start = timer.CurrentState.CurrentTime;

                                if (output_state_info && settings.DetailedDetectionLog)
                                {
                                    Console.WriteLine("Transition to LOAD1:");
                                }
                            }
                            else if (isLoading && Crash4State == Crash4LoadState.LOAD1)
                            {
                                // Everything fine - nothing to do here.
                            }
                            else if (!isLoading && Crash4State == Crash4LoadState.LOAD1)
                            {
                                // Transtiion from load phase 1 into load phase 2 - this checks the next couple of frames until it potentially finds the load screen phase 2.
                                Crash4State     = Crash4LoadState.WAITING_FOR_LOAD2;
                                load1_phase_end = timer.CurrentState.CurrentTime;

                                if (output_state_info && settings.DetailedDetectionLog)
                                {
                                    Console.WriteLine("Transition to WAITING_FOR_LOAD2");
                                }
                            }
                            else if (Crash4State == Crash4LoadState.WAITING_FOR_LOAD2)
                            {
                                // We're waiting for LOAD2 until the tolerance. If LOAD1 detection happens in the mean time, we reset back to LOAD1.

                                // Check if the elapsed time is over our tolerance
                                load1_tolerance_frames = LOAD1_BLACK_SCREEN_TOLERANCE_FRAMES;

                                if (isLoading)
                                {
                                    // Store current time - this is the start of our load - this might happen if orange letters are shortly before the real load screen.
                                    Crash4State       = Crash4LoadState.LOAD1;
                                    load1_phase_start = timer.CurrentState.CurrentTime;

                                    if (output_state_info && settings.DetailedDetectionLog)
                                    {
                                        Console.WriteLine("load screen detected while waiting for LOAD2: Transition to LOAD1: Loading 1: ");
                                    }
                                }
                                else if ((timer.CurrentState.CurrentTime - load1_phase_end).RealTime.Value.TotalSeconds > LOAD_PHASE_TOLERANCE_TIME)
                                {
                                    // Transition to TRANSITION_TO_LOAD2 state.
                                    if (output_state_info && settings.DetailedDetectionLog)
                                    {
                                        Console.WriteLine("TOLERANCE OVER: Transition to TRANSITION_TO_LOAD2");
                                    }

                                    Crash4State = Crash4LoadState.TRANSITION_TO_LOAD2;
                                }
                            }
                        }
                        else
                        {
                            load1_tolerance_frames = LOAD1_BLACK_SCREEN_TOLERANCE_FRAMES;
                            // Do HSV comparison on the raw image, without any features

                            /*float achieved_threshold_1 = 0.0f;
                             * float achieved_threshold_2 = 0.0f;
                             *
                             * FeatureDetector.compareImageCaptureHSVCrash4(capture, 0.3f, out achieved_threshold_1, 200, 230, 80, 101, 50, 101);
                             *
                             * FeatureDetector.compareImageCaptureHSVCrash4(capture, 0.3f, out achieved_threshold_2, -1, 360, 95, 101, -1, 15);*/

                            FeatureDetector.compareImageCaptureCrash4(capture, hsv_ranges_load_2, gradient_thresholds_load_2, achieved_hsv_ranges, achieved_gradient_thresholds, average_thresholded_gradients, 0);

                            isLoading = (achieved_gradient_thresholds[0] > 0.03) && (average_thresholded_gradients[1] > 40);


                            isLoading &= ((achieved_hsv_ranges[0] > 0.40) && (achieved_hsv_ranges[1] > 0.04)) || ((achieved_hsv_ranges[0] > 0.35) && (achieved_hsv_ranges[1] > 0.05)) || ((achieved_hsv_ranges[0] > 0.30) && (achieved_hsv_ranges[1] > 0.06)) || ((achieved_hsv_ranges[0] > 0.25) && (achieved_hsv_ranges[1] > 0.12)) || ((achieved_hsv_ranges[0] > 0.20) && (achieved_hsv_ranges[1] > 0.17));

                            if (output_second_load_debug && settings.DetailedDetectionLog)
                            {
                                string csv_out = "second_load;" + timer.CurrentState.CurrentTime.RealTime.ToString();
                                csv_out += ";" + achieved_hsv_ranges[0];
                                csv_out += ";" + achieved_hsv_ranges[1];
                                csv_out += ";" + achieved_gradient_thresholds[0];
                                csv_out += ";" + average_thresholded_gradients[1];
                                Console.WriteLine(csv_out);
                            }


                            //if((achieved_threshold_1 > 0.35f && achieved_threshold_2 > 0.10f) || (achieved_threshold_1 > 0.20f && achieved_threshold_2 > 0.15f))
                            if (isLoading)
                            {
                                // Everything fine, nothing to do here, except for transitioning to LOAD2
                                // Transition to LOAD2 state.

                                if (Crash4State == Crash4LoadState.TRANSITION_TO_LOAD2)
                                {
                                    if (output_state_info && settings.DetailedDetectionLog)
                                    {
                                        Console.WriteLine("TRANSITION TO LOAD2: Loading 2: ");
                                    }

                                    Crash4State = Crash4LoadState.LOAD2;
                                }
                            }
                            else if (Crash4State == Crash4LoadState.LOAD2)
                            {
                                // We're done and went through a whole load cycle.
                                // Compute the duration and update the timer.
                                var load_time = (timer.CurrentState.CurrentTime - load1_phase_start).RealTime.Value;
                                timer.CurrentState.LoadingTimes += load_time;
                                Crash4State = Crash4LoadState.WAITING_FOR_LOAD1;
                                Console.WriteLine(load_time.TotalSeconds + ";" + load1_phase_start.RealTime.ToString() + ";" + timer.CurrentState.CurrentTime.RealTime.ToString());

                                if (output_state_info && settings.DetailedDetectionLog)
                                {
                                    Console.WriteLine("<<<<<<<<<<<<< LOAD DONE! back to to WAITING_FOR_LOAD1: elapsed time: " + load_time.TotalSeconds);
                                }
                                //Console.WriteLine("LOAD DONE (pt2): Loading 2: " + isLoading.ToString() + ", achieved Threshold (blue): " + achieved_threshold_1.ToString() + ", achieved Threshold (black): " + achieved_threshold_2.ToString());
                            }
                            else
                            {
                                // This was a screen that detected the yellow/orange letters, didn't detect them again for the tolerance frame and then *didn't* detect LOAD2.
                                // Back to WAITING_FOR_LOAD1.
                                if (output_state_info && settings.DetailedDetectionLog)
                                {
                                    Console.WriteLine("TRANSITION TO WAITING_FOR_LOAD1 (didn't see swirl): Loading 2: ");
                                }

                                Crash4State = Crash4LoadState.WAITING_FOR_LOAD1;
                            }

                            //Console.WriteLine("Loading 2: " + isLoading.ToString() + ", achieved Threshold (blue): " + achieved_threshold_1.ToString() + ", achieved Threshold (black): " + achieved_threshold_2.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        isLoading = false;
                        Console.WriteLine("Error: " + ex.ToString());
                        throw ex;
                    }

                    /*
                     * matchingBins = tempMatchingBins;
                     *
                     * timer.CurrentState.IsGameTimePaused = isLoading;
                     *
                     * if (settings.RemoveFadeins || settings.RemoveFadeouts)
                     * {
                     * float new_avg_transition_max = 0.0f;
                     * try
                     * {
                     *    //isTransition = FeatureDetector.compareFeatureVectorTransition(features.ToArray(), FeatureDetector.listOfFeatureVectorsEng, max_per_patch, min_per_patch, - 1.0f, out new_avg_transition_max, out tempMatchingBins, 0.8f, false);//FeatureDetector.isGameTransition(capture, 30);
                     * }
                     * catch (Exception ex)
                     * {
                     *  isTransition = false;
                     *  Console.WriteLine("Error: " + ex.ToString());
                     *  throw ex;
                     * }
                     * //Console.WriteLine("Transition: {0}", isTransition);
                     * if (wasLoading && isTransition && settings.RemoveFadeins)
                     * {
                     *  postLoadTransition = true;
                     *  transitionStart = DateTime.Now;
                     * }
                     *
                     * if (wasTransition == false && isTransition && settings.RemoveFadeouts)
                     * {
                     *  //This could be a pre-load transition, start timing it
                     *  transitionStart = DateTime.Now;
                     * }
                     *
                     *
                     * //Console.WriteLine("GAMETIMEPAUSETIME: {0}", timer.CurrentState.GameTimePauseTime);
                     *
                     *
                     * if (wasTransition && isLoading)
                     * {
                     *  // This was a pre-load transition, subtract the gametime
                     *  TimeSpan delta = (DateTime.Now - transitionStart);
                     *
                     *  if(settings.RemoveFadeouts)
                     *  {
                     *    if (delta.TotalSeconds > numSecondsTransitionMax)
                     *    {
                     *      Console.WriteLine("{2}: Transition longer than {0} seconds, doesn't count! (Took {1} seconds)", numSecondsTransitionMax, delta.TotalSeconds, SplitNames[Math.Max(Math.Min(liveSplitState.CurrentSplitIndex, SplitNames.Count - 1), 0)]);
                     *    }
                     *    else
                     *    {
                     *      timer.CurrentState.SetGameTime(timer.CurrentState.GameTimePauseTime - delta);
                     *
                     *      total_paused_time += delta.TotalSeconds;
                     *      Console.WriteLine("PRE-LOAD TRANSITION {2} seconds: {0}, totalPausedTime: {1}", delta.TotalSeconds, total_paused_time, SplitNames[Math.Max(Math.Min(liveSplitState.CurrentSplitIndex, SplitNames.Count - 1), 0)]);
                     *    }
                     *
                     *  }
                     *
                     * }
                     *
                     * if(settings.RemoveFadeins)
                     * {
                     *  if (postLoadTransition && isTransition == false)
                     *  {
                     *    TimeSpan delta = (DateTime.Now - transitionStart);
                     *
                     *    total_paused_time += delta.TotalSeconds;
                     *    Console.WriteLine("POST-LOAD TRANSITION {2} seconds: {0}, totalPausedTime: {1}", delta.TotalSeconds, total_paused_time, SplitNames[Math.Max(Math.Min(liveSplitState.CurrentSplitIndex, SplitNames.Count - 1), 0)]);
                     *  }
                     *
                     *
                     *  if (postLoadTransition == true && isTransition)
                     *  {
                     *    // We are transitioning after a load screen, this stops the timer, and actually increases the load time
                     *    timer.CurrentState.IsGameTimePaused = true;
                     *
                     *
                     *  }
                     *  else
                     *  {
                     *    postLoadTransition = false;
                     *  }
                     *
                     * }
                     *
                     * }
                     *
                     *
                     *
                     * if (isLoading && !wasLoading)
                     * {
                     * segmentTimeStart = DateTime.Now;
                     * }
                     *
                     * if (isLoading)
                     * {
                     * pausedFramesSegment++;
                     * }
                     *
                     * if (wasLoading && !isLoading)
                     * {
                     * TimeSpan delta = (DateTime.Now - segmentTimeStart);
                     * framesSum += delta.TotalSeconds * 60.0f;
                     * int framesRounded = Convert.ToInt32(delta.TotalSeconds * 60.0f);
                     * framesSumRounded += framesRounded;
                     * total_paused_time += delta.TotalSeconds;
                     *
                     * Console.WriteLine("SEGMENT FRAMES {7}: {0}, fromTime (@60fps) {1}, timeDelta {2}, totalFrames {3}, fromTime(int) {4}, totalFrames(int) {5}, totalPausedTime(double) {6}",
                     *  pausedFramesSegment, delta.TotalSeconds,
                     *  delta.TotalSeconds * 60.0f, framesSum, framesRounded, framesSumRounded, total_paused_time, SplitNames[Math.Max(Math.Min(liveSplitState.CurrentSplitIndex, SplitNames.Count - 1), 0)]);
                     * pausedFramesSegment = 0;
                     * }
                     *
                     *
                     * if (settings.AutoSplitterEnabled && !(settings.AutoSplitterDisableOnSkipUntilSplit && LastSplitSkip))
                     * {
                     * //This is just so that if the detection is not correct by a single frame, it still only splits if a few successive frames are loading
                     * if (isLoading && NSTState == CrashNSTState.RUNNING)
                     * {
                     *  pausedFrames++;
                     *  runningFrames = 0;
                     * }
                     * else if (!isLoading && NSTState == CrashNSTState.LOADING)
                     * {
                     *  runningFrames++;
                     *  pausedFrames = 0;
                     * }
                     *
                     * if (NSTState == CrashNSTState.RUNNING && pausedFrames >= settings.AutoSplitterJitterToleranceFrames)
                     * {
                     *  runningFrames = 0;
                     *  pausedFrames = 0;
                     *  //We enter pause.
                     *  NSTState = CrashNSTState.LOADING;
                     *  if (framesSinceLastManualSplit >= settings.AutoSplitterManualSplitDelayFrames)
                     *  {
                     *    NumberOfLoadsPerSplit[liveSplitState.CurrentSplitIndex]++;
                     *
                     *    if (CumulativeNumberOfLoadsForSplitIndex(liveSplitState.CurrentSplitIndex) >= settings.GetCumulativeNumberOfLoadsForSplit(liveSplitState.CurrentSplit.Name))
                     *    {
                     *
                     *      timer.Split();
                     *
                     *
                     *    }
                     *  }
                     *
                     * }
                     * else if (NSTState == CrashNSTState.LOADING && runningFrames >= settings.AutoSplitterJitterToleranceFrames)
                     * {
                     *  runningFrames = 0;
                     *  pausedFrames = 0;
                     *  //We enter runnning.
                     *  NSTState = CrashNSTState.RUNNING;
                     * }
                     * }
                     *
                     *
                     * //Console.WriteLine("TIME TAKEN FOR DETECTION: {0}", DateTime.Now - lastTime);*/
                }
            }
            catch (Exception ex)
            {
                isTransition = false;
                isLoading    = false;
                Console.WriteLine("Error: " + ex.ToString());
            }
        }
Esempio n. 29
0
 private static bool ShouldCheckMap(TypeMap typeMap)
 {
     return((typeMap.CustomMapper == null && typeMap.CustomProjection == null &&
             typeMap.DestinationTypeOverride == null) && !FeatureDetector.IsIDataRecordType(typeMap.SourceType));
 }
Esempio n. 30
0
        public void LoadFeaturesFromAssemblyMetadata_Does_Not_Load_Any_Features_If_Namespace_Does_Not_Exist_In_Assembly()
        {
            var featureDetector = new FeatureDetector(ParsedFeatureConfigSetupFixture.FeatureConfigWithNonexistentNamespace);

            Assert.False(featureDetector.LoadedFeatureSet.AllFeatures.Any());
        }
Esempio n. 31
0
 public bool ShouldCheckForValid()
 {
     return((CustomMapper == null && CustomProjection == null &&
             DestinationTypeOverride == null) && !FeatureDetector.IsIDataRecordType(SourceType));
 }
        private bool CaptureLoadsXBOX()
        {
            bool isLoad = false;

            if ((timerStart.Ticks - liveSplitState.Run.Offset.Ticks) <= DateTime.Now.Ticks)
            {
                framesSinceLastManualSplit++;
                //Console.WriteLine("TIME NOW: {0}", DateTime.Now - lastTime);
                //Console.WriteLine("TIME DIFF START: {0}", DateTime.Now - lastTime);
                //lastTime = DateTime.Now;

                wasBlackScreen = isBlackScreen;
                //Capture image using the settings defined for the component
                Bitmap capture = settings.CaptureImage();
                isBlackScreen = FeatureDetector.IsBlackScreen(ref capture, settings.blacklevel);
                BitmapToPixConverter btp = new BitmapToPixConverter();
                //if (!testSaved)
                //{
                //    Bitmap jpntestbmp = new Bitmap("cutout.bmp");
                //    FeatureDetector.ClearBackgroundPostLoad(ref jpntestbmp);
                //    jpntestbmp.Save("jpntest.bmp");
                //    Pix jpntest = btp.Convert(jpntestbmp);
                //    using (var page = engine.Process(jpntest, PageSegMode.SingleChar))
                //    {
                //        Console.WriteLine(page.GetText());
                //    }
                //    testSaved = true;
                //}

                if (wasBlackScreen && !isBlackScreen)
                {
                    //This could be a pre-load transition, start timing it
                    transitionStart = DateTime.Now;
                    waitOnLoad      = true;
                }

                if (!isBlackScreen && !waitOnFadeIn && waitOnLoad)
                {
                    specialLoad = FeatureDetector.ClearBackground(ref capture, settings.blacklevel);
                    Pix    img        = btp.Convert(capture);
                    string ResultText = "";
                    using (var page = engine.Process(img, PageSegMode.SingleChar))
                    {
                        ResultText = page.GetText();
                    }
                    int counter = 0;
                    foreach (char c in expectedResultEng)
                    {
                        if (ResultText.Contains(c))
                        {
                            counter++;
                        }
                    }
                    if (counter > 5 && ResultText.Length == 8)
                    {
                        isLoading = true;
                        isLoad    = true;
                    }
                }

                timer.CurrentState.IsGameTimePaused = isLoading || isBlackScreen;

                if (waitOnFadeIn && !specialLoad)
                {
                    capture = settings.CaptureImagePostLoad();
                    int lowestBitLast = lowestBit;
                    lowestBit = FeatureDetector.ClearBackgroundPostLoad(ref capture, settings.blacklevel);
                    if (lowestBit == lowestBitLast && lowestBit != 0)
                    {
                        Pix img = btp.Convert(capture);
                        using (var page = engine.Process(img, PageSegMode.SingleChar))
                        {
                            string result = page.GetText();
                            if (result != "\n")
                            {
                                Console.WriteLine(page.GetText());
                                waitOnFadeIn = false;
                                isLoading    = false;
                                lowestBit    = 0;
                                //the lifecounter coming in from the top takes a quarter of a second to stop
                                TimeSpan quarter = new TimeSpan(2500000);
                                timer.CurrentState.SetGameTime(timer.CurrentState.GameTimePauseTime + quarter);
                            }
                        }
                    }
                }

                if (waitOnFadeIn && isBlackScreen && !specialLoad)
                {
                    waitOnFadeIn = false;
                    isLoading    = false;
                }

                if (waitOnFadeIn && specialLoad && FeatureDetector.IsEndOfSpecialLoad(ref capture, settings.blacklevel))
                {
                    specialLoad  = false;
                    waitOnFadeIn = false;
                    isLoading    = false;
                }

                if (isLoading && waitOnLoad)
                {
                    // This was a pre-load transition, subtract the gametime
                    TimeSpan delta = (DateTime.Now - transitionStart);
                    timer.CurrentState.SetGameTime(timer.CurrentState.GameTimePauseTime - delta);
                    waitOnLoad   = false;
                    waitOnFadeIn = true;
                }
            }
            return(isLoad);
        }