Exemplo n.º 1
0
        private void Build3DImage(object sender, RoutedEventArgs e)
        {
            if(_3dwindow == null)
            {
                _3dwindow = new Image3DWindow();
                _3dwindow.Show();
            }
            else
            {
                if(_3dwindow.IsVisible)
                    _3dwindow.Close();
                _3dwindow = new Image3DWindow();
                _3dwindow.Show();
            }

            _3dwindow.ResetPoints();

            ColorImage image = null;
            if(_imageControl.ImageSource != null)
            {
                image = new ColorImage();
                image.FromBitmapSource(_imageControl.ImageSource);
            }

            foreach(var point in Points3D)
            {
                SharpDX.Vector3 pos = new SharpDX.Vector3((float)point.Real.X, (float)point.Real.Y, (float)point.Real.Z);
                SharpDX.Color4 color = new SharpDX.Color4(1.0f);
                if(image != null)
                {
                    if(!(point.Cam1Img.X < 0.0 ||
                        point.Cam1Img.X > image.ColumnCount ||
                        point.Cam1Img.Y < 0.0 ||
                        point.Cam1Img.Y > image.RowCount))
                    {
                        color = new SharpDX.Color4(
                            (float)image[(int)point.Cam1Img.Y, (int)point.Cam1Img.X, RGBChannel.Red],
                            (float)image[(int)point.Cam1Img.Y, (int)point.Cam1Img.X, RGBChannel.Green],
                            (float)image[(int)point.Cam1Img.Y, (int)point.Cam1Img.X, RGBChannel.Blue],
                            1.0f);
                    }
                }

                _3dwindow.AddPointCube(pos, color);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Loads raw calibration images from children of supplied node  
        /// </summary>
        private void LoadCalibrationImages(XmlNode imgsNode)
        {
            //<CalibrationImages_Raw>
            //  <Image id="1" cam="left" path=""/>
            //  <Image id="1" cam="right" path=""/>
            //</CalibrationImages_Raw>

            _rawCalibImages = new List<ColorImage>();
            _calibImagesIndices = new List<ImageIndex>();
            foreach(XmlNode imgNode in imgsNode.ChildNodes)
            {
                ImageIndex idx = ImageIndex.FromXml(imgNode);
                idx.ListIndex = _rawCalibImages.Count;
                string imgPath = imgNode.Attributes["path"].Value;
                BitmapImage bitmap = new BitmapImage(new Uri(imgPath, UriKind.RelativeOrAbsolute));
                ColorImage image = new ColorImage();
                image.FromBitmapSource(bitmap);
                _rawCalibImages.Add(image);
                _calibImagesIndices.Add(idx);
            }
        }
Exemplo n.º 3
0
        private void MatchImages(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;
            }

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

            _alg.ImageLeft = imgLeft;
            _alg.ImageRight = imgRight;
            _alg.StatusChanged += _alg_StatusChanged;

            _matcherWindow = new AlgorithmWindow(_alg);
            _matcherWindow.Show();
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
        private void _butSegment_Click(object sender, RoutedEventArgs e)
        {
            if(_imageControl.ImageSource != null)
            {
                ColorImage img = new ColorImage();
                img.FromBitmapSource(_imageControl.ImageSource);

                var window = new ParametrizedProcessorsSelectionWindow();
                window.AddProcessorFamily("Segmentation");
                window.AddToFamily("Segmentation", new MeanShiftSegmentation());

                window.ShowDialog();
                if(window.Accepted)
                {
                    ImageSegmentation segmentation = (ImageSegmentation)window.GetSelectedProcessor("Segmentation");

                    GrayScaleImage imgGray = new GrayScaleImage();
                    imgGray.FromColorImage(img);

                    //segmentation.SegmentColor(img);
                    segmentation.SegmentGray(imgGray.ImageMatrix);

                    //var segments = segmentation.Segments_Color;
                    var segments = segmentation.Segments;
                    int[,] indices = segmentation.SegmentAssignments;

                    ColorImage imgFinal = new ColorImage();
                    imgFinal.ImageMatrix[0] = new DenseMatrix(img.RowCount, img.ColumnCount);
                    imgFinal.ImageMatrix[1] = new DenseMatrix(img.RowCount, img.ColumnCount);
                    imgFinal.ImageMatrix[2] = new DenseMatrix(img.RowCount, img.ColumnCount);

                    for(int r = 0; r < img.RowCount; ++r)
                    {
                        for(int c = 0; c < img.ColumnCount; ++c)
                        {
                            imgFinal[r, c, RGBChannel.Red] = ((ImageSegmentation.Segment_Gray)segments[indices[r, c]]).Value;
                            imgFinal[r, c, RGBChannel.Green] = ((ImageSegmentation.Segment_Gray)segments[indices[r, c]]).Value;
                            imgFinal[r, c, RGBChannel.Blue] = ((ImageSegmentation.Segment_Gray)segments[indices[r, c]]).Value;
                            //imgFinal[r, c, RGBChannel.Red] = segments[indices[r, c]].Red;
                            // imgFinal[r, c, RGBChannel.Green] = segments[indices[r, c]].Green;
                            //imgFinal[r, c, RGBChannel.Blue] = segments[indices[r, c]].Blue;
                        }
                    }

                    _imageControl.ImageSource = imgFinal.ToBitmapSource();
                }
            }
        }