Exemplo n.º 1
0
        /// <summary>
        /// Renders the latest frame.
        /// </summary>
        /// <param name="cameraId">Camera identifier.</param>
        public static void RenderLatestFrame(TangoEnums.TangoCameraId cameraId)
        {
            double timestamp   = 0.0f;
            int    returnValue = VideoOverlayAPI.TangoService_updateTexture(cameraId, ref timestamp);

            if (returnValue != Common.ErrorType.TANGO_SUCCESS)
            {
                Debug.Log("VideoOverlayProvider.UpdateTexture() Texture was not updated by camera!");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the callback for notifications when image data is ready.
        /// </summary>
        /// <param name="cameraId">Camera identifier.</param>
        /// <param name="onImageAvailable">On image available callback handler.</param>
        public static void SetCallback(TangoEnums.TangoCameraId cameraId, TangoService_onImageAvailable onImageAvailable)
        {
            int returnValue = VideoOverlayAPI.TangoService_connectOnFrameAvailable(cameraId, callbackContext, onImageAvailable);

            if (returnValue == Tango.Common.ErrorType.TANGO_SUCCESS)
            {
                Debug.Log(CLASS_NAME + ".SetCallback() Callback was set.");
            }
            else
            {
                Debug.Log(CLASS_NAME + ".SetCallback() Callback was not set!");
            }
        }
Exemplo n.º 3
0
        public static void ExperimentalConnectTexture(TangoEnums.TangoCameraId cameraId, YUVTexture textures, TangoService_onUnityFrameAvailable onUnityFrameAvailable)
        {
            int returnValue = VideoOverlayAPI.TangoService_Experimental_connectTextureIdUnity(cameraId,
                                                                                              (uint)textures.m_videoOverlayTextureY.GetNativeTextureID(),
                                                                                              (uint)textures.m_videoOverlayTextureCb.GetNativeTextureID(),
                                                                                              (uint)textures.m_videoOverlayTextureCr.GetNativeTextureID(),
                                                                                              callbackContext,
                                                                                              onUnityFrameAvailable);

            if (returnValue != Common.ErrorType.TANGO_SUCCESS)
            {
                Debug.Log("VideoOverlayProvider.ConnectTexture() Texture was not connected to camera!");
            }
        }
        /// <summary>
        /// Experimental API only, subject to change.  Connect a Texture IDs to a camera.
        ///
        /// The camera is selected via TangoCameraId.  Currently only TANGO_CAMERA_COLOR is supported.  The texture
        /// handles will be regenerated by the API on startup after which the application can use them, and will be
        /// packed RGBA8888 data containing bytes of the image (so a single RGBA8888 will pack 4 neighbouring pixels).
        /// If the config flag experimental_image_pixel_format is set to HAL_PIXEL_FORMAT_YCrCb_420_SP, texture_y will
        /// pack 1280x720 pixels into a 320x720 RGBA8888 texture.  texture_Cb and texture_Cr will contain copies of
        /// the 2x2 downsampled interleaved UV planes packed similarly.  If experimental_image_pixel_format is set to
        /// HAL_PIXEL_FORMAT_YV12 then texture_y will have a stride of 1536 containing 1280 columns of data, packed
        /// similarly in a RGBA8888 texture. texture_Cb and texture_Cr will be 2x2 downsampled versions of the same.
        /// See YV12 and NV21 formats for details.
        ///
        /// Note: The first scan-line of the color image is reserved for metadata instead of image pixels.
        /// </summary>
        /// <param name="cameraId">
        /// The ID of the camera to connect this texture to.  Only TANGO_CAMERA_COLOR and TANGO_CAMERA_FISHEYE are
        /// supported.
        /// </param>
        /// <param name="textures">The texture IDs to use for the Y, Cb, and Cr planes.</param>
        /// <param name="onUnityFrameAvailable">Callback method.</param>
        internal static void ExperimentalConnectTexture(TangoEnums.TangoCameraId cameraId, YUVTexture textures, TangoService_onUnityFrameAvailable onUnityFrameAvailable)
        {
#if UNITY_EDITOR
            if (cameraId == TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR)
            {
                // Resize textures to to simulated width.
                textures.ResizeAll(EMULATED_CAMERA_PACKED_WIDTH, EMULATED_CAMERA_PACKED_Y_HEIGHT,
                                   EMULATED_CAMERA_PACKED_WIDTH, EMULATED_CAMERA_PACKED_UV_HEIGHT);

                if (!m_emulationIsInitialized)
                {
                    _InitializeResourcesForEmulation();
                    m_emulationIsInitialized = true;
                }

#if !UNITY_EDITOR_WIN
                // Rebind Texture2Ds to the underlying OpenGL texture ids of our render textures
                // Which is more or less the inverse of what the acutal tango service does but has the same effect.
                textures.m_videoOverlayTextureY.UpdateExternalTexture(m_emulatedExpId_Y.GetNativeTexturePtr());
                textures.m_videoOverlayTextureCb.UpdateExternalTexture(m_emulatedExpId_CbCr.GetNativeTexturePtr());
                textures.m_videoOverlayTextureCr.UpdateExternalTexture(m_emulatedExpId_CbCr.GetNativeTexturePtr());
#else   // !UNITY_EDITOR_WIN
                // A crash occurs when assigning the pointer of a Unity RenderTexture to a Texture2D (as above)
                // in a DirectX environment. Instead, size the Texture2D's correctly and copy render targets
                // with ReadPixels() when updating experimental textures.
                // Keeping separate paths because ReadPixels() is a significant performance hit.

                textures.m_videoOverlayTextureY.Resize(m_emulatedExpId_Y.width, m_emulatedExpId_Y.height);
                textures.m_videoOverlayTextureCb.Resize(m_emulatedExpId_CbCr.width, m_emulatedExpId_CbCr.height);

                m_emulationTexIdCaptureTextures = textures;
#endif  // !UNITY_EDITOR_WIN
            }
#else
            int returnValue = VideoOverlayAPI.TangoService_Experimental_connectTextureIdUnity(
                cameraId,
                (uint)textures.m_videoOverlayTextureY.GetNativeTexturePtr().ToInt64(),
                (uint)textures.m_videoOverlayTextureCb.GetNativeTexturePtr().ToInt64(),
                (uint)textures.m_videoOverlayTextureCr.GetNativeTexturePtr().ToInt64(),
                callbackContext,
                onUnityFrameAvailable);

            if (returnValue != Common.ErrorType.TANGO_SUCCESS)
            {
                Debug.Log("VideoOverlayProvider.ConnectTexture() Texture was not connected to camera!");
            }
#endif
        }
        /// <summary>
        /// Update the texture that has been connected to camera referenced by TangoCameraId with the latest image
        /// from the camera.
        /// </summary>
        /// <returns>The timestamp of the image that has been pushed to the connected texture.</returns>
        /// <param name="cameraId">
        /// The ID of the camera to connect this texture to.  Only <code>TANGO_CAMERA_COLOR</code> and
        /// <code>TANGO_CAMERA_FISHEYE</code> are supported.
        /// </param>
        public static double RenderLatestFrame(TangoEnums.TangoCameraId cameraId)
        {
#if UNITY_EDITOR
            if (m_emulatedExpId_Y != null && m_emulatedExpId_CbCr != null)
            {
                m_emulatedExpId_Y.DiscardContents();
                m_emulatedExpId_CbCr.DiscardContents();
                Graphics.Blit(m_emulatedColorRenderTexture, m_emulatedExpId_Y, m_yuvFilterY);
                Graphics.Blit(m_emulatedColorRenderTexture, m_emulatedExpId_CbCr, m_yuvFilterCbCr);
#if UNITY_EDITOR_WIN
                // A crash occurs when assigning the pointer of a Unity RenderTexture to a Texture2D in a DirectX
                // environment, so must use the slower technique of using normal Texture2D objects with ReadPixels().
                // See emulation comments in ExperimentalConnectTexture().
                RenderTexture.active = m_emulatedExpId_Y;
                m_emulationTexIdCaptureTextures.m_videoOverlayTextureY.ReadPixels(new Rect(0, 0,
                                                                                           m_emulatedExpId_Y.width,
                                                                                           m_emulatedExpId_Y.height),
                                                                                  0, 0, false);
                m_emulationTexIdCaptureTextures.m_videoOverlayTextureY.Apply();

                RenderTexture.active = m_emulatedExpId_CbCr;
                m_emulationTexIdCaptureTextures.m_videoOverlayTextureCb.ReadPixels(new Rect(0, 0,
                                                                                            m_emulatedExpId_CbCr.width,
                                                                                            m_emulatedExpId_CbCr.height),
                                                                                   0, 0, false);
                m_emulationTexIdCaptureTextures.m_videoOverlayTextureCb.Apply();
#endif  // UNITY_EDITOR_WIN
            }

            return(m_lastColorEmulationTime);
#else
            double timestamp   = 0.0;
            int    returnValue = VideoOverlayAPI.TangoService_updateTexture(cameraId, ref timestamp);
            if (returnValue != Common.ErrorType.TANGO_SUCCESS)
            {
                Debug.Log("VideoOverlayProvider.UpdateTexture() Texture was not updated by camera!");
            }

            return(timestamp);
#endif
        }
Exemplo n.º 6
0
        /// <summary>
        /// Experimental API only, subject to change.  Connect a Texture IDs to a camera.
        ///
        /// The camera is selected via TangoCameraId.  Currently only TANGO_CAMERA_COLOR is supported.  The texture
        /// handles will be regenerated by the API on startup after which the application can use them, and will be
        /// packed RGBA8888 data containing bytes of the image (so a single RGBA8888 will pack 4 neighbouring pixels).
        /// If the config flag experimental_image_pixel_format is set to HAL_PIXEL_FORMAT_YCrCb_420_SP, texture_y will
        /// pack 1280x720 pixels into a 320x720 RGBA8888 texture.  texture_Cb and texture_Cr will contain copies of
        /// the 2x2 downsampled interleaved UV planes packed similarly.  If experimental_image_pixel_format is set to
        /// HAL_PIXEL_FORMAT_YV12 then texture_y will have a stride of 1536 containing 1280 columns of data, packed
        /// similarly in a RGBA8888 texture. texture_Cb and texture_Cr will be 2x2 downsampled versions of the same.
        /// See YV12 and NV21 formats for details.
        ///
        /// Note: The first scan-line of the color image is reserved for metadata instead of image pixels.
        /// </summary>
        /// <param name="cameraId">
        /// The ID of the camera to connect this texture to.  Only TANGO_CAMERA_COLOR and TANGO_CAMERA_FISHEYE are
        /// supported.
        /// </param>
        /// <param name="textures">The texture IDs to use for the Y, Cb, and Cr planes.</param>
        /// <param name="onUnityFrameAvailable">Callback method.</param>
        internal static void ExperimentalConnectTexture(TangoEnums.TangoCameraId cameraId, YUVTexture textures, TangoService_onUnityFrameAvailable onUnityFrameAvailable)
        {
#if UNITY_EDITOR
            if (cameraId == TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR)
            {
                m_emulatedExpId_Y    = (RenderTexture)textures.m_videoOverlayTextureY;
                m_emulatedExpId_CbCr = (RenderTexture)textures.m_videoOverlayTextureCb;
            }
#else
            int returnValue = VideoOverlayAPI.TangoService_Experimental_connectTextureIdUnity(
                cameraId,
                (uint)textures.m_videoOverlayTextureY.GetNativeTexturePtr().ToInt64(),
                (uint)textures.m_videoOverlayTextureCb.GetNativeTexturePtr().ToInt64(),
                (uint)textures.m_videoOverlayTextureCr.GetNativeTexturePtr().ToInt64(),
                callbackContext,
                onUnityFrameAvailable);

            if (returnValue != Common.ErrorType.TANGO_SUCCESS)
            {
                Debug.Log("VideoOverlayProvider.ConnectTexture() Texture was not connected to camera!");
            }
#endif
        }
Exemplo n.º 7
0
        /// <summary>
        /// Update the texture that has been connected to camera referenced by TangoCameraId with the latest image
        /// from the camera.
        /// </summary>
        /// <returns>The timestamp of the image that has been pushed to the connected texture.</returns>
        /// <param name="cameraId">
        /// The ID of the camera to connect this texture to.  Only <code>TANGO_CAMERA_COLOR</code> and
        /// <code>TANGO_CAMERA_FISHEYE</code> are supported.
        /// </param>
        public static double RenderLatestFrame(TangoEnums.TangoCameraId cameraId)
        {
#if UNITY_EDITOR
            if (m_emulatedExpId_Y != null && m_emulatedExpId_CbCr != null)
            {
                m_emulatedExpId_Y.DiscardContents();
                m_emulatedExpId_CbCr.DiscardContents();
                Graphics.Blit(m_emulatedColorRenderTexture, m_emulatedExpId_Y, m_yuvFilterY);
                Graphics.Blit(m_emulatedColorRenderTexture, m_emulatedExpId_CbCr, m_yuvFilterCbCr);
            }

            return(m_lastColorEmulationTime);
#else
            double timestamp   = 0.0;
            int    returnValue = VideoOverlayAPI.TangoService_updateTexture(cameraId, ref timestamp);
            if (returnValue != Common.ErrorType.TANGO_SUCCESS)
            {
                Debug.Log("VideoOverlayProvider.UpdateTexture() Texture was not updated by camera!");
            }

            return(timestamp);
#endif
        }