예제 #1
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();
        }