示例#1
0
        //////////////////////////////////////////////////
        #region Private Methods
        void buildPipeline(string deviceName, string gestureModuleName)
        {
            _pipeline = new UtilMPipeline();
            _pipeline.QueryCapture().SetFilter(deviceName);
            _pipeline.EnableImage(PXCMImage.ColorFormat.COLOR_FORMAT_RGB24);
            _pipeline.EnableImage(PXCMImage.ColorFormat.COLOR_FORMAT_VERTICES);
            _pipeline.EnableGesture(gestureModuleName);
            if (!_pipeline.Init())
            {
                throw new GestureCameraException("Failed to initialize pipeline.");
            }

            float unit;

            GestureCameraUtil.Assert(
                _pipeline.QueryCapture().device.QueryProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_UNIT, out unit),
                "Failed to query sensor depth unit.");
            _unit_m = unit / 1000000;

            GestureCameraUtil.Assert(
                _pipeline.QueryCapture().device.QueryProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_LOW_CONFIDENCE_VALUE, out _depthLowConf),
                "Failed to query sensor depth low confidence value.");
            GestureCameraUtil.Assert(
                _pipeline.QueryCapture().device.QueryProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_SATURATION_VALUE, out _depthSaturation),
                "Failed to query sensor depth saturation value.");
        }
示例#2
0
        void update()
        {
            if (!_pipeline.AcquireFrame(true))
            {
                throw new GestureCameraException("Failed to aquire frame.");
            }
            if (_pipeline.IsDisconnected())
            {
                return;
            }

            var color   = _pipeline.QueryImage(PXCMImage.ImageType.IMAGE_TYPE_COLOR);
            var depth   = _pipeline.QueryImage(PXCMImage.ImageType.IMAGE_TYPE_DEPTH);
            var gesture = _pipeline.QueryGesture();

            PXCMGesture.Blob blobInfo;
            GestureCameraUtil.Assert(gesture.QueryBlobData(PXCMGesture.Blob.Label.LABEL_SCENE, 0, out blobInfo), "Failed to query blob data.");
            PXCMImage blob;

            GestureCameraUtil.Assert(gesture.QueryBlobImage(PXCMGesture.Blob.Label.LABEL_SCENE, 0, out blob), "Failed to query blob image.");

            PXCMGesture.Gesture gestureData;
            var gestureDataList = new List <PXCMGesture.Gesture>();

            for (uint i = 0; ; ++i)
            {
                if (gesture.QueryGestureData(0, PXCMGesture.GeoNode.Label.LABEL_ANY, i, out gestureData) == pxcmStatus.PXCM_STATUS_ITEM_UNAVAILABLE)
                {
                    break;
                }

                gestureDataList.Add(gestureData);
            }

            PXCMImage.ImageData colorData;
            GestureCameraUtil.Assert(
                color.AcquireAccess(PXCMImage.Access.ACCESS_READ, out colorData),
                "Failed to acquire access on color image.");
            PXCMImage.ImageData depthData;
            GestureCameraUtil.Assert(
                depth.AcquireAccess(PXCMImage.Access.ACCESS_READ, out depthData),
                "Failed to acquire access on depth image.");
            PXCMImage.ImageData blobData;
            GestureCameraUtil.Assert(
                blob.AcquireAccess(PXCMImage.Access.ACCESS_READ, out blobData),
                "Failed to acquire access on blob image.");

            int colorWidth  = (int)color.info.width;
            int colorHeight = (int)color.info.height;
            var colorImage  = colorData.ToByteArray(0, 3 * colorWidth * colorHeight);

            int depthWidth  = (int)depth.info.width;
            int depthHeight = (int)depth.info.height;
            var verticies   = depthData.ToShortArray(0, 3 * depthWidth * depthHeight);
            var uv          = depthData.ToFloatArray(2, 2 * depthWidth * depthHeight);

            int blobWidth  = (int)blob.info.width;
            int blobHeight = (int)blob.info.height;
            var blobImage  = blobData.ToByteArray(0, blobWidth * blobHeight);

            var data = new GestureCameraData(depthWidth, depthHeight, colorWidth, colorHeight, colorImage, blobImage, blobInfo.labelBackground, gestureDataList);

            for (int j = 0; j < depthHeight; ++j)
            {
                for (int i = 0; i < depthWidth; ++i)
                {
                    float u      = uv[2 * (j * depthWidth + i) + 0];
                    float v      = uv[2 * (j * depthWidth + i) + 1];
                    int   colorX = (int)(u * (colorWidth - 1));
                    int   colorY = (int)(v * (colorHeight - 1));
                    if (0 > colorX || colorX > colorWidth || 0 > colorY || colorY > colorHeight)
                    {
                        continue;
                    }

                    float x = verticies[3 * (j * depthWidth + i) + 0];
                    float y = verticies[3 * (j * depthWidth + i) + 1];
                    float z = verticies[3 * (j * depthWidth + i) + 2];
                    if (z == _depthLowConf || z == _depthSaturation)
                    {
                        continue;
                    }

                    x *= _unit_m;
                    y *= _unit_m;
                    z *= _unit_m;

                    data.Set(i, j, new Point(u, v, x, y, z));
                }
            }

            GestureCameraUtil.Assert(
                color.ReleaseAccess(ref colorData),
                "Failed to release access on color image.");
            GestureCameraUtil.Assert(
                depth.ReleaseAccess(ref depthData),
                "Failed to release access on depth image.");
            GestureCameraUtil.Assert(
                blob.ReleaseAccess(ref blobData),
                "Failed to release access to blob data)");
            _pipeline.ReleaseFrame();

            RaiseOnUpdated(data);
        }