Example #1
0
        static void Main(string[] args)
        {
            CmdLineParams cmdLineParams = new CmdLineParams();

            CmdLineArgsParser.Parse(args, cmdLineParams);

            Console.WriteLine("Input folder:  {0}", cmdLineParams.InputFolder);
            Console.WriteLine("Output file : {0}", cmdLineParams.OutputFile);

            string[] inputImages = Directory.GetFiles(cmdLineParams.InputFolder).Where(f => IMAGE_EXTENSIONS.Contains(Path.GetExtension(f).ToLower())).ToArray();

            LensParams lensParams = null;

            LensCorrection.Calibrate(inputImages, out lensParams);

            Console.WriteLine("Lens correction matrix (K):");
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Console.Write("{0:0000.000}; ", lensParams.K[i, j]);
                }
                Console.WriteLine(" ");
            }

            Console.WriteLine("Distorsion coefficients (D):");
            for (int i = 0; i < 4; i++)
            {
                Console.Write("{0:0.000}; ", lensParams.D[i, 0]);
            }
            Console.WriteLine(" ");

            lensParams.SaveToJsonFile(cmdLineParams.OutputFile);
        }
            static void loadAllPresets()
            {
                presets = new Dictionary <string, LensParams> ();

                TextAsset localStringsAsset = (TextAsset)Resources.Load("lensPresets");

                if (localStringsAsset != null && !string.IsNullOrEmpty(localStringsAsset.text))
                {
                    System.IO.StringReader textStream = new System.IO.StringReader(localStringsAsset.text);
                    string line = null;
                    while ((line = textStream.ReadLine()) != null)
                    {
                        int eqIndex = line.IndexOf("=");
                        if (eqIndex > 0)
                        {
                            string     presetName = line.Substring(0, eqIndex);
                            LensParams lp         = new LensParams();
                            string[]   vals       = line.Substring(eqIndex + 1, line.Length - eqIndex - 1).Split(',');
                            if (vals.Length != 11)
                            {
                                Debug.LogWarning("Invalid number of values for preset " + presetName);
                            }
                            else
                            {
                                lp.screenx = float.Parse(vals[0]);
                                lp.screeny = float.Parse(vals[1]);
                                lp.lensx   = float.Parse(vals[2]);
                                lp.lensy   = float.Parse(vals[3]);
                                lp.scalex  = float.Parse(vals[4]);
                                lp.scaley  = float.Parse(vals[5]);
                                lp.warpx   = float.Parse(vals[6]);
                                lp.warpy   = float.Parse(vals[7]);
                                lp.warpz   = float.Parse(vals[8]);
                                lp.warpw   = float.Parse(vals[9]);
                                lp.chroma  = float.Parse(vals[10]);

                                if (presets.ContainsKey(presetName))
                                {
                                    presets.Remove(presetName);
                                }
                                presets.Add(presetName, lp);
                            }
                        }
                    }

                    textStream.Close();
                }

                //selectPreset (currentPreset);
            }
Example #3
0
        static void Main(string[] args)
        {
            CmdLineParams cmdLineParams = new CmdLineParams();

            CmdLineArgsParser.Parse(args, cmdLineParams);

            LensParams lensParams = LensParams.ReadFromJson(cmdLineParams.LensParamsJsonPath);

            Console.WriteLine("Lens correction matrix (K):");
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Console.Write("{0:0000.000}; ", lensParams.K[i, j]);
                }
                Console.WriteLine(" ");
            }

            Console.WriteLine("Distorsion coefficients (D):");
            for (int i = 0; i < 4; i++)
            {
                Console.Write("{0:0.000}; ", lensParams.D[i, 0]);
            }
            Console.WriteLine(" ");

            if (!Directory.Exists(cmdLineParams.OutputFolder))
            {
                Console.WriteLine("Create output folder: {0}", cmdLineParams.OutputFolder);
                Directory.CreateDirectory(cmdLineParams.OutputFolder);
            }

            string[] inputImages = Directory.GetFiles(cmdLineParams.InputFolder).Where(f => IMAGE_EXTENSIONS.Contains(Path.GetExtension(f).ToLower())).ToArray();

            foreach (string imgPath in inputImages /*.Take(1).ToArray()*/)
            {
                string fileName = Path.GetFileName(imgPath);
                Console.WriteLine("Image processing {0}...", fileName);
                Mat image = CvInvoke.Imread(imgPath);
                //CvInvoke.Imshow("before", image);
                //CvInvoke.WaitKey(0);
                Mat outputImg = LensCorrection.Correct(image, lensParams);
                //CvInvoke.Imshow("after", outputImg);
                //CvInvoke.WaitKey(0);
                outputImg.Save(Path.Combine(cmdLineParams.OutputFolder, fileName));
            }
        }
 public void selectPreset(string preset)
 {
     currentPreset = preset;
     if (presets == null)
     {
         loadAllPresets();
     }
     if (CUSTOM_PRESET.Equals(currentPreset))
     {
         //Debug.Log ("Setting custom lens preset");
         screenx = PlayerPrefs.GetFloat("screenX", screenx);
         screeny = PlayerPrefs.GetFloat("screenY", screeny);
         lensx   = PlayerPrefs.GetFloat("lensX", lensx);
         lensy   = PlayerPrefs.GetFloat("lensY", lensy);
         scalex  = PlayerPrefs.GetFloat("scalex", scalex);
         scaley  = PlayerPrefs.GetFloat("scaley", scaley);
         warpx   = PlayerPrefs.GetFloat("warpx", warpx);
         warpy   = PlayerPrefs.GetFloat("warpy", warpy);
         warpz   = PlayerPrefs.GetFloat("warpz", warpz);
         warpw   = PlayerPrefs.GetFloat("warpw", warpw);
         chroma  = PlayerPrefs.GetFloat("chroma", chroma);
     }
     else
     {
         if (presets.ContainsKey(preset))
         {
             //Debug.Log ("Setting lens preset: " + preset);
             LensParams lp = presets[preset];
             screenx = lp.screenx;
             screeny = lp.screeny;
             lensx   = lp.lensx;
             lensy   = lp.lensy;
             scalex  = lp.scalex;
             scaley  = lp.scaley;
             warpx   = lp.warpx;
             warpy   = lp.warpy;
             warpz   = lp.warpz;
             warpw   = lp.warpw;
             chroma  = lp.chroma;
         }
     }
 }