コード例 #1
0
ファイル: Controller.cs プロジェクト: togores/Vitruvius
        /// <summary>
        /// Construtor padrão.
        /// </summary>
        private Controller()
        {
            context = new Context();
            while (true)              // espera que o Kinect esteja corretamente conectado
            {
                try {
                    userManager = new UserManager(context);
                    depthSensor = new DepthSensor(context);
                    rgbCamera   = new RGBCamera(context);
                }
                catch (Exception) {
                    if (MessageBox.Show("Kinect is not connected. Connect and retry.", "Error", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        continue;
                    }
                    Application.Current.Shutdown();
                }
                break;
            }

            depthImage     = new DepthImage();
            rgbImage       = new RGBImage();
            drawDepthImage = false;
            drawRGBImage   = false;

            time          = DateTime.Now;
            windowManager = new WindowManager();

            observer = new Observer(new GestureManager(), Parameterization.Extractor, Parameterization.Filter);
            recorder = new Recorder();
            realtime = true;
        }
コード例 #2
0
        public ColorImageView()
        {
            this.mw = (MainWindow)Application.Current.MainWindow;
            this.ci = this.mw.ColorImage;
            this.di = this.mw.DepthImage;
            this.ci.addCIListener(this.Reader_ColorFrameArrived);
            this.di.addDIListener(this.Reader_DepthFrameArrived);
            this.ci.ColorFrameReader.IsPaused = true;
            this.di.DepthFrameReader.IsPaused = true;
            this.mode = Mode.Color;

            // create the colorFrameDescription from the ColorFrameSource using Bgra format
            FrameDescription colorFrameDescription = this.mw.KinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);

            this.depthFrameDescription = this.mw.KinectSensor.DepthFrameSource.FrameDescription;
            this.size        = this.depthFrameDescription.Width * this.depthFrameDescription.Height;
            this.depthPixels = new Byte[this.size];

            // create the bitmaps to display
            this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
            this.depthBitmap = new WriteableBitmap(this.depthFrameDescription.Width, this.depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);

            // use the window object as the view model in this simple example
            this.DataContext = this;

            this.display = false;

            InitializeComponent();

            this.status.Text = "RGB-D and Microphone streaming off";
        }
コード例 #3
0
ファイル: DepthImageMeshVisual3D.cs プロジェクト: skdent/psi
 /// <summary>
 /// Updates the mesh from a specified depth image, intrinsics, and position.
 /// </summary>
 /// <param name="depthImage">The depth image.</param>
 /// <param name="intrinsics">The intrinsics.</param>
 /// <param name="position">The position.</param>
 public void UpdateMesh(DepthImage depthImage, ICameraIntrinsics intrinsics, CoordinateSystem position)
 {
     this.depthImage = depthImage;
     this.intrinsics = intrinsics;
     this.position   = position;
     this.UpdateVisuals();
 }
コード例 #4
0
 public IEnumerable <Vector3> GetCloudPointData()
 {
     for (int x = 0; x < DepthImage.width; x++)
     {
         for (int y = 0; y < DepthImage.height; y++)
         {
             yield return(new Vector3(x, y, DepthImage.GetPixel(x, y).grayscale));
         }
     }
 }
コード例 #5
0
        private void UpdateMesh(DepthImage depthImage)
        {
            if (this.depthFramePoints?.Length != (depthImage.Width * depthImage.Height))
            {
                this.rawDepth         = new int[depthImage.Width * depthImage.Height];
                this.depthFramePoints = new Point3D[depthImage.Width * depthImage.Height];
            }

            this.UpdateDepth(depthImage);
            this.CreateMesh(depthImage.Width, depthImage.Height);
        }
コード例 #6
0
ファイル: DepthImageMeshVisual3D.cs プロジェクト: skdent/psi
        private void UpdateDepthFramePoints(DepthImage depthImage, ICameraIntrinsics intrinsics, euclidean.CoordinateSystem position)
        {
            // Handle null cases by clearing the depthFramePoints
            if (depthImage == null || intrinsics == null || position == null)
            {
                if (this.rawDepth.Length > 0)
                {
                    this.rawDepth         = new int[0];
                    this.depthFramePoints = new System.Windows.Media.Media3D.Point3D[0];
                }

                return;
            }

            if (this.depthFramePoints?.Length != (this.depthImage.Width * this.depthImage.Height))
            {
                this.rawDepth         = new int[this.depthImage.Width * this.depthImage.Height];
                this.depthFramePoints = new System.Windows.Media.Media3D.Point3D[this.depthImage.Width * this.depthImage.Height];
            }

            int width  = depthImage.Width;
            int height = depthImage.Height;

            int cx = width / 2;
            int cy = height / 2;

            double scale = 0.001;

            unsafe
            {
                ushort *depthFrame = (ushort *)((byte *)depthImage.ImageData.ToPointer());

                Parallel.For(0, height, iy =>
                {
                    for (int ix = 0; ix < width; ix++)
                    {
                        int i            = (iy * width) + ix;
                        this.rawDepth[i] = depthFrame[i];

                        if (this.rawDepth[i] == 0)
                        {
                            this.rawDepth[i]         = -1;
                            this.depthFramePoints[i] = default;
                        }
                        else
                        {
                            var other = intrinsics.ToCameraSpace(new euclidean.Point2D(ix, iy), this.rawDepth[i] * scale, true);
                            this.depthFramePoints[i] = other.TransformBy(position).ToPoint3D();
                        }
                    }
                });
            }
        }
コード例 #7
0
        private void UpdateDepth(DepthImage depthImage)
        {
            int width  = depthImage.Width;
            int height = depthImage.Height;

            ushort tooNearDepth = 500;
            ushort tooFarDepth  = 10000;
            ushort unknownDepth = 0;

            int cx = width / 2;
            int cy = height / 2;

            double fxinv = 1.0 / 366;
            double fyinv = 1.0 / 366;

            double scale = 0.001;

            unsafe
            {
                ushort *depthFrame = (ushort *)((byte *)depthImage.ImageData.ToPointer());

                Parallel.For(0, height, iy =>
                {
                    for (int ix = 0; ix < width; ix++)
                    {
                        int i            = (iy * width) + ix;
                        this.rawDepth[i] = depthFrame[(iy * width) + ix];

                        if (this.rawDepth[i] == unknownDepth || this.rawDepth[i] < tooNearDepth || this.rawDepth[i] > tooFarDepth)
                        {
                            this.rawDepth[i]         = -1;
                            this.depthFramePoints[i] = default(Point3D);
                        }
                        else
                        {
                            double zz = (double)this.rawDepth[i] * scale;
                            double x  = (cx - ix) * zz * fxinv;
                            double y  = zz;
                            double z  = (cy - iy) * zz * fyinv;
                            this.depthFramePoints[i] = new Point3D(x, y, z);
                        }
                    }
                });
            }
        }