Question

Hello I'm a beginner in C# and I'm trying an online example to use the Kinect for Windows device.

I think the problem is in my referencing but don't know what to do

I think it has something to do with the .Net framework as the example seems to be based on an older version of the framework

PS: I did reference the kinect dll using "Add References"

and the project references are:

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

The errors I'm getting are:

Error 1: the type or namespace name 'Runtime' Could not be found line 20

Error 2: the type or namespace name 'ImageFrameReadyEventArgs' Could not be found line 43

Error 2: the type or namespace name 'PlanarImage' Could not be found line 50

here's the code:

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();
        }
    }
}
Was it helpful?

Solution

Which version of the Kinect SDK are you using? In the most recent version (1.8), Runtime would most likely be KinectSensor, ImageFrameReadyEventArgs would be ColorFrameReadyEventArgs (or AllFramesReadyEventArgs) and PlanarImage would be ColorImage.

OTHER TIPS

This usually means you need to add some references to assemblies. You are importing Microsoft.Kinect, but you should check that you're actually referencing the microsoft.kinect dlls from your visual studio project.

You can check it on the references folder in your visual studio project. If you haven't added the required kinect dlls as part of the project, do so by using context menu and "add reference".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top