private void Computer3DPointsFromStereoPair(Image <Gray, Byte> left, Image <Gray, Byte> right, out Image <Gray, short> disparityMap, out MCvPoint3D32f[] points)
        {
            Size size = left.Size;

            disparityMap = new Image <Gray, short>(size);
            //using (StereoSGBM stereoSolver = new StereoSGBM(5, 64, 0, 0, 0, 0, 0, 0, 0, 0, false))
            stereoSolver.FindStereoCorrespondence(left, right, disparityMap);

            //Construct a simple Q matrix, if you have a matrix from cvStereoRectify, you should use that instead
            points = PointCollection.ReprojectImageTo3D(disparityMap, Q);
        }
示例#2
0
        /// <summary>
        /// Given the left and right image, computer the disparity map and the 3D point cloud.
        /// </summary>
        /// <param name="left">The left image</param>
        /// <param name="right">The right image</param>
        /// <param name="disparityMap">The left disparity map</param>
        /// <param name="points">The 3D point cloud within a [-0.5, 0.5] cube</param>
        private static void Computer3DPointsFromStereoPair(Image <Gray, Byte> left, Image <Gray, Byte> right, out Image <Gray, short> disparityMap, out MCvPoint3D32f[] points)
        {
            Size size = left.Size;

            disparityMap = new Image <Gray, short>(size);
            //using (StereoSGBM stereoSolver = new StereoSGBM(5, 64, 0, 0, 0, 0, 0, 0, 0, 0, false))
            using (StereoBM stereoSolver = new StereoBM(Emgu.CV.CvEnum.STEREO_BM_TYPE.BASIC, 0))
            {
                stereoSolver.FindStereoCorrespondence(left, right, disparityMap);

                //Construct a simple Q matrix, if you have a matrix from cvStereoRectify, you should use that instead
                using (Matrix <double> q = new Matrix <double>(
                           new double[, ] {
                    { 1.0, 0.0, 0.0, -size.Width / 2 },  //shift the x origin to image center
                    { 0.0, 1.0, 0.0, -size.Height / 2 }, //shift the y origin to image center
                    { 0.0, 0.0, 1.0, 0.0 },              //Multiply the z value by 1.0,
                    { 0.0, 0.0, 0.0, 1.0 }
                }))
                    points = PointCollection.ReprojectImageTo3D(disparityMap, q);
            }
        }