Skip to content
Jeff Schornick edited this page Mar 15, 2014 · 4 revisions

This page will describe how to configure OpenCV on a BeagleBone Black for use with a USB webcam.

Prerequisites

Complete the BBB Setup process.

Installing

Download a tarball of our previous OpenCV build for armhf:

https://drive.google.com/a/ncsu.edu/file/d/0B2hE1bM2VB6JQkk3UDE5UXVPQjg/edit?usp=sharing

Untar on the bone, copy the required files to the right places, and install packages for supporting libraries...

cd OpenCV*
cp release/lib/opencv_core.so.2.4.2 /usr/local/lib
cp release/lib/cv2.so /usr/local/lib/python2.7/dist-packages/
cp modules/python/src2/cv.py /usr/local/lib/python2.7/dist-packages/
cp release/lib/libopencv_flann.so.2.4.2 /usr/local/lib/
cp release/lib/libopencv_imgproc.so.2.4.2 /usr/local/lib/
cp release/lib/libopencv_video.so.2.4.2 /usr/local/lib/
cp release/lib/libopencv_ml.so.2.4.2 /usr/local/lib/
cp release/lib/libopencv_highgui.so.2.4.2 /usr/local/lib/
cp release/lib/libopencv_features2d.so.2.4.2 /usr/local/lib/
cp release/lib/libopencv_calib3d.so.2.4.2 /usr/local/lib/
cp release/lib/libopencv_photo.so.2.4.2 /usr/local/lib/
cp release/lib/libopencv_objdetect.so.2.4.2 /usr/local/lib/
cp release/lib/libopencv_legacy.so.2.4.2 /usr/local/lib/
cp release/lib/libopencv_nonfree.so.2.4.2 /usr/local/lib/

cd /usr/local/lib
ln -s opencv_core.so.2.4.2 opencv_core.so.2.4
ln -s opencv_core.so.2.4.2 opencv_core.so
ln -s opencv_flann.so.2.4.2 ...
ln -s opencv_imgproc.so.2.4.2 ...
ln -s opencv_video.so.2.4.2 ...
ln -s opencv_ml.so.2.4.2 ...
ln -s opencv_highgui.so.2.4.2 ...
ln -s opencv_features2d.so.2.4.2 ...
ln -s opencv_calib3d.so.2.4.2 ...
ln -s opencv_photo.so.2.4.2 ...
ln -s opencv_objdetect.so.2.4.2 ...
ln -s opencv_legacy.so.2.4.2 ...
ln -s opencv_nonfree.so.2.4.2 ...

sudo apt-get install libgtk2.0-0 libv4l-0 libavcodec53 libavformat53 libswscale2

Run

Plug in the USB webcam, check that it shows up under lsusb. Reboot if necessary.

cd bot
python vision/targeting.py --no_gui

Other notes

Compiling OpenCV from source on a bone takes a ridiculously long time, and at least once never completed (swapping due to lack of RAM, error'd out). Somehow (how?), we have this already compiled install that's compatible with the bone's architecture.

I would tell you to wget the tar to the bot directly, but I can't figure out a URL from Drive that allows a direct download. For now, download it to your system and then SFTP/SCP/rsync it over with rsync opencv.tar [email protected]:/root/ or similar (assumes file in CDW).

Login to the bone (ssh [email protected]) and untar the CV tarball.

root@arm:~# ls -rc
startup  am335x_pru_package  venv  bot  i2c_device  DMCC_Library  pypruss  opencv.tar
root@arm:~# tar xf opencv.tar 
root@arm:~# ls -rc
startup  am335x_pru_package  venv  bot  i2c_device  DMCC_Library  pypruss  opencv.tar  opencv

Notice the new ./opencv/ directory. You may want to go ahead and delete the tar, to make room on the bone (check df -h for storage info).

Make sure the bone's clock is right! make/make install depend on correct timestamps. If the clock isn't set correctly, make install may try to compile the binaries from source again (needlessly), which is very much not what you wan.

You can update your time with:

root@arm:~# ntpdate ntp.ubuntu.com
14 Mar 23:55:59 ntpdate[22688]: step time server 91.189.94.4 offset 2234977.441361 sec

There's a directory opencv/OpenCV-2.4.2/release/. Go there and run make install.