public void gradientAtPoint10_IntPoint_Test()              //Проверка градиента  внутренней точки
        {
            //arrange
            IParser parser = new Parser();
            Bitmap  img    = parser.readPNG("Data\\sample_10.png");

            MathematicialSearchPoint core = new MathematicialSearchPoint8();

            core.setImage(img);

            double[,] X = new double[5, 5];
            for (int i = 600; i < 605; i++)
            {
                for (int j = 600; j < 605; j++)
                {
                    X[i - 600, j - 600] = img.GetPixel(i, j).B;   //Матрица окружения точки (602,602)
                }
            }
            double gradX = 0;
            double gradY = 0;
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    gradX += X[i, j] * core.XMatrix[j, i];
                    gradY += X[i, j] * core.YMatrix[j, i];
                }
            }
            //act
            double exepected = (gradX + gradY) / 2;
            double actual    = core.gradientAtPoint(602, 602);
            //assert
            Assert.AreEqual(exepected, actual);
        }
示例#2
0
        public void MathematicialSearchPoint_8Test()          //Проверка ядер свертки
        {
            //arrange
            MathematicialSearchPoint core = new MathematicialSearchPoint8();

            //act
            double[,] exepectedGx = new double[, ] {
                { 0, 0, 1, 0, 0 }, { 0, 0, 2, 0, 0 }, { 1, 2, -12, 2, 1 }, { 0, 0, 2, 0, 0 }, { 0, 0, 1, 0, 0 }
            };
            double[,] exepectedGy = new double[, ] {
                { 1, 0, 0, 0, 1 }, { 0, 2, 0, 2, 0 }, { 0, 0, -12, 0, 0 }, { 0, 2, 0, 2, 0 }, { 1, 0, 0, 0, 1 }
            };
            double[,] actualGx = core.XMatrix;
            double[,] actualGy = core.YMatrix;

            //assert
            Debug.WriteLine("Проверка ядер  свертки Gx и Gy");
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    Assert.AreEqual(exepectedGx[i, j], actualGx[i, j]);
                    Assert.AreEqual(exepectedGy[i, j], actualGy[i, j]);
                }
            }
        }
示例#3
0
        public void gradientAtPoint8_CornerPoint_Test()              //Проверка градиента  угловой точки
        {
            //arrange
            IParser parser = new Parser();
            Bitmap  img    = parser.readPNG("Data\\sample_10.png");

            //Blue[i, j] = 0.3 * img.GetPixel(i, j).R + 0.59 * img.GetPixel(i, j).G + 0.11 * img.GetPixel(i, j).B;    //Заполнение монохромного изображения

            MathematicialSearchPoint core = new MathematicialSearchPoint8();

            core.setImage(img);
            double[,] X = new double[5, 5];
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    X[i, j] = 0;
                }
            }
            for (int i = 2; i < 5; i++)
            {
                for (int j = 2; j < 5; j++)
                {
                    X[i, j] = img.GetPixel(i - 2, j - 2).B;               //Матрица окружения точки (0,0)
                }
            }
            double gradX = 0;
            double gradY = 0;
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    gradX += X[i, j] * core.XMatrix[j, i];
                    gradY += X[i, j] * core.YMatrix[j, i];
                }
            }
            //act
            double exepected = (gradX + gradY) / 2;
            double actual    = core.gradientAtPoint(0, 0);
            //assert
            Assert.AreEqual(exepected, actual);
        }
示例#4
0
        public void gradientAtPoint8_BoundaryPoint_Test()              //Проверка градиента  граничной точки
        {
            //arrange
            IParser parser = new Parser();
            Bitmap  img    = parser.readPNG("Data\\sample_10.png");; //Заполнение монохромного изображения

            MathematicialSearchPoint core = new MathematicialSearchPoint8();

            core.setImage(img);

            double[,] X = new double[5, 5];
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    X[i, j] = 0;
                }
            }
            for (int i = 797; i < 800; i++)
            {
                for (int j = 1; j < 6; j++)
                {
                    X[i - 797, j - 1] = img.GetPixel(i, j).B;             //Матрица окружения точки (799,3)
                }
            }
            double gradX = 0;
            double gradY = 0;
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    gradX += X[i, j] * core.XMatrix[j, i];
                    gradY += X[i, j] * core.YMatrix[j, i];
                }
            }
            //act
            double exepected = (gradX + gradY) / 2;
            double actual    = core.gradientAtPoint(799, 3);
            //assert
            Assert.AreEqual(exepected, actual);
        }
示例#5
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();
        }