public static void Run(string[] args)
        {
            int[] ra = Range.OfInts(52).ToArray();
            string test = "decode.exe options.ini " + string.Join(" ", ra.Select(i => string.Format("picture-{0:000}.bmp", i)).ToArray());
            test.ToArray();
            string dir = @"C:\Users\ASUS\git\procamtools-v1\Debug";

            Thread.Sleep(100);
            ExCamera xcam = new ExCamera();
            Projector proj = new Projector();
            var main = OpenTK.DisplayDevice.AvailableDisplays.First(row => row.IsPrimary);
            var display = new BitmapWindow(main.Bounds.Left + 50, 50, 1280, 960);
            display.Load();
            display.ResizeGraphics();
            proj.DrawBackground(Color.White);
            int c = 0;

            foreach (var file in Directory.GetFiles(dir, "pattern-*.bmp"))
            {
                var map = new Bitmap(Path.Combine(dir, file));
                proj.DrawBitmap(map);
                var pic = xcam.TakePicture();
                display.DrawBitmap(pic);
                var bits = (Bitmap)pic.Clone(new Rectangle(0, 0, pic.Width, pic.Height), PixelFormat.Format32bppRgb);
                bits.Save(Path.Combine(dir, string.Format("picture-{0:000}.bmp", c++)), ImageFormat.Bmp);
            }
            display.Close();
            proj.Close();
            xcam.Dispose();
        }
Exemple #2
0
        public static void Calibrate(string[] args)
        {
            var camfile = args.FirstOrDefault() ?? KinectDefaultFileName;
            var projfile = args.Skip(1).FirstOrDefault() ?? ProjectorDefaultFileName;
            var main = OpenTK.DisplayDevice.AvailableDisplays.First(row => row.IsPrimary);
            var window = new BitmapWindow(main.Bounds.Left + main.Width / 2 + 50, 50, 640, 480);
            window.Load();
            window.ResizeGraphics();
            StereoCalibration.DebugWindow = window;
            KinectSensor sensor = KinectSensor.KinectSensors.First();
            sensor.Start();

            Camera camera = new Camera(sensor, ColorImageFormat.RgbResolution1280x960Fps12);
            Projector projector = new Projector();
            PointF[][] data;
            bool proceed = false;
            CalibrationResult cc, pc;
            do
            {
                cc = CalibrateCamera(camera, projector, out data, false, true, true);

                pc = CalibrateProjector(sensor, camera, projector, cc, data, true, false);

                var peas = new float[][] {
                    new float[] { 0f, 0f, 0.0f },
                    new float[] { 0.5f, 0f, 0.0f },
                    new float[] { 0f, -0.5f, 0.0f },
                    new float[] { 0.5f, -0.5f, 0.0f },
                };
                var tpe = pc.Transform(peas);
                var tpp = cc.Transform(peas);
                projector.DrawPoints(tpe, 25);
                var pic2 = camera.TakePicture(5);
                QuickDraw.Start(pic2).Color(Color.Green).DrawPoint(tpp, 15).Finish();
                window.DrawBitmap(pic2);
                Console.WriteLine("Save result? (y/n)");
                proceed = Console.ReadLine() == "y";
            } while (!proceed);

            Utils.SerializeObject(cc, camfile);
            Utils.SerializeObject(pc, projfile);
            window.Close();
            window.Dispose();
            projector.Close();
            camera.Dispose();
            sensor.Stop();
        }
        public static void RunOld(string[] args)
        {
            var intrinsicfile = args.FirstOrDefault() ?? Calibration.KinectDefaultFileName;
            var camIntrinsic = Utils.DeSerializeObject<CalibrationResult>(intrinsicfile);
            var projFile = args.Skip(1).FirstOrDefault() ?? Calibration.ProjectorDefaultFileName;
            var projIntrinsic = Utils.DeSerializeObject<CalibrationResult>(projFile);
            KinectSensor sensor = KinectSensor.KinectSensors.First();
            Camera cam = new Camera(sensor, ColorImageFormat.RgbResolution1280x960Fps12);
            Projector proj = new Projector();
            var keyl = new KeyboardListener(proj.window.Keyboard);
            double offsetx = 0, offsety = 0, scale = 0.5;
            bool proceed = false, quit = false;
            keyl.AddBinaryAction(0.02, -0.02, OpenTK.Input.Key.Up, OpenTK.Input.Key.Down, new OpenTK.Input.Key[0], (f) => offsety += f);
            keyl.AddBinaryAction(0.02, -0.02, OpenTK.Input.Key.Left, OpenTK.Input.Key.Right, new OpenTK.Input.Key[0], (f) => offsetx -= f);
            keyl.AddBinaryAction(0.02, -0.02, OpenTK.Input.Key.Up, OpenTK.Input.Key.Down, new OpenTK.Input.Key[] { Key.ShiftLeft }, (f) => scale += f);
            keyl.AddAction(() => proceed = true, Key.Space);
            keyl.AddAction(() => quit = proceed = true, Key.Q);
            PointF[] corners;
            proj.DrawBackground(Color.Black);
            while (true)
            {
                Console.WriteLine("Make sure the kinect can see the board");
                Console.ReadLine();
                corners = StereoCalibration.GetCameraCorners(cam.TakePicture(3), new Size(7, 4), false);
                if (corners.All(c => c != null))
                {
                    break;
                }
                else
                    Console.WriteLine("Could not find corners");
            }
            PointF[] projCorners;
            var projectedCorners = proj.DrawCheckerboard(new Size(8, 5), 0, 0, 0, scale, offsetx, offsety);
            while (true)
            {
                Console.WriteLine("Make sure the kinect can see the projection");
                while (!proceed)
                {
                    projectedCorners = proj.DrawCheckerboard(new Size(8, 5), 0, 0, 0, scale, offsetx, offsety);
                    proj.window.ProcessEvents();
                }
                projCorners = StereoCalibration.GetCameraCorners(cam.TakePicture(3), new Size(7, 4), false);
                if (corners.All(c => c != null))
                {
                    break;
                }
                else
                    Console.WriteLine("Could not find any corners, make sure the checkerboard is visible to all Kinects.");
            }

            var camResult = StereoCalibration.CalibrateCamera(corners, new Size(7, 4), 0.05f, camIntrinsic);
            var transform = StereoCalibration.FindHomography(projCorners, projectedCorners);
            var projResult = StereoCalibration.CalibrateCamera(transform(corners), new Size(7, 4), 0.05f, projIntrinsic);
            Utils.SerializeObject(camResult, intrinsicfile);
            Utils.SerializeObject(projResult, projFile);
            proj.Close();
        }
 //Manual pickings
 public static void RunManual(string[] args)
 {
     //var main = OpenTK.DisplayDevice.AvailableDisplays.First(row => row.IsPrimary);
     //var window = new BitmapWindow(main.Bounds.Left + main.Width / 2 + 50, 50, 640, 480);
     //window.Load();
     //window.ResizeGraphics();
     //var window2 = new BitmapWindow(main.Bounds.Left + 50, 50, 640, 480);
     //window2.Load();
     //window2.ResizeGraphics();
     CalibrationResult kinectcalib = null;
     if (args.Length > 0)
     {
         var file = args.First();
         kinectcalib = Utils.DeSerializeObject<CalibrationResult>(file);
     }
     Console.Write("Enter the folders you'd like to use: ");
     var folders = Console.ReadLine().Split(' ').ToArray();
     var maps = folders.SelectMany(f => PictureGrabber.GetManualBitmaps(f)).ToArray();
     Size pattern = new Size(7, 4);
     float chsize = 0.05f;
     var kcorners = maps.Select(ms => StereoCalibration.GetCameraCorners(ms.Camera, pattern)).ToArray();
     var pcorners = maps.Select(ms => ms.ProjCorners).ToArray();
     if (kinectcalib == null)
     {
         if (kcorners.Length == 0)
         {
             Console.WriteLine("Could not find camera corners");
             return;
         }
         kinectcalib = StereoCalibration.CalibrateCamera(kcorners, maps.First().Camera.Size, pattern, chsize);
     }
     Projector proj = new Projector();
     var projcalib = StereoCalibration.CalibrateCamera(pcorners, proj.Size, pattern, chsize);
     proj.Close();
     Console.WriteLine("Save result?");
     Console.ReadLine();
     Utils.SerializeObject(kinectcalib, Calibration.KinectDefaultFileName);
     Utils.SerializeObject(projcalib, Calibration.ProjectorDefaultFileName);
 }
 public static void Run(string[] args)
 {
     //var main = OpenTK.DisplayDevice.AvailableDisplays.First(row => row.IsPrimary);
     //var window = new BitmapWindow(main.Bounds.Left + main.Width / 2 + 50, 50, 640, 480);
     //window.Load();
     //window.ResizeGraphics();
     //var window2 = new BitmapWindow(main.Bounds.Left + 50, 50, 640, 480);
     //window2.Load();
     //window2.ResizeGraphics();
     CalibrationResult kinectcalib = null;
     if (args.Length > 0)
     {
         var file = args.First();
         kinectcalib = Utils.DeSerializeObject<CalibrationResult>(file);
     }
     Console.Write("Enter the folders you'd like to use: ");
     var folders = Console.ReadLine().Split(' ').ToArray();
     var maps = folders.SelectMany(f => PictureGrabber.GetBitmaps(f)).ToArray();
     Size pattern = new Size(10, 7);
     Size ppattern = new Size(10, 8);
     float chsize = 0.1f;
     var kcorners = maps.Select(ms => StereoCalibration.GetCameraCorners(ms.Camera, pattern)).ToArray();
     var pcorners = maps.Select(ms => StereoCalibration.GetCameraCorners(ms.Projector, ppattern)).ToArray();
     kcorners = kcorners.Zip(pcorners, (a, b) => a != null && b != null ? a : null).Where(a => a != null).ToArray();
     pcorners = kcorners.Zip(pcorners, (a, b) => a != null && b != null ? b : null).Where(a => a != null).ToArray();
     if (kcorners.Count() != pcorners.Count())
         Console.WriteLine("Number of good shots did not match.");
     if (kinectcalib == null)
     {
         if (kcorners.Length == 0)
         {
             Console.WriteLine("Could not find camera corners");
             return;
         }
         kinectcalib = StereoCalibration.CalibrateCamera(kcorners, maps.First().Camera.Size, pattern, chsize);
     }
     var tkcorners = kcorners.Select(points => StereoCalibration.Undistort(kinectcalib, points)).ToArray();
     var tpcorners = pcorners.Select(points => StereoCalibration.Undistort(kinectcalib, points)).ToArray();
     var hgraphs = tpcorners.Zip(maps.Select(m => m.ProjCorners), (c, p) => StereoCalibration.FindHomography(c, p));
     var ptkcorners = tkcorners.Zip(hgraphs, (ps, hg) => hg(ps)).ToArray();
     //bool proceed = false;
     //window.Keyboard.KeyDown += (o, e) =>
     //{
     //    proceed = true;
     //};
     //window2.Keyboard.KeyDown += (o, e) =>
     //{
     //    proceed = true;
     //};
     //for (int i = 0; i < maps.Length; i++)
     //{
     //    Projector proj = new Projector();
     //    var map1 = (Bitmap)maps[i].Camera.Clone();
     //    QuickDraw.Start(map1).DrawPoint(kcorners[i], 5).Finish();
     //    var map2 = (Bitmap)maps[i].Projector.Clone();
     //    QuickDraw.Start(map2).DrawPoint(pcorners[i], 5).Finish();
     //    window.DrawBitmap(map1);
     //    window2.DrawBitmap(map2);
     //    proj.DrawPoints(ptkcorners[i], 5f);
     //    while (!proceed)
     //    {
     //        window.ProcessEvents();
     //        window2.ProcessEvents();
     //    }
     //    proceed = false;
     //}
     Projector proj = new Projector();
     var projcalib = StereoCalibration.CalibrateCamera(ptkcorners, proj.Size, pattern, chsize);
     proj.Close();
     Console.WriteLine("Save result?");
     Console.ReadLine();
     Utils.SerializeObject(kinectcalib, Calibration.KinectDefaultFileName);
     Utils.SerializeObject(projcalib, Calibration.ProjectorDefaultFileName);
 }