Difference between revisions of "OpenCV Tennis balls recognizing tutorial"

From ElphelWiki
Jump to: navigation, search
(templating some things out)
 
Line 2: Line 2:
  
 
== Prerequisites ==
 
== Prerequisites ==
=== OpenCV ===
+
;OpenCV
=== V4L/AVLD ===
+
:[http://opencv.willowgarage.com/wiki/ 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_-_Another_Video_Loopback_Device|AVLD]].
 +
 
  
 
== Image acquisition ==
 
== 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)'''.
 +
 +
<pre>
 +
#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);
 +
}
 +
}
 +
</pre>
  
 
== Processing ==
 
== Processing ==
Line 12: Line 44:
 
=== Morphological operations ===
 
=== Morphological operations ===
 
=== Hough transform ===
 
=== Hough transform ===
 +
  
 
== Output ==
 
== Output ==
 +
  
 
== Acknowledgments ==
 
== Acknowledgments ==

Revision as of 06:06, 18 June 2009

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.

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);
	}
}

Processing

Color space

Masks

Morphological operations

Hough transform

Output

Acknowledgments