Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I'm a newbie with emgu cv and the code thingy. And currently i have a camera calibration code using emgucv, and i want to add a code to compute extrinsic parameters here.. Umm but i don't know which one yo add and how.. So anyone can help me? Here is the code for camera calibration..

C#
#region Methods
        public void Solve()
        {
            MCvPoint3D32f[][] platePointsperView = new MCvPoint3D32f[_imageNumber][];
            PointF[][] crossesperView = new PointF[_imageNumber][];
            int index = 0;
            Trace.WriteLine("Camera Calibration");
            foreach (Crosses crosses in _crosses.CrossesOnImage)
            {
 
                ComposeInputPerView(crosses, ref crossesperView[index], ref platePointsperView[index]);
                //crossesperView[index] = ComposeInputCrossesCoordPerView(crosses);
                index++;
            }
 
            //calculate calibration
            CameraCalibration.CalibrateCamera(platePointsperView, crossesperView,
                                                _imageSize,
                                                _ioParams,
                                                Emgu.CV.CvEnum.CALIB_TYPE.DEFAULT,
                                                out _eoParams);
            DisplayIOParams(_ioParams);
            double fovx =0.0;
            double fovy=0.0;
            double focal=0.0;
            MCvPoint2D64f pp = new MCvPoint2D64f();
            double aspect = 0.0;
            CvInvoke.cvCalibrationMatrixValues(_ioParams.IntrinsicMatrix, _imageSize.Width, _imageSize.Height,
                4.9, 3.7, ref fovx, ref fovy, ref focal, ref pp, ref aspect);
            //CvInvoke.cvCalibrationMatrixValues(_ioParams.IntrinsicMatrix, _imageSize.Width, _imageSize.Height,
            //     0.0, 0.0, ref fovx, ref fovy, ref focal, ref pp, ref aspect);
            Trace.WriteLine("fovx = " + fovx.ToString());
            Trace.WriteLine("fovy = " + fovy.ToString());
            Trace.WriteLine("focal = " + focal.ToString());
            Trace.WriteLine("aspect ratio = " + aspect.ToString());
            Trace.WriteLine("principal point x,y: " + pp.x.ToString() + " , " + pp.y.ToString());
            PrintCalibrationParameters();
 
            //CameraCalibration.CalibrateCamera(platePointsperView, crossesperView,
            //                        _imageSize,
            //                        _ioParams,
            //                        Emgu.CV.CvEnum.CALIB_TYPE.CV_CALIB_FIX_FOCAL_LENGTH,
            //                        out _eoParams);

            //Trace.WriteLine("fovx = " + fovx.ToString());
            //Trace.WriteLine("fovy = " + fovy.ToString());
            //Trace.WriteLine("focal = " + focal.ToString());
            //Trace.WriteLine("aspect ratio = " + aspect.ToString());
            //Trace.WriteLine("principal point x,y: " + pp.x.ToString() + " , " + pp.y.ToString());
            //PrintCalibrationParameters();

            //CameraCalibration.CalibrateCamera(platePointsperView, crossesperView,
            //            _imageSize,
            //            _ioParams,
            //            Emgu.CV.CvEnum.CALIB_TYPE.CV_CALIB_FIX_PRINCIPAL_POINT | Emgu.CV.CvEnum.CALIB_TYPE.CV_CALIB_FIX_K1,
            //            out _eoParams);

            //Trace.WriteLine("fovx = " + fovx.ToString());
            //Trace.WriteLine("fovy = " + fovy.ToString());
            //Trace.WriteLine("focal = " + focal.ToString());
            //Trace.WriteLine("aspect ratio = " + aspect.ToString());
            //Trace.WriteLine("principal point x,y: " + pp.x.ToString() + " , " + pp.y.ToString());
            //PrintCalibrationParameters();
        }
 
        private void ComposeInputPerView(Crosses crosses, ref PointF[] imgPoints, ref MCvPoint3D32f[] platePoints)
        {
            //MCvPoint3D32f[] temp = null;
            //create the query for image points
            IEnumerable<Cross> sortedCrossPoints = from crossPt in crosses.CrossPoints
                                    orderby (int.Parse(crossPt.LabelName))
                                    select crossPt;
            List<PointF> tempCross = new List<PointF>();
 
            foreach (Cross c in sortedCrossPoints)
            {
                //create PointF
                PointF pt = new PointF(c.Point2D.X, c.Point2D.Y);
                tempCross.Add(pt);
                //Trace.WriteLine(c.LabelName + c.Point2D.ToString()+ "  " + pt.X.ToString() + " ; " + pt.Y.ToString());
            }
            //Trace.WriteLine("Number of list: " + tempCross.Count.ToString());
            imgPoints = tempCross.ToArray();
 
            //Create the query for plate points
            List<MCvPoint3D32f> ptsCv = new List<MCvPoint3D32f>();
            foreach (Cross c in sortedCrossPoints)
            {
                String label = c.LabelName;
                foreach (PlateCalibrationPoint pt in _plateCoord.PlatePoints)
                {
                    if (int.Parse(label) == int.Parse(pt.Label))
                    {
                        MCvPoint3D32f p = new MCvPoint3D32f(pt.Point2D.X, pt.Point2D.Y, 0.0f);
                        ptsCv.Add(p);
                    }
                }
            }
            platePoints = ptsCv.ToArray();
        }
 
        private void DisplayIOParams(IntrinsicCameraParameters io)
        {
            Trace.WriteLine("Intrinsic Camera Parameters:");
            Trace.WriteLine(io.IntrinsicMatrix.Data.ToString());
        }
 
        private PointF[] ComposeInputCrossesCoordPerView(Crosses crosses)
        {
            PointF[] temp = new PointF[2];
            return temp;
        }
 
        private void PrintIntrinsicMatrix()
        {
            Trace.WriteLine("Intrinsic Matrix:");
            String line1 = String.Format("{0} {1} {2}", _ioParams.IntrinsicMatrix[0, 0], _ioParams.IntrinsicMatrix[0, 1],
                                        _ioParams.IntrinsicMatrix[0, 2]);
            String line2 = String.Format("{0} {1} {2}", _ioParams.IntrinsicMatrix[1, 0], _ioParams.IntrinsicMatrix[1, 1],
                               _ioParams.IntrinsicMatrix[1, 2]);
            String line3 = String.Format("{0} {1} {2}", _ioParams.IntrinsicMatrix[2, 0], _ioParams.IntrinsicMatrix[2, 1],
                                        _ioParams.IntrinsicMatrix[2, 2]);
            Trace.WriteLine(line1);
            Trace.WriteLine(line2);
            Trace.WriteLine(line3);
        }
 
        private void PrintCalibrationParameters()
        {
            Trace.WriteLine("k1: " + _ioParams.DistortionCoeffs[0, 0].ToString());
            Trace.WriteLine("k2: " + _ioParams.DistortionCoeffs[1, 0].ToString());
            Trace.WriteLine("p1: " + _ioParams.DistortionCoeffs[2, 0].ToString());
            Trace.WriteLine("p2: " + _ioParams.DistortionCoeffs[3, 0].ToString());
            Trace.WriteLine("k3: " + _ioParams.DistortionCoeffs[4, 0].ToString());
 
            PrintIntrinsicMatrix();
        }
        #endregion
    }
}


What I have tried:

I tried looking at emgucv webpage but i still didnt get it..
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900