コード例 #1
0
ファイル: MatchedImagesTab.xaml.cs プロジェクト: KFlaga/Cam3D
        private void RectifyImages(object sender, RoutedEventArgs e)
        {
            if(_camImageFirst.ImageSource == null || _camImageSec.ImageSource == null)
            {
                MessageBox.Show("Images must be set");
                return;
            }
            if(_camImageFirst.ImageSource.PixelWidth != _camImageSec.ImageSource.PixelWidth ||
                _camImageFirst.ImageSource.PixelHeight != _camImageSec.ImageSource.PixelHeight)
            {
                MessageBox.Show("Images must have same size");
                return;
            }
            if(CalibrationData.Data.IsCamLeftCalibrated == false ||
                CalibrationData.Data.IsCamRightCalibrated == false)
            {
                MessageBox.Show("Cameras must be calibrated");
                return;
            }

            ImageRectification_ZhangLoop rectifier = new ImageRectification_ZhangLoop();
            RectificationTransformation rectTransformation = new RectificationTransformation();
            rectTransformation.Rectifier = rectifier;

            ImageTransformer transformer = new ImageTransformer();
            transformer.Transformation = rectTransformation;
            transformer.UsedInterpolationMethod = ImageTransformer.InterpolationMethod.Quadratic;

            rectifier.ImageHeight = _camImageFirst.ImageSource.PixelHeight;
            rectifier.ImageWidth = _camImageFirst.ImageSource.PixelWidth;
            rectifier.EpiCrossLeft = CalibrationData.Data.EpipoleCrossLeft;
            rectifier.EpiCrossRight = CalibrationData.Data.EpipoleCrossRight;
            rectifier.EpipoleLeft = CalibrationData.Data.EpipoleLeft;
            rectifier.EpipoleRight = CalibrationData.Data.EpipoleRight;
            rectifier.IsEpiLeftInInfinity = CalibrationData.Data.EpiLeftInInfinity;
            rectifier.IsEpiRightInInfinity = CalibrationData.Data.EpiRightInInfinity;
            rectifier.FundamentalMatrix = CalibrationData.Data.Fundamental;
            rectifier.ComputeRectificationMatrices();

            ColorImage imgLeft = new ColorImage();
            imgLeft.FromBitmapSource(_camImageFirst.ImageSource);
            ColorImage imgRight = new ColorImage();
            imgRight.FromBitmapSource(_camImageSec.ImageSource);

            rectTransformation.WhichImage = RectificationTransformation.ImageIndex.Left;
            ColorImage rectLeft = transformer.TransfromImageBackwards(imgLeft, true);

            rectTransformation.WhichImage = RectificationTransformation.ImageIndex.Right;
            ColorImage rectRight = transformer.TransfromImageBackwards(imgRight, true);

            _camImageFirst.ImageSource = rectLeft.ToBitmapSource();
            _camImageSec.ImageSource = rectRight.ToBitmapSource();
        }
コード例 #2
0
ファイル: FeatureImagesTab.xaml.cs プロジェクト: KFlaga/Cam3D
        private void RectifyImages(object sender, RoutedEventArgs e)
        {
            if(_camImageFirst.ImageSource == null || _camImageSec.ImageSource == null)
            {
                MessageBox.Show("Images must be set");
                return;
            }
            if(_camImageFirst.ImageSource.PixelWidth != _camImageSec.ImageSource.PixelWidth ||
                _camImageFirst.ImageSource.PixelHeight != _camImageSec.ImageSource.PixelHeight)
            {
                MessageBox.Show("Images must have same size");
                return;
            }
            // if(CalibrationData.Data.IsCamLeftCalibrated == false ||
            //     CalibrationData.Data.IsCamRightCalibrated == false)
            // {
            //     MessageBox.Show("Cameras must be calibrated");
            //     return;
            // }

            ImageRectification_FussieloUncalibrated rectifier = new ImageRectification_FussieloUncalibrated();
            RectificationTransformation rectTransformation = new RectificationTransformation();
            rectTransformation.Rectifier = rectifier;

            ImageTransformer transformer = new ImageTransformer();
            transformer.Transformation = rectTransformation;
            transformer.UsedInterpolationMethod = ImageTransformer.InterpolationMethod.Quadratic;

            rectifier.ImageHeight = _camImageFirst.ImageSource.PixelHeight;
            rectifier.ImageWidth = _camImageFirst.ImageSource.PixelWidth;
            rectifier.UseInitialCalibration = false;
            rectifier.PointsLeft = new List<Vector2>();
            rectifier.PointsRight = new List<Vector2>();
            foreach(var m in _matches)
            {
                rectifier.PointsLeft.Add(m.LeftPoint);
                rectifier.PointsRight.Add(m.RightPoint);
            }

            rectifier.ComputeRectificationMatrices();

            rectTransformation.WhichImage = RectificationTransformation.ImageIndex.Left;
            MaskedImage rectLeft = transformer.TransfromImageBackwards(ImageLeft, true);

            rectTransformation.WhichImage = RectificationTransformation.ImageIndex.Right;
            MaskedImage rectRight = transformer.TransfromImageBackwards(ImageRight, true);

            _camImageFirst.ImageSource = rectLeft.ToBitmapSource();
               _camImageSec.ImageSource = rectRight.ToBitmapSource();
        }