I've been experimenting with trying to get a usable OpenCV environment up and running on my Raspberry Pi, so that I can experiment with using it for machine vision. The catch is that I don't have a decent monitor and keyboard hooked up to the Pi, and I'm using Arch Linux - so most available tutorials aren't quite applicable to me. This blog post describes what I've done so far to get up and running using remoted X-Windows to get the job done.
Since I have an iMac as my main development machine, I already have a decent X server built in. I've happily used that in the past to remote VirtualBox virtual machine desktops from Debian, and it's a convenient and efficient way of running graphical apps on a headless server. So, that seems the logical way to go here.
The first step was to get a basic X client up and running on the Pi. This was probably the hardest part, and involved a lot of searching around, via both pacman and Google. Below are what should be the minimal set of steps to get this working, to save future readers from the trouble...
- Install the various necessary packages via pacman:
- First, the bare bones to support X clients:
pacman -S xorg-xauth
- Next, the dummy video driver that persuades clients that the server supports the XRandR extension. Without this, you'll see the error
Xlib: extension "RANDR" missing on display "localhost:10.0"
when trying to run many graphical apps.
pacman -S xf86-video-dummy
- Install xterm as a simple test application.
pacman -S xterm
- Now ensure that sshd is set up to allow X11 forwarding. This was probably the step that had me puzzled for the longest time, as a lot of other Linux distros seem to default this all to being turned on out of the box. Not to worry, it's straightforward:
- Edit
/etc/ssh/sshd_config
- Ensure that the following settings are all configured:
- X11Forwarding = yes
- X11DisplayOffset = 10
- X11UseLocalhost = yes
- AllowTcpForwarding = yes
- Restart the SSH daemon:
rc.d restart sshd
- Test that everything is working so far.
- From the X server (in this case an iMac, but it could be just about any Linux desktop), log in to the RasPi with X11 forwarding enabled:
ssh -X root@raspi1
- Once logged in, try to launch xterm.
xterm &
- If everything was successful, a new terminal window will open on your X server desktop, which is actually running locally on the Pi, but displaying on your desktop. Great, the graphical support is now in place!
Next step is to get OpenCV up and running. I'm planning to use the Python bindings, because that should be good for fast prototyping, I enjoy writing Python, and hey - it's a Raspberry Pi, it should be running Python! Thankfully, all the necessary stuff seems to be already set up in pacman, so:
- Grab the packages.
pacman -S python2
pacman -S python2-numpy
pacman -S opencv
pacman -S opencv-samples
- Try a quick Hello World test. I used the tutorial here, which worked perfectly for me, displaying the image on my iMac's desktop. However, as per guidelines I've seen elsewhere, I've been using
import cv2.cv as cv
rather than the simple
import cv
described in the tutorial.
Alrighty. Now I'm all set up for OpenCV, I'll be able to start hacking around with image capture and hopefully a bit of facial recognition as a starting point. Next stop, Raspberry Pi Skynet!