public static Viz3d GetViz3d(Mat left, Mat right)
        {
            Mat disparityMap = new Mat();

            Stopwatch watch     = Stopwatch.StartNew();
            UMat      leftGray  = new UMat();
            UMat      rightGray = new UMat();

            CvInvoke.CvtColor(left, leftGray, ColorConversion.Bgr2Gray);
            CvInvoke.CvtColor(right, rightGray, ColorConversion.Bgr2Gray);
            Mat points = new Mat();

            Computer3DPointsFromStereoPair(leftGray, rightGray, disparityMap, points);
            watch.Stop();
            long disparityComputationTime = watch.ElapsedMilliseconds;

            Mat pointsArray     = points.Reshape(points.NumberOfChannels, points.Rows * points.Cols);
            Mat colorArray      = left.Reshape(left.NumberOfChannels, left.Rows * left.Cols);
            Mat colorArrayFloat = new Mat();

            colorArray.ConvertTo(colorArrayFloat, DepthType.Cv32F);
            WCloud cloud = new WCloud(pointsArray, colorArray);

            Emgu.CV.Viz3d     v           = new Emgu.CV.Viz3d("Simple stereo reconstruction");
            WText             wtext       = new WText("3d point cloud", new System.Drawing.Point(20, 20), 20, new MCvScalar(255, 255, 255));
            WCoordinateSystem wCoordinate = new WCoordinateSystem(1.0);

            v.ShowWidget("text", wtext);
            //v.ShowWidget("coordinate", wCoordinate);
            v.ShowWidget("cloud", cloud);
            return(v);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            MCvPoint3D32f[] _points;
            Mat             _left        = CvInvoke.Imread("imL.png", ImreadModes.Color);
            Mat             _right       = CvInvoke.Imread("imR.png", ImreadModes.Color);
            Mat             disparityMap = new Mat();

            Stopwatch watch     = Stopwatch.StartNew();
            UMat      leftGray  = new UMat();
            UMat      rightGray = new UMat();

            CvInvoke.CvtColor(_left, leftGray, ColorConversion.Bgr2Gray);
            CvInvoke.CvtColor(_right, rightGray, ColorConversion.Bgr2Gray);
            Mat points = new Mat();

            Computer3DPointsFromStereoPair(leftGray, rightGray, disparityMap, points);
            watch.Stop();
            long disparityComputationTime = watch.ElapsedMilliseconds;

            Mat pointsArray     = points.Reshape(points.NumberOfChannels, points.Rows * points.Cols);
            Mat colorArray      = _left.Reshape(_left.NumberOfChannels, _left.Rows * _left.Cols);
            Mat colorArrayFloat = new Mat();

            colorArray.ConvertTo(colorArrayFloat, DepthType.Cv32F);
            WCloud cloud = new WCloud(pointsArray, colorArray);

            Emgu.CV.Viz3d     v           = new Emgu.CV.Viz3d("Simple stereo reconstruction");
            WText             wtext       = new WText("3d point cloud", new System.Drawing.Point(20, 20), 20, new MCvScalar(255, 255, 255));
            WCoordinateSystem wCoordinate = new WCoordinateSystem(1.0);

            v.ShowWidget("text", wtext);
            //v.ShowWidget("coordinate", wCoordinate);
            v.ShowWidget("cloud", cloud);
            v.Spin();
        }
Esempio n. 3
0
        public Viz3dPage()
        {
            var button = this.GetButton();

            button.Text     = "Show 3D Viz";
            button.Clicked += (sender, args) =>
            {
                using (Viz3d viz = new Viz3d("show_simple_widgets"))
                {
                    viz.SetBackgroundMeshLab();
                    using (WCoordinateSystem coor = new WCoordinateSystem())
                    {
                        viz.ShowWidget("coor", coor);
                        using (WCube cube = new WCube(
                                   new MCvPoint3D64f(-.5, -.5, -.5),
                                   new MCvPoint3D64f(.5, .5, .5),
                                   true,
                                   new MCvScalar(255, 255, 255)))
                        {
                            viz.ShowWidget("cube", cube);
                            using (WCube cube0 = new WCube(
                                       new MCvPoint3D64f(-1, -1, -1),
                                       new MCvPoint3D64f(-.5, -.5, -.5),
                                       false,
                                       new MCvScalar(123, 45, 200)))
                            {
                                viz.ShowWidget("cub0", cube0);
                                viz.Spin();
                            }
                        }
                    }
                }
            };
        }
Esempio n. 4
0
        public static Viz3d GetViz3d(Mat pointMat, Mat colorMat)
        {
            WCloud cloud = new WCloud(pointMat, colorMat);

            Emgu.CV.Viz3d v     = new Emgu.CV.Viz3d("Simple stereo reconstruction");
            WText         wtext = new WText("3d point cloud", new System.Drawing.Point(20, 20), 20,
                                            new MCvScalar(255, 255, 255));
            WCoordinateSystem wCoordinate = new WCoordinateSystem(1.0);

            v.ShowWidget("text", wtext);
            //v.ShowWidget("coordinate", wCoordinate);
            v.ShowWidget("cloud", cloud);
            return(v);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Viz3d viz = new Viz3d("show_simple_widgets");

            viz.SetBackgroundMeshLab();
            WCoordinateSystem coor = new WCoordinateSystem();

            viz.ShowWidget("coor", coor);
            WCube cube = new WCube(new MCvPoint3D64f(-.5, -.5, -.5), new MCvPoint3D64f(.5, .5, .5), true, new MCvScalar(255, 255, 255));

            viz.ShowWidget("cube", cube);
            WCube cube0 = new WCube(new MCvPoint3D64f(-1, -1, -1), new MCvPoint3D64f(-.5, -.5, -.5), false, new MCvScalar(123, 45, 200));

            viz.ShowWidget("cub0", cube0);
            viz.Spin();

            String win1 = "Test Window";                    //The name of the window

            CvInvoke.NamedWindow(win1);                     //Create the window using the specific name

            Mat img = new Mat(200, 400, DepthType.Cv8U, 3); //Create a 3 channel image of 400x200

            img.SetTo(new Bgr(255, 0, 0).MCvScalar);        // set it to Blue color

            //Draw "Hello, world." on the image using the specific font
            CvInvoke.PutText(
                img,
                "Hello, world",
                new System.Drawing.Point(10, 80),
                FontFace.HersheyComplex,
                1.0,
                new Bgr(0, 255, 0).MCvScalar);


            CvInvoke.Imshow(win1, img);   //Show the image
            CvInvoke.WaitKey(0);          //Wait for the key pressing event
            CvInvoke.DestroyWindow(win1); //Destroy the window if key is pressed
        }
Esempio n. 6
0
        public App()
        {
            Button helloWorldButton = new Button();

            helloWorldButton.Text = "Hello world";

            Button planarSubdivisionButton = new Button();

            planarSubdivisionButton.Text = "Planar Subdivision";

            Button faceDetectionButton = new Button();

            faceDetectionButton.Text = "Face Detection";

            Button faceLandmarkDetectionButton = new Button();

            faceLandmarkDetectionButton.Text = "Face Landmark Detection";

            Button featureDetectionButton = new Button();

            featureDetectionButton.Text = "Feature Matching";

            Button pedestrianDetectionButton = new Button();

            pedestrianDetectionButton.Text = "Pedestrian Detection";

            Button ocrButton = new Button();

            ocrButton.Text = "OCR";

            Button dnnButton = new Button();

            dnnButton.Text = "DNN";

            List <View> buttonList = new List <View>()
            {
                helloWorldButton,
                planarSubdivisionButton,
                faceDetectionButton,
                faceLandmarkDetectionButton,
                featureDetectionButton,
                pedestrianDetectionButton,
                ocrButton,
                dnnButton
            };

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Emgu.Util.Platform.ClrType != ClrType.NetFxCore)
            {
                Button viz3dButton = new Button();
                viz3dButton.Text = "Viz3D";

                buttonList.Add(viz3dButton);

                viz3dButton.Clicked += (sender, args) =>
                {
                    using (Viz3d viz = new Viz3d("show_simple_widgets"))
                    {
                        viz.SetBackgroundMeshLab();
                        using (WCoordinateSystem coor = new WCoordinateSystem())
                        {
                            viz.ShowWidget("coor", coor);
                            using (WCube cube = new WCube(
                                       new MCvPoint3D64f(-.5, -.5, -.5),
                                       new MCvPoint3D64f(.5, .5, .5),
                                       true,
                                       new MCvScalar(255, 255, 255)))
                            {
                                viz.ShowWidget("cube", cube);
                                using (WCube cube0 = new WCube(
                                           new MCvPoint3D64f(-1, -1, -1),
                                           new MCvPoint3D64f(-.5, -.5, -.5),
                                           false,
                                           new MCvScalar(123, 45, 200)))
                                {
                                    viz.ShowWidget("cub0", cube0);
                                    viz.Spin();
                                }
                            }
                        }
                    }
                };
            }

            StackLayout buttonsLayout = new StackLayout
            {
                VerticalOptions = LayoutOptions.Start,
            };

            foreach (View b in buttonList)
            {
                buttonsLayout.Children.Add(b);
            }

            // The root page of your application
            ContentPage page =
                new ContentPage()
            {
                Content = new ScrollView()
                {
                    Content = buttonsLayout,
                }
            };

            String aboutIcon;

            if (Emgu.Util.Platform.ClrType != ClrType.NetFxCore)
            {
                aboutIcon = "questionmark.png";
            }
            else
            {
                aboutIcon = null;
            }

            MainPage =
                new NavigationPage(
                    page
                    );

            ToolbarItem aboutItem = new ToolbarItem("About", aboutIcon,
                                                    () =>
            {
                MainPage.Navigation.PushAsync(new AboutPage());
                //page.DisplayAlert("Emgu CV Examples", "App version: ...", "Ok");
            }
                                                    );

            page.ToolbarItems.Add(aboutItem);

            helloWorldButton.Clicked += (sender, args) =>
            {
                MainPage.Navigation.PushAsync(new HelloWorldPage());
            };

            planarSubdivisionButton.Clicked += (sender, args) =>
            {
                MainPage.Navigation.PushAsync(new PlanarSubdivisionPage());
            };

            faceDetectionButton.Clicked += (sender, args) =>
            {
                MainPage.Navigation.PushAsync(new FaceDetectionPage());
            };

            pedestrianDetectionButton.Clicked += (sender, args) =>
            {
                MainPage.Navigation.PushAsync(new PedestrianDetectionPage());
            };

            featureDetectionButton.Clicked += (sender, args) =>
            {
                MainPage.Navigation.PushAsync(new FeatureMatchingPage());
            };

            if (Emgu.Util.Platform.ClrType == ClrType.NetFxCore)
            {
                //No DNN module for UWP apps
                dnnButton.IsVisible = false;
                faceLandmarkDetectionButton.IsVisible = false;
            }
            else
            {
                dnnButton.Clicked += (sender, args) => { MainPage.Navigation.PushAsync(new DnnPage()); };
                faceLandmarkDetectionButton.Clicked += (sender, args) => { MainPage.Navigation.PushAsync(new FaceLandmarkDetectionPage()); };
            }

            ocrButton.Clicked += (sender, args) =>
            {
                MainPage.Navigation.PushAsync(new OcrPage());
            };
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            MCvPoint3D32f[] _points;
            Mat             _left        = CvInvoke.Imread("imL.png", ImreadModes.Color);
            Mat             _right       = CvInvoke.Imread("imR.png", ImreadModes.Color);
            Mat             disparityMap = new Mat();

            Stopwatch watch     = Stopwatch.StartNew();
            UMat      leftGray  = new UMat();
            UMat      rightGray = new UMat();

            CvInvoke.CvtColor(_left, leftGray, ColorConversion.Bgr2Gray);
            CvInvoke.CvtColor(_right, rightGray, ColorConversion.Bgr2Gray);
            Mat points = new Mat();

            Computer3DPointsFromStereoPair(leftGray, rightGray, disparityMap, points);
            watch.Stop();
            long disparityComputationTime = watch.ElapsedMilliseconds;

            Mat pointsArray     = points.Reshape(points.NumberOfChannels, points.Rows * points.Cols);
            Mat colorArray      = _left.Reshape(_left.NumberOfChannels, _left.Rows * _left.Cols);
            Mat colorArrayFloat = new Mat();

            colorArray.ConvertTo(colorArrayFloat, DepthType.Cv32F);
            WCloud cloud = new WCloud(pointsArray, colorArray);

            // My attempt to grab a pixel.
            Image <Bgr, Byte> image = disparityMap.ToImage <Bgr, Byte>();

            int  threshhold  = 190;
            bool objectFound = false;

            for (int i = 0; i < image.Rows; i++)
            {
                for (int j = 0; j < disparityMap.Cols; j++)
                {
                    // If it's below the threshhold black it out.
                    if (image.Data[i, j, 0] < threshhold)
                    {
                        image.Data[i, j, 2] = 0;
                        image.Data[i, j, 1] = 0;
                        image.Data[i, j, 0] = 0;
                    }
                    else
                    {
                        objectFound = true;
                        Console.Write("(" + image.Data[i, j, 0].ToString().PadLeft(3, '0') + ","); // Blue;
                        Console.Write(image.Data[i, j, 1].ToString().PadLeft(3, '0') + ",");       // Green;
                        Console.Write(image.Data[i, j, 2].ToString().PadLeft(3, '0') + ")");       // Red;
                    }
                }
                Console.WriteLine(); // new row end line;
            }

            // 2D Disparity Display
            Mat show = new Mat();

            disparityMap.ConvertTo(show, DepthType.Cv8U);
            CvInvoke.Imshow("Disparity", show);

            disparityMap.ConvertTo(show, DepthType.Cv8U);
            CvInvoke.Imshow("Disparity Restricted", image);


            //try
            //{
            //    if (objectFound)
            //    {
            //        SerialPort serialPort1 = new SerialPort("COM6", 9600);
            //        serialPort1.Open();
            //        serialPort1.WriteLine("");
            //        System.Threading.Thread.Sleep(1000);
            //        serialPort1.WriteLine("");
            //        serialPort1.Close();
            //    }
            //}
            //catch (Exception ex)
            //{

            //}
            // 3D IMAGE DISPLAY
            Emgu.CV.Viz3d     v           = new Emgu.CV.Viz3d("Simple stereo reconstruction");
            WText             wtext       = new WText("3d point cloud", new System.Drawing.Point(20, 20), 20, new MCvScalar(255, 255, 255));
            WCoordinateSystem wCoordinate = new WCoordinateSystem(1.0);

            v.ShowWidget("text", wtext);
            //v.ShowWidget("coordinate", wCoordinate);
            v.ShowWidget("cloud", cloud);
            v.Spin();

            CvInvoke.WaitKey(0);
        }