<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rozengain.com - Creative Technology Blog</title>
	<atom:link href="http://www.rozengain.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rozengain.com/blog</link>
	<description></description>
	<lastBuildDate>Tue, 16 Apr 2013 23:01:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Ogre 3D and the Intel Perceptual Computing SDK / Creative Gesture Camera</title>
		<link>http://www.rozengain.com/blog/2013/01/30/ogre-3d-and-the-intel-perceptual-computing-sdk-creative-gesture-camera/</link>
		<comments>http://www.rozengain.com/blog/2013/01/30/ogre-3d-and-the-intel-perceptual-computing-sdk-creative-gesture-camera/#comments</comments>
		<pubDate>Wed, 30 Jan 2013 13:33:49 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[3D Sensor]]></category>
		<category><![CDATA[Creative Gesture Camera]]></category>
		<category><![CDATA[Intel Perceptual Computing SDK]]></category>
		<category><![CDATA[Ogre]]></category>
		<category><![CDATA[Ogre3D]]></category>

		<guid isPermaLink="false">http://www.rozengain.com/blog/?p=1094</guid>
		<description><![CDATA[2013 will be the year of the 3D sensor. I just finished working on a Kinect project for one of our clients and it has been one of the most fun (and demanding) projects I worked on in a while. I learned a lot of news things: the Microsoft Kinect SDK (I used OpenKinect and [...]]]></description>
			<content:encoded><![CDATA[<p>2013 will be the year of the 3D sensor. I just finished working on a Kinect project for one of our clients and it has been one of the most fun (and demanding) projects I worked on in a while. I learned a lot of news things: the Microsoft Kinect SDK (I used OpenKinect and OpenNI in the past), C#, WPF and XNA. Apart from technology I also learned a load of new math.</p>
<p>I recently posted about the fantastic <a href="/blog/2012/12/10/leap-motion-demo/" title="Leap Motion Demo">Leap Motion</a>. At <a href="http://www.cesweb.org/" title="CES">CES</a> 2013 <a href="http://www.primesense.com" title="PrimeSense">PrimeSense</a> (the company behind the Kinect hardware) announced Capri &#8220;<a href="http://www.primesense.com/news/primesense-unveils-capri/" title="PrimeSense Unveils Capri, World's Smallest 3D Sensing Device">The World&#8217;s Smallest 3D Sensing Device</a>&#8220;.</p>
<p>Another interesting product comes from Intel and Creative. The latter is manufacturing a 3D sensor called &#8220;<a href="http://click.intel.com/intelsdk/Default.aspx" title="Creative Interactive Gesture Camera">Creative Interactive Gesture Camera</a>&#8221; and the former provides an SDK called &#8220;<a href="http://software.intel.com/en-us/vcsource/tools/perceptual-computing-sdk" title="Intel Perceptual Computing SDK">Perceptual Computing SDK</a>&#8220;.</p>
<p>For the project I was working on I actually considered using the Creative camera &amp; Intel SDK. Unfortunately the one thing I needed from the SDK (Face Pose) hasn&#8217;t been implemented yet. It&#8217;s a beta SDK after all. </p>
<p><img src="/files/spotlights/creative-gesture-camera.jpg" alt="Creative Gesture Camera" /></p>
<p>Despite that the SDK is very promising. It has features like speech recognition, close-range tracking, gesture recognition, hand pose detection, finger tracking, facial analysis and a lot more. They also provide wrappers for C#, Unity and Processing.</p>
<p>However, my 3D engine of choice is <a href="http://www.ogre3d.org/" title="Ogre 3D">Ogre 3D</a>. There isn&#8217;t much documentation to be found about the Perceptual Computing SDK yet so I&#8217;m posting my basic Perceptual Computing SDK &#8211; Ogre3D integration code here. It will save you some time if you plan on using these <img src='http://www.rozengain.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;ve used the <a href="https://bitbucket.org/jacmoe/ogreappwizards" title="Ogre App Wizard">Ogre App Wizard</a> to generate my Visual Studio project and base class (BaseApplication.cpp &amp; BaseApplication.h).</p>
<p>Here&#8217;s a brief explanation of the code. You can find all the source files on BitBucket: <a href="https://bitbucket.org/MasDennis/ogre3d-intel-perceptual-computing-sdk/src">https://bitbucket.org/MasDennis/ogre3d-intel-perceptual-computing-sdk/src</a>.</p>
<p>The main Ogre class (Perceptual.cpp) sets up the scene and creates two Rectangle2D instances with textures that will be updated on every frame. It also creates an instance of the class (CreativeSensor) that will connect to the camera:</p>
<pre><code>
void PerceptualDemo::createScene(void)
{
	//
	// -- Set up the camera
	//
	mCamera-&gt;setPosition(0, 0, 0);
	mCamera-&gt;setNearClipDistance(0.01);

	//
	// -- Create color rectangle and texture
	//
	mColorTexture = TextureManager::getSingleton().createManual("ColorTex", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 1280, 720, 0, PF_R8G8B8, TU_DYNAMIC);

	MaterialPtr material = MaterialManager::getSingleton().create("ColorMat", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	material-&gt;getTechnique(0)-&gt;getPass(0)-&gt;createTextureUnitState("ColorTex");

	Rectangle2D* rect = new Rectangle2D(true);
	rect-&gt;setCorners(-1.0, 1.0, 1.0, -1.0);
	rect-&gt;setMaterial("ColorMat");
	rect-&gt;setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);

	AxisAlignedBox aabInf;
	aabInf.setInfinite();
	rect-&gt;setBoundingBox(aabInf);

	SceneNode* node = mSceneMgr-&gt;getRootSceneNode()-&gt;createChildSceneNode("ColorRect");
	node-&gt;attachObject(rect);

	//
	// -- Create depth rectangle and texture
	//
	mDepthTexture = TextureManager::getSingleton().createManual("DepthTex", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 320, 240, 0, PF_R8G8B8, TU_DYNAMIC);

	material = MaterialManager::getSingleton().create("DepthMat", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	material-&gt;getTechnique(0)-&gt;getPass(0)-&gt;createTextureUnitState("DepthTex");

	rect = new Rectangle2D(true);
	rect-&gt;setCorners(0, 0, 1.0, -1.0);
	rect-&gt;setMaterial("DepthMat");
	rect-&gt;setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);
	rect-&gt;setBoundingBox(aabInf);

	node = mSceneMgr-&gt;getRootSceneNode()-&gt;createChildSceneNode("DepthRect");
	node-&gt;attachObject(rect);
	node-&gt;setVisible(true);

	//
	// -- Create a new sensor instance
	//
	mSensor = new CreativeSensor(this);
	mSensor-&gt;connect();
}
</code></pre>
<p>On each frame the sensor is updated:</p>
<pre><code>
bool PerceptualDemo::frameStarted(const FrameEvent&amp; evt)
{
	if(!mSensor-&gt;updateFrame()) return false;
}
</code></pre>
<p>Two methods which are defined in an interface called IImageTarget are implemented in PerceptualDemo.cpp. They convert raw data from the sensor to Ogre textures.</p>
<pre><code>
void PerceptualDemo::setColorBitmapData(char* data)
{
	HardwarePixelBufferSharedPtr pixelBuffer = mColorTexture-&gt;getBuffer();
	pixelBuffer-&gt;lock(HardwareBuffer::HBL_DISCARD);
	const PixelBox&amp; pixelBox = pixelBuffer-&gt;getCurrentLock();
	uint8* pDest = static_cast<uint8*>(pixelBox.data);

	for(size_t i=0; i<720; i++)
	{
		for(size_t j=0; j<1280; j++)
		{
			*pDest++ = *data++;
			*pDest++ = *data++;
			*pDest++ = *data++;
			*pDest++ = 255;
		}
	}

	pixelBuffer-&gt;unlock();
}

void PerceptualDemo::setDepthBitmapData(short* data)
{
	HardwarePixelBufferSharedPtr pixelBuffer = mDepthTexture-&gt;getBuffer();
	pixelBuffer-&gt;lock(HardwareBuffer::HBL_DISCARD);
	const PixelBox&amp; pixelBox = pixelBuffer-&gt;getCurrentLock();
	uint8* pDest = static_cast&lt;uint8*&gt;(pixelBox.data);

	for(size_t i=0; i&lt;240; i++)
	{
		for(size_t j=0; j&lt;320; j++)
		{
			short depthVal = *data++ / 16;
			*pDest++ = depthVal;
			*pDest++ = depthVal;
			*pDest++ = depthVal;
			*pDest++ = 255;
		}
	}

	pixelBuffer-&gt;unlock();
}
</code></pre>
<p>The connection with the camera is set up in the CreativeSensor class. This class also sets up an SDK session:</p>
<pre><code>
bool CreativeSensor::connect()
{
	//
	// -- Set up an SDK session
	//
	if(PXCSession_Create(&#038;mSession) &lt; PXC_STATUS_NO_ERROR)
	{
		OutputDebugString("Failed to create a session");
		return false;
	}

	//
	// -- Configure the video streams
	//
	PXCCapture::VideoStream::DataDesc request;
	memset(&amp;request, 0, sizeof(request));
	request.streams[0].format = PXCImage::COLOR_FORMAT_RGB24;
	request.streams[0].sizeMin.width = request.streams[0].sizeMax.width = 1280;
	request.streams[0].sizeMin.height = request.streams[0].sizeMax.height = 720;
	request.streams[1].format = PXCImage::COLOR_FORMAT_DEPTH;

	//
	// -- Create the streams
	//
	mCapture = new UtilCapture(mSession);
	mCapture-&gt;LocateStreams(&amp;request);

	//
	// -- Get the profiles the verify if we got the desired streams
	//
	PXCCapture::VideoStream::ProfileInfo colorProfile;
	mCapture-&gt;QueryVideoStream(0)-&gt;QueryProfile(&amp;colorProfile);
	PXCCapture::VideoStream::ProfileInfo depthProfile;
	mCapture-&gt;QueryVideoStream(1)-&gt;QueryProfile(&amp;depthProfile);

	//
	// -- Output to console
	//
	char line[64];
	sprintf(line, "Depth %d x %d\n", depthProfile.imageInfo.width, depthProfile.imageInfo.height);
	OutputDebugString(line);
	sprintf(line, "Color %d x %d\n", colorProfile.imageInfo.width, colorProfile.imageInfo.height);
	OutputDebugString(line);

	return true;
}
</code></pre>
<p>Once this is set up we can add the code that will execute on every frame. The color and depth images are retrieved and sent to the CreativeSensor class.</p>
<pre><code>
bool CreativeSensor::updateFrame()
{
	PXCSmartArray&lt;PXCImage&gt; images;
	PXCSmartSPArray syncPoints(1);

	pxcStatus status = mCapture-&gt;ReadStreamAsync(images, &amp;syncPoints[0]);
	if(status &lt; PXC_STATUS_NO_ERROR) return false;

	status = syncPoints.SynchronizeEx();
	if(syncPoints[0]-&gt;Synchronize(0) &lt; PXC_STATUS_NO_ERROR) return false;

	//
	// -- get the color image
	//
	PXCImage *colorImage = mCapture-&gt;QueryImage(images, PXCImage::IMAGE_TYPE_COLOR);
	PXCImage::ImageData colorImageData;
	if(colorImage-&gt;AcquireAccess(PXCImage::ACCESS_READ, &amp;colorImageData) &lt; PXC_STATUS_NO_ERROR)
		return false;
	mPerceptualDemo-&gt;setColorBitmapData((char*)colorImageData.planes[0]);
	colorImage-&gt;ReleaseAccess(&amp;colorImageData);

	//
	// -- get the depth image
	//
	PXCImage *depthImage = mCapture-&gt;QueryImage(images, PXCImage::IMAGE_TYPE_DEPTH);
	PXCImage::ImageData depthImageData;
	if(depthImage-&gt;AcquireAccess(PXCImage::ACCESS_READ, &amp;depthImageData) &lt; PXC_STATUS_NO_ERROR)
		return false;
	mPerceptualDemo-&gt;setDepthBitmapData((short*)depthImageData.planes[0]);
	depthImage-&gt;ReleaseAccess(&amp;depthImageData);

	return true;
}
</code></pre>
<p>... and that's all there is to it <img src='http://www.rozengain.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here's what it looks like:</p>
<p><img src="/files/spotlights/intel-perceptual-sdk-ogre3d-screen.jpg" alt="Ogre3D and Intel Perceptual Computing SDK Integration" /></p>
<p>The complete source code can be found on BitBucket: <a href="https://bitbucket.org/MasDennis/ogre3d-intel-perceptual-computing-sdk/src">https://bitbucket.org/MasDennis/ogre3d-intel-perceptual-computing-sdk/src</a></p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rozengain.com/blog/2013/01/30/ogre-3d-and-the-intel-perceptual-computing-sdk-creative-gesture-camera/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leap Motion Demo</title>
		<link>http://www.rozengain.com/blog/2012/12/10/leap-motion-demo/</link>
		<comments>http://www.rozengain.com/blog/2012/12/10/leap-motion-demo/#comments</comments>
		<pubDate>Mon, 10 Dec 2012 16:01:33 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Kinect]]></category>
		<category><![CDATA[Leap Motion]]></category>
		<category><![CDATA[Ogre]]></category>
		<category><![CDATA[PhysX]]></category>

		<guid isPermaLink="false">http://www.rozengain.com/blog/?p=1084</guid>
		<description><![CDATA[We managed to get our hands on a Leap Motion Developer Kit. If you have never heard about Leap Motion then I recommend you watch the video on their homepage. This is how they describe it themselves: The Leap is a small iPod sized USB peripheral that creates a 3D interaction space of 8 cubic [...]]]></description>
			<content:encoded><![CDATA[<p>We managed to get our hands on a <a title="Leap Motion" href="https://leapmotion.com/">Leap Motion</a> Developer Kit. If you have never heard about Leap Motion then I recommend you watch the video on their homepage.</p>
<p>This is how they describe it themselves:</p>
<p><em>The Leap is a small iPod sized USB peripheral that creates a 3D interaction space of 8 cubic feet to precisely interact with and control software on your laptop or desktop computer. It’s like being able to reach into the computer and pull out information as easily as reaching into a cookie jar.</em></p>
<p><em>The Leap senses your individual hand and finger movements independently, as well as items like a pen. In fact, it’s 200x more sensitive than existing touch-free products and technologies. It’s the difference between sensing an arm swiping through the air and being able to create a precise digital signature with a fingertip or pen.</em></p>
<p>These are some big promises and I was very happy to experience that they can live up to it <img src='http://www.rozengain.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I am amazed by how accurate it is.</p>
<p>To familiarise myself with the Leap Motion and to check out its accuracy I created a demo using Ogre3D, PhysX and the Leap C++ API.</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/rMwK0ftZIGY" frameborder="0" allowfullscreen></iframe></p>
<p>You can also watch it here: <a href="http://productification.tumblr.com/post/36884902432/weve-now-got-the-first-release-of-the-leap">http://productification.tumblr.com/post/36884902432/weve-now-got-the-first-release-of-the-leap</a></p>
<p>Some screen grabs:</p>
<p><img class="alignnone" title="Leap Motion Demo" src="/files/leap/leap_motion_demo_01.jpg" alt="" width="600" height="450" /></p>
<p><img class="alignnone" title="Leap Motion Demo" src="/files/leap/leap_motion_demo_02.jpg" alt="" width="600" height="450" /></p>
<p><img class="alignnone" title="Leap Motion Demo" src="/files/leap/leap_motion_demo_03.jpg" alt="" width="600" height="450" /></p>
<p><img class="alignnone" title="Leap Motion Demo" src="/files/leap/leap_motion_demo_04.jpg" alt="" width="600" height="450" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rozengain.com/blog/2012/12/10/leap-motion-demo/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Unused, Unfinished WebGL Prototypes</title>
		<link>http://www.rozengain.com/blog/2012/09/19/unused-unfinished-webgl-prototypes/</link>
		<comments>http://www.rozengain.com/blog/2012/09/19/unused-unfinished-webgl-prototypes/#comments</comments>
		<pubDate>Wed, 19 Sep 2012 08:59:27 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[WebGL]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[three.js]]></category>

		<guid isPermaLink="false">http://www.rozengain.com/blog/?p=1073</guid>
		<description><![CDATA[It&#8217;s been quite a while since I posted anything WebGL related. That doesn&#8217;t mean I haven&#8217;t touched it during this time. I have used it a lot to do quick 3D prototyping. Three.js is the engine of choice because of its rich feature set, consistent API, stability and general awesomeness. I decided to upload these [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been quite a while since I posted anything WebGL related. That doesn&#8217;t mean I haven&#8217;t touched it during this time. I have used it a lot to do quick 3D prototyping. Three.js is the engine of choice because of its rich feature set, consistent API, stability and general awesomeness.</p>
<p>I decided to upload these prototypes despite the fact that I&#8217;ve never finished them. They&#8217;re quite random and unpolished. I guess uploading them means they won&#8217;t disappear into the graveyard of digital content <img src='http://www.rozengain.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Anyway, here we go.</p>
<h1>Goal Creator</h1>
<p><a href="/files/webgl/prototypes/goal_creator.html"><img src="/files/spotlights/webgl_goal_creator.jpg" alt="WebGL Goal Creator" title="WebGL Goal Creator" width="600" height="250"></a><br />
Click three times on the pitch and then in the goal. No realistic physics simulation whatsoever. Just a very lame curve <img src='http://www.rozengain.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<h1>Shirt Particles</h1>
<p><a href="/files/webgl/prototypes/shirt_particles.html"><img src="/files/spotlights/webgl_shirt_particles.jpg" alt="WebGL Shirt Particles" title="WebGL Shirt Particles" width="600" height="250"></a><br />
Particles that build up the fabric of the shirt. Their final positions are the vertices of the shirt mesh.</p>
<h1>Shirt Strands</h1>
<p><a href="/files/webgl/prototypes/shirt_strands.html"><img src="/files/spotlights/webgl_shirt_strands.jpg" alt="WebGL Shirt Strands" title="WebGL Shirt Strands" width="600" height="250"></a><br />
Same things as the previous demo but with strands instead of particles. The strands follow the path of the mesh vertices.</p>
<h1>Pitch with Animated Player Positions</h1>
<p><a href="/files/webgl/prototypes/pitch.html"><img src="/files/spotlights/webgl_pitch.jpg" alt="WebGL Football Pitch" title="WebGL Football Pitch" width="600" height="250"></a><br />
This example uses player position data to move the objects across the pitch.</p>
<h1>Track Created with GPS Data</h1>
<p><a href="/files/webgl/prototypes/gps_run.html"><img src="/files/spotlights/webgl_gps_run.jpg" alt="WebGL GPS Run Track" title="WebGL GPS Run Track" width="600" height="250"></a><br />
I recorded GPS coordinates during one of my runs through London. The GPS coordinates are converted into Cartesian coordinates to create the track.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rozengain.com/blog/2012/09/19/unused-unfinished-webgl-prototypes/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Rajawali Tutorial 25: Video Material</title>
		<link>http://www.rozengain.com/blog/2012/08/08/rajawali-tutorial-25-video-material/</link>
		<comments>http://www.rozengain.com/blog/2012/08/08/rajawali-tutorial-25-video-material/#comments</comments>
		<pubDate>Wed, 08 Aug 2012 08:03:13 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Rajawali]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.rozengain.com/blog/?p=1067</guid>
		<description><![CDATA[This tutorial has moved to the Rajawali Wiki.]]></description>
			<content:encoded><![CDATA[<p>This tutorial has moved to the <a href="https://github.com/MasDennis/Rajawali/wiki/Tutorial-25-Video-Material">Rajawali Wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rozengain.com/blog/2012/08/08/rajawali-tutorial-25-video-material/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Using OpenCV 2 with Kinect SDK 1.5</title>
		<link>http://www.rozengain.com/blog/2012/08/01/using-opencv-2-with-kinect-sdk-1-5/</link>
		<comments>http://www.rozengain.com/blog/2012/08/01/using-opencv-2-with-kinect-sdk-1-5/#comments</comments>
		<pubDate>Wed, 01 Aug 2012 07:27:55 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[Kinect]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.rozengain.com/blog/?p=1055</guid>
		<description><![CDATA[OpenCV always makes a great combination with the Kinect SDK. I&#8217;m currently working on a project where I need to combine the two. Optical Flow and Face Recognition are just two out of many powerful features that complement the Kinect SDK. I though this bit of code might be useful for anybody who wants to [...]]]></description>
			<content:encoded><![CDATA[<p>OpenCV always makes a great combination with the Kinect SDK. I&#8217;m currently working on a project where I need to combine the two. Optical Flow and Face Recognition are just two out of many powerful features that complement the Kinect SDK.<br />
I though this bit of code might be useful for anybody who wants to use these two frameworks together.<br />
I&#8217;m just posting the whole class (C++) here (with links to the SDKs). Please feel free to ask any questions in the comments.</p>
<pre><code>#include &lt;iostream&gt;

#include &lt;opencv2\imgproc\imgproc.hpp&gt;
#include &lt;opencv2\core\core.hpp&gt;

#include &lt;NuiApi.h&gt;

using namespace std;
using namespace cv;

class DepthSensor
{
private:
	static const int WIDTH = 320;
	static const int HEIGHT = 240;
	static const int BYTES_PER_PIXEL = 4;

	<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuisensor.aspx">INuiSensor</a>*		mNuiSensor;
	<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#handle">HANDLE</a>			mNextDepthFrameEvent;
	<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#handle">HANDLE</a>			mNextColorFrameEvent;
	<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#handle">HANDLE</a>			mDepthStreamHandle;
	<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#handle">HANDLE</a>			mColorStreamHandle;
	// -- this is the grey scale depth image
	<a href="http://opencv.itseez.com/modules/core/doc/basic_structures.html?highlight=mat#Mat">Mat</a>				mCVImageDepth;
	// -- this is the color image
	<a href="http://opencv.itseez.com/modules/core/doc/basic_structures.html?highlight=mat#Mat">Mat</a>				mCVImageColor;
	// -- this is the color image mapped to the depth image
	<a href="http://opencv.itseez.com/modules/core/doc/basic_structures.html?highlight=mat#Mat">Mat</a>				mCVImageColorDepth;
	// -- color pixel to depth pixel mapping
	<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd162938(v=vs.85).aspx">RGBQUAD</a>			mRGB[WIDTH * HEIGHT];

public:
	bool init() {
		int sensorCount = 0;

		<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#hresult">HRESULT</a> hr = <a href="http://msdn.microsoft.com/en-us/library/nuisensor.nuigetsensorcount.aspx">NuiGetSensorCount</a>(&#038;sensorCount);
		if(FAILED(hr)) return false;

		hr = <a href="http://msdn.microsoft.com/en-us/library/nuisensor.nuicreatesensorbyindex">NuiCreateSensorByIndex</a>(0, &#038;mNuiSensor);
		if(FAILED(hr)) return false;

		hr = mNuiSensor-&gt;<a href="http://msdn.microsoft.com/en-us/library/hh973099.aspx">NuiStatus()</a>;
		if(hr != S_OK) {
			mNuiSensor-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuisensor.release">Release()</a>;
			return false;
		}

		if(mNuiSensor == NULL) return false;

		hr = mNuiSensor-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuisensor.nuiinitialize">NuiInitialize</a>(NUI_INITIALIZE_FLAG_USES_DEPTH | NUI_INITIALIZE_FLAG_USES_COLOR);
		if(!SUCCEEDED(hr)) return false;

		mNextDepthFrameEvent = <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396(v=vs.85).aspx">CreateEvent</a>(NULL, TRUE, FALSE, NULL);
		mNextColorFrameEvent = <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396(v=vs.85).aspx">CreateEvent</a>(NULL, TRUE, FALSE, NULL);

		hr = mNuiSensor-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuisensor.nuiimagestreamopen">NuiImageStreamOpen</a>(NUI_IMAGE_TYPE_DEPTH, NUI_IMAGE_RESOLUTION_640x480, 0, 2, mNextDepthFrameEvent, &#038;mDepthStreamHandle);
		hr = mNuiSensor-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuisensor.nuiimagestreamopen">NuiImageStreamOpen</a>(NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, 0, 2, mNextColorFrameEvent, &#038;mColorStreamHandle);

		mNuiSensor-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuisensor.nuiimagestreamsetimageframeflags">NuiImageStreamSetImageFrameFlags</a>(mDepthStreamHandle, NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE);

		if(mNuiSensor == NULL || FAILED(hr))
			return false;

		mCVImageDepth = <a href="http://opencv.itseez.com/modules/core/doc/basic_structures.html?highlight=mat#Mat">Mat</a>(Size(WIDTH, HEIGHT), CV_8UC1);
		mCVImageColorDepth = <a href="http://opencv.itseez.com/modules/core/doc/basic_structures.html?highlight=mat#Mat">Mat</a>(Size(WIDTH, HEIGHT), CV_8UC3);

		return true;
	}

	DepthSensor()
	{
	}

	<a href="http://opencv.itseez.com/modules/core/doc/basic_structures.html?highlight=mat#Mat">Mat</a>&#038; getDepthMat()
	{
		return mCVImageDepth;
	}

	<a href="http://opencv.itseez.com/modules/core/doc/basic_structures.html?highlight=mat#Mat">Mat</a>&#038; getColorDepthMat()
	{
		return mCVImageColorDepth;
	}

	<a href="http://opencv.itseez.com/modules/core/doc/basic_structures.html?highlight=mat#Mat">Mat</a>&#038; getColorMat()
	{
		return mCVImageColor;
	}

	void processDepth() {
		<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx#hresult">HRESULT</a> hr;
		<a href="http://msdn.microsoft.com/en-us/library/nuiimagecamera.nui_image_frame.aspx">NUI_IMAGE_FRAME</a> depthFrame, colorFrame;

		hr = mNuiSensor-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuiimagecamera.nuiimagestreamgetnextframe.aspx">NuiImageStreamGetNextFrame</a>(mDepthStreamHandle, 0, &#038;depthFrame);
		if(FAILED(hr)) return;
		hr = mNuiSensor-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuiimagecamera.nuiimagestreamgetnextframe.aspx">NuiImageStreamGetNextFrame</a>(mColorStreamHandle, 20, &#038;colorFrame);
		if(FAILED(hr)) return;

		<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuiframetexture.aspx">INuiFrameTexture</a>* depthTex = depthFrame.pFrameTexture;
		<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuiframetexture.aspx">INuiFrameTexture</a>* colorTex = colorFrame.pFrameTexture;
		<a href="http://msdn.microsoft.com/en-us/library/nuiimagecamera.nui_locked_rect.aspx">NUI_LOCKED_RECT</a> lockedRectDepth;
		<a href="http://msdn.microsoft.com/en-us/library/nuiimagecamera.nui_locked_rect.aspx">NUI_LOCKED_RECT</a> lockedRectColor;

		depthTex-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuiframetexture.lockrect.aspx">LockRect</a>(0, &#038;lockedRectDepth, NULL, 0);
		colorTex-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuiframetexture.lockrect.aspx">LockRect</a>(0, &#038;lockedRectColor, NULL, 0);

		if(lockedRectDepth.Pitch != 0 &#038;&#038; lockedRectColor.Pitch != 0) {
			const USHORT *depthBufferRun = (const USHORT*)lockedRectDepth.pBits;
			const USHORT *depthBufferEnd = (const USHORT*)depthBufferRun + (WIDTH * HEIGHT);
			const BYTE *colorBufferRun = (const BYTE*)lockedRectColor.pBits;
			const BYTE *colorBufferEnd = (const BYTE*)colorBufferRun + (WIDTH * HEIGHT * 4);

			memcpy(mRGB, colorBufferRun, WIDTH * HEIGHT * sizeof(<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd162938(v=vs.85).aspx">RGBQUAD</a>));

			int count = 0;
			int x, y;

			while(depthBufferRun &lt; depthBufferEnd)
			{
				USHORT depth = <a href="http://msdn.microsoft.com/en-us/library/nuiimagecamera.nuidepthpixeltodepth.aspx">NuiDepthPixelToDepth</a>(*depthBufferRun);

				BYTE intensity = 256 - static_cast&lt;BYTE&gt;(((float)depth / DEPTH_THRESH) * 256.);

				x = count % WIDTH;
				y = floor((float)count / (float)WIDTH);

				mCVImageDepth.at&lt;uchar&gt;(y, x) = intensity;

				LONG colorInDepthX;
				LONG colorInDepthY;

				mNuiSensor-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuiimagecamera.nuiimagegetcolorpixelcoordinatesfromdepthpixel">NuiImageGetColorPixelCoordinatesFromDepthPixel</a>(NUI_IMAGE_RESOLUTION_640x480, NULL, x/2, y/2, *depthBufferRun, &#038;colorInDepthX, &#038;colorInDepthY);

				if(colorInDepthX &gt;=0 &#038;&#038; colorInDepthX &lt; WIDTH &#038;&#038; colorInDepthY &gt;=0 &#038;&#038; colorInDepthY &lt; HEIGHT)
				{
					<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd162938(v=vs.85).aspx">RGBQUAD</a> &#038;color = mRGB[colorInDepthX + colorInDepthY * WIDTH];
					LONG colorIndex = colorInDepthX + colorInDepthY * WIDTH * 3;
					mCVImageColorDepth.at&lt;Vec3b&gt;(y, x) = Vec3b(color.rgbBlue, color.rgbGreen, color.rgbRed);
				} else {
					mCVImageColorDepth.at&lt;Vec3b&gt;(y, x) = Vec3b(0, 0, 0);
				}

				<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd162938(v=vs.85).aspx">RGBQUAD</a> &#038;color = mRGB[count];
				mCVImageColor.at&lt;Vec3b&gt;(y, x) = Vec3b(color.rgbBlue, color.rgbGreen, color.rgbRed);

				count++;
				depthBufferRun++;
			}
		}

		depthTex-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuiframetexture.unlockrect.aspx">UnlockRect</a>(0);
		colorTex-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuisensor.inuiframetexture.unlockrect.aspx">UnlockRect</a>(0);
		mNuiSensor-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuiimagecamera.nuiimagestreamreleaseframe.aspx">NuiImageStreamReleaseFrame</a>(mDepthStreamHandle, &#038;depthFrame);
		mNuiSensor-&gt;<a href="http://msdn.microsoft.com/en-us/library/nuiimagecamera.nuiimagestreamreleaseframe.aspx">NuiImageStreamReleaseFrame</a>(mColorStreamHandle, &#038;colorFrame);
	}

	~DepthSensor()
	{
		if(mNuiSensor)
			mNuiSensor-&gt;NuiShutdown();
	}
};
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rozengain.com/blog/2012/08/01/using-opencv-2-with-kinect-sdk-1-5/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Rajawali Tutorial 24: Using Geometry Data To Position And Rotate Objects</title>
		<link>http://www.rozengain.com/blog/2012/05/30/rajawali-tutorial-24-using-geometry-data-to-position-and-rotate-objects/</link>
		<comments>http://www.rozengain.com/blog/2012/05/30/rajawali-tutorial-24-using-geometry-data-to-position-and-rotate-objects/#comments</comments>
		<pubDate>Wed, 30 May 2012 16:49:46 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Rajawali]]></category>
		<category><![CDATA[OpenGL ES]]></category>

		<guid isPermaLink="false">http://www.rozengain.com/blog/?p=1042</guid>
		<description><![CDATA[This tutorial has moved to the Rajawali Wiki.]]></description>
			<content:encoded><![CDATA[<p>This tutorial has moved to the <a href="https://github.com/MasDennis/Rajawali/wiki/Tutorial-24-Using-Geometry-Data-To-Position-And-Rotate-Objects">Rajawali Wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rozengain.com/blog/2012/05/30/rajawali-tutorial-24-using-geometry-data-to-position-and-rotate-objects/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Rajawali Tutorial 23: Custom Vertex Shader</title>
		<link>http://www.rozengain.com/blog/2012/05/16/rajawali-tutorial-23-custom-vertex-shader/</link>
		<comments>http://www.rozengain.com/blog/2012/05/16/rajawali-tutorial-23-custom-vertex-shader/#comments</comments>
		<pubDate>Wed, 16 May 2012 14:54:23 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Rajawali]]></category>
		<category><![CDATA[GLSL]]></category>
		<category><![CDATA[OpenGL ES]]></category>

		<guid isPermaLink="false">http://www.rozengain.com/blog/?p=1022</guid>
		<description><![CDATA[This tutorial has moved to the Rajawali Wiki.]]></description>
			<content:encoded><![CDATA[<p>This tutorial has moved to the <a href="https://github.com/MasDennis/Rajawali/wiki/Tutorial-23-Custom-Vertex-Shader">Rajawali Wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rozengain.com/blog/2012/05/16/rajawali-tutorial-23-custom-vertex-shader/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Microsoft Kinect SDK Wrapper For Unity Crash Bug Fix</title>
		<link>http://www.rozengain.com/blog/2012/05/10/microsoft-kinect-sdk-wrapper-for-unity-crash-bug-fix/</link>
		<comments>http://www.rozengain.com/blog/2012/05/10/microsoft-kinect-sdk-wrapper-for-unity-crash-bug-fix/#comments</comments>
		<pubDate>Thu, 10 May 2012 10:50:06 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Kinect]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://www.rozengain.com/blog/?p=979</guid>
		<description><![CDATA[There&#8217;s a great free Kinect SDK wrapper available for Unity. It&#8217;s free &#38; open source but there are still a few problems getting it to run with the 1.0 SDK (as opposed to the beta). The first problem is that it is pointing to the wrong dll file. When you get this exception: DllNotFoundException: C:\Program [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a great <a title="Microsoft SDK Wrapper for Unity" href="https://channel9.msdn.com/coding4fun/kinect/Unity-and-the-Kinect-SDK">free Kinect SDK wrapper available for Unity</a>. It&#8217;s free &amp; open source but there are still a few problems getting it to run with the 1.0 SDK (as opposed to the beta).</p>
<p>The first problem is that it is pointing to the wrong dll file. When you get this exception:</p>
<pre><code>DllNotFoundException: C:\Program Files (x86)\Microsoft Research KinectSDK\MSRKINECTNUI.DLL</code></pre>
<p>You should open the file <em>KinectInterop.cs</em> and changes all dll paths to:</p>
<pre><code>C:\Windows\System32\Kinect10.dll</code></pre>
<p>This will fix all compiler errors and it should run without problems.</p>
<p>However, it will only run once. When you run it the second time Unity will freeze and you will have to kill the process. Not very convenient.</p>
<p>This is caused by a bug in the Microsoft SDK. According to <a href="http://www.microsoft.com/en-us/kinectforwindows/develop/release-notes.aspx#_6._known_issues">this page</a> the problem is:</p>
<pre><code>If C++ code is executing NuiInitializa/NuiShutdown multiple times through
the application's lifetime, SetDeviceStatusCallback should be called once,
before invoking those calls.
</code></pre>
<p>So apparently a single call to <em>SetDeviceStatusCallback()</em> should fix the problem. To be able to call this method we need to add some code to the <em>KinectInterop.cs</em> file. First of all we need to add an empty struct:</p>
<pre><code>public struct NuiStatusProc
{
}
</code></pre>
<p>Then we need to link the native method. In the NativeMethods class add:</p>
<pre><code>
[DllImportAttribute(@"C:\Windows\System32\Kinect10.dll", EntryPoint = "NuiSetDeviceStatusCallback")]
	    public static extern void NuiSetDeviceStatusCallback(NuiStatusProc callback);
</code></pre>
<p>Now open the file <em>KinectSensor.cs</em> and add this line to the <em>void Awake()</em> method (just before the line &#8220;catch (Exception e)&#8221;):</p>
<pre><code>
NativeMethods.NuiSetDeviceStatusCallback(new NuiStatusProc());
</code></pre>
<p>Now everything should run fine. If it doesn&#8217;t let me know :O</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rozengain.com/blog/2012/05/10/microsoft-kinect-sdk-wrapper-for-unity-crash-bug-fix/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Rajawali Tutorial 22: More Optimisation</title>
		<link>http://www.rozengain.com/blog/2012/05/03/rajawali-tutorial-22-more-optimisation/</link>
		<comments>http://www.rozengain.com/blog/2012/05/03/rajawali-tutorial-22-more-optimisation/#comments</comments>
		<pubDate>Thu, 03 May 2012 08:21:11 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Rajawali]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[OpenGL ES]]></category>

		<guid isPermaLink="false">http://www.rozengain.com/blog/?p=974</guid>
		<description><![CDATA[This tutorial has moved to the Rajawali Wiki.]]></description>
			<content:encoded><![CDATA[<p>This tutorial has moved to the <a href="https://github.com/MasDennis/Rajawali/wiki/Tutorial-22-More-Optimisation">Rajawali Wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rozengain.com/blog/2012/05/03/rajawali-tutorial-22-more-optimisation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rajawali Tutorial 21: Fog</title>
		<link>http://www.rozengain.com/blog/2012/05/02/rajawali-tutorial-21-fog/</link>
		<comments>http://www.rozengain.com/blog/2012/05/02/rajawali-tutorial-21-fog/#comments</comments>
		<pubDate>Wed, 02 May 2012 06:59:02 +0000</pubDate>
		<dc:creator>Dennis</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Rajawali]]></category>
		<category><![CDATA[Fog]]></category>
		<category><![CDATA[OpenGL ES]]></category>

		<guid isPermaLink="false">http://www.rozengain.com/blog/?p=961</guid>
		<description><![CDATA[This tutorial has moved to the Rajawali Wiki.]]></description>
			<content:encoded><![CDATA[<p>This tutorial has moved to the <a href="https://github.com/MasDennis/Rajawali/wiki/Tutorial-21-Fog">Rajawali Wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rozengain.com/blog/2012/05/02/rajawali-tutorial-21-fog/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
