Showing posts with label openni. Show all posts
Showing posts with label openni. Show all posts

Friday, 4 November 2011

OpenNI updates

Recently I updated the OpenNI library to version 1.3.4.3 in the unstable branch, but playing from recorded files doesn't work after that. Then I switch back to  the latest version (1.3.3.6) in the master branch which works for playing recorded files.


The OpenNI developers are not very responsive to pull requests. In particular, the bug that I mentioned in the earlier post that is related to the wrong use of memcpy has not been fixed. So I forked the project and added the fix. I also added a method copyToBuffer to wrapper/OpenNI.java/src/org/OpenNI/Map.java so that we only need to allocate the buffer for the depth or image map once.

Wednesday, 26 October 2011

Using Kinect with OpenNI on Ubuntu 11.10

I recently upgraded to Ubuntu 11.10 and then my Kinect stopped working. I'm using OpenNI library for getting data from the Kinect.

At the beginning, when I ran the sample program NiViewer from the OpenNI libaray, I got the following error:

Open failed: failed to set USB interface.

I found the solution on OpenNI Google group discussion. You need to remove the gspca_kinect kernel module that comes with the upgrade by doing:
rmmod gspca_kinect
It seems to work even though it says "cann't find the module gspca_kinect". However, every time you restart the computer or replugin the Kinect USB, the module will be loaded again. To permanently remove the module, you can change the name of the module file:
sudo mv /lib/modules/3.0.0-12-generic/kernel/drivers/media/video/gspca/
gspca_kinect.ko /lib/modules/3.0.0-12-generic/kernel/drivers/media/video/gspca/gspca_kinect.ko.BAK

A better way may be blacklisting the module as suggested by this post. In this way, even after a kernel upgrade, the module will not be loaded.
$sudo gedit /etc/modprobe.d/blacklist.conf
Then add the following line to the end of the file and reboot:
blacklist gspcs_kinect

After this, the program could run, but I only got the RGB image data and the depth image was blank. Someone find out that this is due to the wrong use of memcpy in the OpenNI library. The line of code that causes the problem is in "/Source/OpenNI/Linux-x86/XnUSBLinux-x86.cpp" function "XN_THREAD_PROC xnUSBReadThreadMain(XN_THREAD_PARAM pThreadParam)" around line 1057. Instead of using memcpy, it should be:
memmove(pTransfer->buffer + nTotalBytes, pBuffer, pPacket->actual_length);
The difference between memcpy and memmove is that with memcpy, the destination cannot overlap the source at all, while with memmove, it can. For example, memcpy might always copy addresses from low to high. If the destination overlaps after the source, this means some addresses will be overwritten before copied. memmove would detect this and copy in the other direction - from high to low - in this case. However, checking this and switching to another (possibly less efficient) algorithm takes time.

The previous version of memcpy in libc6 may not make the difference so distinct, but in the new updated version of libc6 version 2.13, it might copy memory backward in some conditions, which causes issues if the source and destination overlap. You can read more about the changes in the new version in "/usr/share/doc/libc6/NEWS.Debian.gz".

Tuesday, 20 September 2011

NiViewer


Today I ran NiViewer provided by OpenNI again on Captured_08_22_11.oni, and observed vertical lines on the depth image. The vertical lines also shift with time.

The default coloring of the depth image is according to linear histogram. MAX_DEPTH is set to be 10000. The histogram is calculated according the following steps (in Draw.cpp, line 549, calculateHistogram()):
  - Count the number of pixels with the same depth_value and store it in depthHist[depth_value].
  - Calculate the accumulative frequency.
  - Invert the accumulative frequency.

In this way, pixels with greater depth values will have darker color. The use of histogram is good because the color is not scaled linearly with depth but with the frequency of the occurrences of the depth values.