Example #1
0
    /// <summary>
    /// Enables the thread to get the trackingr.up
    /// </summary>
    void EnableTrackingThreaded()
    {
        enablePoseSmoothing = enableSpatialMemory;
        lock (grabLock) {
            //Make sure we have "grabbed" on frame first
            sl.ERROR_CODE e            = zedCamera.Grab(ref runtimeParameters);
            int           timeOut_grab = 0;
            while (e != sl.ERROR_CODE.SUCCESS && timeOut_grab < 100)
            {
                e = zedCamera.Grab(ref runtimeParameters);
                Thread.Sleep(10);
                timeOut_grab++;
            }

            //Now enable the tracking with the proper parameters
            if (!(enableTracking = (zedCamera.EnableTracking(ref initialRotation, ref initialPosition, enableSpatialMemory, enablePoseSmoothing, pathSpatialMemory) == sl.ERROR_CODE.SUCCESS)))
            {
                throw new Exception(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.TRACKING_NOT_INITIALIZED));
            }
            else
            {
                isTrackingEnable = true;
            }
        }
    }
Example #2
0
    /// <summary>
    /// Enables the thread to get the trackingr.up
    /// </summary>
    void EnableTrackingThreaded()
    {
        enablePoseSmoothing = enableSpatialMemory;
        lock (grabLock)
        {
            //Make sure we have "grabbed" on frame first
            sl.ERROR_CODE e            = zedCamera.Grab(ref runtimeParameters);
            int           timeOut_grab = 0;
            while (e != sl.ERROR_CODE.SUCCESS && timeOut_grab < 100)
            {
                e = zedCamera.Grab(ref runtimeParameters);
                Thread.Sleep(10);
                timeOut_grab++;
            }

            //Make sure the .area path is valid
            if (pathSpatialMemory != "" && !System.IO.File.Exists(pathSpatialMemory))
            {
                Debug.Log("Specified path to .area file '" + pathSpatialMemory + "' does not exist. Ignoring.");
                pathSpatialMemory = "";
            }

            //Now enable the tracking with the proper parameters
            //if (!(enableTracking = (zedCamera.EnableTracking(ref initialRotation, ref initialPosition, enableSpatialMemory, enablePoseSmoothing, pathSpatialMemory) == sl.ERROR_CODE.SUCCESS)))
            if (!(enableTracking = (zedCamera.EnableTracking(ref zedOrientation, ref zedPosition, enableSpatialMemory, enablePoseSmoothing, pathSpatialMemory) == sl.ERROR_CODE.SUCCESS)))
            {
                throw new Exception(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.TRACKING_NOT_INITIALIZED));
            }
            else
            {
                isTrackingEnable = true;
            }
        }
    }
Example #3
0
 void OpenZEDInBackground()
 {
     openingLaunched = true;
     LastInitStatus  = sl.ERROR_CODE.ERROR_CODE_LAST;
     LastInitStatus  = zedCamera.Init(ref initParameters);
     openingLaunched = false;
 }
Example #4
0
        /// <summary>
        /// Grab a new image, rectifies it and computes the
        /// disparity map and optionally the depth map.
        /// The grabbing function is typically called in the main loop.
        /// </summary>
        /// <param name="sensingMode">defines the type of disparity map, more info : SENSING_MODE definition</param>
        /// <returns>the function returns false if no problem was encountered,
        /// true otherwise.</returns>

        public sl.ERROR_CODE Grab(SENSING_MODE sensingMode = SENSING_MODE.FILL, bool computeDepth = true, REFERENCE_FRAME referenceFrame = REFERENCE_FRAME.CAMERA)
        {
            AssertCameraIsReady();
            sl.ERROR_CODE error = sl.ERROR_CODE.FAILURE;
            error = (sl.ERROR_CODE)dllz_grab((int)sensingMode, Convert.ToInt32(computeDepth), (int)referenceFrame);
            return error;
        }
Example #5
0
    void Awake()
    {
        positionInit = transform.localPosition;
        rotationInit = transform.localRotation;
        position     = positionInit;
        orientation  = Quaternion.identity;

        isThreaded = multithreading;
        zedCamera  = sl.ZEDCamera.GetInstance();

        ZedSVOManager = GetComponent <SVOManager>();
        if (ZedSVOManager != null)
        {
            //Create a camera
            if ((ZedSVOManager.read || ZedSVOManager.record) && ZedSVOManager.videoFile.Length == 0)
            {
                ZedSVOManager.record = false;
                ZedSVOManager.read   = false;
            }
            if (ZedSVOManager.read)
            {
                ZedSVOManager.record = false;
                zedCamera.CreateCameraSVO(ZedSVOManager.videoFile);
            }
            else
            {
                zedCamera.CreateCameraLive(videoMode, FPS);
            }
        }
        else
        {
            zedCamera.CreateCameraLive(videoMode, FPS);
        }

        Debug.Log("ZED SDK Version " + sl.ZEDCamera.GetSDKVersion());

        //Initialize the camera in performance mode.
        sl.ERROR_CODE e = zedCamera.Init(depthMode);

        if (e != sl.ERROR_CODE.SUCCESS)
        {
            throw new Exception("Initialization failed " + e.ToString());
        }


        if (ZedSVOManager != null)
        {
            if (ZedSVOManager.record)
            {
                if (zedCamera.EnableRecording(ZedSVOManager.videoFile) != sl.ERROR_CODE.SUCCESS)
                {
                    ZedSVOManager.record = false;
                }
            }
        }
    }
Example #6
0
    void Awake()
    {
        //Position later gets updated every update tracking call
        positionInit = transform.localPosition;
        position     = positionInit;

        isThreaded = multithreading;
        zedCamera  = sl.ZEDCamera.GetInstance();

        ZedSVOManager = GetComponent <SVOManager>();
        if (ZedSVOManager != null)
        {
            //Create a camera
            if ((ZedSVOManager.read || ZedSVOManager.record) && ZedSVOManager.videoFile.Length == 0)
            {
                ZedSVOManager.record = false;
                ZedSVOManager.read   = false;
            }
            if (ZedSVOManager.read)
            {
                ZedSVOManager.record = false;
                zedCamera.CreateCameraSVO(ZedSVOManager.videoFile);
            }
            else
            {
                zedCamera.CreateCameraLive(videoMode, FPS);
            }
        }
        else
        {
            zedCamera.CreateCameraLive(videoMode, FPS);
        }

        Debug.Log("ZED SDK Version " + sl.ZEDCamera.GetSDKVersion());

        //Initialize the camera in performance mode, make minimum depth
        //be minDist meters to avoid inaccurate hand occlusions
        sl.ERROR_CODE e = zedCamera.Init(depthMode, minDist);

        if (e != sl.ERROR_CODE.SUCCESS)
        {
            throw new Exception("Initialization failed " + e.ToString());
        }


        if (ZedSVOManager != null)
        {
            if (ZedSVOManager.record)
            {
                if (zedCamera.EnableRecording(ZedSVOManager.videoFile) != sl.ERROR_CODE.SUCCESS)
                {
                    ZedSVOManager.record = false;
                }
            }
        }
    }
 /// <summary>
 /// Disable the ZED's spatial mapping.
 /// The mesh will no longer be updated, but it is not delete.
 /// </summary>
 private void DisableSpatialMapping()
 {
     lock (lockScanning)
     {
         updateThreadRunning = false;
         zedSpatialMapping.DisableSpatialMapping();
         scanningInitState       = sl.ERROR_CODE.FAILURE;
         spatialMappingRequested = false;
     }
 }
Example #8
0
        /// <summary>
        /// Initialize and Start the tracking functions
        /// </summary>
        /// <param name="quat"> rotation used as initial world transform.By default it should be identity.</param>
        /// <param name="vec"> translation used as initial world transform. By default it should be identity.</param>
        /// <param name="enableSpatialMemory">  (optional) define if spatial memory is enable or not.</param>
        /// <param name="areaFilePath"> (optional) file of spatial memory file that has to be loaded to relocate in the scene.</param>
        /// <returns></returns>

        public sl.ERROR_CODE EnableTracking(ref Quaternion quat, ref Vector3 vec, bool enableSpatialMemory = true, string areaFilePath = "")
        {
            AssertCameraIsReady();
            sl.ERROR_CODE trackingStatus = sl.ERROR_CODE.CAMERA_NOT_DETECTED;
            lock (ZEDUpdater.GetInstance().grabLock)
            {
                trackingStatus = (sl.ERROR_CODE)dllz_enable_tracking(ref quat, ref vec, enableSpatialMemory, areaFilePath);
            }
            return trackingStatus;
        }
Example #9
0
    private void AcquireImages()
    {
        if (requestNewFrame && zedReady)
        {
            /// call grab() to request a new frame
            sl.ERROR_CODE e = zedCamera.Grab(ref runtimeParameters);

            lock (grabLock)
            {
                if (e == sl.ERROR_CODE.CAMERA_NOT_DETECTED)
                {
                    Debug.Log("Camera not detected or disconnected.");
                    isDisconnected = true;
                    Thread.Sleep(10);
                    requestNewFrame = false;
                }
                else if (e == sl.ERROR_CODE.SUCCESS)
                {
                    //Save the timestamp
                    cameraTimeStamp = zedCamera.GetCameraTimeStamp();

#if UNITY_EDITOR
                    float camera_fps = zedCamera.GetCameraFPS();
                    cameraFPS = camera_fps.ToString() + "Fps";

                    if (camera_fps <= FPS * 0.8)
                    {
                        cameraFPS += " WARNING: Low USB bandwidth detected";
                    }
#endif

                    //Get position of camera
                    if (isTrackingEnable)
                    {
                        zedtrackingState = zedCamera.GetPosition(ref zedOrientation, ref zedPosition, ref rotationOffset, ref positionOffset);
                    }
                    else
                    {
                        zedtrackingState = sl.TRACKING_STATE.TRACKING_OFF;
                    }


                    // Indicate that a new frame is available and pause the thread until a new request is called
                    newFrameAvailable = true;
                    requestNewFrame   = false;
                }
            }
        }
        else
        {
            //to avoid "overheat"
            Thread.Sleep(1);
        }
    }
Example #10
0
    /// <summary>
    /// Creates canvas(es) and canvas elements depending on whether the ZED rig is mono (ZED_Rig_Mono)
    /// or stereo (ZED_Rig_Stereo).
    /// </summary>
    private void Awake()
    {
        zedManager    = GetComponent <ZEDManager> ();
        oldInitStatus = sl.ERROR_CODE.ERROR_CODE_LAST;
        if (!zedManager.IsStereoRig)         //Without VR, we use a Screen Space - Overlay canvas.
        {
            //Instantiate the mono warning prefab and set basic settings for it.
            warningmono = Instantiate(Resources.Load("PrefabsUI/Warning") as GameObject, transform);
            warningmono.SetActive(true);
            warningmono.GetComponent <Canvas> ().renderMode  = RenderMode.ScreenSpaceCamera;
            warningmono.GetComponent <Canvas> ().worldCamera = zedManager.GetLeftCameraTransform().GetComponent <Camera>();

            textmono       = warningmono.GetComponentInChildren <UnityEngine.UI.Text>();
            textmono.color = Color.white;

            if (!sl.ZEDCamera.CheckPlugin())
            {
                textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED);
            }
            imagemono = warningmono.transform.GetChild(0).GetChild(1).gameObject;
            imagemono.transform.parent.gameObject.SetActive(true);
            ready = false;
        }
        else //In VR, we use two Screen Space - Camera canvases, one for each eye.
        {
            //Instantiate the left warning prefab and set basic settings for it.
            warningleft = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject, zedManager.GetLeftCameraTransform());
            warningleft.SetActive(true);
            warningleft.GetComponent <Canvas>().worldCamera   = zedManager.GetLeftCameraTransform().GetComponent <Camera>();
            warningleft.GetComponent <Canvas>().planeDistance = 1;
            textleft       = warningleft.GetComponentInChildren <UnityEngine.UI.Text>();
            textleft.color = Color.white;
            imageleft      = warningleft.transform.GetChild(0).GetChild(1).gameObject;
            imageleft.transform.parent.gameObject.SetActive(true);

            //Instantiate the right warning prefab and set basic settings for it.
            warningright = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject, zedManager.GetRightCameraTransform());
            warningright.SetActive(true);
            warningright.GetComponent <Canvas>().worldCamera   = zedManager.GetRightCameraTransform().GetComponent <Camera>();
            warningright.GetComponent <Canvas>().planeDistance = 1;
            textright       = warningright.GetComponentInChildren <UnityEngine.UI.Text>();
            textright.color = Color.white;
            imageright      = warningright.transform.GetChild(0).GetChild(1).gameObject;
            imageright.transform.parent.gameObject.SetActive(true);

            if (!sl.ZEDCamera.CheckPlugin()) //Warn the use there's no SDK installed.
            {
                textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED);
                textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED);
            }

            ready = false;
        }
    }
    /// <summary>
    /// Starts the spatial mapping
    /// </summary>
    /// <param name="resolutionPreset"></param>
    /// <param name="rangePreset"></param>
    /// <param name="isTextured"></param>
    public void StartStatialMapping(RESOLUTION resolutionPreset, RANGE rangePreset, bool isTextured)
    {
        holder.transform.position = Vector3.zero;
        holder.transform.rotation = Quaternion.identity;
        spatialMappingRequested   = true;
        if (spatialMappingRequested && scanningInitState != sl.ERROR_CODE.SUCCESS)
        {
            scanningInitState = EnableSpatialMapping(resolutionPreset, rangePreset, isTextured);
        }

        zedManager.gravityRotation = Quaternion.identity;
    }
    public ZEDSpatialMapping(Transform transform, sl.ZEDCamera zedCamera, ZEDManager zedManager)
    {
        zedSpatialMapping = new ZEDSpatialMappingHelper(Resources.Load("Materials/SpatialMapping/Mat_ZED_Texture") as Material, Resources.Load("Materials/SpatialMapping/Mat_ZED_Geometry_Wireframe") as Material);

        this.zedCamera    = zedCamera;
        this.zedManager   = zedManager;
        scanningInitState = sl.ERROR_CODE.FAILURE;

        holder      = new GameObject();
        holder.name = "[ZED Mesh Holder]";
        //holder.hideFlags = HideFlags.HideInInspector;
        holder.transform.position = Vector3.zero;
        holder.transform.rotation = Quaternion.identity;
        StaticBatchingUtility.Combine(holder);
    }
Example #13
0
    // Update is called once per frame
    void Update()
    {
        if (!init)
        {
            sl.ERROR_CODE e = ZEDManager.LastInitStatus;

            if (e == sl.ERROR_CODE.SUCCESS)
            {
                timer += Time.deltaTime;
                if (timer > 0.2f)
                {
                    text.text = "";
                }
                image.gameObject.SetActive(false);
            }
            else if (e == sl.ERROR_CODE.ERROR_CODE_LAST)
            {
                text.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING);
                text.color = Color.white;
            }
            else if (e == sl.ERROR_CODE.CAMERA_NOT_DETECTED)
            {
                text.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA);
            }
            else
            {
                text.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED);
            }

            if (ready)
            {
                timerWarning += Time.deltaTime;
                if (timerWarning > 0.5f)
                {
                    warning.SetActive(false);
                    init         = true;
                    timerWarning = 0;
                }
                image.gameObject.transform.parent.gameObject.SetActive(false);
            }
        }
    }
Example #14
0
    /// <summary>
    /// Changes the value of record if recording fails, and gets the length of a read SVO file.
    /// </summary>
    /// <param name="zedCamera">Reference to the Scene's ZEDCamera instance.</param>
    public void InitSVO(sl.ZEDCamera zedCamera)
    {
        if (record)
        {
            sl.ERROR_CODE svoerror = zedCamera.EnableRecording(videoFile, compressionMode);
            if (svoerror != sl.ERROR_CODE.SUCCESS)
            {
                record = false;
            }
            else if (svoerror == sl.ERROR_CODE.SVO_RECORDING_ERROR)
            {
                Debug.LogError("SVO recording failed. Check that there is enough space on the drive and that the "
                               + "path provided is valid.");
            }
        }

        if (read)
        {
            NumberFrameMax = zedCamera.GetSVONumberOfFrames();
        }
    }
Example #15
0
    System.Collections.IEnumerator InitZED()
    {
        zedReady = false;
        while (LastInitStatus != sl.ERROR_CODE.SUCCESS)
        {
            //Initialize the camera
            if (!openingLaunched)
            {
                threadOpening = new Thread(new ThreadStart(OpenZEDInBackground));

                if (LastInitStatus != sl.ERROR_CODE.SUCCESS)
                {
#if UNITY_EDITOR
                    numberTriesOpening++;
                    if (numberTriesOpening % 2 == 0 && LastInitStatus == PreviousInitStatus)
                    {
                        Debug.LogWarning("[ZEDPlugin]: " + LastInitStatus);
                    }

                    if (numberTriesOpening > MAX_OPENING_TRIES)
                    {
                        Debug.Log("[ZEDPlugin]: Stops initialization");
                        yield break;
                    }
#endif


                    PreviousInitStatus = LastInitStatus;
                }


                threadOpening.Start();
            }

            yield return(new WaitForSeconds(0.3f));
        }


        //ZED has opened
        if (LastInitStatus == sl.ERROR_CODE.SUCCESS)
        {
            threadOpening.Join();

            //Initialize the threading mode, the positions with the AR and the SVO if needed
            //Launch the threading to enable the tracking
            ZEDReady();

            //Wait until the ZED of the init of the tracking
            while (enableTracking && !isTrackingEnable)
            {
                yield return(new WaitForSeconds(0.5f));
            }

            //Calls all the observers, the ZED is ready :)
            if (OnZEDReady != null)
            {
                OnZEDReady();
            }

            float ratio  = (float)Screen.width / (float)Screen.height;
            float target = 16.0f / 9.0f;
            if (Mathf.Abs(ratio - target) > 0.01)
            {
                ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SCREEN_RESOLUTION);
            }



            //If not already launched, launch the grabbing thread
            if (!running)
            {
                running         = true;
                requestNewFrame = true;

                threadGrab = new Thread(new ThreadStart(ThreadedZEDGrab));
                threadGrab.Start();
            }

            zedReady       = true;
            isDisconnected = false; //In case we just regained connection

            setRenderingSettings();
            AdjustZEDRigCameraPosition();
        }
    }
Example #16
0
    /// <summary>
    /// If visible, print the loading status of the ZED, including relevant errors.
    /// </summary>
    void Update()
    {
        if (!init) //This check will pass until 0.5 seconds after the ZED is done initializing.
        {
            sl.ERROR_CODE e = zedManager.LastInitStatus;

            if (e == sl.ERROR_CODE.SUCCESS) //Last initialization attempt was successful.
            {
                if (!ready)
                {
                    if (textmono)
                    {
                        textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_MODULE_LOADING);
                    }
                    else if (textleft)
                    {
                        textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_MODULE_LOADING);
                        textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_MODULE_LOADING);
                    }
                }
                else
                {
                    timer += Time.deltaTime;                     //Clear text after a short delay.
                    if (timer > 0.2f)
                    {
                        if (textmono)
                        {
                            textmono.text = "";
                        }
                        else if (textleft)
                        {
                            textleft.text  = "";
                            textright.text = "";
                        }
                    }

                    if (imagemono)                       //Disable mono rig canvas.
                    {
                        imagemono.gameObject.SetActive(false);
                    }
                    else if (imageleft)                         //Disable stereo rig canvases.
                    {
                        imageleft.gameObject.SetActive(false);
                        imageright.gameObject.SetActive(false);
                    }
                }
            }
            else if (e == sl.ERROR_CODE.ERROR_CODE_LAST)             //"Loading..."
            {
                //Initial error code set before an initialization attempt has returned successful or failed.
                //In short, it means it's still loading.
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING);
                }
                else if (textleft)
                {
                    textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING);
                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING);
                }
            }
            else if (e == sl.ERROR_CODE.CAMERA_NOT_DETECTED && oldInitStatus == sl.ERROR_CODE.CAMERA_NOT_DETECTED)             //"Camera not detected"
            {
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA);
                }
                else if (textleft)
                {
                    textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA);
                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA);
                }
            }
            else if (e == sl.ERROR_CODE.CAMERA_DETECTION_ISSUE && oldInitStatus == sl.ERROR_CODE.CAMERA_DETECTION_ISSUE)             //"Unable to open camera"
            {
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE);
                }
                else if (textleft)
                {
                    textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE);
                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE);
                }
            }
            else if (e == sl.ERROR_CODE.SENSOR_NOT_DETECTED && oldInitStatus == sl.ERROR_CODE.SENSOR_NOT_DETECTED)             //"Camera motion sensor not detected"
            {
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED);
                }
                else if (textleft)
                {
                    textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED);
                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED);
                }
            }
            else if (e == sl.ERROR_CODE.LOW_USB_BANDWIDTH && oldInitStatus == sl.ERROR_CODE.LOW_USB_BANDWIDTH)            //"Low USB bandwidth"
            {
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH);
                }
                else if (textleft)
                {
                    textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH);
                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH);
                }
            }
            else if (e == sl.ERROR_CODE.INVALID_SVO_FILE && oldInitStatus == sl.ERROR_CODE.INVALID_SVO_FILE)
            {
                if (textmono)
                {
                    textmono.text = "Invalid SVO File/Path";
                }
                else if (textleft)
                {
                    textleft.text  = "Invalid SVO File/Path";
                    textright.text = "Invalid SVO File/Path";
                }
            }
            else if (e == oldInitStatus)
            {
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED);
                }
                else if (textleft)
                {
                    textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED);
                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED);
                }
            }
            oldInitStatus = e;
        }

        if (ready) //ZED has finished initializing. Set a timer, then disable texts after it expires.
        {
            timerWarning += Time.deltaTime;
            if (timerWarning > 0.5f)
            {
                if (warningmono)
                {
                    warningmono.SetActive(false);
                }
                else if (warningleft)
                {
                    warningleft.SetActive(false);
                    warningright.SetActive(false);
                }
            }

            init = true; //Prevents logic above the if (ready) check from running each frame.

            if (imagemono)
            {
                imagemono.gameObject.transform.parent.gameObject.SetActive(false);
            }
            else if (imageleft)
            {
                imageleft.gameObject.transform.parent.gameObject.SetActive(false);
                imageright.gameObject.transform.parent.gameObject.SetActive(false);
            }
        }
    }
Example #17
0
    // Update is called once per frame
    void Update()
    {
        if (!init)
        {
            sl.ERROR_CODE e = ZEDManager.LastInitStatus;

            if (e == sl.ERROR_CODE.SUCCESS)
            {
                timer += Time.deltaTime;
                if (timer > 0.2f)
                {
                    if (textmono)
                    {
                        textmono.text = "";
                    }
                    else if (textleft)
                    {
                        textleft.text  = "";
                        textright.text = "";
                    }
                }
                if (imagemono)
                {
                    imagemono.gameObject.SetActive(false);
                }
                else if (imageleft)
                {
                    imageleft.gameObject.SetActive(false);
                    imageright.gameObject.SetActive(false);
                }
            }
            else if (e == sl.ERROR_CODE.ERROR_CODE_LAST)
            {
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING);
                    //textmono.color = Color.white;
                }
                else if (textleft)
                {
                    textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING);
                    //textleft.color = Color.white;

                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING);
                    //textright.color = Color.white;
                }
            }
            else if (e == sl.ERROR_CODE.CAMERA_NOT_DETECTED && oldInitStatus == sl.ERROR_CODE.CAMERA_NOT_DETECTED)
            {
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA);
                }
                else if (textleft)
                {
                    textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA);
                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA);
                }
            }
            else if (e == sl.ERROR_CODE.CAMERA_DETECTION_ISSUE && oldInitStatus == sl.ERROR_CODE.CAMERA_DETECTION_ISSUE)
            {
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE);
                }
                else if (textleft)
                {
                    textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE);
                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE);
                }
            }
            else if (e == sl.ERROR_CODE.SENSOR_NOT_DETECTED && oldInitStatus == sl.ERROR_CODE.SENSOR_NOT_DETECTED)
            {
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED);
                }
                else if (textleft)
                {
                    textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED);
                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED);
                }
            }
            else if (e == sl.ERROR_CODE.LOW_USB_BANDWIDTH && oldInitStatus == sl.ERROR_CODE.LOW_USB_BANDWIDTH)
            {
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH);
                }
                else if (textleft)
                {
                    textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH);
                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH);
                }
            }
            else if (e == oldInitStatus)
            {
                if (textmono)
                {
                    textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED);
                }
                else if (textleft)
                {
                    textleft.text  = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED);
                    textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED);
                }
            }
            oldInitStatus = e;
        }
        if (ready)
        {
            timerWarning += Time.deltaTime;
            if (timerWarning > 0.5f)
            {
                if (warningmono)
                {
                    warningmono.SetActive(false);
                }
                else if (warningleft)
                {
                    warningleft.SetActive(false);
                    warningright.SetActive(false);
                }
            }

            init = true;
            //timerWarning = 0;

            if (imagemono)
            {
                imagemono.gameObject.transform.parent.gameObject.SetActive(false);
            }
            else if (imageleft)
            {
                imageleft.gameObject.transform.parent.gameObject.SetActive(false);
                imageright.gameObject.transform.parent.gameObject.SetActive(false);
            }
        }
    }
Example #18
0
    void Awake()
    {
        instance = this;
        zedReady = false;
        //If you want the ZEDRig not to be destroyed
        DontDestroyOnLoad(transform.root);

        //Init the first parameters
        initParameters                    = new sl.InitParameters();
        initParameters.resolution         = resolution;
        initParameters.depthMode          = depthMode;
        initParameters.depthStabilization = depthStabilizer;

        //Check if the AR is needed and if possible to add
        CheckStereoMode();

        //Init the other options
        isZEDTracked    = enableTracking;
        initialPosition = zedRigRoot.transform.localPosition;
        zedPosition     = initialPosition;
        zedOrientation  = initialRotation;


        //Create a camera and return an error message if the dependencies are not detected
        zedCamera      = sl.ZEDCamera.GetInstance();
        LastInitStatus = sl.ERROR_CODE.ERROR_CODE_LAST;

        zedSVOManager = GetComponent <ZEDSVOManager>();
        zedCamera.CreateCamera(wrapperVerbose);

        if (zedSVOManager != null)
        {
            //Create a camera
            if ((zedSVOManager.read || zedSVOManager.record) && zedSVOManager.videoFile.Length == 0)
            {
                zedSVOManager.record = false;
                zedSVOManager.read   = false;
            }
            if (zedSVOManager.read)
            {
                zedSVOManager.record              = false;
                initParameters.pathSVO            = zedSVOManager.videoFile;
                initParameters.svoRealTimeMode    = zedSVOManager.realtimePlayback;
                initParameters.depthStabilization = depthStabilizer;
            }
        }

        versionZED = "[SDK]: " + sl.ZEDCamera.GetSDKVersion().ToString() + " [Plugin]: " + sl.ZEDCamera.PluginVersion.ToString();


        //Set the ZED Tracking frame as Left eye
        if (isStereoRig)
        {
            //Creates a CameraRig (the 2 last cameras)
            GameObject o = CreateZEDRigDisplayer();
            o.hideFlags        = HideFlags.HideAndDontSave;
            o.transform.parent = transform;

            //Force some initParameters that are required for MR experience
            initParameters.enableRightSideMeasure = isStereoRig;
            initParameters.depthMinimumDistance   = 0.1f;
            initParameters.depthMode          = sl.DEPTH_MODE.PERFORMANCE;
            initParameters.depthStabilization = depthStabilizer;

            //Create the mirror, the texture from the firsts cameras is rendered to avoid a black border
            CreateMirror();
        }

        //Start the co routine to initialize the ZED and avoid to block the user
        LastInitStatus  = sl.ERROR_CODE.ERROR_CODE_LAST;
        openingLaunched = false;
        StartCoroutine("InitZED");

        OnCamBrightnessChange += CameraBrightnessChangeHandler;
    }
Example #19
0
    void Awake()
    {
        isMoving = tracking;

        positionInit = transform.localPosition;
        rotationInit = transform.localRotation;
        position     = positionInit;
        orientation  = Quaternion.identity;

        isThreaded    = multithreading;
        zedCamera     = sl.ZEDCamera.GetInstance();
        zedSVOManager = GetComponent <SVOManager>();
        if (zedSVOManager != null)
        {
            //Create a camera
            if ((zedSVOManager.read || zedSVOManager.record) && zedSVOManager.videoFile.Length == 0)
            {
                zedSVOManager.record = false;
                zedSVOManager.read   = false;
            }
            if (zedSVOManager.read)
            {
                zedSVOManager.record = false;
                zedCamera.CreateCameraSVO(zedSVOManager.videoFile);
            }
            else
            {
                zedCamera.CreateCameraLive(resolution, FPS);
            }
        }
        else
        {
            zedCamera.CreateCameraLive(resolution, FPS);
        }

        Debug.Log("ZED SDK Version " + sl.ZEDCamera.GetSDKVersion());

        //Initialize the camera in performance mode.
        sl.ERROR_CODE e = zedCamera.Init(depthMode);

        if (e != sl.ERROR_CODE.SUCCESS)
        {
            throw new Exception("Initialization failed " + e.ToString());
        }


        if (zedSVOManager != null)
        {
            if (zedSVOManager.record)
            {
                if (zedCamera.EnableRecording(zedSVOManager.videoFile) != sl.ERROR_CODE.SUCCESS)
                {
                    zedSVOManager.record = false;
                }
            }


            if (zedSVOManager.read)
            {
                zedSVOManager.NumberFrameMax = zedCamera.GetSVONumberOfFrames();
            }
        }

        Component[] cams = gameObject.transform.GetComponentsInChildren(typeof(Camera));
        foreach (Camera cam in cams)
        {
            if (cam.stereoTargetEye == StereoTargetEyeMask.None)
            {
                cameraLeft = cam.transform;
                // cam.cullingMask &= ~(1 << sl.ZEDCamera.TagOneObject);
            }
        }
    }
Example #20
0
    void Awake()
    {
        position    = new Vector3(0, 0.0f, 0);
        orientation = Quaternion.identity;

        zedCamera     = sl.ZEDCamera.GetInstance();
        ZedSVOManager = GetComponent <SVOManager>();

        if (ZedSVOManager != null)
        {
            //Create a camera
            if ((ZedSVOManager.read || ZedSVOManager.record) && ZedSVOManager.videoFile.Length == 0)
            {
                ZedSVOManager.record = false;
                ZedSVOManager.read   = false;
            }
            if (ZedSVOManager.read)
            {
                ZedSVOManager.record = false;
                zedCamera.CreateCameraSVO(ZedSVOManager.videoFile);
            }
            else
            {
                zedCamera.CreateCameraLive(resolution, 0.0f);
            }
        }
        else
        {
            zedCamera.CreateCameraLive(resolution, 0.0f);
        }
        Debug.Log("ZED SDK Version " + sl.ZEDCamera.GetSDKVersion());

        //Initialize the camera in performance mode.
        sl.ERROR_CODE e = zedCamera.Init(sl.DEPTH_MODE.PERFORMANCE);

        if (e != sl.ERROR_CODE.SUCCESS)
        {
            throw new Exception("Initialization failed " + e.ToString());
        }



        if (ZedSVOManager != null)
        {
            if (ZedSVOManager.record)
            {
                if (zedCamera.EnableRecording(ZedSVOManager.videoFile) != sl.ERROR_CODE.SUCCESS)
                {
                    ZedSVOManager.record = false;
                }
            }
        }
        if (UnityEngine.VR.VRSettings.enabled)
        {
            headset = true;
            UnityEngine.VR.InputTracking.Recenter();
        }
        else
        {
            headset            = false;
            cameraHeadOffset.y = 0;
            cameraHeadOffset.z = 0;

            Debug.LogWarning("This script needs the VR to work correctly");
        }
    }
Example #21
0
    private void AcquireImages()
    {
        if (requestNewFrame && zedReady)
        {
            sl.ERROR_CODE e = sl.ERROR_CODE.NOT_A_NEW_FRAME;

            // Live or SVO ? if SVO is in pause, don't need to call grab again since image will not change
            if (zedSVOManager == null)
            {
                e = zedCamera.Grab(ref runtimeParameters);
            }
            else
            {
                if (!zedSVOManager.pause)
                {
                    e = zedCamera.Grab(ref runtimeParameters);
                }
                else
                {
                    if (zedSVOManager.NeedNewFrameGrab)
                    {
                        e = zedCamera.Grab(ref runtimeParameters);
                        zedSVOManager.NeedNewFrameGrab = false;
                    }
                    else
                    {
                        e = sl.ERROR_CODE.SUCCESS;
                    }
                }
            }


            lock (grabLock)
            {
                if (e == sl.ERROR_CODE.CAMERA_NOT_DETECTED)
                {
                    Debug.Log("Camera not detected or disconnected.");
                    isDisconnected = true;
                    Thread.Sleep(10);
                    requestNewFrame = false;
                }
                else if (e == sl.ERROR_CODE.SUCCESS)
                {
                    //Save the timestamp
                    cameraTimeStamp = zedCamera.GetCameraTimeStamp();

#if UNITY_EDITOR
                    float camera_fps = zedCamera.GetCameraFPS();
                    cameraFPS = camera_fps.ToString() + "Fps";

                    if (camera_fps <= FPS * 0.8)
                    {
                        cameraFPS += " WARNING: Low USB bandwidth detected";
                    }
#endif

                    //Get position of camera
                    if (isTrackingEnable)
                    {
                        zedtrackingState = zedCamera.GetPosition(ref zedOrientation, ref zedPosition, sl.TRACKING_FRAME.LEFT_EYE);
                    }
                    else
                    {
                        zedtrackingState = sl.TRACKING_STATE.TRACKING_OFF;
                    }


                    // Indicate that a new frame is available and pause the thread until a new request is called
                    newFrameAvailable = true;
                    requestNewFrame   = false;
                }
                else
                {
                    Thread.Sleep(1);
                }
            }
        }
        else
        {
            //to avoid "overheat"
            Thread.Sleep(1);
        }
    }