예제 #1
0
        private static void _OnImageAvailable(
            IntPtr callbackContext, TangoEnums.TangoCameraId cameraId, ref TangoImage image,
            ref TangoCameraMetadata cameraMetadata)
        {
            if (cameraId != COLOR_CAMERA_ID)
            {
                return;
            }

            if (m_onTangoImageMultithreadedAvailable != null)
            {
                m_onTangoImageMultithreadedAvailable(cameraId, image, cameraMetadata);
            }

            lock (m_lockObject)
            {
                // This is correct because Tango is required to support YUV888 as Y plane, UV interleaved plane.
                int uvPlaneSize = image.m_planeSize2 + 1;
                if (m_previousImageBuffer.data == null)
                {
                    m_previousImageBuffer.data = new byte[image.m_planeSize0 + uvPlaneSize];
                }

                m_previousImageBuffer.width        = image.m_width;
                m_previousImageBuffer.height       = image.m_height;
                m_previousImageBuffer.stride       = (uint)image.m_planeRowStride0;
                m_previousImageBuffer.timestamp    = ((double)image.m_timestampNs) * Common.SECS_PER_NANOSECS;
                m_previousImageBuffer.format       = image.m_format;
                m_previousImageBuffer.frame_number = cameraMetadata.m_frameNumber;

                //// Convert from YUV888 to NV21.
                //// Get Ys.
                Marshal.Copy(image.m_planeData0, m_previousImageBuffer.data, 0, image.m_planeSize0);

                //// Size of UV plane is image.plane_2_size + 1, since Tango guarantees that YUV888 has UV interleaved.
                Marshal.Copy(image.m_planeData2, m_previousImageBuffer.data, image.m_planeSize0, uvPlaneSize);

                m_shouldSendByteBufferMethodEvent = true;


                // ERROR TESTING - ADDED IN
                GameObject.FindObjectOfType <CloakingBox.PoseImageCreator>().BufferCameraImage(callbackContext, cameraId, ref image, ref cameraMetadata);
            }
        }
        /// <summary>
        /// It's backwards, but fill tango image buffer data with already-emulated data.
        /// It is the responsibility of the caller to GC pin/free the colorImageData's data array.
        /// </summary>
        /// <returns>Emulated raw color buffer.</returns>
        /// <param name="colorImageData">Emulated color buffer data.</param>>
        /// <param name="pinnedColorBuffer">Pinned array of imageBuffer.data.</param>
        /// <param name="image"> TangoImage populated with emulator image data.</param>
        /// <param name="cameraMetadata">Camera metadata for emulated image.</param>
        private static void _GetEmulatedTangoImage(TangoUnityImageData colorImageData, GCHandle pinnedColorBuffer,
                                                   out TangoImage image, out TangoCameraMetadata cameraMetadata)
        {
            image              = new TangoImage();
            cameraMetadata     = new TangoCameraMetadata();
            image.m_planeData0 = pinnedColorBuffer.AddrOfPinnedObject();
            image.m_planeData2 = new IntPtr(pinnedColorBuffer.AddrOfPinnedObject().ToInt64() + image.m_width * image.m_height);
            image.m_planeData1 = new IntPtr(image.m_planeData2.ToInt64() + 1);
            image.m_width      = colorImageData.width;
            image.m_height     = colorImageData.height;

            // The existing system assumes the whole image has the same row stride across all planes.
            int stride = (int)colorImageData.stride;

            image.m_planeRowStride0 = stride;
            image.m_planeRowStride1 = stride;
            image.m_planeRowStride2 = stride;
            image.m_planeRowStride3 = stride;

            image.m_format               = colorImageData.format;
            image.m_timestampNs          = Convert.ToInt64(colorImageData.timestamp / Common.SECS_PER_NANOSECS);
            cameraMetadata.m_frameNumber = colorImageData.frame_number;
            cameraMetadata.m_timestampNs = image.m_timestampNs;
        }