Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Getting most of the Kinect SDK in C# - Part 1 of ?: Initialization

, 6 Jan 2012
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)

About the Author

Jarek Kruza
Other 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.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 6 Jan 2012
Article Copyright 2011 by Jarek Kruza
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid