示例#1
0
        public void clarifySolution(Data.Image image)
        {
            if (swingSharpness == null)
            {
                swingSharpness = new double[image.width(), image.height()];
                for (int x = 0; x < image.width(); x++)
                {
                    for (int y = 0; y < image.height(); y++)
                    {
                        swingSharpness[x, y] = 0;
                    }
                }
                width  = image.width();
                height = image.height();
            }

            List <Data.Point> listPoint   = new List <Data.Point>();
            Bitmap            curentImage = image.image;

            curentImage = changeImage.translateToMonochrome(curentImage);
            matematical.setImage(curentImage);
            for (int x = 0; x < image.width(); x++)
            {
                for (int y = 0; y < image.height(); y++)
                {
                    double gradient = matematical.gradientAtPoint(x, y);
                    if (gradient > swingSharpness[x, y])
                    {
                        listPoint.Add(new Data.Point(x, y));
                        swingSharpness[x, y] = gradient;
                    }
                }
            }
            solution.setValue(listPoint, image);
        }
示例#2
0
        public void calculateGradientImageTest()   //Проверка подсчета градиентов на картинке
        {
            //arrange
            IParser       parser = new Parser();
            Bitmap        bitmap = parser.readPNG("Data\\sample_10.png");
            IMathematical strat  = new MathematicialSearchPoint1();  //Подсчет градиента первой стратегией

            strat.setImage(bitmap);

            Elimination elemenation = new Elimination(strat);

            Data.Image img = new Data.Image("Data\\sample_10.png");

            //act
            elemenation.calculateGradientImage(img);
            double[,] exepected = new double[img.width(), img.height()];
            double[,] actual    = elemenation.swingSharpness;

            //assert
            for (int i = 0; i < img.width(); i++)
            {
                for (int j = 0; j < img.height(); j++)
                {
                    Assert.AreEqual(strat.gradientAtPoint(i, j), actual[i, j]);
                }
            }
        }
示例#3
0
        public void calculateGradientImage(Data.Image image)
        {
            if (swingSharpness == null)
            {
                swingSharpness = new double[image.width(), image.height()];
                for (int x = 0; x < image.width(); x++)
                {
                    for (int y = 0; y < image.height(); y++)
                    {
                        swingSharpness[x, y] = -255;
                    }
                }
            }

            curentImage = image.image;
            curentImage = changeImage.translateToMonochrome(curentImage);
            matematical.setImage(curentImage);

            /*
             * for (int x = 0; x < image.width(); x++)
             *    for (int y = 0; y < image.height(); y++)
             *    {
             *        double gradient = matematical.gradientAtPoint(x, y);
             *        if (gradient > swingSharpness[x, y])
             *            swingSharpness[x, y] = gradient;
             *    }
             */
            Parallel.For(0, 4, calculateGradientImage);
        }
示例#4
0
        public void heightTest()         //Проверка получения высоты изображения в пикселях
        {
            //arrange
            Data.Image img = new Data.Image("Data\\sample_01.png");

            //act
            double height = img.height();

            //assert
            Debug.WriteLine("Проверка ширины");
            Assert.AreEqual(height, 10);
        }
示例#5
0
        public void widthTest()            //Проверка получения ширины изображения в пикселях
        {
            //arrange
            Data.Image img = new Data.Image("Data\\sample_01.png");

            //act
            double widh = img.width();

            //assert
            Debug.WriteLine("Проверка ширины");
            Assert.AreEqual(widh, 20);
        }
示例#6
0
        public void tallTest()                        //Проверка считывания высоты изображения при создании объекта конструктором Image(path)
        {
            //arrange
            string path = "Data\\sample_01.png";

            Data.Image img = new Data.Image(path);
            //act
            double rez       = img.tall;
            double exepected = 1;

            //assert
            Assert.AreEqual(exepected, rez);
        }
示例#7
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++;
            }
        }
示例#8
0
        public void GetPixelTest()        //Проверка получения цвета пикселя изображения
        {
            //arrange
            Data.Image img = new Data.Image("Data\\sample_01.png");

            //act

            //assert
            Debug.WriteLine("Проверка цвета пикселя");
            for (int i = 0; i < img.width(); i++)        //По всем пикселям
            {
                for (int j = 0; j < img.height(); j++)
                {
                    Assert.AreEqual(img.GetPixel(i, j), Color.FromArgb(0, 0, 0));
                }
            }
        }
示例#9
0
        public void clarifySolution(Data.Image image)
        {
            Random       random    = new Random();
            List <Point> listPoint = new List <Point>();
            //Задаем случайное количество точек попавших в фокус
            int countFocusPoint = random.Next(image.width(), image.width() * image.height());

            for (int i = 0; i < countFocusPoint; i++)
            {
                int   x     = random.Next(1, image.width());
                int   y     = random.Next(1, image.height());
                Point point = new Point(x, y);
                listPoint.Add(point);
            }

            solution.setValue(listPoint, image);
        }
示例#10
0
        public void clarifySolution(Data.Image image, List <IMathematical> coreGoodPoint, List <Data.Point> goodPoint)
        {
            if (swingSharpness == null)
            {
                swingSharpness = new double[image.width(), image.height()];

                /*  for (int x = 0; x < image.width(); x++)
                 *    for (int y = 0; y < image.height(); y++)
                 *        swingSharpness[x, y] = 0;*/
                width  = image.width();
                height = image.height();
            }

            List <Data.Point> listPoint   = new List <Data.Point>();
            Bitmap            curentImage = image.image;

            curentImage = changeImage.translateToMonochrome(curentImage);
            HashSet <IMathematical> set = new HashSet <IMathematical>(coreGoodPoint);

            foreach (var i in set)
            {
                i.setImage(curentImage);
            }
            for (int i = 0; i < goodPoint.Count; i++)
            {
                int x = goodPoint[i].x;
                int y = goodPoint[i].y;
                matematical = set.First(item => item.GetType() == coreGoodPoint[i].GetType());

                double gradient = matematical.gradientAtPoint(x, y);
                if (gradient > swingSharpness[x, y])
                {
                    listPoint.Add(new Data.Point(x, y));
                    swingSharpness[x, y] = gradient;
                }
            }
            solution.setValue(listPoint, image);
        }
示例#11
0
        static void Main(string[] args)
        {
            IParser      parser = new Parser();
            ICalculated  calculated;
            IPreserveOBJ preserveOBJ = new PreserveOBJ();
            IPreservePNG preservePNG = new PreservePNG();
            IElimination elimination;
            IAnalysis    analysis;
            Setting      setting = null;
            INIManager   manager;

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

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

            pathSetting = pathFolder + "\\setting.ini";

            manager = new INIManager(pathSetting);

            string[] separators = { "\\" };
            string[] words      = pathFolder.Split(separators, StringSplitOptions.RemoveEmptyEntries);
            saveFolder = words[0];
            for (int i = 1; i < words.Length - 1; i++)
            {
                saveFolder = saveFolder + "\\" + words[i];
            }
            saveFolder = saveFolder + "\\Resulst_" + words[words.Length - 1];

            Directory.CreateDirectory(saveFolder);

            StreamWriter timeTxt = new StreamWriter(saveFolder + "\\time.txt");

            string[] listFileFolder = Directory.GetDirectories(pathFolder);
            foreach (string folder in listFileFolder)
            {
                FileInfo fileInfFolder     = new FileInfo(folder);
                string   nameFolder        = fileInfFolder.Name;
                string   saveFolderCurrent = saveFolder + "\\" + nameFolder;

                Directory.CreateDirectory(saveFolderCurrent);

                filesImagesname = Directory.GetFiles(folder, "*.png").ToList <string>();

                pathConfig = Directory.GetFiles(folder).ToList().First(
                    x => x.EndsWith(".camera") || x.EndsWith(".ini") || x.EndsWith("ConfigurationFile.txt"));

                FileInfo fileInf = new FileInfo(pathConfig);
                if (fileInf.Exists)
                {
                    setting = new Setting(pathConfig);
                }
                else
                {
                    Console.WriteLine("the configuration file is not found");
                    Environment.Exit(-1);
                }
                Stopwatch timeForParsing = new Stopwatch();
                timeForParsing.Restart();

                string        nameCoreElimination = manager.GetPrivateString("ELIMINATION", "core");
                IMathematical coreElimination     = getMathematical(nameCoreElimination);
                if (coreElimination != null)
                {
                    string thresholdElimination = manager.GetPrivateString("ELIMINATION", "threshold");
                    if (thresholdElimination != "default")
                    {
                        double deltaTheshold = Convert.ToDouble(thresholdElimination);
                        coreElimination.setDeltaThreshold(deltaTheshold);
                    }
                    elimination = new Elimination(coreElimination);
                }
                else
                {
                    elimination = new Elimination();
                }

                for (int i = 0; i < filesImagesname.Count; i++)
                {
                    if (filesImagesname[i].EndsWith("sharpImage.png"))
                    {
                        continue;
                    }
                    Data.Image itemImage = new Data.Image(filesImagesname[i]);
                    elimination.calculateGradientImage(itemImage);
                }
                List <Data.Point> goodPoint = elimination.getSolution();

                string boolSelectionCore = manager.GetPrivateString("SELECTION_CORE", "selection_core");
                if (boolSelectionCore == "true")
                {
                    string        nameCore3x3 = manager.GetPrivateString("CORE", "3_core");
                    IMathematical core3x3     = getMathematical(nameCore3x3);
                    if (core3x3 == null)
                    {
                        core3x3 = new MathematicialSearchPoint1();
                    }

                    string        nameCore5x5 = manager.GetPrivateString("CORE", "5_core");
                    IMathematical core5x5     = getMathematical(nameCore5x5);
                    if (core5x5 == null)
                    {
                        core5x5 = new MathematicialSearchPoint8();
                    }

                    string        nameCore7x7 = manager.GetPrivateString("CORE", "7_core");
                    IMathematical core7x7     = getMathematical(nameCore5x5);
                    if (core7x7 == null)
                    {
                        core7x7 = new MathematicialSearchPoint9();
                    }

                    analysis = new Analysis(goodPoint, core3x3, core5x5, core7x7);
                    for (int i = 0; i < filesImagesname.Count; i++)
                    {
                        if (filesImagesname[i].EndsWith("sharpImage.png"))
                        {
                            continue;
                        }
                        Data.Image itemImage = new Data.Image(filesImagesname[i]);
                        analysis.addImageAnalysis(itemImage);
                    }
                    List <IMathematical> coreGoodPoint = analysis.getCore();
                    calculated = new Calculated();
                    calculated.createdBeginSolution();
                    for (int i = 0; i < filesImagesname.Count; i++)
                    {
                        if (filesImagesname[i].EndsWith("sharpImage.png"))
                        {
                            continue;
                        }
                        Data.Image itemImage = new Data.Image(filesImagesname[i]);
                        calculated.clarifySolution(itemImage, coreGoodPoint, goodPoint);
                    }
                }
                else
                {
                    string        nameCore = manager.GetPrivateString("SELECTION_CORE", "default_core");
                    IMathematical core     = getMathematical(nameCore);
                    if (core == null)
                    {
                        core = new MathematicialSearchPoint1();
                    }

                    calculated = new Calculated(core);
                    calculated.createdBeginSolution();
                    for (int i = 0; i < filesImagesname.Count; i++)
                    {
                        if (filesImagesname[i].EndsWith("sharpImage.png"))
                        {
                            continue;
                        }
                        Data.Image itemImage = new Data.Image(filesImagesname[i]);
                        calculated.clarifySolution(itemImage, goodPoint);
                    }
                }

                Solution solution = calculated.getSolution();
                timeForParsing.Stop();
                timeTxt.WriteLine(nameFolder + " - " + timeForParsing.ElapsedMilliseconds + " timeForParsing");
                preserveOBJ.saveOBJ(solution, setting, saveFolderCurrent);
                preservePNG.savePNG(solution, saveFolderCurrent);
                saveDat(solution.Map, saveFolderCurrent);
            }
            timeTxt.Close();
        }
示例#12
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);
        }