Using OpenCV

With your camera connected, you can access amazing vision capabilities that have been provided by the open source community. One of the most powerful capabilities is OpenCV.

You already installed OpenCV in Chapter 1, Preparing the BeagleBone Black. If you'd like a good overview on OpenCV and more documentation, see http://docs.opencv.org/.

Now you can try OpenCV. It is easiest to use Python when programming simple tasks, so let's start with the Python examples. If you prefer the C examples, they are also available. In order to use the Python examples, you'll need the python-numpy library. Type sudo apt-get install python-numpy. You will need this to manipulate the matrices that OpenCV uses to hold the images.

Start with one of the Python examples. You can access the Python examples by typing cd /home/ubuntu/examples/python. There are a number of useful examples; you'll start with the most basic. It is called camera.py. To run this example, you'll either need to have a display connected to the BeagleBone Black, or you can do this over the VNC server connection. Bring up a terminal window and type python camera.py. You should see an output similar to this screenshot:

Using OpenCV

When I first did this, the camera window eventually turned black and did not show the output from the camera. To actually see the image, I needed to change the resolution of the image captured by the USB webcam to one supported by the camera and OpenCV. To do this, you need to edit the camera.py file by adding two lines like this:

Using OpenCV

These two lines change the resolution of the captured image to 360 x 240 pixels. Now run camera.py and you should be able to see the following screenshot:

Using OpenCV

You should now have vision capability! You will use it to do a number of impressive tasks. You may want to vary the resolution to find the optimum for your application. Larger resolution images give you a more detailed view of the world, but they also take up significantly more memory and processing power. An image that is twice the size (width/height) will involve four times more memory and processing power.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.170.14