Use Block Matching algorithm to find stereo correspondence
Inheritance: Emgu.Util.UnmanagedObject
Ejemplo n.º 1
0
        public Image<Gray, short> GetDispMapGPU(Image<Gray, byte> leftImg, Image<Gray, byte> rightImg, DispMapFounderParameters parameters)
        {
            var ap = (GpuStereoBMDispMapFounderParameters)parameters;

            using(var leftGpuImg = new GpuImage<Gray, byte>(leftImg))
            using(var rightGpuImg = new GpuImage<Gray, byte>(rightImg))
            using (GpuStereoBM sbm = new GpuStereoBM(
                numberOfDisparities: ap.NumberOfDisparities,
                blockSize: ap.BlockSize))
            {
                var dispMap = new GpuImage<Gray, byte>(leftGpuImg.Size);
                sbm.FindStereoCorrespondence(leftGpuImg, rightGpuImg, dispMap, null);
                return dispMap.ToImage().Convert<Gray, short>();
            }
        }
Ejemplo n.º 2
0
        private void OnFormMainLoad(object sender, EventArgs e)
        {
            try
            {
                _capture1 = new Capture(1);
                _capture2 = new Capture(2);

                OnResolutionMenuItemClick(resolutionToolStripMenuItem.DropDownItems[1], EventArgs.Empty);
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show(excpt.Message);
            }

            var SADWindowSize = 3;

            _stereoSolver = new GpuStereoBM(GpuStereoBM.PresetType.BasicPreset, 64, SADWindowSize);


            _random  = new Random();
            _cameras = new List <Camera>(2)
            {
                new Camera(),
                new Camera()
            };

            _rotateBackground = new Bgr(Color.Black);

            Options.StereoCalibrationOptions = new StereoCalibrationOptions();
            Options.StereoCalibrationOptions.Load("Calibration720p.sc");

            _captureThread = new Thread(CaptureFrames)
            {
                IsBackground = false
            };
            _captureThread.Start();

            _processThread = new Thread(ProcessFrame)
            {
                IsBackground = false
            };
            _processThread.Start();
        }
Ejemplo n.º 3
0
        public StereoSystem(string CalibrationMatFile, string CalibrationMatFile_Rectified)
        {
            MatFileReader mfr = new MatFileReader(CalibrationMatFile);
            MatFileReader mfr2 = new MatFileReader(CalibrationMatFile_Rectified);
            double[,] A1 = MLDoubleParser("KK_left_new", mfr2);
            double[,] A2 = MLDoubleParser("KK_right_new", mfr2);
            double[,] kc1 = MLDoubleParser("kc_left", mfr);
            double[,] kc2 = MLDoubleParser("kc_right", mfr);
            double[,] fc1 = MLDoubleParser("fc_left", mfr);
            double[,] fc2 = MLDoubleParser("fc_right", mfr);
            double[,] cc1 = MLDoubleParser("cc_left", mfr);
            double[,] cc2 = MLDoubleParser("cc_right", mfr);
            double[,] R = MLDoubleParser("R", mfr);
            double[,] T = MLDoubleParser("T", mfr);
            double[,] nx = MLDoubleParser("nx", mfr);
            double[,] ny = MLDoubleParser("ny", mfr);
            int ImageWidth = (int)nx[0, 0];
            int ImageHeight = (int)ny[0, 0];

            LeftCam = new CameraParameters(A1, kc1, fc1, cc1, ImageWidth, ImageHeight);
            RightCam = new CameraParameters(A2, kc2, fc2, cc2, ImageWidth, ImageHeight);
            TranslationVector = new Matrix<double>(T);
            RotationMatrix = new Matrix<double>(R);
            DisparityDepthMapMatrix = new Matrix<double>(4, 4);
            ImageSize = new Size(ImageWidth, ImageHeight);

            CvInvoke.cvStereoRectify(
                LeftCam.CameraMatrix.Ptr,
                RightCam.CameraMatrix.Ptr,
                LeftCam.distCoeffs.Ptr,
                RightCam.distCoeffs.Ptr,
                ImageSize,
                RotationMatrix.Ptr,
                TranslationVector.Ptr,
                LeftCam.RectificationTransform.Ptr,
                RightCam.RectificationTransform.Ptr,
                LeftCam.ProjectionMatrix.Ptr,
                RightCam.ProjectionMatrix.Ptr,
                DisparityDepthMapMatrix.Ptr,
                Emgu.CV.CvEnum.STEREO_RECTIFY_TYPE.DEFAULT,
                1,
                Size.Empty,
                ref LeftCam.ROI,
                ref RightCam.ROI);

            LeftCam.UndistortRectifyMap();
            RightCam.UndistortRectifyMap();

            var Variables = new List<MLArray>();
            int[] Dims = {ImageHeight, ImageWidth};
            Variables.Add(MLVariableCreator("LeftMapX", LeftCam.mapx));
            Variables.Add(MLVariableCreator("RightMapX", RightCam.mapx));
            Variables.Add(MLVariableCreator("LeftMapY", LeftCam.mapy));
            Variables.Add(MLVariableCreator("RightMapY", RightCam.mapy));
            var Writer = new MatFileWriter("ImageMap.mat", Variables, false);
            DisparityMapGPU = new GpuImage<Gray, byte>(ImageHeight, ImageWidth);
            DisparityMap = new Image<Gray, byte>(ImageWidth, ImageHeight);
            GPU_Block_Matcher = new GpuStereoBM(NumDisparities, BlockSize);
        }
Ejemplo n.º 4
0
        private void OnFormMainLoad(object sender, EventArgs e)
        {
            try
            {
                _capture1 = new Capture(1);
                _capture2 = new Capture(2);

                OnResolutionMenuItemClick(resolutionToolStripMenuItem.DropDownItems[1], EventArgs.Empty);
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show(excpt.Message);
            }

            var SADWindowSize = 3;

            _stereoSolver = new GpuStereoBM(GpuStereoBM.PresetType.BasicPreset, 64, SADWindowSize);

            _random = new Random();
            _cameras = new List<Camera>(2)
                       {
                           new Camera(),
                           new Camera()
                       };

            _rotateBackground = new Bgr(Color.Black);

            Options.StereoCalibrationOptions = new StereoCalibrationOptions();
            Options.StereoCalibrationOptions.Load("Calibration720p.sc");

            _captureThread = new Thread(CaptureFrames) {IsBackground = false};
            _captureThread.Start();

            _processThread = new Thread(ProcessFrame) {IsBackground = false};
            _processThread.Start();
        }