关于Kinect V2 SDK的Microsoft教程中的kinect代码问题(PixelBuffer和Invalidate) [英] Problem with the kinect code from Microsoft tutorial on Kinect V2 SDK (PixelBuffer and Invalidate)

查看:69
本文介绍了关于Kinect V2 SDK的Microsoft教程中的kinect代码问题(PixelBuffer和Invalidate)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我是Kinect和C#的新手,我正在关注微软发布的官方教程(https://www.youtube.com/watch?v= 3cz9UJOaoB8)。我按照教程中给出的编码步骤进行操作。但该程序在最后两行给出错误:

I am new to Kinect and C# and I am following the official tutorial released by microsoft (https://www.youtube.com/watch?v=3cz9UJOaoB8). I followed the coding steps as given in the tutorial. But the program gives errors at the last two lines:

错误:

<强> irDataConverted.CopyTo(irBitmap.PixelBuffer);

错误:System.Windows.Media.Imaging.WriteableBitmap不包含关于'的定义PixelBuffer"和没有扩展方法‘PixelBuffer’接受型的第一参数‘System.Windows.Medai.Imaging.WriteableBitmap’可以发现(您使用的指令或程序集参考缺少
?)

error: System.Windows.Media.Imaging.WriteableBitmap does not contain a definition for 'PixelBuffer' and no extension method 'PixelBuffer' accepting a first argument of type 'System.Windows.Medai.Imaging.WriteableBitmap' could be found (are you missing a using directive or an assembly reference?)

<强> irBitmap.InvalidateProperty();

误差:无重载方法 'InvalidateProperty' 取0参数

error:No overload for method 'InvalidateProperty' takes 0 arguments

此外,writeableBitmap不允许我只插入两个参数。因此,它被改变为这样的:

&NBSP; irBitmap =新WriteableBitmap的(fd.Width,fd.Height,96,96,PixelFormats.Bgr32,空);

 irBitmap = new WriteableBitmap(fd.Width, fd.Height,96,96, PixelFormats.Bgr32,null);

这里给出了我的整个代码。你能否告诉我应该做些什么来避免上述两个错误? 

My entire code is given here. Can you please tell me what I should do to avoid the above two errors? 

谢谢。

-------- -------------------------------------------------- -------------------------------------------------- ---------------------

---------------------------------------------------------------------------------------------------------------------------------

使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Text;

使用System.Threading.Tasks;

使用System.Windows;

使用System.Windows.Controls;

使用System.Windows.Data;

使用System.Windows.Documents;

使用System.Windows.Input;

使用System.Windows.Media;

使用System.Windows.Media.Imaging;

使用System.Windows.Navigation;

使用System.Windows.Shapes;

使用Microsoft.Kinect;

使用Microsoft。 Kinect.Tools;



命名空间mykinect3

{

    ///< summary>

    /// MainWindow.xaml的交互逻辑

    ///< / summary>

    public partial class MainWindow:Window

    {

        public MainWindow()

        {

            this.InitializeComponent();

            this.Loaded + = MainWindow_Loaded;

        }


        KinectSensor传感器;

        InfraredFrameReader irReader;

        ushort [] irData;

        byte [] irDataConverted;

        WriteableBitmap irBitmap;

        void MainWindow_Loaded(object sender,RoutedEventArgs e)

        {

            sensor = KinectSensor.GetDefault();

            irReader = sensor.InfraredFrameSource.OpenReader();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; FrameDescription FD = sensor.InfraredFrameSource.FrameDescription;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; irData = new ushort [fd.LengthInPixels];

            irDataConverted =新的字节[fd.LengthInPixels * 4];

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; irBitmap =新WriteableBitmap的(FD .WIDTH,fd.Height,96,96,PixelFormats.Bgr32,NULL);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; image.Source = irBitmap;



            sensor.Open();

            irReader.FrameArrived + = irReader_FrameArrived;
$


        }


        void irReader_FrameArrived(object sender,InfraredFrameArrivedEventArgs e)

        {

           使用(InfraredFrame irFrame = e.FrameReference.AcquireFrame())

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

                if(irFrame!= null)

                {

&N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P; irDataConverted [I * 4 + 1] =强度;

&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; irDataConverted [I * 4 + 2] =强度;

&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; irDataConverted [I * 4 + 3] = 255;

&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;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; irDataConverted.CopyTo(irBitmap.PixelBuffer); //错误这里

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP; irBitmap.InvalidateProperty(); //错误这里

&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;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;  

                }
 

            

            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using Microsoft.Kinect.Tools;

namespace mykinect3
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }

        KinectSensor sensor;
        InfraredFrameReader irReader;
        ushort[] irData;
        byte[] irDataConverted;
        WriteableBitmap irBitmap;
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            sensor = KinectSensor.GetDefault();
            irReader = sensor.InfraredFrameSource.OpenReader();
            FrameDescription fd = sensor.InfraredFrameSource.FrameDescription;
            irData = new ushort[fd.LengthInPixels];
            irDataConverted = new byte[fd.LengthInPixels * 4];
            irBitmap = new WriteableBitmap(fd.Width, fd.Height,96,96, PixelFormats.Bgr32,null);
            image.Source = irBitmap;

            sensor.Open();
            irReader.FrameArrived += irReader_FrameArrived;

        }

        void irReader_FrameArrived(object sender, InfraredFrameArrivedEventArgs e)
        {
            using (InfraredFrame irFrame = e.FrameReference.AcquireFrame())
            {
                if (irFrame != null)
                {
                    irFrame.CopyFrameDataToArray(irData);
                    
                    for (int i = 0; i < irData.Length;i++)
                    {
                            byte intensity = (byte)(irData[i] >> 8);
                            irDataConverted[i * 4] = intensity;
                            irDataConverted[i * 4+1] = intensity;
                            irDataConverted[i * 4+2] = intensity;
                            irDataConverted[i * 4+3] = 255;
                    }

                    irDataConverted.CopyTo(irBitmap.PixelBuffer);//ERROR here
                    irBitmap.InvalidateProperty();//ERROR here
                                        
                }
 
            
            }
        }
    }
}

推荐答案

Hello Laksi,

Hello Laksi,

你遇到的问题非常简单。根据命名空间的使用情况,我确信您正在尝试创建.NET桌面应用程序。在您链接的视频教程中 - 检查项目的项目类型 它们是
正在处理的项目(它位于解决方案资源管理器中可见的括号中)。

the issue you're having is quite simple. Based on the namespaces usage I am convinced, that that you are trying to create .NET desktop application. In the video tutorial you linked - Check the project type of the project they are working on (it is in the brackets visible in Solution Explorer).

或检查这样的:

WriteableBitmap  (。NET,WPF)

WriteableBitmap (.NET, WPF)

WriteableBitmap的(WinRT的,XAML)

WriteableBitmap (WinRT, XAML)

要在.NET WPF版本的WriteableBitmap类中写入数据,可以使用
WriteableBitmap.WritePixels()
 方法。你可以在Kinect2 SDK的WPF样本中获得更多灵感(例如Depth Basics样本以这种方式使用WriteableBitmap)

To write data in .NET WPF version of WriteableBitmap class you can use WriteableBitmap.WritePixels() method. You can get further inspiration in WPF samples of Kinect2 SDK (e.g. Depth Basics sample uses WriteableBitmap this way)


这篇关于关于Kinect V2 SDK的Microsoft教程中的kinect代码问题(PixelBuffer和Invalidate)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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