Freeing the Kinect

Xbox Kinect using Libfreenect

This page is for documentation of libfreenect.

TO DO

  • Installation
  • get machine
  • install fedora
  • install libfreenect (document this)
  • libfreenect
  • options to only output .pgm data
  • options to record a frame at less than 30 fps
  • conversion to .txt files
  • python script for raw conversion (needs lots of work)
  • delete last .pgm file in case of corruption
  • tar the files up
    • only need the .txt converted data
    • datafiles.txt -> file with names of data files
  • mathematica: {time, x, y, z}
  • get the list of files from datafiles.txt
  • for a single file:
    • extract the time from the filename
    • use a module for getting the x,y,z data
  • append the data to a list
  • write the list to file for use later
  • make a python gui that takes the data and saves the .zip file
  • file name (only saves to desktop)
  • frequency of capture
  • status bar
  • start stop

=====Installation ===== First install CentOS6. update and turn off selinux/firewall.

Install EPEL.

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm</code>

Then do the following: adopted from here.

sudo yum install git cmake gcc gcc-c++ libXi libXi-devel libXmu libXmu-devel freeglut freeglut-devel libusb1-devel ImageMagick ffmpeg

cd /tmp
mkdir kinect
cd kinect

git clone git://github.com/OpenKinect/libfreenect.git
cd libfreenect
mkdir build
cd build
ccmake ..

Inside the ccmake editor, press c to configure
Using the arrow keys, move to line with LIBUSB_1_INCLUDE_DIR
Press enter to edit the line, then change it to /usr/include/libusb-1.0
Press enter when finished editing
Press g to generate and exit

cmake ..
make
sudo make install

Next you have to add the user that will run the executables to the video group in /etc/group. Then add the following to /etc/udev/rules.d/66-kinect.rules

#Rules for Kinect ####################################################
SYSFS{idVendor}=="045e", SYSFS{idProduct}=="02ae", MODE="0660",GROUP="video"
SYSFS{idVendor}=="045e", SYSFS{idProduct}=="02ad", MODE="0660",GROUP="video"
SYSFS{idVendor}=="045e", SYSFS{idProduct}=="02b0", MODE="0660",GROUP="video"
### END #############################################################

Now there will be a set of binaries in /tmp/kinect/libfreenect/build/bin. Execute glview and make sure it is working correctly. You should see a video of the RGB and the depth.

cd /tmp/kinect/libfreenect/build/bin
sudo ./glview

Once this is known to work you have to edit some source code to get the binaries to only output the infrared file. The reason to do this is to have a lower amount of transfered data through the USB bus and thus avoid saturation. In order to do this you have to rebuild the libfreenect packages for record. redownload the git repository and edit the file kinect/libfreenect/fakenect/record.c. You want to comment out all of the body of the functions "snapshot_accel" and "rgb.cb". Now make the packages as above and the record binary will only save the pgm (depth) data.

Converting the pgm's to data files

#!/usr/bin/python

import numpy
from subprocess import Popen, PIPE
import time

start = time.clock()
#list folder contents and save output to the list lsall
ls = Popen(["ls"], stdout=PIPE)
lsall = ls.communicate()[0].decode("utf-8").split()

#search through lsall and make a new list of enteries with "pgm" in the name
#exits if no file with that name is in the folder
pgmlist=[] # make lis to store search results
for i in range(len(lsall)):
  if lsall[i].find("pgm") != -1: #TODO: should test for .pgm extension
    pgmlist.append(lsall[i])
if len(pgmlist)==0: # exception: pgm not found exits
  print("No PGM files found. Exiting!")
  exit() #TODO make this a real exception
pgmlist.pop()

# do the actual conversion of the pgm to numbers (0-2047)
filelist = open("filelist","w") #file stores a list of generated data files
for i in range(len(pgmlist)):
  filename=pgmlist[i]
  with open(filename, 'r') as infile:
    header = infile.readline()
    width, height, maxval = [int(item) for item in header.split()[1:]]
    image = numpy.fromfile(infile, dtype=numpy.uint16).reshape((height, width))
  numpy.savetxt(pgmlist[i][:-4]+".csv",image,fmt='%d , ')
  filelist.write(pgmlist[i][:-4]+".csv \n")
  print ("file: %s -> %s" %(pgmlist[i],pgmlist[i][:-4]+".csv"))
filelist.close()

stop=time.clock()
print ("conversion time (seconds): %f " %(stop-start))

Using a mac to convert the pgm's

  • move the pgm files to a folder on the local machine
  • copy the above script into the above folder (pgmconvert.py)
  • run "/usr/bin/python PortableGrayMapConvert.py" in the above folder using a terminal