Tag: ubuntu (page 1 of 2)

Getting up and running with the Kinect in Ubuntu 12.04

I’m currently experimenting a bit with the Kinect depth camera, which I intend to use for a prototype. I’ve played around with the device before on Windows using the Microsoft Kinect SDK. Setting up libfreenect on Windows is actually quite a pain, which was the reason why I started with the Microsoft SDK. As I wanted to code in Python, I’ve had a look at PyKinect and the Python Tools for Visual Studio (see also this PyCon US 2012 talk about building a Kinect game with Python). Unfortunately, the PyKinect samples seem to be outdated, and don’t work with the latest version of the Kinect SDK (version 1.0, released in February).

So I decided to see how far I would get with the Kinect and libfreenect on Ubuntu (12.04). Step 1: install the libfreenect demos to test if it works (this will also install libfreenect and its dependencies).

$ sudo apt-get install libfreenect-demos

So far so good. Unfortunately, the demo application wouldn’t start:

$ freenect-glview 
Kinect camera test
Number of devices found: 1
Could not claim interface on camera: -6
Could not open device

Strange.. I did another check to see if my user was in the plugdev group (which
was the case):

$ groups jo
jo : jo adm cdrom sudo dip plugdev lpadmin sambashare

Then I noticed that the Kinect’s LED kept blinking continously, which usually means there’s some sort of connection problem. It was correctly recognized, though:

$ lsusb
...
Bus 002 Device 007: ID 045e:02b0 Microsoft Corp. Xbox NUI Motor
Bus 002 Device 008: ID 045e:02ad Microsoft Corp. Xbox NUI Audio
Bus 002 Device 009: ID 045e:02ae Microsoft Corp. Xbox NUI Camera

After a quick web search for the specific libfreenect-glview error message, I learned that recent versions of the Linux kernel prevent libfreenect from claiming the Kinect as they now include a driver to support the device as a regular webcam (see kinect.c), which is actually quite cool. This also means there should be a specific video device for the Kinect (/dev/video1 in my case).

The kernel modules are indeed loaded:

$ lsmod | grep -i gspca
gspca_kinect           12936  0
gspca_main             28366  1 gspca_kinect
videodev               98259  2 gspca_main,uvcvideo 

Let’s try playing the camera stream using GStreamer and Video4Linux:

$ gst-launch-0.10 v4l2src device=/dev/video1 ! video/x-raw-yuv ! ffmpegcolorspace ! xvimagesink

That seems to work!

The Kinect actually has two image sensors: an RGB camera and a depth sensor, which consists of an infrared laser projector and a monochrome CMOS sensor. A depth map is created by projecting structured infrared light and capturing the resulting image from the monochrome sensor. As I wasn’t sure how to grab an image from the monochrome sensor, I contacted the author of the kernel module (Antonio Ospite). He told me it’s possible to get a monochrome image by specifying an image size of of 640×488 pixels (instead of the usual 640×480). Note that the kernel module currently only supports video streams from the monochrome sensor as unprocessed output.

If we pass that specific width and height to GStreamer, we get this:

It’s also possible to get the full-size (1280×1024) monochrome image. However, most webcam apps will just show the video stream from the RGB sensor for that resolution as you can’t specify that you want the specific Y10B format. To do that, you can use a separate program like qv4l2, which can be installed as follows:

$ sudo apt-get install qv4l2

To get the full-size monochrome image, run qv4l2, open the /dev/video1 device in raw mode (File > Open raw device), select 1280×1024 for the frame size, and “Y10B – Y10B” for the capture format, and click the red capture button:

OK, back to running the libfreenect demo. Someone over at superuser.com suggested to remove the modules (so that the user-mode libfreenect driver could
take over) and run libfreenect-glview again.

And indeed, after removing both gspca modules, the freenect-glview demo did work:

$ sudo modprobe -r gspca_kinect 
$ sudo modprobe -r gspca_main
$ freenect-glview 
Kinect camera test
Number of devices found: 1
GL thread
Write Reg 0x0006 <= 0x00
Write Reg 0x0012 <= 0x03
Write Reg 0x0013 <= 0x01
Write Reg 0x0014 <= 0x1e
Write Reg 0x0006 <= 0x02
Write Reg 0x0005 <= 0x00
Write Reg 0x000c <= 0x00
Write Reg 0x000d <= 0x01
Write Reg 0x000e <= 0x1e
Write Reg 0x0005 <= 0x01
...

The left side of the window shows a colored depth image, while the right side shows the RGB image from the camera. Of course, it would be quite cumbersome to remove the modules again every time you want to use libfreenect. One option is to blacklist the gspca module as follows:

$ echo "blacklist gspca_kinect" >> /etc/modprobe.d/blacklist.conf

Now that we've got that sorted out, I'll try out the libfreenect Python wrapper (or perhaps SimpleCV).

Update: Antonio Ospite pointed out in the comments that recent versions of libfreenect (0.1.2) can automatically detach the kernel driver. There's a PPA available by Florian Echtler with updated libfreenect packages for Ubuntu 12.04.

Lenovo ThinkPad X121e

I am writing this on my new laptop: a Lenovo ThinkPad X121e:

Although my employer is so generous to provide me with a laptop for work purposes, I also wanted a new laptop at home for personal use. My only personal machine right now is my aging (and quite slow) 17 inch Apple Powerbook G4. Since most Apple software currently requires Intel processors, I can’t really upgrade it either. I also wanted something a bit more portable (no heavy, bulky 15-incher) with better battery life, which would be great for travelling.

While my work laptop runs Windows 7, I really miss having a UNIX environment available at times. I worked almost exclusively on Linux since 2003, starting out with Mandrake, moving from that to Gentoo and then to Debian to eventually settle on Ubuntu. A few years ago, I decided to move back to Windows due to bad hardware support on Linux (especially for newer laptops) and annoying bugs in Ubuntu. Nevertheless, I still prefer a UNIX environment for programming, and I love the power of the shell and how you can quickly chain commands together to produce something useful.

At first, I was thinking of just getting a new Apple laptop. Indeed, OS X is also based on UNIX but does have great hardware support and a nice UI. Furthermore, Apple builds high-quality hardware (I loved my Powerbook), and they sell the ultimate ultraportable laptop: the Macbook Air.

Unfortunately, I quickly discarded that idea when I realized again how expensive Apple laptops are. I didn’t really feel like shelling out about 1200 EUR just to get a Macbook Air with a decent amount of RAM and an SSD bigger than 64 GB. So I started looking around for cheaper alternatives. Instead of complaining about Ubuntu not supporting certain hardware, I decided to look for hardware that would Just Work (TM) on Ubuntu. There are also some things I didn’t like that much on OS X, such as the lack of a well-integrated package manager. At FOSDEM, I remember seeing most developers work on either Apple machines or IBM (now Lenovo) ThinkPads. Some people even used to say that Apple and IBM ThinkPad laptops are the only laptops really worth considering. ThinkPads also come in an ultraportable X series, which I thought was worth looking into.

While the professional ThinkPad X series laptops are again quite expensive, Lenovo also has entry-level models, such as the X100e, X120e or the X121e. These models come with either an AMD Fusion or an Intel Core i3 processor. The nice thing about the Intel model of the X121e is the fact that it’s quite well supported in Linux, and has received nice reviews. So, I decided to buy myself one.

In summary, here’s what I like about this laptop, compared the Macbook Air:

  • Half the price. It costs around 630 EUR, and when purchasing a 53 EUR 2-year Next Business Day On Site Warranty, you get a 100 EUR cashback. That means you can get the laptop plus 2-year warranty for around 580 EUR, which is a great deal, in my opinion. The AMD version even starts from 400 EUR.
  • More ports (Ethernet, 3x USB, VGA, HDMI).
  • Better battery life (up to 9 hours according to Lenovo).
  • Customizability (it’s quite easy to replace the HDD, battery or add more RAM).
  • Built-in 3G (HSPA) WAN and GPS module (I really like this feature).
  • Comparable size and weight (11.6 inch and 1.3 kgs, about 250g heavier).
  • Comparable build quality (the laptop feels very sturdy).
  • Comparable keyboard quality (with TrackPoint).

Disadvantages are the slower processor (Core i3 versus the Macbook’s Core i5 or Core i7, but probably fine for my needs), the lower-quality display (same resolution but the Macbook Air’s is better, although I do prefer matte screens), slightly noisy fan at times, and the less sexy design (I myself actually quite like the look and feel of the device).

Oh, and it has a nice sleep animation (probably inspired by Apple’s own pulsing LED sleep animation):

Let’s see how installing Ubuntu goes on this one.

Vibrantink colorscheme might end up in Ubuntu

Neil Wilson contacted me about the Vibrantink colorscheme for Vim I created a while ago based on John Lam’s settings. He wanted to include it in the vim-rails package, which might be distributed with Ubuntu Gutsy, the next release of the Ubuntu Linux distro.

The vim-rails package is a collection of vim scripts that make editing Rails applications much easier. Neil also included another Vibrantink clone for Vim: vividchalk by Tim Pope, the author of rails.vim.

Here is a comparison between the original TextMate color scheme, vibrantink.vim and vividchalk.vim. Vibrantink.vim is less colorful than vividchalk but it resembles the original TextMate theme the most, although it applies the wrong color to the class method attr_reader.

Texmate Vibrantink theme versus vibrantink.vim and vividchalk.vim

I would like to have good syntax highlighting for other languages besides Ruby (e.g. C# and LaTeX) in the future. Who knows, when I find some spare time …

PyGTK GUI for the PhidgetRFID reader

I had some fun writing a Python wrapper around libphidgets for an RFID reader we had lying around here. To do so, I used ctypes (apparantly the Python bindings for libphidgets were broken). To check for a connected RFID reader, I interfaced with hal through dbus. Afterwards I created a simple GUI for the device with PyGTK.

Here is the result:

PyGTK GUI for RFID reader

I experienced some weird permissions problems though. The device could only be opened with root privileges. Takis helped me step through libphidgets to see if there was a bug in it. In the end, we solved it by changing the /etc/udev/rules.d/permissions.rules file (in my case it was called 40-permissions.rules). I’m not sure if there are any security problems with this though.

I changed these lines:

# USB devices (usbfs replacement)
SUBSYSTEM=="usb_device", MODE="0664"

to:

# USB devices (usbfs replacement)
SUBSYSTEM=="usb_device", GROUP="plugdev", MODE="0664"

I will probably put the code online when I have some spare time (and after I cleaned it up a bit).

Package updates for Uiml.net

There are new packages available for Uiml.net. Previously, when you just ran uiml.net.exe, it would exit saying that it could not find the frontend UIML files. These are now included in the packages, meaning that you get a nice graphical interface for choosing a UIML file to render. There is now also a dependency on at least one of the rendering backends.

Takis also moved his repository to another server. To install Uiml.net or Cassowary.net packages, just add this line to your /etc/apt/sources.list:

deb http://issaris.be/breezy/ ./

In other news, Takis has been playing with a Nokia 770 lately: