private void FindKeypoint(int ID, InputFileModel inputFile, IFeatureDetector detector, bool AddToList = true) { WindowsFormHelper.AddLogToConsole($"Start finding key points for: {inputFile.fileInfo.Name.ToString()}\n"); var detectedKeyPoints = detector.DetectKeyPoints(new Mat(inputFile.fileInfo.FullName)); if (AddToList) { DetectedKeyPoints.Add(ID, new KeyPointModel() { DetectedKeyPoints = new VectorOfKeyPoint(detectedKeyPoints), InputFile = inputFile, ID = ID } ); } WindowsFormHelper.AddLogToConsole($"FINISH finding key points for: {inputFile.fileInfo.Name.ToString()}\n"); // Save drawing image Mat output = new Mat(); Directory.CreateDirectory($@"{tempDirectory}\DrawKeypoint"); Features2DToolbox.DrawKeypoints(new Mat(inputFile.fileInfo.FullName), new VectorOfKeyPoint(detectedKeyPoints), output, new Bgr(0, 0, 255), KeypointDrawType.DrawRichKeypoints); output.Save(Path.Combine($@"{tempDirectory}\DrawKeypoint", $"{Path.GetFileNameWithoutExtension(inputFile.fileInfo.Name)}.JPG")); fileManager.listViewerModel._lastDrawnKeypoint = new Image <Bgr, byte>(output.Bitmap); var file = new InputFileModel(Path.Combine($@"{tempDirectory}\DrawKeypoint", $"{Path.GetFileNameWithoutExtension(inputFile.fileInfo.Name)}.JPG")); var imageList = _winForm.ImageList[(int)EListViewGroup.DrawnKeyPoint]; var listViewer = _winForm.ListViews[(int)EListViewGroup.DrawnKeyPoint]; fileManager.AddInputFileToList(file, fileManager.listViewerModel.ListOfListInputFolder[(int)EListViewGroup.DrawnKeyPoint], imageList, listViewer); }
public void Match(IInputArray queryDescriptors, IInputArray trainDescriptors, VectorOfVectorOfDMatch matches) { Monitor.Enter(locker); WindowsFormHelper.AddLogToConsole("In monitor"); var _cudaBruteForceMatcher = CreateMatcher(); var left = new GpuMat(queryDescriptors as Mat); var right = new GpuMat(trainDescriptors as Mat); _cudaBruteForceMatcher.KnnMatch(right, left, matches, 1); left.Dispose(); right.Dispose(); _cudaBruteForceMatcher.Dispose(); WindowsFormHelper.AddLogToConsole("Exit monitor"); Monitor.Exit(locker); }
public MainForm() { InitializeComponent(); cameraManager = new CameraManager(this); fileManager = new FileManager(this, cameraManager); displayManager = new DisplayManager(this, fileManager, cameraManager); stereoVisionManager = new StereoVisionManager(fileManager, displayManager, cameraManager, this); structureFromMotionManager = new SfM(fileManager, displayManager, this, cameraManager); mainFormManager = new MainFormManager(this, displayManager, fileManager, stereoVisionManager, structureFromMotionManager, cameraManager); WindowsFormHelper.SetWinForm(this); InitializeStringForComponents(); Application.Idle += new EventHandler(displayManager.Display); }
private void ComputeDescriptor(KeyPointModel keypoint, IFeatureDescriptor descriptor, bool AddToList = true, bool SaveOnDisk = true) { WindowsFormHelper.AddLogToConsole($"Start computing descriptor for: {keypoint.InputFile.fileInfo.Name.ToString()}\n"); var computedDescriptor = descriptor.ComputeDescriptor(keypoint); var descriptorNode = new DescriptorModel() { Descriptors = computedDescriptor, KeyPoint = keypoint }; WindowsFormHelper.AddLogToConsole($"FINISH computing descriptor for: {keypoint.InputFile.fileInfo.Name.ToString()}\n"); if (AddToList) { ComputedDescriptors.Add(keypoint.ID, descriptorNode); } if (SaveOnDisk) { SaveSiftFile(descriptorNode); } }
private void trackBar_ValueChangedMultiple16(object sender, EventArgs e) { WindowsFormHelper.trackBar_ValueChangedMultiple16(sender as TrackBar, toolTip1, GetPropertiesAndSetModel); }
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); } }