Ejemplo n.º 1
0
        public void SetupSolve(CalibrationInfo ci, bool useConstraints, bool radialDistortion)
        {
            foreach (ProjectorEntry pe in ci.Projectors)
            {
                SolveProjector sp = new SolveProjector(pe, ci.DomeSize, ci.ScreenType == ScreenTypes.FishEye ? ProjectionType.FishEye : ProjectionType.Projector, ScreenTypes.Spherical, ci.ScreenType == ScreenTypes.FishEye ? SolveParameters.FishEye : (SolveParameters)ci.SolveParameters);
                sp.RadialDistorion = radialDistortion;
                projectors.Add(sp);

                if (useConstraints)
                {
                    foreach (GroundTruthPoint gt in pe.Constraints)
                    {
                        SolveList.Add(new Constraint(sp, gt));
                    }
                }
            }

            foreach (Edge edge in ci.Edges)
            {
                foreach (EdgePoint pnt in edge.Points)
                {
                    SolveList.Add(new Coorespondence(projectors[edge.Left - 1], projectors[edge.Right - 1], pnt));
                }
            }


            foreach (SolveProjector sp in projectors)
            {
                regressionParameters.AddRange(sp.Parameters);
            }


            int count = SolveList.Count;

            double[,] data = new double[2, count];
            for (int i = 0; i < count; i++)
            {
                data[0, i] = i;
                data[1, i] = 0;
            }
            Parameter[] observed = new Parameter[] { ParmeterIndex };

            lm = new LevenbergMarquardt(new functionDelegate(SolveFunction), regressionParameters.ToArray(), observed, data);
        }
 public Coorespondence(SolveProjector left, SolveProjector right, EdgePoint point)
 {
     this.left = left;
     this.right = right;
     this.point = point;
 }
 public Constraint(SolveProjector projector, GroundTruthPoint point)
 {
     this.projector = projector;
     this.point = point;
 }
        public void SetupSolve(CalibrationInfo ci, bool useConstraints, bool radialDistortion)
        {
            foreach (var pe in ci.Projectors)
            {
                var sp = new SolveProjector(pe, ci.DomeSize, ci.ScreenType == ScreenTypes.FishEye ? ProjectionType.FishEye : ProjectionType.Projector, ScreenTypes.Spherical, ci.ScreenType == ScreenTypes.FishEye ? SolveParameters.FishEye : (SolveParameters)ci.SolveParameters)
                {
                    RadialDistorion = radialDistortion
                };
                projectors.Add(sp);

                if (useConstraints)
                {
                    foreach (var gt in pe.Constraints)
                    {
                        SolveList.Add(new Constraint(sp, gt));
                    }
                }

            }

            foreach (var edge in ci.Edges)
            {
                foreach (var pnt in edge.Points)
                {
                    SolveList.Add( new Coorespondence(projectors[edge.Left-1],projectors[edge.Right-1],pnt));
                }
            }

            foreach (var sp in projectors)
            {
                regressionParameters.AddRange(sp.Parameters);
            }

            var count = SolveList.Count;
            var data = new double[2, count];
            for (var i = 0; i < count; i++)
            {
                data[0, i] = i;
                data[1, i] = 0;
            }
            var observed = new[] { ParmeterIndex };

            lm = new LevenbergMarquardt(SolveFunction, regressionParameters.ToArray(), observed, data);
        }
Ejemplo n.º 5
0
 public Coorespondence(SolveProjector left, SolveProjector right, EdgePoint point)
 {
     this.left  = left;
     this.right = right;
     this.point = point;
 }
        public static Bitmap MakeWarpMap(ProjectorEntry pe, double domeSize, bool radialDistortion, List<GroundTruthPoint> gtPointList, ScreenTypes screenType)
        {
            List<Vector2d> PointTo = new List<Vector2d>();
            List<Vector2d> PointFrom = new List<Vector2d>();

            double xFactor = pe.Width / 512.0;
            double yFactor = pe.Height / 512.0;

            Bitmap bmp = new Bitmap(512, 512);
            FastBitmap fastBmp = new FastBitmap(bmp);

            SolveProjector spProjector = new SolveProjector(pe, domeSize, ProjectionType.Projector, screenType, SolveParameters.Default);
            spProjector.RadialDistorion = radialDistortion;

            SolveProjector spView = new SolveProjector(pe, domeSize, ProjectionType.View, ScreenTypes.Spherical, SolveParameters.Default);
            spView.RadialDistorion = false;

            foreach (GroundTruthPoint gt in gtPointList)
            {
                PointFrom.Add(new Vector2d((double)gt.X / (double)pe.Width * 512, (double)gt.Y / (double)pe.Height * 512));

                Vector2d pntOutTarget = spView.ProjectPoint(new Vector2d(gt.Az, gt.Alt));
                Vector2d AltAzMapped = spProjector.GetCoordinatesForScreenPoint(gt.X,gt.Y);
                Vector2d pntOutMapped = spView.ProjectPoint(new Vector2d(AltAzMapped.X, AltAzMapped.Y));

                pntOutTarget.X = pntOutTarget.X *(512 / 2.0) + (512 / 2.0);
                pntOutTarget.Y = pntOutTarget.Y *(-512 / 2.0) + (512 / 2.0);
                pntOutMapped.X = pntOutMapped.X *(512 / 2.0) + (512 / 2.0);
                pntOutMapped.Y =  pntOutMapped.Y *(-512 / 2.0) + (512 / 2.0);

                PointTo.Add(new Vector2d(pntOutTarget.X - pntOutMapped.X, pntOutTarget.Y - pntOutMapped.Y));

            }

            //Matrix3d projMat = spView.GetCameraMatrix();
            unsafe
            {
                fastBmp.LockBitmap();
                for (int y = 0; y < 512; y++)
                {

                    for (int x = 0; x < 512; x++)
                    {
                        Vector2d pnt = spProjector.GetCoordinatesForScreenPoint(x * xFactor, y * yFactor);

                        Vector2d pntOut = spView.ProjectPoint(pnt);

                        // Map
                        pntOut.X = pntOut.X * (512 / 2.0) + (512 / 2.0);
                        pntOut.Y = pntOut.Y * (-512 / 2.0) + (512 / 2.0);

                        pntOut = MapPoint(new Vector2d(x,y), pntOut, PointTo, PointFrom);

                        pntOut.X = (pntOut.X - (512 / 2.0)) / (512 / 2.0);
                        pntOut.Y = (pntOut.Y - (512 / 2.0)) / (-512 / 2.0);
                        // End Map

                        double xo = pntOut.X * (4096 / 2.0) + (4096 / 2.0);
                        double yo = pntOut.Y * (-4096 / 2.0) + (4096 / 2.0);

                        int blue = (int)xo & 255;
                        int green = (int)yo & 255;
                        int red = (((int)yo) >> 4 & 240) + (((int)xo) >> 8 & 15);
                        *fastBmp[x, y] = new PixelData(red, green, blue, 255);

                    }
                }
                fastBmp.UnlockBitmap();

            }
            return bmp;
        }
Ejemplo n.º 7
0
 public Constraint(SolveProjector projector, GroundTruthPoint point)
 {
     this.projector = projector;
     this.point     = point;
 }
        public void SetupSolve(CalibrationInfo ci, bool useConstraints, bool radialDistortion)
        {
            foreach (ProjectorEntry pe in ci.Projectors)
            {
                SolveProjector sp = new SolveProjector(pe, ci.DomeSize, ci.ScreenType == ScreenTypes.FishEye ? ProjectionType.FishEye : ProjectionType.Projector, ScreenTypes.Spherical, ci.ScreenType == ScreenTypes.FishEye ? SolveParameters.FishEye : (SolveParameters)ci.SolveParameters);
                sp.RadialDistorion = radialDistortion;
                projectors.Add(sp);

                if (useConstraints)
                {
                    foreach (GroundTruthPoint gt in pe.Constraints)
                    {
                        SolveList.Add(new Constraint(sp, gt));
                    }
                }

            }

            foreach (Edge edge in ci.Edges)
            {
                foreach (EdgePoint pnt in edge.Points)
                {
                    SolveList.Add( new Coorespondence(projectors[edge.Left-1],projectors[edge.Right-1],pnt));
                }
            }

            foreach (SolveProjector sp in projectors)
            {
                regressionParameters.AddRange(sp.Parameters);
            }

            int count = SolveList.Count;
            double[,] data = new double[2, count];
            for (int i = 0; i < count; i++)
            {
                data[0, i] = i;
                data[1, i] = 0;
            }
            Parameter[] observed = new Parameter[] { ParmeterIndex };

            lm = new LevenbergMarquardt(new functionDelegate(SolveFunction), regressionParameters.ToArray(), observed, data);
        }
Ejemplo n.º 9
0
        private SolveProjector GetSolveProjector(int index)
        {
            if (solveProjectors.Count == 0)
            {
                var pe = CalibrationInfo.Projectors.Find(p => p.ID == index);

                var sp = new SolveProjector(pe, CalibrationInfo.DomeSize, CalibrationInfo.ScreenType == ScreenTypes.FishEye ? ProjectionType.FishEye : ProjectionType.Projector, CalibrationInfo.ScreenType, CalibrationInfo.ScreenType == ScreenTypes.FishEye ? SolveParameters.FishEye : SolveParameters.Default)
                {
                    RadialDistorion = CalibrationInfo.ScreenType != ScreenTypes.FishEye && UseRadial.Checked
                };
                return sp;
            }
            return solveProjectors[index-1];
        }
Ejemplo n.º 10
0
        private void ProjectorList_SelectedIndexChanged(object sender, EventArgs e)
        {
            var pe = (ProjectorEntry)ProjectorList.SelectedItem;

            var sp = new SolveProjector(pe, CalibrationInfo.DomeSize, CalibrationInfo.ScreenType == ScreenTypes.FishEye ? ProjectionType.FishEye : ProjectionType.Projector, ScreenTypes.Spherical, SolveParameters.Default);

            var pnt = sp.GetCoordinatesForScreenPoint(pe.Width / 2.0, pe.Height / 2.0);
            sp.GetCoordinatesForScreenPoint(pe.Width/2 + 1, pe.Height/2.0);
            var pntCamera = sp.GetCoordinatesForProjector();

            var pntRayDirection = GetPointFromAltAz(new PointF((float)pnt.X+90, (float)pnt.Y));
            var pntProj = GetPointFromAltAz(new PointF((float)pntCamera.X+90, (float)pntCamera.Y));

            Refresh();
            MousePad.Refresh();
            var g = MousePad.CreateGraphics();

            g.DrawLine(Pens.Yellow, pntRayDirection, pntProj);
            g.DrawRectangle(Pens.Red, pntProj.X - 5, pntProj.Y - 5, 10, 10);

            g.Dispose();
        }
        private SolveProjector GetSolveProjector(int index)
        {
            if (solveProjectors.Count == 0)
            {
                ProjectorEntry pe = CalibrationInfo.Projectors.Find(delegate(ProjectorEntry p) { return p.ID == index; });

                SolveProjector sp = new SolveProjector(pe, CalibrationInfo.DomeSize, CalibrationInfo.ScreenType == ScreenTypes.FishEye ? ProjectionType.FishEye : ProjectionType.Projector, CalibrationInfo.ScreenType, CalibrationInfo.ScreenType == ScreenTypes.FishEye ? SolveParameters.FishEye : SolveParameters.Default);
                sp.RadialDistorion = CalibrationInfo.ScreenType == ScreenTypes.FishEye ? false : UseRadial.Checked;
                return sp;
            }
            else
            {
                return solveProjectors[index-1];
            }
        }
Ejemplo n.º 12
0
        public static Bitmap MakeWarpMap(ProjectorEntry pe, double domeSize, bool radialDistortion, List <GroundTruthPoint> gtPointList, ScreenTypes screenType)
        {
            List <Vector2d> PointTo   = new List <Vector2d>();
            List <Vector2d> PointFrom = new List <Vector2d>();

            double xFactor = pe.Width / 512.0;
            double yFactor = pe.Height / 512.0;

            Bitmap     bmp     = new Bitmap(512, 512);
            FastBitmap fastBmp = new FastBitmap(bmp);

            SolveProjector spProjector = new SolveProjector(pe, domeSize, ProjectionType.Projector, screenType, SolveParameters.Default);

            spProjector.RadialDistorion = radialDistortion;

            SolveProjector spView = new SolveProjector(pe, domeSize, ProjectionType.View, ScreenTypes.Spherical, SolveParameters.Default);

            spView.RadialDistorion = false;


            foreach (GroundTruthPoint gt in gtPointList)
            {
                PointFrom.Add(new Vector2d((double)gt.X / (double)pe.Width * 512, (double)gt.Y / (double)pe.Height * 512));

                Vector2d pntOutTarget = spView.ProjectPoint(new Vector2d(gt.Az, gt.Alt));
                Vector2d AltAzMapped  = spProjector.GetCoordinatesForScreenPoint(gt.X, gt.Y);
                Vector2d pntOutMapped = spView.ProjectPoint(new Vector2d(AltAzMapped.X, AltAzMapped.Y));

                pntOutTarget.X = pntOutTarget.X * (512 / 2.0) + (512 / 2.0);
                pntOutTarget.Y = pntOutTarget.Y * (-512 / 2.0) + (512 / 2.0);
                pntOutMapped.X = pntOutMapped.X * (512 / 2.0) + (512 / 2.0);
                pntOutMapped.Y = pntOutMapped.Y * (-512 / 2.0) + (512 / 2.0);

                PointTo.Add(new Vector2d(pntOutTarget.X - pntOutMapped.X, pntOutTarget.Y - pntOutMapped.Y));
            }



            //Matrix3d projMat = spView.GetCameraMatrix();
            unsafe
            {
                fastBmp.LockBitmap();
                for (int y = 0; y < 512; y++)
                {
                    for (int x = 0; x < 512; x++)
                    {
                        Vector2d pnt = spProjector.GetCoordinatesForScreenPoint(x * xFactor, y * yFactor);

                        Vector2d pntOut = spView.ProjectPoint(pnt);

                        // Map
                        pntOut.X = pntOut.X * (512 / 2.0) + (512 / 2.0);
                        pntOut.Y = pntOut.Y * (-512 / 2.0) + (512 / 2.0);

                        pntOut = MapPoint(new Vector2d(x, y), pntOut, PointTo, PointFrom);

                        pntOut.X = (pntOut.X - (512 / 2.0)) / (512 / 2.0);
                        pntOut.Y = (pntOut.Y - (512 / 2.0)) / (-512 / 2.0);
                        // End Map


                        double xo = pntOut.X * (4096 / 2.0) + (4096 / 2.0);
                        double yo = pntOut.Y * (-4096 / 2.0) + (4096 / 2.0);

                        int blue          = (int)xo & 255;
                        int green         = (int)yo & 255;
                        int red           = (((int)yo) >> 4 & 240) + (((int)xo) >> 8 & 15);
                        *   fastBmp[x, y] = new PixelData(red, green, blue, 255);
                    }
                }
                fastBmp.UnlockBitmap();
            }
            return(bmp);
        }