Beispiel #1
0
    /// <summary>
    ///  Creates an OpenCV version of a ZED Mat.
    /// </summary>
    /// <param name="zedmat">Source ZED Mat.</param>
    /// <param name="zedmattype">Type of ZED Mat - data type and channel number.
    /// <returns></returns>
    private static OpenCvSharp.Mat SLMat2CVMat(ref sl.Mat zedmat, MAT_TYPE zedmattype)
    {
        int cvmattype = SLMatType2CVMatType(zedmattype);

        OpenCvSharp.Mat cvmat = new OpenCvSharp.Mat(zedmat.GetHeight(), zedmat.GetWidth(), cvmattype, zedmat.GetPtr());

        return(cvmat);
    }
Beispiel #2
0
    static void Main(string[] args)
    {
        Camera zed = new Camera(0);

        InitParameters initParameters = new InitParameters()
        {
            sdkVerbose = true,
            resolution = RESOLUTION.HD720,
            depthMode  = DEPTH_MODE.NONE
        };

        parseArgs(args, ref initParameters);

        ERROR_CODE returnedState = zed.Open(ref initParameters);

        if (returnedState != ERROR_CODE.SUCCESS)
        {
            Environment.Exit(-1);
        }

        string winName = "Camera control";

        Cv2.NamedWindow(winName);

        Console.WriteLine("ZED Model             : " + zed.GetCameraModel());
        Console.WriteLine("ZED Serial Number     : " + zed.GetZEDSerialNumber());
        Console.WriteLine("ZED Camera Firmware   : " + zed.GetCameraFirmwareVersion());
        Console.WriteLine("ZED Camera Resolution : " + zed.GetInitParameters().resolution);
        Console.WriteLine("ZED Camera FPS        : " + zed.GetInitParameters().cameraFPS);

        // Print help control
        printHelp();

        sl.Mat zedImage = new sl.Mat();
        zedImage.Create(new Resolution((uint)zed.ImageWidth, (uint)zed.ImageHeight), MAT_TYPE.MAT_8U_C4);

        // Initialise camera setting
        switchCameraSettings();

        char key = ' ';

        RuntimeParameters rtParams = new RuntimeParameters();

        while (key != 'q')
        {
            // Check that a new image is successfully acquired
            returnedState = zed.Grab(ref rtParams);
            if (returnedState == ERROR_CODE.SUCCESS)
            {
                //Retrieve left image
                zed.RetrieveImage(zedImage, VIEW.LEFT);

                // Convert to cvMat
                OpenCvSharp.Mat cvImage = new OpenCvSharp.Mat(zedImage.GetHeight(), zedImage.GetWidth(), OpenCvSharp.MatType.CV_8UC4, zedImage.GetPtr());

                Cv2.ImShow(winName, cvImage);
            }
            else
            {
                Console.WriteLine("ERROR during capture");
                break;
            }

            key = (char)Cv2.WaitKey(10);
            // Change camera settings with keyboard
            updateCameraSettings(key, ref zed);
        }
    }
Beispiel #3
0
 public void pushNewImage(Mat zedImage)
 {
     // Update Texture with current zedImage
     Gl.TexSubImage2D(TextureTarget.Texture2d, 0, 0, 0, zedImage.GetWidth(), zedImage.GetHeight(), PixelFormat.Rgba, PixelType.UnsignedByte, zedImage.GetPtr());
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            // Set Initialization parameters
            InitParameters init_params = new InitParameters();

            init_params.resolution = RESOLUTION.HD1080;

            Camera zedCamera = new Camera(0);
            // Open the camera
            ERROR_CODE err = zedCamera.Open(ref init_params);

            if (err != ERROR_CODE.SUCCESS)
            {
                Environment.Exit(-1);
            }

            // Get resolution of camera
            uint mWidth  = (uint)zedCamera.ImageWidth;
            uint mHeight = (uint)zedCamera.ImageHeight;

            // Initialize the Mat that will contain the left image
            Mat image = new Mat();

            image.Create(mWidth, mHeight, MAT_TYPE.MAT_8U_C4, MEM.CPU); // Mat need to be created before use.

            // defin default Runtime parameters
            RuntimeParameters runtimeParameters = new RuntimeParameters();

            // Initialize runtime parameters and frame counter
            int i = 0;

            while (i < 1000)
            {
                if (zedCamera.Grab(ref runtimeParameters) == ERROR_CODE.SUCCESS)
                {
                    zedCamera.RetrieveImage(image, VIEW.LEFT);        // Get the left image
                    ulong timestamp = zedCamera.GetCameraTimeStamp(); // Get image timestamp
                    Console.WriteLine("Image resolution: " + image.GetWidth() + "x" + image.GetHeight() + "|| Image timestamp: " + timestamp);
                    // increment frame count
                    i++;
                }
            }

            // Disable positional tracking and close the camera
            zedCamera.DisablePositionalTracking("");
            zedCamera.Close();
        }