OpenCV Tennis balls recognizing tutorial
From ElphelWiki
Revision as of 05:06, 18 June 2009 by Andy753421 (talk | contribs)
This tutorial demonstrates how to use an Elphel (or perhaps another) camera to perform some basic computer vision tasks, such as identifying objects. For this example, we will be recognizing tennis balls.
Contents
Prerequisites
- OpenCV
- OpenCV is a C library designed to help with computer vision programs. It provides quite a few useful functions that can save a lot typing when performing operations on images.
- V4L/AVLD
- OpenCV provides a V4L API that can be used to acquire images from Elphel cameras. This is done using AVLD.
Image acquisition
The first step is to get some images into OpenCV and display them. This assumes you have AVLD and V4L already set up. Below is a fairly minimal example that captures and displays images. It can be compiled with gcc -o main main.c $(pkg-config --libs --cflags opencv).
#include <opencv/cv.h> #include <opencv/highgui.h> #include <X11/keysym.h> int main(int argc, char **argv) { /* Start the CV system and get the first v4l camera */ cvInitSystem(argc, argv); CvCapture *cam = cvCreateCameraCapture(0); /* Create a window to use for displaying the images */ cvNamedWindow("img", 0); cvMoveWindow("img", 200, 200); /* Display images until the user presses q */ while (1) { cvGrabFrame(cam); IplImage *img = cvRetrieveFrame(cam); cvShowImage("img", img); if (cvWaitKey(10) == XK_q) return 0; cvReleaseImage(&img); } }