Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / C# 4.0

Getting the most of Kinect SDK in C# - Part 2 of ?: ImageStreams

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
6 Jan 2012Ms-PL4 min read 36.2K   1.2K   12  
A series about experimenting with Kinect for Windows SDK.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Research.Kinect.Nui;

namespace JK.KinectExperiments.ImageStreamTest
{
    public class PlanarImageHelper
    {
        private PlanarImage _img;
        public PlanarImage Image { get { return _img; } }
        public PlanarImageHelper(PlanarImage src)
        {
            _img = src;
        }

        public Byte GetRedAt(int x, int y)
        {
            return _img.Bits[y * _img.Width * _img.BytesPerPixel + x * _img.BytesPerPixel + 2];
        }

        public Byte GetGreenAt(int x, int y)
        {
            return _img.Bits[y * _img.Width * _img.BytesPerPixel + x * _img.BytesPerPixel + 1];
        }

        public Byte GetBlueAt(int x, int y)
        {
            return _img.Bits[y * _img.Width * _img.BytesPerPixel + x * _img.BytesPerPixel + 0];
        }

        public int GetPlayerAt(int x, int y)
        {
            return _img.Bits[y * _img.Width * _img.BytesPerPixel + x * _img.BytesPerPixel] & 0x07;
        }

        public int GetDepthAt(int x, int y, bool hasPlayerData)
        {
            try
            {
                int BaseByte = y * _img.Width * _img.BytesPerPixel + x * _img.BytesPerPixel;
                if (hasPlayerData)
                {
                    return (_img.Bits[BaseByte + 1] << 5) | (_img.Bits[BaseByte] >> 3);
                }
                else
                {
                    return (_img.Bits[BaseByte + 1] << 8) | (_img.Bits[BaseByte]);
                }
            }
            catch
            {
                return 0;
            }
        }


    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Flextronics
Poland Poland
Programming since 10 years old with first commercial app sold in age of 16.

In past got Bachelor's degree in Computer Sciences and worked as Linux administrator and software developer.

Currently slightly over 30 and working as IT Project Manager for Flextronics.

Still coding for fun and/or money.

Comments and Discussions