This tutorial will walk through a quick machine vision application. Don't run away just yet. I've already done most of the mundane, low-level work for you. Well, let's get started. First of all, we have to include the classes we'll be using. For this example, that means Camera, Frame, GUI, and Font.
// Paths assume this file is in the /src diretory #include "../include/camera.h" #include "../include/frame.h" #include "../include/gui.h" #include "../include/font.h"
This is the only tricky part. We have to set up the camera and prepare the display window. This should be one of the only parts of any OSRC application that require digging through the documentation. To start, we create the instance of Camera and create the structures to hold it's parameters. We also specify the name of the camera to read. Any V4L (Video for Linux) compatible camera or webcam should work. Then we read, modify, and write the camera parameters. Finally, we create the frame buffer and the configure the display window.
// Set up camera and settings variables Camera cam; cam.dev = "/dev/video0"; picParams pic_params; camParams cam_params; // Start camera and get settings pic_params = cam.getPicParams(); cam_params = cam.getCamParams(); // Switch to 320x240 at 30FPS cam_params.width = 320; cam_params.height = 240; cam_params.framerate = 30; cam.setCamParams(cam_params); cam.setPicParams(pic_params); // Create a frame buffer for the camera Frame* f; f = new Frame(cam_params); // Set up gui GUI gui; gui.init(); gui.setDisplayMode(MODE_640x480x24);
I meant it when I said that was the hardest part. Let's take a picture and show it on screen. The picture data goes into a frame buffer, into the display buffer, and then to the screen. That's three steps and only three lines of code.
// Save camera data to frame buffer "f" cam.capture(f); // Copy buffer to center of display gui.drawFrame(f, 160, 120); // Show the display buffer gui.showScreen();
Congratulations, you've just written a image capture program. That little bit of code will connect to a camera or webcam, create a display window, and show a camera frame on screen. Let's go a bit further now and display live video and do some basic image processing. The live video part is pretty easy. Just put those three magic lines of code in a loop and you be seeing video. To do image processing, we just display the camera frame buffer before and after running the algorithm on the buffer. Just for fun, I'll show both frames side-by-side.
// Image processing loop
while (1) {
// Take a picture
cam.capture(f);
// Draw original frame
gui.drawFrame(f, 0, 0);
// Run image processing algorithm
f->convertToHSV();
// Draw new frame to the right
gui.drawFrame(f, 320, 0);
// Show the display buffer
gui.showScreen();
}
The entired code used to generate the video and image processing demo is in the file cameratest.cpp. The compiled code will show a 640x480 viewport looking something like this:

To top of page