xxorde / librekinect

Depth data from a kinect sensor! Small and fast kernel driver. Also for embedded devices like the raspberry pi!
407 stars 68 forks source link

Already can get depth image from kinect on PC,but I've met problems on Raspberry Pi with the same code #22

Open lucyking opened 9 years ago

lucyking commented 9 years ago

I've tried months to get the depth data from Kinect. Thinks to Alexander's pretty driver, now we can get the Y10B image just using fopen() && fread() to read /dev/vedio0. here is my code,with OpenCV + librekinect everything goes well on PC:>the screenshot<.

But, I've met problems on Raspberry PI. when I run the binarry built from the same code , the program can not open the Kinect or get the data instantlly. though the program still can get the data,but the data format is wrong,which just are broken fragments from one or two depth frames. In my opinion is due to Raspberry Pi's poor hardware,because when we use Camorama open the Kinect with this librekinect drive, the vedio have a short time-delay. May the camorama use Gtk's buffer to avoid above problem, but I wanna use Kinect with Raspberry in embedded environment without monito so do somebody have good ideas about how to correct my code or other meanings to get the depth frame data fluencily? I am a beginner to Kinect, feel free to disscuss this problem with me && great to hear your suggestions :-)

TimboInSpace commented 9 years ago

Yeah it's something about the raspberry pi. I had the exact same issue. What fixed it for me was uninstalling OpenCV that was installed from binary. Downloaded source, modified it so it will open Y10B by default, then installed from that source. You may be running into the same issue that openCV fails to detect encoding properly when opening up the stream, and as such defaults to wrong encoding, so you don't get full frames. Your code looks much more slick than mine, I'll try running it on my setup (which includes the above fix) and see if I get an image.

TimboInSpace commented 9 years ago

I tried out your code on my Raspberry Pi. It compiled and ran fine, but I experienced the same errors that you were. The images looked like mostly white noise, but there were strips of portions of valid depth image frames mixed in. These strips were often quite distorted. I'm not sure the source of your issues, but it looks like the depth image has only been partially written... some kind of buffer might be required.

My code is far from perfect, but it does run reliably on a raspberry pi: https://github.com/TimboInSpace/Armin/blob/master/kinect_depthimage.cpp

lucyking commented 9 years ago

I know why the valid depth image frames distorted is that Raspberry Pi do not get the whole frame at once,but often time-delay(as you say, it may need a buffer) that make the Y10B not in right format .

My code using fopen() read the Y10B date from Raspberry Pi first, then use OpenCV just a tool to trans the Y10B to RGB picture. If you'd like,we can fopen /dev/video0 straightly and get the raw Y10B without RGB picture(just comment these codes related to OpenCV).Why we use OpenCV to generate RGB frame from Y10B is just try to certify the depth data we got is right or not.

your code seems using OpenCV's official API and very concise. Great to hear that your code works well,then as you say that you've modified && reinstall the OpenCV source,then may you show me that which && how the particular source should be modified? ;-)