Video Overlay Provider class provide video functions to get frame textures.
Exemplo n.º 1
0
        /// <summary>
        /// Register to get Tango image events.
        ///
        /// NOTE: Tango image events happen on a different thread than the main
        /// Unity thread.
        /// </summary>
        /// <param name="cameraId">Camera identifier to get events for.</param>
        /// <param name="useExperimentalOverlay">If true, use the experimental video overlay.</param>
        /// <param name="videoOverlayTexture">The video overlay texture to use.  Only used in experimental mode.</param>
        internal virtual void SetCallback(Tango.TangoEnums.TangoCameraId cameraId, bool useExperimentalOverlay, YUVTexture videoOverlayTexture)
        {
            m_usingExperimentalOverlay = useExperimentalOverlay;
            if (!useExperimentalOverlay)
            {
                m_previousImageBuffer = new TangoUnityImageData();
                m_onImageAvailable    = new Tango.VideoOverlayProvider.TangoService_onImageAvailable(_OnImageAvailable);
                Tango.VideoOverlayProvider.SetCallback(cameraId, m_onImageAvailable);
            }
            else
            {
                if (videoOverlayTexture != null)
                {
                    m_onUnityFrameAvailable = new Tango.VideoOverlayProvider.TangoService_onUnityFrameAvailable(_OnExperimentalUnityFrameAvailable);
                    VideoOverlayProvider.ExperimentalConnectTexture(cameraId,
                                                                    videoOverlayTexture,
                                                                    m_onUnityFrameAvailable);

                    Debug.Log("VideoOverlayListener.SetCallback() : Experimental Overlay listener hooked up");
                }
                else
                {
                    Debug.Log("VideoOverlayListener.SetCallback() : No Texture2D found!");
                }
            }
        }
        /// <summary>
        /// Register to get Tango image events for getting the texture byte buffer callback.
        ///
        /// NOTE: Tango image events happen on a different thread than the main
        /// Unity thread.
        /// </summary>
        internal static void SetCallbackByteBufferMethod()
        {
            if (m_onImageAvailable != null)
            {
                Debug.Log("VideoOverlayProvider.SetCallbackByteBufferMethod() called when a callback is already set.");
                return;
            }

            Debug.Log("VideoOverlayProvider.SetCallbackByteBufferMethod()");
            m_onImageAvailable = new VideoOverlayProvider.APIOnImageAvailable(_OnImageAvailable);
            VideoOverlayProvider.SetCallback(COLOR_CAMERA_ID, m_onImageAvailable);
        }
        /// <summary>
        /// Register to get Tango texture events when the camera is updated.
        ///
        /// NOTE: Tango texture events happen on a different thread than the main Unity thread.
        /// </summary>
        internal static void SetCallbackTextureMethod()
        {
            if (m_onTextureAvailable != null)
            {
                Debug.Log("VideoOverlayProvider.SetCallbackTextureMethod() called when a callback is already set.");
                return;
            }

            Debug.Log("VideoOverlayProvider.SetCallbackTextureMethod()");
            m_onTextureAvailable = new VideoOverlayProvider.APIOnTextureAvailable(_OnTangoCameraTextureAvailable);
            VideoOverlayProvider.SetCallback(COLOR_CAMERA_ID, m_onTextureAvailable);
        }
        /// <summary>
        /// Calculate the camera extrinsics for this device.
        /// </summary>
        private void _UpdateExtrinsics()
        {
            TangoCoordinateFramePair pair;

            TangoPoseData imu_T_devicePose = new TangoPoseData();

            pair.baseFrame   = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU;
            pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
            PoseProvider.GetPoseAtTime(imu_T_devicePose, 0, pair);

            TangoPoseData imu_T_depthCameraPose = new TangoPoseData();

            pair.baseFrame   = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU;
            pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_CAMERA_DEPTH;
            PoseProvider.GetPoseAtTime(imu_T_depthCameraPose, 0, pair);

            TangoPoseData imu_T_colorCameraPose = new TangoPoseData();

            pair.baseFrame   = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU;
            pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_CAMERA_COLOR;
            PoseProvider.GetPoseAtTime(imu_T_colorCameraPose, 0, pair);

            // Convert into matrix form to combine the poses.
            Matrix4x4 device_T_imu = Matrix4x4.Inverse(imu_T_devicePose.ToMatrix4x4());

            m_device_T_depthCamera = device_T_imu * imu_T_depthCameraPose.ToMatrix4x4();
            m_device_T_colorCamera = device_T_imu * imu_T_colorCameraPose.ToMatrix4x4();

            m_unityWorld_T_startService.SetColumn(0, new Vector4(1, 0, 0, 0));
            m_unityWorld_T_startService.SetColumn(1, new Vector4(0, 0, 1, 0));
            m_unityWorld_T_startService.SetColumn(2, new Vector4(0, 1, 0, 0));
            m_unityWorld_T_startService.SetColumn(3, new Vector4(0, 0, 0, 1));

            // Update the camera intrinsics too.
            TangoCameraIntrinsics colorCameraIntrinsics = new TangoCameraIntrinsics();

            VideoOverlayProvider.GetIntrinsics(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR, colorCameraIntrinsics);
            m_colorCameraIntrinsics.calibration_type = (int)colorCameraIntrinsics.calibration_type;
            m_colorCameraIntrinsics.width            = colorCameraIntrinsics.width;
            m_colorCameraIntrinsics.height           = colorCameraIntrinsics.height;
            m_colorCameraIntrinsics.cx          = colorCameraIntrinsics.cx;
            m_colorCameraIntrinsics.cy          = colorCameraIntrinsics.cy;
            m_colorCameraIntrinsics.fx          = colorCameraIntrinsics.fx;
            m_colorCameraIntrinsics.fy          = colorCameraIntrinsics.fy;
            m_colorCameraIntrinsics.distortion0 = colorCameraIntrinsics.distortion0;
            m_colorCameraIntrinsics.distortion1 = colorCameraIntrinsics.distortion1;
            m_colorCameraIntrinsics.distortion2 = colorCameraIntrinsics.distortion2;
            m_colorCameraIntrinsics.distortion3 = colorCameraIntrinsics.distortion3;
            m_colorCameraIntrinsics.distortion4 = colorCameraIntrinsics.distortion4;
        }
Exemplo n.º 5
0
        /// <summary>
        /// DEPRECATED: Register to get Tango texture events for the texture ID is updated.
        ///
        /// NOTE: Tango texture events happen on a different thread than the main
        /// Unity thread.
        /// </summary>
        /// <param name="videoOverlayTexture">The video overlay texture to use.</param>
        internal void SetCallbackYUVTextureIdMethod(YUVTexture videoOverlayTexture)
        {
            if (videoOverlayTexture != null)
            {
                m_onYUVTextureAvailable =
                    new VideoOverlayProvider.TangoService_onTextureAvailable(_OnTangoYUVTextureAvailable);
                VideoOverlayProvider.ExperimentalConnectTexture(
                    COLOR_CAMERA_ID, videoOverlayTexture, m_onYUVTextureAvailable);

                Debug.Log("VideoOverlayListener.SetCallback() : YUVTexture listener hooked up");
            }
            else
            {
                Debug.Log("VideoOverlayListener.SetCallback() : No Texture2D found!");
            }
        }
        /// <summary>
        /// Register to get Tango image events for the texture ID is updated.
        ///
        /// NOTE: Tango image events happen on a different thread than the main
        /// Unity thread.
        /// </summary>
        /// <param name="cameraId">Camera identifier to get events for.</param>
        /// <param name="videoOverlayTexture">The video overlay texture to use.</param>
        internal virtual void SetCallbackTextureIdMethod(Tango.TangoEnums.TangoCameraId cameraId,
                                                         YUVTexture videoOverlayTexture)
        {
            if (videoOverlayTexture != null)
            {
                m_onUnityFrameAvailable =
                    new Tango.VideoOverlayProvider.TangoService_onUnityFrameAvailable(_OnExperimentalUnityFrameAvailable);
                VideoOverlayProvider.ExperimentalConnectTexture(cameraId,
                                                                videoOverlayTexture,
                                                                m_onUnityFrameAvailable);

                Debug.Log("VideoOverlayListener.SetCallback() : Experimental Overlay listener hooked up");
            }
            else
            {
                Debug.Log("VideoOverlayListener.SetCallback() : No Texture2D found!");
            }
        }
        /// <summary>
        /// Stop getting Tango image or texture callbacks.
        /// </summary>
        internal static void Reset()
        {
            // Avoid calling into tango_client_api before the correct library is loaded.
            if (m_onImageAvailable != null || m_onTextureAvailable != null || m_onYUVTextureAvailable != null)
            {
                VideoOverlayProvider.ClearCallback(COLOR_CAMERA_ID);
            }

            m_onImageAvailable                   = null;
            m_onTextureAvailable                 = null;
            m_onYUVTextureAvailable              = null;
            m_previousImageBuffer                = new TangoUnityImageData();
            m_shouldSendTextureMethodEvent       = false;
            m_shouldSendByteBufferMethodEvent    = false;
            m_shouldSendYUVTextureIdMethodEvent  = false;
            m_onTangoImageAvailable              = null;
            m_onTangoCameraTextureAvailable      = null;
            m_onTangoYUVTextureAvailable         = null;
            m_onTangoImageMultithreadedAvailable = null;
        }
        /// <summary>
        /// DEPRECATED: Register to get Tango texture events for the texture ID is updated.
        ///
        /// NOTE: Tango texture events happen on a different thread than the main
        /// Unity thread.
        /// </summary>
        /// <param name="videoOverlayTexture">The video overlay texture to use.</param>
        internal static void SetCallbackYUVTextureIdMethod(YUVTexture videoOverlayTexture)
        {
            if (videoOverlayTexture != null)
            {
                if (m_onYUVTextureAvailable != null)
                {
                    Debug.Log("VideoOverlayProvider.SetCallbackYUVTextureIdMethod() called when a callback is already set.");
                    return;
                }

                Debug.Log("VideoOverlayProvider.SetCallbackYUVTextureIdMethod()");
                m_onYUVTextureAvailable =
                    new VideoOverlayProvider.APIOnTextureAvailable(_OnTangoYUVTextureAvailable);
                VideoOverlayProvider.ExperimentalConnectTexture(
                    COLOR_CAMERA_ID, videoOverlayTexture, m_onYUVTextureAvailable);
            }
            else
            {
                Debug.Log("VideoOverlayListener.SetCallbackYUVTextureIdMethod() : No Texture2D found!");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initialize application and providers.
        /// </summary>
        public void InitApplication()
        {
            if (m_applicationHandle != System.IntPtr.Zero)
            {
                DebugLogger.GetInstance.WriteToLog(DebugLogger.EDebugLevel.DEBUG_ERROR,
                                                   "Duplicated application handler");
                return;
            }

            // let's hardcode depth image reoslution
            // but eventially we can get resolution using VideoMode interface
            Resolution imageResolution = new Resolution();

            imageResolution.width       = 320;
            imageResolution.height      = 180;
            imageResolution.refreshRate = 5;
            Common.DepthFrameResolution = imageResolution;
            Common.DepthBufferSize      = 320 * 180;

            m_applicationHandle = TangoApplicationAPI.ApplicationInitialize("[Superframes Small-Peanut]");
            if (m_applicationHandle == System.IntPtr.Zero)
            {
                ErrorHandler.instance.presentErrorMessage("Application initialization failed");
            }
            if (m_enableVio)
            {
                VIOProvider.SetAutoReset(m_vioAutoReset);
                VIOProvider.Init(m_operationMode, m_sparseMapPath);
            }
            if (m_enableDepth)
            {
                DepthProvider.Init();
            }
            if (m_enableVideoOverlay)
            {
                VideoOverlayProvider.Init();
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Shut down the providers and application.
 /// </summary>
 public void ShutDownApplication()
 {
     if (m_enableVio)
     {
         VIOProvider.ShutDown();
     }
     if (m_enableDepth)
     {
         DepthProvider.ShutDown();
     }
     if (m_enableVideoOverlay)
     {
         VideoOverlayProvider.Shutdown();
     }
     if (m_applicationHandle == System.IntPtr.Zero)
     {
         DebugLogger.GetInstance.WriteToLog(
             DebugLogger.EDebugLevel.DEBUG_ERROR, "No application initialized");
         return;
     }
     TangoApplicationAPI.ApplicationShutdown(m_applicationHandle);
     m_applicationHandle = System.IntPtr.Zero;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Fill out <c>colorCameraData</c> with emulated values from Tango.
 /// </summary>
 /// <param name="colorCameraData">The image data to fill out.</param>
 private static void _FillEmulatedColorCameraData(TangoUnityImageData colorCameraData)
 {
     VideoOverlayProvider.GetTangoEmulation(colorCameraData);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Register to get Tango image events for getting the texture byte buffer callback.
 ///
 /// NOTE: Tango image events happen on a different thread than the main
 /// Unity thread.
 /// </summary>
 internal void SetCallbackByteBufferMethod()
 {
     m_previousImageBuffer = new TangoUnityImageData();
     m_onImageAvailable    = new VideoOverlayProvider.TangoService_onImageAvailable(_OnImageAvailable);
     VideoOverlayProvider.SetCallback(COLOR_CAMERA_ID, m_onImageAvailable);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Register to get Tango texture events when the camera is updated.
 ///
 /// NOTE: Tango texture events happen on a different thread than the main Unity thread.
 /// </summary>
 internal void SetCallbackTextureMethod()
 {
     m_onTextureAvailable = new VideoOverlayProvider.TangoService_onTextureAvailable(_OnTangoCameraTextureAvailable);
     VideoOverlayProvider.SetCallback(COLOR_CAMERA_ID, m_onTextureAvailable);
     Debug.Log("VideoOverlayListener.SetCallback() : Texture listener hooked up");
 }