示例#1
0
    public int WhichUserDoesThisPointBelongTo(Point3D point)
    {
        // get userID of user to whom the hand is attached
        Point3D       ProjectiveHandPoint = depthGenerator.ConvertRealWorldToProjective(point);
        SceneMetaData sceneMD             = userGenerator.GetUserPixels(0);

        return(sceneMD[(int)ProjectiveHandPoint.X, (int)ProjectiveHandPoint.Y]);
    }
示例#2
0
        // 描画
        private unsafe void xnDraw()
        {
            // カメライメージの更新を待ち、画像データを取得する
            context.WaitOneUpdateAll(image);
            ImageMetaData imageMD = image.GetMetaData();
            SceneMetaData sceneMD = user.GetUserPixels(0);

            // カメラ画像の作成
            lock (this) {
                // 書き込み用のビットマップデータを作成
                Rectangle  rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                BitmapData data = bitmap.LockBits(rect, ImageLockMode.WriteOnly,
                                                  System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                // 生データへのポインタを取得
                byte *  dst   = (byte *)data.Scan0.ToPointer();
                byte *  src   = (byte *)image.ImageMapPtr.ToPointer();
                ushort *label = (ushort *)sceneMD.LabelMapPtr.ToPointer();

                for (int i = 0; i < imageMD.DataSize; i += 3, src += 3, dst += 3, ++label)
                {
                    dst[0] = (byte)(src[2] * colors[*label, 0]);
                    dst[1] = (byte)(src[1] * colors[*label, 1]);
                    dst[2] = (byte)(src[0] * colors[*label, 2]);
                }

                bitmap.UnlockBits(data);

                // スケルトンの描画
                foreach (int id in user.GetUsers())
                {
                    // トラッキング対象のユーザーでなければ次へ
                    if (!user.SkeletonCapability.IsTracking(id))
                    {
                        continue;
                    }

                    // スケルトンを描画する
                    DrawSkeleton(id);

                    // 腕の交点を描画する
                    DrawCrossPoint(id);
                }


                // 現在の状態を表示する
                Graphics g = Graphics.FromImage(bitmap);
                g.DrawString(message, font, brush, point);
            }
        }
        /// <summary>
        /// Processes the current image sensor data and loads it to the
        /// <see cref="Image"/>-property.
        /// </summary>
        private unsafe void loadImageDataToBitmap()
        {
            lock (ImageLock)
            {
                imageGenerator.GetMetaData(imageMD);

                if (shouldDrawPixels)
                {
                    // If highlights should be drawn or background subtracted
                    // a more difficult (and slower) drawing function is
                    // necessary.
                    if (shouldDrawHighlight || !shouldDrawBackground)
                    {
                        drawImageWithHighlightAndBackgroundSubtraction(
                            imageMD, (ushort *)userGenerator.GetUserPixels(0).LabelMapPtr.ToPointer(),
                            shouldDrawBackground, shouldDrawHighlight, new List <int>());
                    }
                    else
                    {
                        drawImageWithoutHighlightAndBackgroundSubtraction(imageMD);
                    }
                }
                else
                {
                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        // In this case, the image must be cleared
                        if (!shouldDrawPixels)
                        {
                            g.FillRectangle(Brushes.Black,
                                            new Rectangle(0, 0, imageMD.XRes, imageMD.YRes));
                        }
                    }
                }
                drawAndLogUserInformation();
            }
        }
        /// <summary>
        /// Saves the labelmap with the provided stream.
        /// </summary>
        protected unsafe void saveUserDataToFileStream(BinaryWriter userInformationWriter, UserGenerator userGenerator)
        {
            ushort *pLabels = (ushort *)userGenerator.GetUserPixels(0).LabelMapPtr.ToPointer();

            // At one position, only three bits of the 16 actual ushort bits
            // are used to indicate the user id. So by combining four of these
            // values, it is possible to write three bytes to the stream.
            // This might be implemented for a future release.

            for (int y = 0; y < imageMD.YRes; ++y)
            {
                for (int x = 0; x < imageMD.XRes; ++x)
                {
                    userInformationWriter.Write(*pLabels++);
                }
            }
        }
示例#5
0
        void Update()
        {
            if (FStarted)
            {
                IntPtr userPixels = FUserGenerator.GetUserPixels(0).LabelMapPtr;
                FImageMask.Image.SetPixels(userPixels);
                FImageMask.Send();

                lock (FLockUserData)
                {
                    FUserPositions.SliceCount = FUserData.Count;
                    foreach (var u in FUserData)
                    {
                        Point3D p = FUserGenerator.GetCoM(u.Key);
                        FUserData[u.Key].Position = new Vector3D(p.X / 1000.0d, p.Y / 1000.0d, p.Z / 1000.0d);
                    }
                }
            }
        }
        // 描画
        private unsafe void xnDraw()
        {
            // カメライメージの更新を待ち、画像データを取得する
            context.WaitOneUpdateAll(image);
            ImageMetaData imageMD = image.GetMetaData();
            SceneMetaData sceneMD = user.GetUserPixels(0);

            // カメラ画像の作成
            lock (this) {
                // 書き込み用のビットマップデータを作成
                Rectangle  rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                BitmapData data = bitmap.LockBits(rect, ImageLockMode.WriteOnly,
                                                  System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                // 生データへのポインタを取得
                byte *  dst   = (byte *)data.Scan0.ToPointer();
                byte *  src   = (byte *)image.ImageMapPtr.ToPointer();
                ushort *label = (ushort *)sceneMD.LabelMapPtr.ToPointer();

                // 画面用の描画
                for (int i = 0; i < imageMD.DataSize; i += 3, src += 3, dst += 3, ++label)
                {
                    // 背景描画が有効か、ユーザーがいる場合、カメラ画像を描画する
                    if (isBackground || (*label != 0))
                    {
                        dst[0] = src[2];
                        dst[1] = src[1];
                        dst[2] = src[0];
                    }
                    // その他の場合は描画しない
                    else
                    {
                        dst[0] = 255;
                        dst[1] = 255;
                        dst[2] = 255;
                    }
                }

                bitmap.UnlockBits(data);
            }
        }
示例#7
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FContextChanged)
            {
                if (FContextIn.PluginIO.IsConnected)
                {
                    if (FContextIn[0] != null)
                    {
                        try
                        {
                            // Creates the User Generator from the Context Object
                            FUserGenerator = new UserGenerator(FContextIn[0]);

                            //Set the resolution of the texture
                            FTexWidth  = FUserGenerator.GetUserPixels(0).FullXRes;
                            FTexHeight = FUserGenerator.GetUserPixels(0).FullYRes;

                            //Reinitalie the vvvv texture
                            Reinitialize();

                            FUserGenerator.StartGenerating();

                            FContextChanged = false;
                        }
                        catch (Exception ex)
                        {
                            FLogger.Log(ex);
                        }
                    }
                }
                else
                {
                    CleanUp();
                    FContextChanged = false;
                }
            }

            //create new texture if outputmode changed
            if (FOutputMode.IsChanged)
            {
                Reinitialize();
            }

            if (FUserGenerator != null)
            {
                if (FEnabledIn.IsChanged)
                {
                    if (FEnabledIn[0])
                    {
                        FUserGenerator.StartGenerating();
                    }
                    else
                    {
                        FUserGenerator.StopGenerating();
                    }
                }

                if (FUserGenerator.IsDataNew)
                {
                    FUserIdOut.SliceCount   = FUserGenerator.NumberOfUsers;
                    FPositionOut.SliceCount = FUserGenerator.NumberOfUsers;
                    FTextureOut.SliceCount  = 1;

                    if (FUserGenerator.NumberOfUsers > 0)
                    {
                        //copies a list of all users and sort them
                        int[] tUsers = FUserGenerator.GetUsers();
                        int[] Users  = (int[])tUsers.Clone();
                        Array.Sort(Users);

                        for (int i = 0; i < Users.Length; i++)
                        {
                            FUserIdOut[i] = Users[i];
                            try
                            {
                                //middle point of the User
                                Point3D  Point    = FUserGenerator.GetCoM(Users[i]);
                                Vector3D Position = new Vector3D(Point.X, Point.Y, Point.Z);

                                //map postion values to vvvv coordinates
                                FPositionOut[i] = Position / 1000;
                            }
                            catch (StatusException ex)
                            {
                                FLogger.Log(ex);
                            }
                        }
                    }

                    //update the vvvv texture
                    Update();
                }
            }
            else
            {
                FUserIdOut.SliceCount   = 0;
                FPositionOut.SliceCount = 0;
                FTextureOut.SliceCount  = 0;
            }
        }
示例#8
0
        //this method gets called, when Update() was called in evaluate,
        //or a graphics device asks for its texture, here you fill the texture with the actual data
        //this is called for each renderer, careful here with multiscreen setups, in that case
        //calculate the pixels in evaluate and just copy the data to the device texture here
        unsafe protected override void UpdateTexture(int Slice, Texture texture)
        {
            DataRectangle rect;

            if (texture.Device is DeviceEx)
            {
                rect = texture.LockRectangle(0, LockFlags.None);
            }
            else
            {
                rect = texture.LockRectangle(0, LockFlags.Discard);
            }

            try
            {
                if (FOutputMode[0] == UserTexturetMode.Raw)
                {
                    //copy full lines
                    for (int i = 0; i < FTexHeight; i++)
                    {
                        CopyMemory(rect.Data.DataPointer.Move(rect.Pitch * i), FUserGenerator.GetUserPixels(0).LabelMapPtr.Move(FTexWidth * i * 2), FTexWidth * 2);
                    }
                }
                else
                {
                    ushort *pSrc  = (ushort *)FUserGenerator.GetUserPixels(0).LabelMapPtr;
                    byte *  pDest = (byte *)rect.Data.DataPointer;

                    // write the Depth pointer to Destination pointer
                    for (int y = 0; y < FTexHeight; y++)
                    {
                        var off = 0;
                        for (int x = 0; x < FTexWidth; x++, pSrc++, pDest += 4)
                        {
                            var color = VColor.Black;

                            if (*pSrc == 0)
                            {
                                color.A = 0;
                            }
                            else
                            {
                                color = FUserColor[*pSrc - 1];
                            }

                            pDest[0] = (byte)(color.B * 255);
                            pDest[1] = (byte)(color.G * 255);
                            pDest[2] = (byte)(color.R * 255);
                            pDest[3] = (byte)(color.A * 255);

                            off += 4;
                        }

                        //advance dest by rest of pitch
                        pDest += rect.Pitch - off;
                    }
                }
            }
            finally
            {
                texture.UnlockRectangle(0);
            }
        }
示例#9
0
        // 描画
        private unsafe void xnDraw()
        {
            // カメライメージの更新を待ち、画像データを取得する
            context.WaitOneUpdateAll(image);
            ImageMetaData imageMD = image.GetMetaData();
            SceneMetaData sceneMD = user.GetUserPixels(0);

            // カメラ画像の作成
            lock (this) {
                // 書き込み用のビットマップデータを作成
                Rectangle  rect = new Rectangle(0, 0, this.bitmap.Width, this.bitmap.Height);
                BitmapData data = bitmap.LockBits(rect, ImageLockMode.WriteOnly,
                                                  System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                // 背景のビットマップデータを作成
                BitmapData back = background.LockBits(rect, ImageLockMode.ReadWrite,
                                                      System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                // 生データへのポインタを取得
                byte *  dst   = (byte *)data.Scan0.ToPointer();
                byte *  bk    = (byte *)back.Scan0.ToPointer();
                byte *  src   = (byte *)image.ImageMapPtr.ToPointer();
                ushort *label = (ushort *)sceneMD.LabelMapPtr.ToPointer();

                // 背景の更新
                if (isBackgroundRefresh)
                {
                    isBackgroundRefresh = false;

                    for (int i = 0; i < imageMD.DataSize; i += 3, src += 3, bk += 3)
                    {
                        bk[0] = src[2];
                        bk[1] = src[1];
                        bk[2] = src[0];
                    }

                    bk  = (byte *)back.Scan0.ToPointer();
                    src = (byte *)image.ImageMapPtr.ToPointer();
                }

                // 画面用の描画
                for (int i = 0; i < imageMD.DataSize;
                     i += 3, src += 3, dst += 3, bk += 3, ++label)
                {
                    // 光学迷彩が有効で、ユーザーがいる場合、背景を描画する
                    if (isCamouflage && (*label != 0))
                    {
                        dst[0] = bk[0];
                        dst[1] = bk[1];
                        dst[2] = bk[2];
                    }
                    // ユーザーではないので、カメラ画像を描画する
                    else
                    {
                        dst[0] = src[2];
                        dst[1] = src[1];
                        dst[2] = src[0];
                    }
                }

                bitmap.UnlockBits(data);
                background.UnlockBits(back);
            }
        }