Beispiel #1
0
        public void getSolutionTest()          //Проверка отсева (получения хороших точек)
        {
            //Хорошая точка-значение градиента больше порогового значения
            //arrange
            IMathematical strat       = new MathematicialSearchPoint1();
            Elimination   elemenation = new Elimination(strat);

            Data.Image img = new Data.Image("Data\\sample_10.png");
            elemenation.calculateGradientImage(img);      //Вычисление градиента
            //act
            double maxGradient = elemenation.swingSharpness[0, 0];
            double minGradient = elemenation.swingSharpness[0, 0];

            for (int i = 0; i < img.width(); i++)       //Найти макс и мин
            {
                for (int j = 0; j < img.height(); j++)
                {
                    maxGradient = Math.Max(maxGradient, elemenation.swingSharpness[i, j]);
                    minGradient = Math.Min(minGradient, elemenation.swingSharpness[i, j]);
                }
            }
            double            threshold = minGradient + ((maxGradient - minGradient) * 0.1); //порог
            List <Data.Point> exepected = new List <Data.Point>();

            for (int i = 0; i < img.width(); i++)
            {
                for (int j = 0; j < img.height(); j++)
                {
                    if (elemenation.swingSharpness[i, j] >= threshold)
                    {
                        exepected.Add(new Data.Point(i, j));
                    }
                }
            }

            List <Data.Point> actual = new List <Data.Point>();

            actual = elemenation.getSolution();
            //assert
            Debug.WriteLine("Проверка количества точек");
            Assert.AreEqual(actual.Count, exepected.Count);
            Debug.WriteLine("Проверка самих точек");
            int t = 0;

            foreach (Data.Point p1 in exepected)
            {
                Assert.AreEqual(p1.x, actual[t].x);
                Assert.AreEqual(p1.y, actual[t].y);
                t++;
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            IParser      parser      = new Parser();
            ICalculated  calculated  = new Calculated(new MathematicialSearchPoint1());
            IPreserveOBJ preserveOBJ = new PreserveOBJ();
            IPreservePNG preservePNG = new PreservePNG();
            IElimination elimination = new Elimination();
            IAnalysis    analysis;
            Setting      setting = null;
            double       delta   = 0.0;

            List <string> filesImagesname;
            string        pathFolder;
            string        pathConfig;

            if (args.Length == 0)
            {
                Console.WriteLine("usage: Get3DModel.exe <path to folder>"); Environment.Exit(-1);
            }
            pathFolder = args[0];

            filesImagesname = Directory.GetFiles(pathFolder, "*.png").ToList <string>();
            if (args.Length > 1)
            {
                delta = Convert.ToDouble(args[1]);
            }

            pathConfig = Directory.GetFiles(pathFolder).ToList().First(
                x => x.EndsWith(".camera"));
            FileInfo fileInf = new FileInfo(pathConfig);

            if (fileInf.Exists)
            {
                setting = new Setting(pathConfig);
                Console.WriteLine("the verification of the optics configuration file completed successfully");
            }
            else
            {
                Console.WriteLine("the configuration file is not found");
                Environment.Exit(-1);
            }

            Stopwatch timeForParsing = new Stopwatch();

            for (int i = 0; i < filesImagesname.Count && i < 50; i++)
            {
                if (filesImagesname[i].EndsWith("sharpImage.png"))
                {
                    continue;
                }
                timeForParsing.Restart();
                Data.Image itemImage = new Data.Image(filesImagesname[i]);
                elimination.calculateGradientImage(itemImage);
                timeForParsing.Stop();
                Console.WriteLine(
                    string.Format("elimination of the {0} has finished\n\telapsed time: {1} milliseconds",
                                  filesImagesname[i], timeForParsing.ElapsedMilliseconds));
                GC.Collect();
            }
            List <Data.Point> goodPoint = elimination.getSolution();

            analysis = new Analysis(goodPoint);
            for (int i = 0; i < filesImagesname.Count; i++)
            // Parallel.For(0, filesImagesname.Count, i =>
            {
                if (filesImagesname[i].EndsWith("sharpImage.png"))
                {
                    continue;
                }
                timeForParsing.Restart();
                Data.Image itemImage = new Data.Image(filesImagesname[i]);
                lock (analysis) analysis.addImageAnalysis(itemImage);
                timeForParsing.Stop();
                Console.WriteLine(
                    string.Format("analysing of the {0} has finished\n\telapsed time: {1} milliseconds",
                                  filesImagesname[i], timeForParsing.ElapsedMilliseconds));
            } //);
            List <IMathematical> coreGoodPoint = analysis.getCore();

            analysis    = null;
            elimination = null;
            GC.Collect();
            calculated.createdBeginSolution();
            for (int i = 0; i < filesImagesname.Count; i++)
            {
                if (filesImagesname[i].EndsWith("sharpImage.png"))
                {
                    continue;
                }
                timeForParsing.Restart();
                Data.Image itemImage = new Data.Image(filesImagesname[i]);
                calculated.clarifySolution(itemImage, coreGoodPoint, goodPoint);
                timeForParsing.Stop();
                Console.WriteLine(
                    string.Format("processing of the {0} has finished\n\telapsed time: {1} milliseconds",
                                  filesImagesname[i], timeForParsing.ElapsedMilliseconds));
            }
            Solution solution = calculated.getSolution();

            Console.WriteLine("saving data was started");
            preserveOBJ.saveOBJ(solution, setting, pathFolder);
            preservePNG.savePNG(solution, pathFolder);
        }