Get Depth Pixels from ofxMSKinect into ofxOpenCv in 007

Hello all openF-Forum
I’m trying out this ofxMSKinect on a project I had some time ago that used the old ofxKinect in order to get the Depth Pixels into ofxOpenCv. It used to work like this:

grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);  

…but I cannot seem to get ofxMSKinect and ofxOpenCV working in 007 using the following code:


I get this:
[tt]OF: OF_LOG_ERROR: in setFromPixels, size mismatch[/tt]

I’m not sure about the size mismatch but I set both resolutions to 320x240.
Any help would be greatly appreciated! :smiley:

1.- I managed to get the depth data into a ofTexture, can that texture be sent to openCV as an ofxCvColorImage? How?

2.- I tried ofPixels but it tells me “Format is not supported”

3.- I tried ofImage and I think I got the same “Format is not supported”.

nothing? :frowning:
Please help, I don’t understand why I get Format not supported and the ofxMSKinect mentions that it does support depth to video ( )
Feature list:
4. transform depth to video[/tt]

I managed to get the depth data onto an ofTexture, now how can I get that onto an openCV ofxCvColorImage? xD
setFromPixels is not made for this now is it?

if you have a ‘size mismatch’ it’s probably because it’s 640x480, not 320x240

if you have ‘format not supported’ it might be because the raw ofxmskinect depth is unsigned short rather than unsigned byte, which would mean you need to use an ofShortPixels instead of ofPixels.

if you want to get data from an ofTexture to an ofPixels you need to use ofTexture::loadData() to set some ofPixels.

but i’m still not sure exactly what you’re trying to do, the more code you can post, the better.

Sure, I will upload the code. It is just ofxOpenCv blob detection using ofxMSKinect depth image as source, that is to say… a mix of two examples you guys already have, nothing too fancy.
It used to work without the Kinect SDK or ofxMSKinect but I wanted to try it out now.

I will rewrite the code from scratch just in case I made a big mistake.

Here it is and as simple as I mentioned.
I use Visual C++ 2010 Express in Windows x64, I get no error when compiling but you can see that in the attached image the code is not working. When I used the old ofxKinect it never failed.
This time I get no format or size errors in the console and I used this:

colorImg.setFromPixels(firstDevice->GetDepthPixels(), 320,240);  

May I also ask how I can get the old depth grey gradient? All the colors may be discared later by openCV but I don’t want to add distortion to analysis.<–I’m not sure that happens.
Thank you Kyle!

Correction… Why do I get no depth gradients at all? :frowning:

Would there be any newer comments about this? I really wouldn’t know where to start fixing this. =D

i downloaded and looked through your code. my feeling is that these problems stem from trying to work with the kinect at 320x240. pretty much everyone uses 640x480, and 320x240 isn’t as rigorously tested.

right now you’re kind of mixing 320x240 and 640x480. i would switch all of your code to using 640x480 only, and see what happens.

also, try using GetofDepthPixels() instead of GetDepthPixels(). GetofDepthPixels() will return an ofPixels instead of an unsigned char*, so it should be formatted correctly already.

i would switch all of your code to using 640x480 only, and see what happens

Well, I had avoided that since this is what ofxMSKinect says in the code:

// default depth resolution is 320x240  
isOk = firstDevice->StartDepth(IMAGE_RESOLUTION_320x240);  

But I followed your advice. First I set everything to 640x480 with GetDepthPixels() and instead of the depth camera I get a black window.Then…

also, try using GetofDepthPixels() instead of GetDepthPixels(). GetofDepthPixels() will return an ofPixels instead of an unsigned char*, so it should be formatted correctly already.

I don’t know how to do this and I’d like to learn more about it. Could you explain a bit more of how one could manage this?
Thank you for your time Kyle.

the comment that says “default depth resolution is 320x240” is just about the way the MS SDK example is set up. it doesn’t have anything to do with the kinect defaults, and there’s no reason you have to use it unless you really want to.

to use GetofDepthPixels(), you can just say:

colorImg = firstDevice->GetofDepthPixels();  

and don’t forget the update(), otherwise the pixels will update but not the texture for drawing.

I’m sorry… I’m not getting it.
I’ll set everything to 640x480, but I cannot get it to work now, so I’d like to review the process.
1.-In the *.h file declare:

ofPixels 				colorImgTemp;  
ofxCvColorImage			colorImg;  

2.-In the setup() put:


3.-In the update() put the following:

colorImgTemp = firstDevice->GetofDepthPixels();  

The problem I have now is " ‘update’ : is not a member of 'ofPixels_ " so it won’t let me compile.

sorry, i forgot that colorImgTemp is ofPixels, i thought it was an ofImage.

in this case, you need to update the colorImg, not colorImgTemp.

except ofxOpenCv does not use the OF style of “update()”. so replace this line:


with this:


no luck! :frowning:

What I did learn is the firstDevice->DrawDepthTexture will only draw depth if the resolution is set to 320x240, otherwise it just displays a black screen (I double checked).

Having changed every single resolution to 320x240 I did what you told me to do but I got the exact same result as the previous post I made with the attached image.

I’d like to be able to solve this problem myself but everything does seem to be correct and I get no compilation errors.

hmm i can’t help you at this point because i don’t have access to a windows machine running ofxMSKinect. my suggestion is to post on the original ofxMSKinect thread, or message the creator of the addon.

Will do. Thank you. ;D

Hi irregular,

have you find a solution for your issue?
i’m facing a similar problem when trying to play around with the depth and display it on a ofxgrayscaleimage…



Hello laton

I haven’t found a solution to the problem. Following kylemcdonald’s suggestion I posted the issue here:

It has been there for a since the 15th of December.

Thanks for your reply,

it seems also that issue#1 was related to almost the same issue:

BTW, have a look to this thread