Esempio n. 1
0
 private void StartMatching(int countOfExistedKeypoint, IFeatureMatcher matcher)
 {
     if (_useParallel)
     {
         StartParallelMatching(countOfExistedKeypoint, matcher);
     }
     else
     {
         StartSequenceMatching(countOfExistedKeypoint, matcher);
     }
 }
Esempio n. 2
0
        private void StartStereoParallelMatching(int countOfExistedKeypoint, IFeatureMatcher matcher)
        {
            FindMatches(matcher, ComputedDescriptors[countOfExistedKeypoint - 2], ComputedDescriptors[countOfExistedKeypoint - 1]);

            switch (_matchingType)
            {
            case EMatchingType.OnePrevious:
                Parallel.For(countOfExistedKeypoint, ComputedDescriptors.Count, index =>
                {
                    if (index >= 1 * 2)
                    {
                        Parallel.For(index - (1 * 2), index, i =>
                        {
                            if ((index - i) % 2 == 0)
                            {
                                FindMatches(matcher, ComputedDescriptors[index], ComputedDescriptors[i]);
                            }
                        });
                    }
                });
                break;

            case EMatchingType.TwoPrevious:
                Parallel.For(countOfExistedKeypoint, ComputedDescriptors.Count, index =>
                {
                    if (index >= 2 * 2)
                    {
                        Parallel.For(index - (2 * 2), index, i =>
                        {
                            if ((index - i) % 2 == 0)
                            {
                                FindMatches(matcher, ComputedDescriptors[index], ComputedDescriptors[i]);
                            }
                        });
                    }
                });
                break;

            case EMatchingType.AllWithAll:
                throw new NotImplementedException();
                Parallel.For(countOfExistedKeypoint, ComputedDescriptors.Count, index =>
                {
                    Parallel.For(index + 1, ComputedDescriptors.Count, i =>
                    {
                        FindMatches(matcher, ComputedDescriptors[index], ComputedDescriptors[i]);
                    });
                });
                break;
            }
        }
Esempio n. 3
0
        public void SetFeatureMatcher(object sender, EventArgs e)
        {
            var currentItem = sender as ToolStripComboBox;
            var enumItem    = EnumExtension.ReturnEnumValue <EFeaturesMatcher>(currentItem.SelectedItem.ToString());

            IFeatureMatcher tempItem = null;

            switch (enumItem)
            {
            case EFeaturesMatcher.BruteForce: tempItem = new BruteForce(); break;

            case EFeaturesMatcher.CudaBruteForce: tempItem = new CudaBruteForce(); break;
            }

            _sfmManager._matcher = tempItem;
        }
Esempio n. 4
0
        private void StartStereoSequenceMatching(int countOfExistedKeypoint, IFeatureMatcher matcher)
        {
            FindMatches(matcher, ComputedDescriptors[countOfExistedKeypoint - 2], ComputedDescriptors[countOfExistedKeypoint - 1]);

            switch (_matchingType)
            {
            case EMatchingType.OnePrevious:
                for (int m = countOfExistedKeypoint; m < ComputedDescriptors.Count; m++)
                {
                    for (int n = m - (1 * 2); n < m; n += 2)
                    {
                        if (n >= 0)
                        {
                            FindMatches(matcher, ComputedDescriptors[m], ComputedDescriptors[n]);
                        }
                    }
                }
                break;

            case EMatchingType.TwoPrevious:
                for (int m = countOfExistedKeypoint; m < ComputedDescriptors.Count; m++)
                {
                    for (int n = m - (2 * 2); n < m; n += 2)
                    {
                        if (n >= 0)
                        {
                            FindMatches(matcher, ComputedDescriptors[m], ComputedDescriptors[n]);
                        }
                    }
                }
                break;

            case EMatchingType.AllWithAll:
                throw new NotImplementedException();
                for (int m = countOfExistedKeypoint; m < ComputedDescriptors.Count; m++)
                {
                    for (int n = m + 1; n < ComputedDescriptors.Count; n++)
                    {
                        FindMatches(matcher, ComputedDescriptors[m], ComputedDescriptors[n]);
                    }
                }
                break;
            }
        }
Esempio n. 5
0
        private void FindMatches(IFeatureMatcher matcher, DescriptorModel leftDescriptor, DescriptorModel rightDescriptor, bool AddToList = true, bool FilterMatches = true, bool ComputeHomography = true, bool SaveInMatchNode = true)
        {
            WindowsFormHelper.AddLogToConsole($"Start computing matches for: \n" +
                                              $"\t{leftDescriptor.KeyPoint.InputFile.fileInfo.Name.ToString()}\n" +
                                              $"\t{rightDescriptor.KeyPoint.InputFile.fileInfo.Name.ToString()}\n");


            var foundedMatch = new DescriptorsMatchModel()
            {
                FilteredMatch   = FilterMatches,
                LeftDescriptor  = leftDescriptor,
                RightDescriptor = rightDescriptor
            };

            var matches = new VectorOfVectorOfDMatch();

            matcher.Match(leftDescriptor.Descriptors, rightDescriptor.Descriptors, matches);

            WindowsFormHelper.AddLogToConsole(
                $"FINISH computing matches for: \n" +
                $"\t{leftDescriptor.KeyPoint.InputFile.fileInfo.Name.ToString()}\n" +
                $"\t{rightDescriptor.KeyPoint.InputFile.fileInfo.Name.ToString()}\n"
                );


            MDMatch[][] matchesArray = matches.ToArrayOfArray();
            foundedMatch.MatchesList = matchesArray.ToList();

            if (FilterMatches)
            {
                FindMinMaxDistInMatches(matchesArray, ref ms_MAX_DIST, ref ms_MIN_DIST);
                List <MDMatch[]> filteredMatchesList = FilterMatchesByMaxDist(matchesArray);
                foundedMatch.FilteredMatchesList = filteredMatchesList;
            }

            if (ComputeHomography)
            {
                var PerspectiveMatrix = new Mat();
                Mat Mask = new Mat();

                lock (locker)
                {
                    var matchesForHomography = FilterMatches ? foundedMatch.FilteredMatchesList : foundedMatch.MatchesList;
                    if (matchesForHomography.Count > 0)
                    {
                        PerspectiveMatrix = FindHomography(leftDescriptor.KeyPoint.DetectedKeyPoints, rightDescriptor.KeyPoint.DetectedKeyPoints, FilterMatches ? foundedMatch.FilteredMatchesList : foundedMatch.MatchesList, Mask);
                        foundedMatch.Mask = Mask;
                        foundedMatch.PerspectiveMatrix = PerspectiveMatrix;
                    }
                }
            }

            // Save drawing image
            Mat output = new Mat();

            Directory.CreateDirectory($@"{tempDirectory}\DrawMatches");
            Features2DToolbox.DrawMatches(new Mat(foundedMatch.LeftDescriptor.KeyPoint.InputFile.fileInfo.FullName), foundedMatch.LeftDescriptor.KeyPoint.DetectedKeyPoints, new Mat(foundedMatch.RightDescriptor.KeyPoint.InputFile.fileInfo.FullName), foundedMatch.RightDescriptor.KeyPoint.DetectedKeyPoints, new VectorOfVectorOfDMatch(foundedMatch.FilteredMatchesList.ToArray()), output, new MCvScalar(0, 0, 255), new MCvScalar(0, 255, 0), foundedMatch.Mask);
            output.Save(Path.Combine($@"{tempDirectory}\DrawMatches", $"{Path.GetFileNameWithoutExtension(foundedMatch.RightDescriptor.KeyPoint.InputFile.fileInfo.Name)}-{Path.GetFileNameWithoutExtension(foundedMatch.LeftDescriptor.KeyPoint.InputFile.fileInfo.Name)}.JPG"));
            fileManager.listViewerModel._lastDrawnMatches = new Image <Bgr, byte>(output.Bitmap);

            var inputFile  = new InputFileModel(Path.Combine($@"{tempDirectory}\DrawMatches", $"{Path.GetFileNameWithoutExtension(foundedMatch.RightDescriptor.KeyPoint.InputFile.fileInfo.Name)}-{Path.GetFileNameWithoutExtension(foundedMatch.LeftDescriptor.KeyPoint.InputFile.fileInfo.Name)}.JPG"));
            var imageList  = _winForm.ImageList[(int)EListViewGroup.DrawnMatches];
            var listViewer = _winForm.ListViews[(int)EListViewGroup.DrawnMatches];

            fileManager.AddInputFileToList(inputFile, fileManager.listViewerModel.ListOfListInputFolder[(int)EListViewGroup.DrawnMatches], imageList, listViewer);

            if (SaveInMatchNode)
            {
                SaveMatchString(foundedMatch, true);
            }

            if (AddToList)
            {
                FoundedMatches.Add(foundedMatch);
            }
        }
Esempio n. 6
0
        public void ContinueInComputingSFM(IFeatureDetector detector, IFeatureDescriptor descriptor, IFeatureMatcher matcher, List <InputFileModel> listOfInput)
        {
            var iterMatches = FoundedMatches.Count;

            countInputFile = DetectedKeyPoints.Count;

            StartDetectingKeyPoint(countInputFile, listOfInput, detector);
            StartComputingDescriptor(countInputFile, descriptor);
            StartMatching(countInputFile, matcher);

            WriteAddedImages(listOfInput);
            AppendMatches(FoundedMatches, iterMatches);
            ContinueVisualSFM();
        }
Esempio n. 7
0
        public void ComputeSfM(IFeatureDetector detector, IFeatureDescriptor descriptor, IFeatureMatcher matcher, List <InputFileModel> listOfInput)
        {
            countInputFile = 0;
            DetectedKeyPoints.Clear();
            ComputedDescriptors.Clear();
            FoundedMatches.Clear();

            switch (fileManager._inputType)
            {
            case EInput.ListView:
                StartDetectingKeyPoint(0, listOfInput, detector);
                StartComputingDescriptor(0, descriptor);
                StartMatching(0, matcher);
                break;

            case EInput.ConnectedStereoCamera:

                countInputFile = DetectedKeyPoints.Count;
                listOfInput    = GetInputFromStereoCamera(countInputFile);


                StartDetectingKeyPoint(countInputFile, listOfInput, detector);
                StartComputingDescriptor(countInputFile, descriptor);
                while (!stopSFM)
                {
                    countInputFile = DetectedKeyPoints.Count;
                    listOfInput    = GetInputFromStereoCamera(countInputFile);


                    StartDetectingKeyPoint(countInputFile, listOfInput, detector);
                    StartComputingDescriptor(countInputFile, descriptor);
                    StartStereoMatching(countInputFile, matcher);
                }
                break;
            }

            WriteAllMatches(FoundedMatches);
            RunVisualSFM();
        }
 public FeatureFilter Where(IFeatureMatcher predicate)
 {
     Matcher = predicate;
     return(this);
 }
 public FeatureFilter()
 {
     Matcher           = new FeatureMatcher();
     CollectionNameSet = new List <string>();
 }