您好我是C#的初学者,我正在尝试使用Kinect for Windows设备的在线示例。
我认为问题出在我的引用中,但不知道该怎么做
我认为它与.Net框架有关,因为该示例似乎是基于旧版本的框架
PS:我确实使用"添加引用"
引用了kinect dll,项目参考是:
Microsoft.CSharp
Microsoft.Kinect
System
System.ComponentModel.Composition
System.ComponentModel.DataAnnotations
System.Core
System.Data
System.Data.DataSetExtensions
System.Deployment
System.Drawing
System.Runtime.DurableInstancing
System.Runtime.Remoting
System.Runtime.Serialization
System.Windows.Forms
System.Runtime.Serialization.Formatters.Soap
System.Xml
System.Xml.Linq
我得到的错误是:
错误1:类型或命名空间名称'运行时'无法找到行 20
错误2:类型或命名空间名称' ImageFrameReadyEventArgs'可以 没有找到第43行
错误2:类型或命名空间名称' PlanarImage'无法找到 第50行
这里是代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using Microsoft.Kinect;
namespace HelloKinectWorld
{
public partial class Form1 : Form
{
Runtime nui = Runtime.Kinects[0];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(
object sender, EventArgs e)
{
nui.Initialize(RuntimeOptions.UseColor);
nui.VideoStream.Open(
ImageStreamType.Video,
2,
ImageResolution.Resolution640x480,
ImageType.Color);
nui.VideoFrameReady +=
new EventHandler<ImageFrameReadyEventArgs>(
FrameReady);
}
void FrameReady(object sender,
ImageFrameReadyEventArgs e)
{
PlanarImage Image = e.ImageFrame.Image;
Bitmap bmap = PImageToBitmap(Image);
pictureBox1.Image = bmap;
}
Bitmap PImageToBitmap(PlanarImage PImage)
{
Bitmap bmap = new Bitmap(
PImage.Width,
PImage.Height,
PixelFormat.Format32bppRgb);
BitmapData bmapdata = bmap.LockBits(
new Rectangle(0, 0, PImage.Width,
PImage.Height),
ImageLockMode.WriteOnly,
bmap.PixelFormat);
IntPtr ptr = bmapdata.Scan0;
Marshal.Copy(PImage.Bits,
0,
ptr,
PImage.Width *
PImage.BytesPerPixel *
PImage.Height);
bmap.UnlockBits(bmapdata);
return bmap;
}
private void button1_Click(
object sender, EventArgs e)
{
nui.NuiCamera.ElevationAngle += 4;
}
private void button2_Click(
object sender,
EventArgs e)
{
nui.NuiCamera.ElevationAngle -= 4;
}
private void Form1_FormClosing(
object sender,
FormClosingEventArgs e)
{
nui.Uninitialize();
}
}
}
答案 0 :(得分:1)
您使用的是哪个版本的Kinect SDK?在最新版本( 1.8 )中,运行时很可能是 KinectSensor, ImageFrameReadyEventArgs 将 ColorFrameReadyEventArgs (或AllFramesReadyEventArgs)和 PlanarImage 将是 ColorImage 。
答案 1 :(得分:0)
这通常意味着您需要添加一些对程序集的引用。您正在导入Microsoft.Kinect,但您应该检查您是否实际引用了Visual Studio项目中的microsoft.kinect dll。
您可以在visual studio项目的references文件夹中查看它。如果您还没有将所需的kinect dll添加为项目的一部分,请使用上下文菜单和&#34;添加引用&#34;。