public Simple3DReconstruction()
      {
         InitializeComponent();

         _left = new Image<Bgr, byte>("left.jpg");
         Image<Bgr, Byte> right = new Image<Bgr, byte>("right.jpg");
         Image<Gray, Int16> leftDisparityMap;
         Computer3DPointsFromImages(_left.Convert<Gray, Byte>(), right.Convert<Gray, Byte>(), out leftDisparityMap, out _points);

         //remove some depth outliers
         for (int i = 0; i < _points.Length; i++)
         {
            if (Math.Abs(_points[i].z) >= 1000) _points[i].z = 0;
         }

         //Display the disparity map
         imageBox1.Image = leftDisparityMap;

         Osg.Geode geode = new Osg.Geode();
         Osg.Geometry geometry = new Osg.Geometry();

         int textureSize = 256;
         //create and setup the texture
         SetTexture(_left.Resize(textureSize, textureSize, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC), geode);

         #region setup the vertices
         Osg.Vec3Array vertices = new Osg.Vec3Array();
         foreach (MCvPoint3D32f p in _points)
            vertices.Add(new Osg.Vec3(-p.x, p.y, p.z));
         geometry.setVertexArray(vertices);
         #endregion

         #region setup the primitive as point cloud
         Osg.DrawElementsUInt draw = new Osg.DrawElementsUInt(
            (uint)Osg.PrimitiveSet.Mode.POINTS, 0);
         for (uint i = 0; i < _points.Length; i++)
            draw.Add(i);
         geometry.addPrimitiveSet(draw);
         #endregion

         #region setup the texture coordinates for the pixels
         Osg.Vec2Array textureCoor = new Osg.Vec2Array();
         foreach (MCvPoint3D32f p in _points)
            textureCoor.Add(new Osg.Vec2(p.x / _left.Width + 0.5f, p.y / _left.Height + 0.5f));
         geometry.setTexCoordArray(0, textureCoor);
         #endregion

         geode.addDrawable(geometry);

         #region apply the rotation on the scene
         Osg.MatrixTransform transform = new Osg.MatrixTransform(
            Osg.Matrix.rotate(90.0 / 180.0 * Math.PI, new Osg.Vec3d(1.0, 0.0, 0.0)) *
            Osg.Matrix.rotate(180.0 / 180.0 * Math.PI, new Osg.Vec3d(0.0, 1.0, 0.0)));
         transform.addChild(geode);
         #endregion         

         viewer3D.Viewer.setSceneData(transform);
         viewer3D.Viewer.realize();
      }
        public void SetData(Image <Gray, byte> left, Image <Gray, byte> right)
        {
            Image <Gray, short> disparityMap;

            Computer3DPointsFromStereoPair(left, right, out disparityMap, out _points);

            //Display the disparity map
            imageBox1.Image = disparityMap;

            Osg.Geode    geode    = new Osg.Geode();
            Osg.Geometry geometry = new Osg.Geometry();

            int textureSize = 256;

            //create and setup the texture
            SetTexture(left.Resize(textureSize, textureSize, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC), geode);

            #region setup the vertices, the primitive and the texture

            Osg.Vec3Array        vertices = new Osg.Vec3Array();
            Osg.DrawElementsUInt draw     = new Osg.DrawElementsUInt
                                                ((uint)Osg.PrimitiveSet.Mode.POINTS, 0);

            Osg.Vec2Array textureCoor   = new Osg.Vec2Array();
            uint          verticesCount = 0;

            foreach (MCvPoint3D32f p in _points)
            {
                //skip the depth outliers
                if (Math.Abs(p.z) < 1000)
                {
                    vertices.Add(new Osg.Vec3(-p.x, p.y, p.z));
                    draw.Add(verticesCount);
                    textureCoor.Add(new Osg.Vec2(p.x / left.Width + 0.5f, p.y / left.Height + 0.5f));
                    verticesCount++;
                }
            }
            geometry.setVertexArray(vertices);
            geometry.addPrimitiveSet(draw);
            geometry.setTexCoordArray(0, textureCoor);

            #endregion

            geode.addDrawable(geometry);

            #region apply the rotation on the scene

            //Osg.MatrixTransform transform = new Osg.MatrixTransform
            //    (Osg.Matrix.rotate(90.0 / 180.0 * Math.PI, new Osg.Vec3d(1.0, 0.0, 0.0)) *
            //    Osg.Matrix.rotate(180.0 / 180.0 * Math.PI, new Osg.Vec3d(0.0, 1.0, 0.0)));
            //transform.addChild(geode);

            #endregion

            //viewer3D.Viewer.setSceneData(transform);
            viewer3D.Viewer.realize();
        }
Example #3
0
        public Simple3DReconstruction()
        {
            InitializeComponent();

            _left = new Image <Bgr, byte>("left.jpg");
            Image <Bgr, Byte>   right = new Image <Bgr, byte>("right.jpg");
            Image <Gray, Int16> leftDisparityMap;

            Computer3DPointsFromImages(_left.Convert <Gray, Byte>(), right.Convert <Gray, Byte>(), out leftDisparityMap, out _points);

            //remove some depth outliers
            for (int i = 0; i < _points.Length; i++)
            {
                if (Math.Abs(_points[i].z) >= 1000)
                {
                    _points[i].z = 0;
                }
            }

            //Display the disparity map
            imageBox1.Image = leftDisparityMap;

            Osg.Geode    geode    = new Osg.Geode();
            Osg.Geometry geometry = new Osg.Geometry();

            int textureSize = 256;

            //create and setup the texture
            SetTexture(_left.Resize(textureSize, textureSize, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC), geode);

            #region setup the vertices
            Osg.Vec3Array vertices = new Osg.Vec3Array();
            foreach (MCvPoint3D32f p in _points)
            {
                vertices.Add(new Osg.Vec3(-p.x, p.y, p.z));
            }
            geometry.setVertexArray(vertices);
            #endregion

            #region setup the primitive as point cloud
            Osg.DrawElementsUInt draw = new Osg.DrawElementsUInt(
                (uint)Osg.PrimitiveSet.Mode.POINTS, 0);
            for (uint i = 0; i < _points.Length; i++)
            {
                draw.Add(i);
            }
            geometry.addPrimitiveSet(draw);
            #endregion

            #region setup the texture coordinates for the pixels
            Osg.Vec2Array textureCoor = new Osg.Vec2Array();
            foreach (MCvPoint3D32f p in _points)
            {
                textureCoor.Add(new Osg.Vec2(p.x / _left.Width + 0.5f, p.y / _left.Height + 0.5f));
            }
            geometry.setTexCoordArray(0, textureCoor);
            #endregion

            geode.addDrawable(geometry);

            #region apply the rotation on the scene
            Osg.MatrixTransform transform = new Osg.MatrixTransform(
                Osg.Matrix.rotate(90.0 / 180.0 * Math.PI, new Osg.Vec3d(1.0, 0.0, 0.0)) *
                Osg.Matrix.rotate(180.0 / 180.0 * Math.PI, new Osg.Vec3d(0.0, 1.0, 0.0)));
            transform.addChild(geode);
            #endregion

            viewer3D.Viewer.setSceneData(transform);
            viewer3D.Viewer.realize();
        }
Example #4
0
        public Simple3DReconstruction()
        {
            InitializeComponent();
            Image <Bgr, Byte>   left  = new Image <Bgr, byte>("left.jpg");
            Image <Bgr, Byte>   right = new Image <Bgr, byte>("right.jpg");
            Image <Gray, short> disparityMap;

            MCvPoint3D32f[] _points;

            Stopwatch watch = Stopwatch.StartNew();

            Computer3DPointsFromStereoPair(left.Convert <Gray, Byte>(), right.Convert <Gray, Byte>(), out disparityMap, out _points);
            watch.Stop();
            long disparityComputationTime = watch.ElapsedMilliseconds;

            //Display the disparity map
            imageBox1.Image = disparityMap;

            watch.Reset(); watch.Start();

            Osg.Geode    geode    = new Osg.Geode();
            Osg.Geometry geometry = new Osg.Geometry();

            int textureSize = 256;

            //create and setup the texture
            SetTexture(left.Resize(textureSize, textureSize, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC), geode);

            #region setup the vertices, the primitive and the texture
            Osg.Vec3Array        vertices = new Osg.Vec3Array();
            Osg.DrawElementsUInt draw     = new Osg.DrawElementsUInt(
                (uint)Osg.PrimitiveSet.Mode.POINTS, 0);
            Osg.Vec2Array textureCoor   = new Osg.Vec2Array();
            uint          verticesCount = 0;
            foreach (MCvPoint3D32f p in _points)
            {
                //skip the depth outliers
                if (Math.Abs(p.z) < 1000)
                {
                    vertices.Add(new Osg.Vec3(-p.x, p.y, p.z));
                    draw.Add(verticesCount);
                    textureCoor.Add(new Osg.Vec2(p.x / left.Width + 0.5f, p.y / left.Height + 0.5f));
                    verticesCount++;
                }
            }
            geometry.setVertexArray(vertices);
            geometry.addPrimitiveSet(draw);
            geometry.setTexCoordArray(0, textureCoor);
            #endregion

            geode.addDrawable(geometry);

            #region apply the rotation on the scene
            Osg.MatrixTransform transform = new Osg.MatrixTransform(
                Osg.Matrix.rotate(90.0 / 180.0 * Math.PI, new Osg.Vec3d(1.0, 0.0, 0.0)) *
                Osg.Matrix.rotate(180.0 / 180.0 * Math.PI, new Osg.Vec3d(0.0, 1.0, 0.0)));
            transform.addChild(geode);
            #endregion

            watch.Stop();

            Text = String.Format("Disparity and 3D points computed in {0} millseconds. 3D model created in {1} milliseconds",
                                 disparityComputationTime, watch.ElapsedMilliseconds);

            viewer3D.Viewer.setSceneData(transform);
            viewer3D.Viewer.realize();
        }
        public void SetData(Image<Gray, byte> left, Image<Gray, byte> right)
        {
            Image<Gray, short> disparityMap;

            Computer3DPointsFromStereoPair(left, right, out disparityMap, out _points);

            //Display the disparity map
            imageBox1.Image = disparityMap;

            Osg.Geode geode = new Osg.Geode();
            Osg.Geometry geometry = new Osg.Geometry();

            int textureSize = 256;
            //create and setup the texture
            SetTexture(left.Resize(textureSize, textureSize, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC), geode);

            #region setup the vertices, the primitive and the texture

            Osg.Vec3Array vertices = new Osg.Vec3Array();
            Osg.DrawElementsUInt draw = new Osg.DrawElementsUInt
                ((uint)Osg.PrimitiveSet.Mode.POINTS, 0);

            Osg.Vec2Array textureCoor = new Osg.Vec2Array();
            uint verticesCount = 0;

            foreach (MCvPoint3D32f p in _points)
            {
                //skip the depth outliers
                if (Math.Abs(p.z) < 1000)
                {
                    vertices.Add(new Osg.Vec3(-p.x, p.y, p.z));
                    draw.Add(verticesCount);
                    textureCoor.Add(new Osg.Vec2(p.x / left.Width + 0.5f, p.y / left.Height + 0.5f));
                    verticesCount++;
                }
            }
            geometry.setVertexArray(vertices);
            geometry.addPrimitiveSet(draw);
            geometry.setTexCoordArray(0, textureCoor);

            #endregion

            geode.addDrawable(geometry);

            #region apply the rotation on the scene

            //Osg.MatrixTransform transform = new Osg.MatrixTransform
            //    (Osg.Matrix.rotate(90.0 / 180.0 * Math.PI, new Osg.Vec3d(1.0, 0.0, 0.0)) *
            //    Osg.Matrix.rotate(180.0 / 180.0 * Math.PI, new Osg.Vec3d(0.0, 1.0, 0.0)));
            //transform.addChild(geode);

            #endregion

            //viewer3D.Viewer.setSceneData(transform);
            viewer3D.Viewer.realize();
        }