private static void DetectInput(string input) { switch (input) { case "-help": DisplayHelp(); break; case "-exit": Save(); running = false; break; case "-clear": Console.Clear(); break; case "-colorThreshold": Console.WriteLine("Enter new color threshold: "); var colInput = Console.ReadLine(); if (int.TryParse(colInput, out var colVal)) { ColorThreshold = colVal; Console.WriteLine("New Threshold: " + ColorThreshold); } else { Console.WriteLine("--Invalid Input--"); } Save(); break; case "-calibrate": Calibration(); break; case "-run": Console.WriteLine("Not yet implemented, use the debug command"); RunDetection(); break; case "-import": ImageHandler.CaptureImage("background.bmp"); break; case "-export": Console.WriteLine("Set image export file:"); export = Console.ReadLine(); Console.WriteLine("New export file: " + export); Save(); break; case "-threshold": Console.WriteLine("Set threshold:"); var thresholdInput = Console.ReadLine(); if (int.TryParse(thresholdInput, out var value)) { Threshold = value; Console.WriteLine("New Threshold: " + Threshold); } else { Console.WriteLine("--Invalid Input--"); } Save(); break; case "-background": Console.WriteLine("Set background: "); SetBackground(); break; case "-debug": Debug(); break; case "-reset": Reset(); break; case "-minBlobSize": Console.WriteLine("Set Min Blob Size in Pixels:"); minBlobSize = BlobSize(Console.ReadLine()); break; default: Console.WriteLine("--Invalid input--"); break; } int BlobSize(string consoleInput) { if (int.TryParse(consoleInput, out int value)) { Console.WriteLine("Threshold set: " + value); return(value); } Console.WriteLine("--Invalid Input--"); return(0); } }
public static void StartProgram(string bImagePath, string imagePath, string fileName, int minBlobSize) { string root = System.Reflection.Assembly.GetExecutingAssembly().Location; string rootPath = Path.GetFullPath(Path.Combine(root, "..")) + "/StreamingAssets/"; List <Blob> _b = new List <Blob>(); Bitmap _img = ImageHandler.LoadImage(imagePath); Bitmap _bImg = ImageHandler.LoadImage(bImagePath); CCHandler CC = new CCHandler(_img); ColorProcessing colorProcess = new ColorProcessing(); Console.WriteLine("\nThresholding..."); Bitmap _timg = CC.BackgroundSubtraction(_bImg, _img, CommandConsole.Threshold); Console.WriteLine("\nDetecting Blobs..."); _b = CC.FindBlobs(); Console.WriteLine(" Blobs Found: " + _b.Count); foreach (Blob b in _b) { if (b.points.Count > minBlobSize) { bb.Add(b); } } Console.WriteLine("\nCreating Mask..."); Bitmap _mimg = CC.MaskInverse(bb); Console.WriteLine("\nCleaning colors"); _timg = colorProcess.CleanImage(_timg, _mimg); foreach (Blob b in bb) { b.DrawCorners(_timg, b.getCorners()); } Console.WriteLine("\nSaving files..."); if (File.Exists(rootPath + fileName)) { Console.WriteLine(" File Already Exists. Overwriting"); File.Delete(rootPath + fileName); } if (File.Exists(rootPath + "Mask.bmp")) { File.Delete(rootPath + "Mask.bmp"); } Console.WriteLine(" Exporting Bitmap..."); _mimg.Save(rootPath + "Mask.bmp"); _timg.Save(rootPath + fileName); Console.WriteLine("\nBlob Detection Execution: Success!"); Console.WriteLine("Exporting binary file..."); //TODO: For now, the exporter spits out binaries into rootPath. Eventually, this should be into StreamingAssets. Exporter.Run(bb, rootPath, "binary", _timg); Console.WriteLine("Export complete."); _b.Clear(); bb.Clear(); _mimg.Dispose(); _timg.Dispose(); _img.Dispose(); _bImg.Dispose(); }