コード例 #1
0
        public void DFrameTest_LT_1Sec()
        {
            string[] files = Directory.GetFiles("C:\\KStudioRepo", "*.xef");

            using (KStudioClient client = KStudio.CreateClient()) {
                client.ConnectToService();
                var broken = false;
                using (KStudioPlayback playback = client.CreatePlayback(files[0])) {
                    playback.Start();
                    Stopwatch time = new Stopwatch();

                    DepthStream stream = DepthStream.Instance;

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        time.Start();
                        BaseFrame frame = stream.GetFrame();
                        if (time.ElapsedMilliseconds > (1 * 1000))
                        {
                            //Console.WriteLine("Elapsed time: {0}, frame: {1}", time.ElapsedMilliseconds, frame);
                            if (frame == null)
                            {
                                broken = true;
                                System.DateTime now = DateTime.Now;
                                //System.Diagnostics.////Debug.WriteLine("Failed at: {0}:{1}:{2}:{3}", now.Hour, now.Minute, now.Second, now.Millisecond);
                            }
                        }
                        Thread.Sleep(100);
                    }
                }

                client.DisconnectFromService();
                Assert.IsFalse(broken, "The frame should not be null after 1 second");
            }
        }
コード例 #2
0
        public void GetDepthArrayTest()
        {
            string[] files = Directory.GetFiles("C:\\KStudioRepo", "*.xef");
            using (KStudioClient client = KStudio.CreateClient()) {
                client.ConnectToService();
                using (KStudioPlayback playback = client.CreatePlayback(files[0])) {
                    playback.Start();
                    DepthStream stream = DepthStream.Instance;
                    Assert.IsNotNull(stream);

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        System.Threading.Thread.Sleep(500);
                        DFrame frame = (DFrame)stream.GetFrame();
                        if (frame != null)
                        {
                            //ushort[] testArr = frame.GetDepthArray();
                            //System.Diagnostics.////Debug.WriteLine("Test Arr length : " + testArr.Length);
                            //Assert.IsNotNull(testArr);
                        }
                    }

                    Assert.AreNotEqual(playback.State, KStudioPlaybackState.Error);
                }
                client.DisconnectFromService();
            }
        }
コード例 #3
0
        public void GetDepthBitmapTest()
        {
            string[] files = Directory.GetFiles("C:\\KStudioRepo", "*.xef");
            using (KStudioClient client = KStudio.CreateClient()) {
                client.ConnectToService();
                using (KStudioPlayback playback = client.CreatePlayback(files[0])) {
                    playback.Start();
                    DepthStream stream = DepthStream.Instance;
                    Assert.IsNotNull(stream);

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        System.Threading.Thread.Sleep(500);
                        DFrame frame = (DFrame)stream.GetFrame();
                        if (frame == null)
                        {
                            continue;
                        }
                        WriteableBitmap bmp = frame.GetBitmap();
                        Assert.IsNotNull(bmp);
                        //System.Diagnostics.////Debug.WriteLine("Bitmap : " + bmp.ToString());
                    }

                    Assert.AreNotEqual(playback.State, KStudioPlaybackState.Error);
                }
            }
        }
コード例 #4
0
        private void initStreams()
        {
            StreamBase color = new ColorStream();

            _streams.Add(color);
            Stream = color;
            StreamBase depth = new DepthStream();

            _streams.Add(depth);
        }
コード例 #5
0
    private void InitializeStreams()
    {
        try
        {
            _streamSet           = Astra.StreamSet.Open();
            _reader1             = _streamSet.CreateReader();
            _reader1.FrameReady += FrameReady;

            _reader2             = _streamSet.CreateReader();
            _reader2.FrameReady += FrameReady;

            _reader3             = _streamSet.CreateReader();
            _reader3.FrameReady += FrameReady;

            _reader4             = _streamSet.CreateReader();
            _reader4.FrameReady += FrameReady;

            _reader5             = _streamSet.CreateReader();
            _reader5.FrameReady += FrameReady;

            _depthStream = _reader1.GetStream <DepthStream>();

            var       depthModes        = _depthStream.AvailableModes;
            ImageMode selectedDepthMode = depthModes[0];

    #if ASTRA_UNITY_ANDROID_NATIVE
            int targetDepthWidth  = 160;
            int targetDepthHeight = 120;
            int targetDepthFps    = 30;
    #else
            int targetDepthWidth  = 320;
            int targetDepthHeight = 240;
            int targetDepthFps    = 60;
    #endif

            foreach (var m in depthModes)
            {
                if (m.Width == targetDepthWidth &&
                    m.Height == targetDepthHeight &&
                    m.FramesPerSecond == targetDepthFps)
                {
                    selectedDepthMode = m;
                    break;
                }
            }

            _depthStream.SetMode(selectedDepthMode);

            _colorStream = _reader2.GetStream <ColorStream>();

            var       colorModes        = _colorStream.AvailableModes;
            ImageMode selectedColorMode = colorModes[0];

    #if ASTRA_UNITY_ANDROID_NATIVE
            int targetColorWidth  = 320;
            int targetColorHeight = 240;
            int targetColorFps    = 30;
    #else
            int targetColorWidth  = 640;
            int targetColorHeight = 480;
            int targetColorFps    = 60;
    #endif

            foreach (var m in colorModes)
            {
                if (m.Width == targetColorWidth &&
                    m.Height == targetColorHeight &&
                    m.FramesPerSecond == targetColorFps)
                {
                    selectedColorMode = m;
                    break;
                }
            }

            _colorStream.SetMode(selectedColorMode);

            _bodyStream = _reader3.GetStream <BodyStream>();

            _maskedColorStream = _reader4.GetStream <MaskedColorStream>();

            _colorizedBodyStream = _reader5.GetStream <ColorizedBodyStream>();

            _areStreamsInitialized = true;
        }
        catch (AstraException e)
        {
            Debug.Log("AstraController: Couldn't initialize streams: " + e.ToString());
            UninitializeStreams();
        }
    }
コード例 #6
0
    private void InitializeStreams()
    {
        try
        {
            AstraUnityContext.Instance.WaitForUpdate(AstraBackgroundUpdater.WaitIndefinitely);

            _streamSet = Astra.StreamSet.Open();

            _readerDepth         = _streamSet.CreateReader();
            _readerColor         = _streamSet.CreateReader();
            _readerBody          = _streamSet.CreateReader();
            _readerMaskedColor   = _streamSet.CreateReader();
            _readerColorizedBody = _streamSet.CreateReader();
            _readerPoint         = _streamSet.CreateReader();

            _depthStream = _readerDepth.GetStream <DepthStream>();

            var       depthModes        = _depthStream.AvailableModes;
            ImageMode selectedDepthMode = depthModes[0];

    #if ASTRA_UNITY_ANDROID_NATIVE
            int targetDepthWidth  = 160;
            int targetDepthHeight = 120;
            int targetDepthFps    = 30;
    #else
            int targetDepthWidth  = 320;
            int targetDepthHeight = 240;
            int targetDepthFps    = 30;
    #endif

            foreach (var m in depthModes)
            {
                if (m.Width == targetDepthWidth &&
                    m.Height == targetDepthHeight &&
                    m.FramesPerSecond == targetDepthFps)
                {
                    selectedDepthMode = m;
                    break;
                }
            }

            _depthStream.SetMode(selectedDepthMode);

            _colorStream = _readerColor.GetStream <ColorStream>();

            var       colorModes        = _colorStream.AvailableModes;
            ImageMode selectedColorMode = colorModes[0];

    #if ASTRA_UNITY_ANDROID_NATIVE
            int targetColorWidth  = 320;
            int targetColorHeight = 240;
            int targetColorFps    = 30;
    #else
            int targetColorWidth  = 640;
            int targetColorHeight = 480;
            int targetColorFps    = 30;
    #endif

            foreach (var m in colorModes)
            {
                if (m.Width == targetColorWidth &&
                    m.Height == targetColorHeight &&
                    m.FramesPerSecond == targetColorFps)
                {
                    selectedColorMode = m;
                    break;
                }
            }

            _colorStream.SetMode(selectedColorMode);

            _bodyStream = _readerBody.GetStream <BodyStream>();

            _maskedColorStream = _readerMaskedColor.GetStream <MaskedColorStream>();

            _colorizedBodyStream = _readerColorizedBody.GetStream <ColorizedBodyStream>();

            _pointStream = _readerPoint.GetStream <PointStream>();

            _areStreamsInitialized = true;
        }
        catch (AstraException e)
        {
            Debug.Log("AstraController: Couldn't initialize streams: " + e.ToString());
            UninitializeStreams();
        }
    }
コード例 #7
0
    public void InitializeStreams()
    {
        try
        {
            AstraUnityContext.Instance.WaitForUpdate(AstraBackgroundUpdater.WaitIndefinitely);

            _streamSet = Astra.StreamSet.Open();

            _readerDepth         = _streamSet.CreateReader();
            _readerColor         = _streamSet.CreateReader();
            _readerNV21Color     = _streamSet.CreateReader();
            _readerBody          = _streamSet.CreateReader();
            _readerMaskedColor   = _streamSet.CreateReader();
            _readerColorizedBody = _streamSet.CreateReader();

            _depthStream = _readerDepth.GetStream <DepthStream>();

            var       depthModes        = _depthStream.AvailableModes;
            ImageMode selectedDepthMode = depthModes[0];

            int targetDepthWidth, targetDepthHeight, targetDepthFps;
#if ASTRA_UNITY_ANDROID_NATIVE
            //Deeyea and Dabai doesn't support qqvga and qvga resolution.
            //use 640*400.
            if (_depthStream.usbInfo.Pid == 0x60b ||
                _depthStream.usbInfo.Pid == 0x60e ||
                _depthStream.usbInfo.Pid == 0x608 ||
                _depthStream.usbInfo.Pid == 0x617)
            {
                targetDepthWidth  = 640;
                targetDepthHeight = 400;
                targetDepthFps    = 30;
            }
            else
            {
                targetDepthWidth  = 160;
                targetDepthHeight = 120;
                targetDepthFps    = 30;
            }
#else
            if (_depthStream.usbInfo.Pid == 0x60b ||
                _depthStream.usbInfo.Pid == 0x60e ||
                _depthStream.usbInfo.Pid == 0x608 ||
                _depthStream.usbInfo.Pid == 0x617)
            {
                targetDepthWidth  = 640;
                targetDepthHeight = 400;
                targetDepthFps    = 30;
            }
            else
            {
                targetDepthWidth  = 320;
                targetDepthHeight = 240;
                targetDepthFps    = 30;
            }
    #endif

            foreach (var m in depthModes)
            {
                if (m.Width == targetDepthWidth &&
                    m.Height == targetDepthHeight &&
                    m.FramesPerSecond == targetDepthFps)
                {
                    selectedDepthMode = m;
                    break;
                }
            }

            _depthStream.SetMode(selectedDepthMode);

            _colorStream = _readerColor.GetStream <ColorStream>();

            var       colorModes        = _colorStream.AvailableModes;
            ImageMode selectedColorMode = colorModes[0];

            if (_depthStream.usbInfo.Pid == 0x60b ||
                _depthStream.usbInfo.Pid == 0x617)
            {
                //for deeyea, set mirror to false to match depth.
                _colorStream.IsMirroring = false;
            }
#if ASTRA_UNITY_ANDROID_NATIVE
            int targetColorWidth, targetColorHeight, targetColorFps;
            if (_depthStream.usbInfo.Pid == 0x608 ||
                _depthStream.usbInfo.Pid == 0x60f ||
                _depthStream.usbInfo.Pid == 0x617)
            {
                targetColorWidth  = 640;
                targetColorHeight = 480;
                targetColorFps    = 30;
            }
            else
            {
                targetColorWidth  = 320;
                targetColorHeight = 240;
                targetColorFps    = 30;
            }
#else
            int targetColorWidth  = 640;
            int targetColorHeight = 480;
            int targetColorFps    = 30;
#endif

            foreach (var m in colorModes)
            {
                if (m.Width == targetColorWidth &&
                    m.Height == targetColorHeight &&
                    m.FramesPerSecond == targetColorFps)
                {
                    selectedColorMode = m;
                    break;
                }
            }

            _colorStream.SetMode(selectedColorMode);

#if ASTRA_UNITY_ANDROID_NATIVE
            _nv21ColorStream = _readerNV21Color.GetStream <ColorStream>(Astra.Core.StreamSubType.COLOR_NV21_SUBTYPE);
            if (_nv21ColorStream.IsAvailable)
            {
                //COLOR_NV21_SUBTYPE is only available when using astra pro and astra pro plus.
                colorModes        = _nv21ColorStream.AvailableModes;
                selectedColorMode = colorModes[0];

                foreach (var m in colorModes)
                {
                    if (m.Width == targetColorWidth &&
                        m.Height == targetColorHeight &&
                        m.FramesPerSecond == targetColorFps)
                    {
                        selectedColorMode = m;
                        break;
                    }
                }

                _nv21ColorStream.SetMode(selectedColorMode);
                if (_depthStream.usbInfo.Pid == 0x60b ||
                    _depthStream.usbInfo.Pid == 0x617)
                {
                    //for deeyea, set mirror to false to match depth.
                    _nv21ColorStream.IsMirroring = false;
                }
            }
            else
            {
                _readerNV21Color.Dispose();
                _readerNV21Color = null;
                _nv21ColorStream = null;
            }
#endif

            _bodyStream = _readerBody.GetStream <BodyStream>();

            _maskedColorStream = _readerMaskedColor.GetStream <MaskedColorStream>();

            _colorizedBodyStream = _readerColorizedBody.GetStream <ColorizedBodyStream>();

            _areStreamsInitialized = true;
        }
        catch (AstraException e)
        {
            Debug.Log("AstraController: Couldn't initialize streams: " + e.ToString());
            UninitializeStreams();
        }
    }
コード例 #8
0
ファイル: AstraManager.cs プロジェクト: GabrielCruzT/Teste
    private void InitializeStreams()
    {
        try
        {
            AstraUnityContext.Instance.WaitForUpdate(AstraBackgroundUpdater.WaitIndefinitely);

            _streamSet = Astra.StreamSet.Open();

            _readerDepth         = _streamSet.CreateReader();
            _readerColor         = _streamSet.CreateReader();
            _readerBody          = _streamSet.CreateReader();
            _readerMaskedColor   = _streamSet.CreateReader();
            _readerColorizedBody = _streamSet.CreateReader();

            _depthStream = _readerDepth.GetStream <DepthStream>();

            _depthModes = _depthStream.AvailableModes;
            ImageMode selectedDepthMode = _depthModes[0];

#if ASTRA_UNITY_ANDROID_NATIVE
            int targetDepthWidth  = 160;
            int targetDepthHeight = 120;
            int targetDepthFps    = 30;
#else
            int targetDepthWidth  = 320;
            int targetDepthHeight = 240;
            int targetDepthFps    = 30;
#endif

            foreach (var m in _depthModes)
            {
                Debug.Log("Depth mode: " + m.Width + "x" + m.Height + "@" + m.FramesPerSecond);
                if (m.Width == targetDepthWidth &&
                    m.Height == targetDepthHeight)
                {
                    selectedDepthMode = m;
                    break;
                }
            }

            _depthStream.SetMode(selectedDepthMode);

            _colorStream = _readerColor.GetStream <ColorStream>();
            try
            {
                _colorModes = _colorStream.AvailableModes;
                ImageMode selectedColorMode = _colorModes[0];

#if ASTRA_UNITY_ANDROID_NATIVE
                int targetColorWidth  = 320;
                int targetColorHeight = 240;
                int targetColorFps    = 30;
#else
                int targetColorWidth  = 640;
                int targetColorHeight = 480;
                int targetColorFps    = 30;
#endif

                foreach (var m in _colorModes)
                {
                    Debug.Log("Color mode: " + m.Width + "x" + m.Height + "@" + m.FramesPerSecond);
                    if (m.Width == targetColorWidth &&
                        m.Height == targetColorHeight)
                    {
                        selectedColorMode = m;
                        break;
                    }
                }

                _colorStream.SetMode(selectedColorMode);
            }
            catch (System.Exception e)
            {
                Debug.Log("Couldn't initialize color stream: " + e.ToString());
            }

            _bodyStream = _readerBody.GetStream <BodyStream>();

            _maskedColorStream = _readerMaskedColor.GetStream <MaskedColorStream>();

            _colorizedBodyStream = _readerColorizedBody.GetStream <ColorizedBodyStream>();

            _areStreamsInitialized = true;

            Debug.Log("Stream initialize success");
            OnInitializeSuccess.Invoke();
        }
        catch (System.Exception e)
        {
            Debug.Log("Couldn't initialize streams: " + e.ToString());
            UninitializeStreams();

            if (_initializeCount > 0)
            {
                _initializeCount--;
            }
            else
            {
                Debug.Log("Initialize failed");
                OnInitializeFailed.Invoke();
            }
        }
    }
コード例 #9
0
    void clientHandler(object o)
    {
        byte[]      _buffer   = new byte[868352];
        byte[]      _dbuffer  = new byte[868352];
        int         SIZEHELLO = 200;
        TcpClient   client    = (TcpClient)o;
        DepthStream kstream   = new DepthStream(client);

        _depthStreams.Add(kstream);

        using (NetworkStream ns = client.GetStream())
        {
            byte[] message   = new byte[SIZEHELLO];
            int    bytesRead = 0;
            try
            {
                bytesRead = ns.Read(message, 0, SIZEHELLO);
            }
            catch
            {
                Debug.Log("Connection Lost from " + kstream.name);
                client.Close();
                _depthStreams.Remove(kstream);;
            }

            if (bytesRead == 0)
            {
                Debug.Log("Connection Lost from " + kstream.name);
                client.Close();
                _depthStreams.Remove(kstream);;
            }

            //Login
            string   s = System.Text.Encoding.Default.GetString(message);
            string[] l = s.Split('/');

            if (l.Length == 3 && l[0] == "k")
            {
                kstream.name = l[1];
                Debug.Log("New stream from " + l[1]);
            }


            bool colorFrame = false;
            while (_running)
            {
                try
                {
                    bytesRead = ns.Read(message, 0, 13);
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message);
                    // _running = false;
                    break;
                }
                if (bytesRead == 0)
                {
                    //  _running = false;
                    break;
                }


                byte[] idb = { message[0], message[1], message[2], message[3] };
                uint   id  = BitConverter.ToUInt32(idb, 0);
                kstream.lastID = id;
                byte[] sizeb = { message[4], message[5], message[6], message[7] };
                int    size  = BitConverter.ToInt32(sizeb, 0);

                if (colorFrame)
                {
                    kstream.sizec = size;
                }
                else
                {
                    kstream.sized = size;
                }

                if (message[8] == 1)
                {
                    kstream.compressed = true;
                }
                else
                {
                    kstream.compressed = false;
                }


                byte[] sc    = { message[9], message[10], message[11], message[12] };
                int    scale = BitConverter.ToInt32(sc, 0);
                while (size > 0)
                {
                    try
                    {
                        if (colorFrame)
                        {
                            bytesRead = ns.Read(_buffer, 0, size);
                        }
                        else
                        {
                            bytesRead = ns.Read(_dbuffer, 0, size);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e.Message + "color frame " + colorFrame + " size " + size);
                        //_running = false;
                        break;
                    }
                    if (bytesRead == 0)
                    {
                        // _running = false;
                        break;
                    }
                    //save because can't update from outside main thread
                    if (colorFrame)
                    {
                        //Wait till things are processed
                        while (kstream.dirty)
                        {
                            Thread.Sleep(5);
                        }
                        Array.Copy(_buffer, 0, kstream.colorData, kstream.sizec - size, bytesRead);
                    }
                    else
                    {
                        //Wait till things are processed
                        while (kstream.dirty)
                        {
                            Thread.Sleep(5);
                        }
                        Array.Copy(_dbuffer, 0, kstream.depthData, kstream.sized - size, bytesRead);
                    }

                    size -= bytesRead;
                }
                if (colorFrame)
                {
                    kstream.scale = scale;
                    kstream.dirty = true;
                }
                colorFrame = !colorFrame;
            }
        }
    }