private List <InputFileModel> GetInputFromStereoCamera(VideoCapture LeftCamera, VideoCapture RightCamera, int countInputFile = 0) { LeftCamera.Grab(); RightCamera.Grab(); Mat LeftImage = new Mat(); Mat RightImage = new Mat(); LeftCamera.Retrieve(LeftImage); RightCamera.Retrieve(RightImage); LeftImage.Save(Path.Combine($@"{tempLeftStackDirectory}", $"Left_{countInputFile}.JPG")); RightImage.Save(Path.Combine($@"{tempRightStackDirectory}", $"Right_{countInputFile}.JPG")); var inputFileLeft = new InputFileModel(Path.Combine($@"{tempLeftStackDirectory}", $"Left_{countInputFile}.JPG")); var imageList = _winForm.ImageList[(int)EListViewGroup.LeftCameraStack]; var listViewer = _winForm.ListViews[(int)EListViewGroup.LeftCameraStack]; _fileManager.AddInputFileToList(inputFileLeft, _fileManager.listViewerModel.ListOfListInputFolder[(int)EListViewGroup.LeftCameraStack], imageList, listViewer); var inputFileRight = new InputFileModel(Path.Combine($@"{tempRightStackDirectory}", $"Right_{countInputFile}.JPG")); imageList = _winForm.ImageList[(int)EListViewGroup.RightCameraStack]; listViewer = _winForm.ListViews[(int)EListViewGroup.RightCameraStack]; _fileManager.AddInputFileToList(inputFileLeft, _fileManager.listViewerModel.ListOfListInputFolder[(int)EListViewGroup.RightCameraStack], imageList, listViewer); var returnList = new List <InputFileModel>(); returnList.Add(inputFileLeft); returnList.Add(inputFileRight); return(returnList); }
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 InputFileModel GetInputParamsFromCSV() { System.Console.WriteLine("Reading input parameters from csv file: Input.csv"); try { using (var reader = File.OpenText("Files/Input.csv")) { var inputCSV = new CsvReader(reader); var inputModel = new InputFileModel(); while (inputCSV.Read()) { inputModel.InitialPosition = inputCSV.GetField <int>(0); inputModel.InitialVelocity = inputCSV.GetField <int>(1); } return(inputModel); } } catch (Exception e) { System.Console.WriteLine(e); var errorModel = new InputFileModel() { IsError = true }; return(errorModel); } }
private void ProcessCarFinderInBackground(InputFileModel inputValues) { var carModel = new Car(inputValues.InitialPosition, inputValues.InitialVelocity, new CarFinderManager()); carModel.GameEnd += CarModel_GameEnd; carModel.Play(); }
private void AddDepthMapToListView(Image <Bgr, byte> disparityMap) { disparityMap.Save(Path.Combine($@"{tempDepthMapDirectory}", $"DepthMap_{_fileManager.listViewerModel.LeftCameraStack.Count}.JPG")); var inputFileLeft = new InputFileModel(Path.Combine($@"{tempDepthMapDirectory}", $"DepthMap_{_fileManager.listViewerModel.LeftCameraStack.Count}.JPG")); var imageList = _winForm.ImageList[(int)EListViewGroup.DepthMap]; var listViewer = _winForm.ListViews[(int)EListViewGroup.DepthMap]; _fileManager.AddInputFileToList(inputFileLeft, _fileManager.listViewerModel.ListOfListInputFolder[(int)EListViewGroup.DepthMap], imageList, listViewer); }
public void AddInputFileToList(InputFileModel inputFile, List <InputFileModel> listOfInput, ImageList imageList, ListView listView) { if (listView.InvokeRequired) { listView.Invoke((Action) delegate { AddInputFileToList(inputFile, listOfInput, imageList, listView); }); } else { imageList.Images.Add(inputFile.fileInfo.Name, inputFile.image); var listItem = new ListViewItem(inputFile.fileInfo.Name, imageList.Images.IndexOfKey(inputFile.fileInfo.Name)) { ImageKey = inputFile.fileInfo.Name }; listOfInput.Add(inputFile); listView.Items.Add(listItem); } }
public void AddToListView() { using (OpenFileDialog ofd = new OpenFileDialog() { Multiselect = true, ValidateNames = true, CheckFileExists = true, CheckPathExists = true, Filter = "" }) { DialogHelper.AddFilterToDialog <EImageFormat>(ofd, "All Image Files"); DialogHelper.AddFilterToDialog <EVideoFormat>(ofd, "All Video Files"); if (ofd.ShowDialog() == DialogResult.OK) { foreach (var fileName in ofd.FileNames) { var inputFile = new InputFileModel(fileName); var imageList = _winForm.ImageList[(int)ListViewerDisplay]; var listViewer = _winForm.ListViews[(int)ListViewerDisplay]; AddInputFileToList(inputFile, listViewerModel.ListOfListInputFolder[(int)ListViewerDisplay], imageList, listViewer); } } ; } }
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); } }