Esempio n. 1
0
    static void Main()
    {
        try
        {
            var zivid = new Zivid.NET.Application();

            var resultFile = "result.zdf";

            Console.WriteLine("Connecting to camera");
            var camera = zivid.ConnectCamera();

            Console.WriteLine("Adjusting the iris");
            camera.UpdateSettings(s =>
            {
                s.Iris                      = 22;
                s.ExposureTime              = Duration.FromMicroseconds(8333);
                s.Filters.Outlier.Enabled   = true;
                s.Filters.Outlier.Threshold = 5;
            });

            Console.WriteLine("Capture a frame");
            var frame = camera.Capture();

            Console.WriteLine("Saving frame to file: " + resultFile);
            frame.Save(resultFile);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
            Environment.ExitCode = 1;
        }
    }
Esempio n. 2
0
    static void Main()
    {
        try
        {
            var zivid = new Zivid.NET.Application();

            Console.WriteLine("Connecting to camera");
            var camera = zivid.ConnectCamera();

            Console.WriteLine("Configuring settings");
            var settings = new Zivid.NET.Settings
            {
                Acquisitions = { new Zivid.NET.Settings.Acquisition {
                                     Aperture     = 5.66,
                                     ExposureTime = Duration.FromMicroseconds(6500)
                                 } },
                Processing = { Filters = { Outlier = { Removal = { Enabled = true, Threshold = 5.0 } } } }
            };

            Console.WriteLine("Capturing frame");
            using (var frame = camera.Capture(settings))
            {
                var dataFile = "Frame.zdf";
                Console.WriteLine("Saving frame to file: " + dataFile);
                frame.Save(dataFile);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
            Environment.ExitCode = 1;
        }
    }
Esempio n. 3
0
    static void Main()
    {
        try
        {
            var zivid = new Zivid.NET.Application();

            Console.WriteLine("Connecting to camera");
            var camera = zivid.ConnectCamera();

            Console.WriteLine("Setting the capture settings");
            var settings = new Zivid.NET.Settings2D()
            {
                Iris         = 22,
                ExposureTime = Duration.FromMicroseconds(10000),
                Gain         = 1.0
            };

            Console.WriteLine("Capture a 2D frame");
            var frame2D = camera.Capture2D(settings);

            Console.WriteLine("Get RGBA8 image from Frame2D");
            var image = frame2D.Image <Zivid.NET.RGBA8>();

            Console.WriteLine("Image Width: {0}, Height: {1}", image.Width, image.Height);
            Console.WriteLine("Pixel (0, 0): R={0}, G={1}, B={2}, A={3}",
                              image[0, 0].r,
                              image[0, 0].g,
                              image[0, 0].b,
                              image[0, 0].a);

            byte[] byteArray = image.ToArray();
            Console.WriteLine("First four bytes:  [0]: {0}, [1]: {1}, [2]: {2}, [3]: {3}",
                              byteArray[0],
                              byteArray[1],
                              byteArray[2],
                              byteArray[3]);

            var resultFile = "image.png";
            Console.WriteLine("Saving the image to {0}", resultFile);
            image.Save(resultFile);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
            Environment.ExitCode = 1;
        }
    }
    static void Main()
    {
        try
        {
            var zivid = new Zivid.NET.Application();

            Console.WriteLine("Connecting to camera");
            var camera = zivid.ConnectCamera();

            Console.WriteLine("Configuring settings");
            var settings = new Zivid.NET.Settings
            {
                Acquisitions = { new Zivid.NET.Settings.Acquisition {
                                     Aperture     = 5.66,
                                     ExposureTime = Duration.FromMicroseconds(8333)
                                 } },
                Processing = { Filters = { Outlier = { Removal = { Enabled = true, Threshold = 5.0 } } } }
            };

            Console.WriteLine("Capturing frame");
            var frame      = camera.Capture(settings);
            var pointCloud = frame.PointCloud;

            Console.WriteLine("Converting to Halcon point cloud");
            HalconDotNet.HObjectModel3D objectModel3D = ZividToHalconPointCloud(pointCloud);

            string pointCloudFile = "Zivid3D.ply";
            Console.WriteLine("Saving point cloud to: " + pointCloudFile);
            SaveHalconPointCloud(objectModel3D, pointCloudFile);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
            Environment.ExitCode = 1;
        }
    }
    static void Main()
    {
        try
        {
            var zivid = new Zivid.NET.Application();

            Console.WriteLine("Setting up visualization");
            var visualizer = new Zivid.NET.CloudVisualizer();
            zivid.DefaultComputeDevice = visualizer.ComputeDevice;

            Console.WriteLine("Connecting to the camera");
            var camera = zivid.ConnectCamera();

            Console.WriteLine("Recording HDR source images");
            var frames = new List <Zivid.NET.Frame>();

            camera.UpdateSettings(s =>
            {
                s.Iris                       = 10;
                s.ExposureTime               = Duration.FromMicroseconds(10000);
                s.Brightness                 = 1;
                s.Gain                       = 1;
                s.Bidirectional              = false;
                s.Filters.Contrast.Enabled   = true;
                s.Filters.Contrast.Threshold = 5;
                s.Filters.Gaussian.Enabled   = true;
                s.Filters.Gaussian.Sigma     = 1.5;
                s.Filters.Outlier.Enabled    = true;
                s.Filters.Outlier.Threshold  = 5;
                s.Filters.Reflection.Enabled = true;
                s.Filters.Saturated.Enabled  = true;
                s.BlueBalance                = 1.081;
                s.RedBalance                 = 1.709;
            });

            ulong[] iris     = { 10, 20, 30 };
            long[]  exposure = { 10000, 20000, 30000 };

            for (int i = 0; i < 3; ++i)
            {
                camera.UpdateSettings(s =>
                {
                    s.Iris         = iris[i];
                    s.ExposureTime = Duration.FromMicroseconds(exposure[i]);
                });
                frames.Add(camera.Capture());
                Console.WriteLine("Frame " + (i + 1) + " " + camera.Settings.ToString());
            }

            Console.WriteLine("Creating the HDR frame");
            var hdrFrame = Zivid.NET.HDR.CombineFrames(frames);

            Console.WriteLine("Saving the frames");
            frames[0].Save("10.zdf");
            frames[1].Save("20.zdf");
            frames[2].Save("30.zdf");
            hdrFrame.Save("HDR.zdf");

            Console.WriteLine("Displaying the HDR frame");
            visualizer.ShowMaximized();
            visualizer.Show(hdrFrame);
            visualizer.ResetToFit();

            Console.WriteLine("Running the visualizer. Blocking until the window closes");
            visualizer.Run();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
            Environment.ExitCode = 1;
        }
    }
Esempio n. 6
0
    static void Main()
    {
        try
        {
            var zivid = new Zivid.NET.Application();

            Console.WriteLine("Connecting to camera");
            var camera = zivid.ConnectCamera();

            Console.WriteLine("Configuring 2D settings");
            // Note: The Zivid SDK supports 2D captures with a single acquisition only
            var settings2D = new Zivid.NET.Settings2D
            {
                Acquisitions = { new Zivid.NET.Settings2D.Acquisition {
                                     Aperture = 11.31, ExposureTime = Duration.FromMicroseconds(30000), Gain = 2.0, Brightness = 1.80
                                 } },
                Processing = { Color = { Balance = { Red = 1.0, Blue = 1.0, Green = 1.0 }, Gamma = 1.0 } }
            };

            Console.WriteLine("Capturing 2D frame");
            using (var frame2D = camera.Capture(settings2D))
            {
                Console.WriteLine("Getting RGBA image");
                var image    = frame2D.ImageRGBA();
                var pixelRow = 100;
                var pixelCol = 50;

                Console.WriteLine("Extracting 2D pixel array");
                var pixelArray = image.ToArray();
                Console.WriteLine("Height: {0}, Width: {1}", pixelArray.GetLength(0), pixelArray.GetLength(1));
                Console.WriteLine("Color at pixel ({0},{1}):  R:{2}  G:{3}  B:{4}  A:{5}",
                                  pixelRow,
                                  pixelCol,
                                  pixelArray[pixelRow, pixelCol].r,
                                  pixelArray[pixelRow, pixelCol].g,
                                  pixelArray[pixelRow, pixelCol].b,
                                  pixelArray[pixelRow, pixelCol].a);

                Console.WriteLine("Extracting 3D array of bytes");
                var nativeArray = image.ToByteArray();
                Console.WriteLine("Height: {0}, Width: {1}, Channels: {2}",
                                  nativeArray.GetLength(0),
                                  nativeArray.GetLength(1),
                                  nativeArray.GetLength(2));
                Console.WriteLine("Color at pixel ({0},{1}):  R:{2}  G:{3}  B:{4}  A:{5}",
                                  pixelRow,
                                  pixelCol,
                                  nativeArray[pixelRow, pixelCol, 0],
                                  nativeArray[pixelRow, pixelCol, 1],
                                  nativeArray[pixelRow, pixelCol, 2],
                                  nativeArray[pixelRow, pixelCol, 3]);

                var imageFile = "Image.png";
                Console.WriteLine("Saving image to file: {0}", imageFile);
                image.Save(imageFile);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
            Environment.ExitCode = 1;
        }
    }
    static void Main()
    {
        try
        {
            var zivid = new Zivid.NET.Application();

            Console.WriteLine("Connecting to camera");
            var camera = zivid.ConnectCamera();

            Console.WriteLine("Configuring global processing settings:");
            var settings = new Zivid.NET.Settings()
            {
                Experimental = { Engine = Zivid.NET.Settings.ExperimentalGroup.EngineOption.Phase },
                Processing   = { Filters                                                                   = { Smoothing    = { Gaussian           = { Enabled    = true, Sigma     = 1.5 } },
                                                                                                               Noise        = { Removal            = { Enabled    = true, Threshold = 7.0 } },
                                                                                                               Outlier      = { Removal            = { Enabled    = true, Threshold = 5.0 } },
                                                                                                               Reflection   = { Removal            = { Enabled    = true } },
                                                                                                               Experimental = { ContrastDistortion = { Correction         = { Enabled                                                                   = true,
                                                                                                                                                                                                                                               Strength =                                                                                      0.4 },
                                                                                                                                                                                                                        Removal                                                                                      = { Enabled   = true,
                                                                                                                                                                                                                                                                                                                         Threshold =                                                                       0.5 } } } },
                                 Color                                                                       = { Balance            = { Red        = 1.0, Green = 1.0, Blue = 1.0 }, Gamma = 1.0 } }
            };
            Console.WriteLine(settings);

            Console.WriteLine("Configuring base acquisition with settings same for all HDR acquisitions:");
            var baseAcquisition = new Zivid.NET.Settings.Acquisition {
                Brightness = 1.8
            };
            Console.WriteLine(baseAcquisition);

            Console.WriteLine("Configuring acquisition settings different for all HDR acquisitions:");
            Tuple <double[], int[], double[]> exposureValues = GetExposureValues(camera);
            double[] aperture     = exposureValues.Item1;
            int[]    exposureTime = exposureValues.Item2;
            double[] gain         = exposureValues.Item3;
            for (int i = 0; i < aperture.Length; i++)
            {
                Console.WriteLine("Acquisition {0}:", i + 1);
                Console.WriteLine("  Exposure Time: {0}", exposureTime[i]);
                Console.WriteLine("  Aperture: {0}", aperture[i]);
                Console.WriteLine("  Gain: {0}", gain[i]);
                var acquisitionSettings = baseAcquisition.CopyWith(s =>
                {
                    s.Aperture     = aperture[i];
                    s.ExposureTime = Duration.FromMicroseconds(exposureTime[i]);
                    s.Gain         = gain[i];
                });
                settings.Acquisitions.Add(acquisitionSettings);
            }

            Console.WriteLine("Capturing frame (HDR)");
            using (var frame = camera.Capture(settings))
            {
                Console.WriteLine("Complete settings used:");
                Console.WriteLine(frame.Settings);

                var dataFile = "Frame.zdf";
                Console.WriteLine("Saving frame to file: " + dataFile);
                frame.Save(dataFile);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
            Environment.ExitCode = 1;
        }
    }