/// <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!"); } }
/// <summary> /// Get the camera/sensor intrinsics. /// </summary> /// <param name="cameraId">Camera identifier.</param> /// <param name="intrinsics">Camera intrinsics data.</param> public static void GetIntrinsics(TangoEnums.TangoCameraId cameraId, [Out] TangoCameraIntrinsics intrinsics) { int returnValue = VideoOverlayAPI.TangoService_getCameraIntrinsics(cameraId, intrinsics); if (returnValue != Common.ErrorType.TANGO_SUCCESS) { Debug.Log("IntrinsicsProviderAPI.TangoService_getCameraIntrinsics() failed!"); } }
/// <summary> /// Connects the texture. /// </summary> /// <param name="cameraId">Camera identifier.</param> /// <param name="textureId">Texture identifier.</param> public static void ConnectTexture(TangoEnums.TangoCameraId cameraId, int textureId) { int returnValue = VideoOverlayAPI.TangoService_connectTextureId(cameraId, textureId); if (returnValue != Common.ErrorType.TANGO_SUCCESS) { Debug.Log("VideoOverlayProvider.ConnectTexture() Texture was not connected to camera!"); } }
public static void ExperimentalConnectTexture(TangoEnums.TangoCameraId cameraId, int textureId, TangoService_onUnityFrameAvailable onUnityFrameAvailable) { int returnValue = VideoOverlayAPI.TangoService_Experimental_connectTextureIdUnity(cameraId, (uint)textureId, callbackContext, onUnityFrameAvailable); if (returnValue != Common.ErrorType.TANGO_SUCCESS) { Debug.Log("VideoOverlayProvider.ConnectTexture() Texture was not connected to camera!"); } }
/// <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!"); } }
public static extern int TangoService_Experimental_connectTextureIdUnity(TangoEnums.TangoCameraId id, uint tex, IntPtr context, TangoService_onUnityFrameAvailable onUnityFrameAvailable);
public static int TangoService_Experimental_connectTextureIdUnity( TangoEnums.TangoCameraId id, UInt32 texture_y, UInt32 texture_Cb, UInt32 texture_Cr, IntPtr context, APIOnTextureAvailable callback) { return Common.ErrorType.TANGO_SUCCESS; }
public static int TangoService_getCameraIntrinsics( TangoEnums.TangoCameraId cameraId, [Out] TangoCameraIntrinsics intrinsics) { return Common.ErrorType.TANGO_SUCCESS; }
public static int TangoService_updateTexture(TangoEnums.TangoCameraId cameraId, ref double timestamp) { return Common.ErrorType.TANGO_SUCCESS; }
public static extern int TangoService_connectOnTextureAvailable( TangoEnums.TangoCameraId cameraId, IntPtr ContextMenu, APIOnTextureAvailable callback);
public static extern int TangoService_getCameraIntrinsics( TangoEnums.TangoCameraId cameraId, [Out] TangoCameraIntrinsics intrinsics);
public static extern int TangoService_updateTexture( TangoEnums.TangoCameraId cameraId, ref double timestamp);
public static int TangoService_Experimental_connectTextureIdUnity(TangoEnums.TangoCameraId id, uint tex, IntPtr context, TangoService_onUnityFrameAvailable onUnityFrameAvailable) { return Tango.Common.ErrorType.TANGO_SUCCESS; }
public static int TangoService_connectOnFrameAvailable(TangoEnums.TangoCameraId cameraId, IntPtr context, [In,Out] TangoService_onImageAvailable onImageAvailable) { return Tango.Common.ErrorType.TANGO_SUCCESS; }
public static int TangoService_connectTextureId(TangoEnums.TangoCameraId cameraId, int textureHandle) { return Tango.Common.ErrorType.TANGO_SUCCESS; }
/// <summary> /// Connect a callback to a camera for texture updates. /// </summary> /// <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> /// <param name="callback">Function called when a new frame is available from the camera.</param> internal static void SetCallback(TangoEnums.TangoCameraId cameraId, APIOnTextureAvailable callback) { int returnValue = API.TangoService_connectOnTextureAvailable(cameraId, IntPtr.Zero, callback); if (returnValue == Common.ErrorType.TANGO_SUCCESS) { Debug.Log(CLASS_NAME + ".SetCallback(OnTextureAvailable) Callback was set."); } else { Debug.Log(CLASS_NAME + ".SetCallback(OnTextureAvailable) Callback was not set!"); } }
/// <summary> /// Clear all camera callbacks. /// </summary> /// <param name="cameraId">Camera identifier.</param> internal static void ClearCallback(TangoEnums.TangoCameraId cameraId) { int returnValue = API.TangoService_Experimental_connectTextureIdUnity(cameraId, 0, 0, 0, IntPtr.Zero, null); if (returnValue == Common.ErrorType.TANGO_SUCCESS) { Debug.Log(CLASS_NAME + ".ClearCallback() Unity callback was cleared."); } else { Debug.Log(CLASS_NAME + ".ClearCallback() Unity callback was not cleared!"); } returnValue = API.TangoService_connectOnFrameAvailable(cameraId, IntPtr.Zero, null); if (returnValue == Common.ErrorType.TANGO_SUCCESS) { Debug.Log(CLASS_NAME + ".ClearCallback() Frame callback was cleared."); } else { Debug.Log(CLASS_NAME + ".ClearCallback() Frame callback was not cleared!"); } returnValue = API.TangoService_connectOnTextureAvailable(cameraId, IntPtr.Zero, null); if (returnValue == Common.ErrorType.TANGO_SUCCESS) { Debug.Log(CLASS_NAME + ".ClearCallback() Texture callback was cleared."); } else { Debug.Log(CLASS_NAME + ".ClearCallback() Texture callback was not cleared!"); } }
/// <summary> /// Handle the callback sent by the Tango Service /// when a new image is sampled. /// </summary> /// <param name="cameraId">Camera identifier.</param> /// <param name="callbackContext">Callback context.</param> /// <param name="imageBuffer">Image buffer.</param> protected void _OnImageAvailable(IntPtr callbackContext, TangoEnums.TangoCameraId cameraId, TangoImageBuffer imageBuffer) { m_previousCameraId = cameraId; if(m_previousImageBuffer.data == null) { m_previousImageBuffer.data = new byte[imageBuffer.width * imageBuffer.height * 2]; } m_previousImageBuffer.width = imageBuffer.width; m_previousImageBuffer.height = imageBuffer.height; m_previousImageBuffer.stride = imageBuffer.stride; m_previousImageBuffer.timestamp = imageBuffer.timestamp; m_previousImageBuffer.format = imageBuffer.format; m_previousImageBuffer.frame_number = imageBuffer.frame_number; Marshal.Copy(imageBuffer.data, m_previousImageBuffer.data, 0, m_previousImageBuffer.data.Length); m_shouldSendEvent = true; }
public static extern int TangoService_updateTextureExternalOes( TangoEnums.TangoCameraId cameraId, UInt32 glTextureId, out double timestamp);
/// <summary> /// This will be called when a new frame is available from the camera. /// /// The first scan-line of the color image is reserved for metadata instead of image pixels. /// </summary> /// <param name="cameraId">Camera identifier.</param> public void OnExperimentalTangoImageAvailable(TangoEnums.TangoCameraId cameraId) { if (cameraId == TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR) { m_screenUpdateTime = VideoOverlayProvider.RenderLatestFrame(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR); // Rendering the latest frame changes a bunch of OpenGL state. Ensure Unity knows the current OpenGL state. GL.InvalidateState(); } }
public static extern int TangoService_connectOnFrameAvailable( TangoEnums.TangoCameraId cameraId, IntPtr context, [In, Out] APIOnImageAvailable callback);
/// <summary> /// DEPRECATED: 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 <c>TANGO_CAMERA_COLOR</c> is 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 = API.TangoService_updateTexture(cameraId, ref timestamp); if (returnValue != Common.ErrorType.TANGO_SUCCESS) { Debug.Log("VideoOverlayProvider.UpdateTexture() Texture was not updated by camera!"); } return timestamp; #endif }
public static extern int TangoService_Experimental_connectTextureIdUnity( TangoEnums.TangoCameraId id, UInt32 texture_y, UInt32 texture_Cb, UInt32 texture_Cr, IntPtr context, APIOnTextureAvailable callback);
/// <summary> /// Update the AR screen's texture to the most recent state of the specified camera. /// </summary> /// <returns>The timestamp of the image that has been pushed to the AR screen's texture.</returns> /// <param name="cameraId"> /// The ID of the camera to connect this texture to. Only <c>TANGO_CAMERA_COLOR</c> is supported. /// </param> public static double UpdateARScreen(TangoEnums.TangoCameraId cameraId) { #if UNITY_EDITOR if (m_emulatedARScreenTexture != null) { m_emulatedARScreenTexture.DiscardContents(); Graphics.Blit(m_emulatedColorRenderTexture, m_emulatedARScreenTexture); } return m_lastColorEmulationTime; #else double timestamp = 0.0; uint tex = API.TangoUnity_getArTexture(); int returnValue = API.TangoService_updateTextureExternalOes(cameraId, tex, out timestamp); if (returnValue != Common.ErrorType.TANGO_SUCCESS) { Debug.Log("Unable to update texture. " + Environment.StackTrace); } // Rendering the latest frame changes a bunch of OpenGL state. Ensure Unity knows the current OpenGL // state. GL.InvalidateState(); return timestamp; #endif }
public static int TangoService_updateTextureExternalOes( TangoEnums.TangoCameraId cameraId, UInt32 glTextureId, out double timestamp) { timestamp = 0; return Common.ErrorType.TANGO_SUCCESS; }
/// <summary> /// Get the intrinsic calibration parameters for a given camera, this also aligns the camera intrinsics based /// on device orientation. /// /// For example, if the device orientation is portrait and camera intrinsics is in /// landscape. This function will inverse the intrinsic x and y, and report intrinsics in portrait mode. /// /// The intrinsics are as specified by the TangoCameraIntrinsics struct. Intrinsics are read from the /// on-device intrinsics file (typically <code>/sdcard/config/calibration.xml</code>, but to ensure /// compatibility applications should only access these parameters via the API), or default internal model /// parameters corresponding to the device are used if the calibration.xml file is not found. /// </summary> /// <param name="cameraId">The camera ID to retrieve the calibration intrinsics for.</param> /// <param name="alignedIntrinsics"> /// A TangoCameraIntrinsics filled with calibration intrinsics for the camera, this intrinsics is also /// aligned with device orientation. /// </param> public static void GetDeviceOientationAlignedIntrinsics(TangoEnums.TangoCameraId cameraId, TangoCameraIntrinsics alignedIntrinsics) { TangoCameraIntrinsics intrinsics = new TangoCameraIntrinsics(); GetIntrinsics(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR, intrinsics); float intrinsicsRatio = (float)intrinsics.width / (float)intrinsics.height; bool isLandscape = (AndroidHelper.GetDefaultOrientation() + (int)AndroidHelper.GetDisplayRotation()) % 2 == 0; // If the intrinsics ratio and camera render ratio don't agree with each other, we invert the intrinsics // reading to align to camera render orientation. if ((!isLandscape && intrinsicsRatio > 1.0f) || (isLandscape && intrinsicsRatio < 1.0f)) { alignedIntrinsics.cx = intrinsics.cy; alignedIntrinsics.cy = intrinsics.cx; alignedIntrinsics.fx = intrinsics.fy; alignedIntrinsics.fy = intrinsics.fx; alignedIntrinsics.height = intrinsics.width; alignedIntrinsics.width = intrinsics.height; } else { alignedIntrinsics.cx = intrinsics.cx; alignedIntrinsics.cy = intrinsics.cy; alignedIntrinsics.fx = intrinsics.fx; alignedIntrinsics.fy = intrinsics.fy; alignedIntrinsics.height = intrinsics.height; alignedIntrinsics.width = intrinsics.width; } alignedIntrinsics.distortion0 = intrinsics.distortion0; alignedIntrinsics.distortion1 = intrinsics.distortion1; alignedIntrinsics.distortion2 = intrinsics.distortion2; alignedIntrinsics.distortion3 = intrinsics.distortion3; alignedIntrinsics.distortion4 = intrinsics.distortion4; alignedIntrinsics.camera_id = intrinsics.camera_id; alignedIntrinsics.calibration_type = intrinsics.calibration_type; }
public static int TangoService_connectOnTextureAvailable( TangoEnums.TangoCameraId cameraId, IntPtr context, APIOnTextureAvailable callback) { return Common.ErrorType.TANGO_SUCCESS; }
/// <summary> /// Get the intrinsic calibration parameters for a given camera. /// /// The intrinsics are as specified by the TangoCameraIntrinsics struct. Intrinsics are read from the /// on-device intrinsics file (typically <code>/sdcard/config/calibration.xml</code>, but to ensure /// compatibility applications should only access these parameters via the API), or default internal model /// parameters corresponding to the device are used if the calibration.xml file is not found. /// </summary> /// <param name="cameraId">The camera ID to retrieve the calibration intrinsics for.</param> /// <param name="intrinsics">A TangoCameraIntrinsics filled with calibration intrinsics for the camera.</param> public static void GetIntrinsics(TangoEnums.TangoCameraId cameraId, TangoCameraIntrinsics intrinsics) { int returnValue = API.TangoService_getCameraIntrinsics(cameraId, intrinsics); #if UNITY_EDITOR // In editor, base 'intrinsics' off of properties of emulation camera. if (cameraId == TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR && EmulatedEnvironmentRenderHelper.m_emulationCamera != null) { // Instantiate any resources that we haven't yet. _InternResourcesForEmulation(); EmulatedEnvironmentRenderHelper.m_emulationCamera.targetTexture = m_emulatedColorRenderTexture; intrinsics.width = (uint)EMULATED_CAMERA_WIDTH; intrinsics.height = (uint)EMULATED_CAMERA_HEIGHT; float fov = EmulatedEnvironmentRenderHelper.m_emulationCamera.fieldOfView; float focalLengthInPixels = (1 / Mathf.Tan(fov * 0.5f * Mathf.Deg2Rad)) * (intrinsics.height * 0.5f); intrinsics.fy = intrinsics.fx = focalLengthInPixels; intrinsics.cx = intrinsics.width / 2f; intrinsics.cy = intrinsics.height / 2f; } #endif if (returnValue != Common.ErrorType.TANGO_SUCCESS) { Debug.Log("IntrinsicsProviderAPI.TangoService_getCameraIntrinsics() failed!"); } }
/// <summary> /// Construct readable string from TangoPoseStatusType. /// </summary> /// <returns>Printable string.</returns> /// <param name="status">Tango pose status.</param> private string _GetLoggingStringFromPoseStatus(TangoEnums.TangoPoseStatusType status) { string statusString = string.Empty; switch (status) { case TangoEnums.TangoPoseStatusType.TANGO_POSE_INITIALIZING: statusString = "initializing"; break; case TangoEnums.TangoPoseStatusType.TANGO_POSE_INVALID: statusString = "invalid"; break; case TangoEnums.TangoPoseStatusType.TANGO_POSE_UNKNOWN: statusString = "unknown"; break; case TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID: statusString = "valid"; break; default: statusString = "N/A"; break; } return statusString; }
/// <summary> /// DEPRECATED: 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 neighboring 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="callback">Callback method.</param> internal static void ExperimentalConnectTexture( TangoEnums.TangoCameraId cameraId, YUVTexture textures, APIOnTextureAvailable callback) { #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 = API.TangoService_Experimental_connectTextureIdUnity( cameraId, (uint)textures.m_videoOverlayTextureY.GetNativeTexturePtr().ToInt64(), (uint)textures.m_videoOverlayTextureCb.GetNativeTexturePtr().ToInt64(), (uint)textures.m_videoOverlayTextureCr.GetNativeTexturePtr().ToInt64(), IntPtr.Zero, callback); if (returnValue != Common.ErrorType.TANGO_SUCCESS) { Debug.Log("VideoOverlayProvider.ConnectTexture() Texture was not connected to camera!"); } #endif }