Thursday, February 4, 2016

Installing CUDA + compiling Infinitam

This post describes how to install and compile Infinitam. A prerequisite for this is to install CUDA (this is also shown here).

Install CUDA
  • I have installed CUDA 8.0.44 (download here)
  • CUDA proposes different ways of installation
    • A .run file, and a .deb file
    • I am currently using the .run file
    • Follow the steps in the install guide with great care (as the CUDA install can be very tricky)
  • After this the CUDA samples and Infinitam compile fine

Install Infinitam
  • Clone Infinitam from here
  • Follow the steps from the on github
    • From the created build folder  
             cmake ../InfiniTAM -DOPEN_NI_ROOT=/home/arennuit/Tools/AsusXtion/OpenNI2/
    • If cmake complains about missing GLUT libraries (GLUT_Xi_LIBRARY and GLUT_Xmu_LIBRARY) 
             sudo apt-get install libxmu-dev libxi-dev  (more info here)
  • At this point use ccmake check that cmake is pointing to the right version of OpenNI (which should be OpenNI2)
    • ccmake ../InfiniTAM
    • press 't' to toggle to the advatnced mode
    • check cmake variables OpenNI_LIBRARY (there are 3 OpenNI variables)
    • cmake has a tendency to choose old OpenNI 1 path in /usr/lib or /usr/local/lib (the error is described here)
    • change the value of OpenNI_LIBRARY to where it should point to /home/arennuit/Tools/AsusXtion/OpenNI2/Bin/x64-Release/ 
    • configure with 'c' and regenerate with 'g'
    • run cmake ../InfiniTAM
  • make
  • test using sudo ./Infinitam
    • without sudo we get Warning: USB events thread - failed to set priority. This might cause loss of data
    • sudo is required to set the USB async priority thread to critical (more details here)
  • Also it can happen that the camera is not detected
    • we get cout messages stalling at trying OpenNI device: <OpenNI default device>
    • or at OpenNI: Initialization ...
    • and ctrl+c may not work
    • in this case change USB port and restart (from a new terminal?)

NOTE: in my situation (but it seems to only occur in some specific configurations) there is a USB bandwidth problem. Even though the RGB data is not used in the registration it is streamed over USB. And in some configurations the USB is a bottleneck.
A workaround is to ask for a reduced resolution RGB image. This can be done by modifying the constructor in file InfiniTAM/InfiniTAM/Engine/OpenNIEngine.h and replacing
imageSize_rgb = Vector2i(640, 480) by imageSize_rgb = Vector2i(320, 240). More details in this issue.

Thursday, January 14, 2016

Installing Asus Xtion (on Ubuntu 14.04)

As of writing these lines (14/01/2016), the PrimeSense / Asus Xtion is a rather old device now. It has not really found its equivalent as a standard in depth sensing though and is still very much the standard in depth-based dev (i.e. SLAM...). Because of this we will show you some steps which have worked for us to install an Asus Xtion on a Gigabyte P34 laptop running Ubuntu 14.04.5 (also tested with 14.04.2).

Let's first start by stating that it takes a few seconds to set-up when you know the steps to follow but it takes hours to get to know which steps are relevant (in jungle of possible problems found on the Internet.

The painful symptom is that whatever you do, the device is not found:
  • The error output is:
After initialization:
SimpleViewer: Device open failed:
DeviceOpen using default: no devices found

  • Despite ASUS being listed when using lsusb
  • And despite the device being recognized when plugging it and running dmesg

What was tested and does NOT work (device not found):
  • Installing the OpenNI 2 binaries from the Structure website
    • The solution uses OpenNI 2 but recompiled 
  •  Recompiling the primesense driver from github/primesense
    • It is still available
    • There were 2 errors during the compilation (XnOS.h is not found and when I look at it from the source, it is only present in the PSCommon folder, which does not look right... There is also a 2nd error...)
  • A lot of posts on the web refer to using the Asus Xtion with ROS
    • These advices are irrelevant to our case that do not include ROS
  • Installing libfreenect and OpenNI2-FreenectDriver from OpenKinect 
    • These are for the Kinect (v1), not for the Asus Xtion 

Uncertain steps (we have no idea whether they had an influence):
  • We have updated the firmware
    • This operation has to be done on windows
    • The Firmware update is provided on the Asus website (windows section)
    • The device was of type 0600 before the firmware update and 0601 after (use lsusb to check)
  • Under windows the device only works if the XHCI mode is disabled in the BIOS
    • Not sure about this (I have not re-enabled the XHCI mode)
    • In a general way there seem to be problems with using the device on a USB 3 port. Disabling XHCI transforms USB 3 ports in USB 2
    • Some more explanations here

What has worked:
  • In folder Tools, create folder AsusXtion/Sensor
  • Installing the Linux drivers & SDK binaries from the Asus website
    • The version to download comes from the linux platform (not the Ubuntu platform)
    • This file contains a folder SDK, which itself contains a Linux_x64_20.2.0.rar file. Unrar this file (the unrar package need to be installed) and copy the content of archive Sensor_Bin_Linux64_v5.0.2.3.tar.bz2 into folder Tools/AsusXtion/Sensor
    • Then I have called script sudo ./install
      • It outputs a log error: niReg is not found, at line 50, and you should not mind about this error message
    • OpenNI + NITE (nothing to do for these - we do not use them)
      • The OpenNI and NITE version provided by Asus in where not used
      • Asus also propose another version of the OpenNI package (v20.4.2.20) which I have not tested
  • Recompiling OpenNI 2 from occipital the Structure website
    • The sources are here in github/occipital
      • Les cloner dans Tools/AsusXtion
    • Use branch develop
    • There are few dependencies to install 
      • Suivre les indications du
      • Among them the java dev kit (jdk)
        • Otherwise it gives (hardly noticeable) errors
        • Type javac in a terminal to know if it is installed
    • make 
      • From Tools/asusXtion/OpenNI2
      • make
    • install 
      • From folder Tools/asusXtion/OpenNI2/Packaging/Linux
      • sudo ./install  
  • Tester avec NiViewer:
    • cd Tools/AsusXtion/OpenNI2/Bin/x64_Release
    • ./NiViewer
    • I had to wait a bit after the compilation / install of OpenNI2 for the system to work, I have also plugged / unplugged a few times... 

  • Because they are so important to us:
    • Archive was saved into the dev folder of our google drive
    • Repo was forked in our github

Useful links: