用图像或视频替换身体索引像素。 [英] replacing body index pixels with an image or video.

查看:66
本文介绍了用图像或视频替换身体索引像素。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何用图像或视频替换身体索引像素吗?每次我尝试我得到零点异常。用纯色替换像素似乎很好。


这是我的代码的一部分:


        private unsafe void ProcessBodyIndexFrameData(IntPtr bodyIndexFrameData,uint bodyIndexFrameDataSize)

        {

            byte * frameData =(byte *)bodyIndexFrameData;



            OpenImage();



            //将身体索引转换为直观表示

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; for(int i = 0; i<(int)bodyIndexFrameDataSize; ++ i)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // BodyColor数组的大小适合与
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // BodyFrameSource.BodyCount

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(frameData [i]< BodyColor.Length)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //此像素是玩家的一部分,

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //this.bodyIndexPixels [i] = 0x00000000;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; this.bodyIndexPixels [i] = ImageBackground1 [frameData [i]];

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;否则

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //这些是背景像素

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; this.bodyIndexPixels [i] = 0x99FFFF;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; }



  &NBSP; &NBSP; &NBSP; private void OpenImage()

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;试试
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; String PhotoFilePath = @" C:\ Users \ Vlux \Desktop \kinect code\BodyIndexBasics-WPF\Images\Picture.jpg" ;;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;位图image1 =(位图)Image.FromFile(PhotoFilePath,true);



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; FileStream fs = new FileStream(PhotoFilePath,FileMode.Open,FileAccess.Read);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; BinaryReader br = new BinaryReader(fs);



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; byte [] ImageBackground1 = br.ReadBytes((int)fs.Length); 


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; br.Close();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; fs.Close();



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; catch(System.IO.FileNotFoundException)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; MessageBox.Show("打开位图时出错。" +

          "请检查路径。");

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; } // OpenImage结束();



解决方案

< blockquote>

Hi Vlux,


在C ++示例中,这很容易做到。


只需用图像替换绘图缓冲区即可。在填充缓冲区的方法中,只需检查像素是否属于用户,如果是,则使用预取缓冲区中的像素到图像。 C ++坐标映射器示例为您提供
,其中包含您需要的所有代码。


在C#中,这需要更多代码。对于WPF应用程序,您需要使用1个可写和1个常规位图。一个使用预取图像(常规)和可写位图,使用相同的逻辑修改缓冲区。


does anybody know how to replace the body index pixels with an image or video? each time i try i get null point exception. replacing the pixels with a solid color seems to be fine though.

here is part of my code:

        private unsafe void ProcessBodyIndexFrameData(IntPtr bodyIndexFrameData, uint bodyIndexFrameDataSize)
        {
            byte* frameData = (byte*)bodyIndexFrameData;

            OpenImage();

            // convert body index to a visual representation
            for (int i = 0; i < (int)bodyIndexFrameDataSize; ++i)
            {
                // the BodyColor array has been sized to match
                // BodyFrameSource.BodyCount
                if (frameData[i] < BodyColor.Length)
                {
                    // this pixel is part of a player,
                    //this.bodyIndexPixels[i] = 0x00000000;
                    this.bodyIndexPixels[i] = ImageBackground1[frameData[i]];
                }
                else
                {
                    // these are background pixels
                    this.bodyIndexPixels[i] = 0x99FFFF;
                }
            }
        }

        private void OpenImage()
        {
            try
            {
                String PhotoFilePath = @"C:\Users\Vlux\Desktop\kinect code\BodyIndexBasics-WPF\Images\Picture.jpg";

                Bitmap image1 = (Bitmap)Image.FromFile(PhotoFilePath, true);

                FileStream fs = new FileStream(PhotoFilePath, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);

                byte[] ImageBackground1 = br.ReadBytes((int)fs.Length); 

                br.Close();
                fs.Close();

            }

            catch (System.IO.FileNotFoundException)
            {
                MessageBox.Show("There was an error opening the bitmap." +
                    "Please check the path.");
            }
        }//end of OpenImage();

解决方案

Hi Vlux,

In the C++ example this is pretty easy to do.

Just replace the drawing buffer with your image. In the method to fill the buffer, just check to see if the pixel belongs to the user and if so, use the pixels from the pre fetched buffer to the image. The C++ Coordinate mapper sample provides you with all the code you need.

In C# this requires a bit more code. For a WPF app you'd need to use probably 1 writable and 1 regular bitmap. One with your prefetched image (regular) and the writable bitmap to modify the buffer using the same logic above.


这篇关于用图像或视频替换身体索引像素。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆