Resources
Sourceforge site
http://sourceforge.net/projects/opencvlibrary
Official OpenCV usergroup
http://tech.groups.yahoo.com/group/OpenCV
OpenCV Wiki
http://opencvlibrary.sourceforge.net
Source code for the program listings in this article are available
for download at www.cognotics.com/opencv/servo.
void cvSet2D(CvArr*, int row, int col,
CvScalar);
2. Fast Pixel Access
Although cvGet2D() and cvSet2D() are easy to use,
if you want to access more than a few pixel values, and
performance matters, you’ll want to read values directly
from the raw data buffer, IplImage.imageData.
Image data in the buffer are stored as a 1D array, in row-major order. That is, all pixel values in the first row are listed
first, followed by pixel values in the second row, and so on.
For performance reasons, pixel data are aligned, and
padded if necessary, so that each row starts on an even four-byte
multiple. A second field, IplImage.widthStep, indicates the
number of bytes between the start of each row’s pixel data. That
is, row i starts at IplImage.imageData + i*IplImage.widthStep.
IplImage.imageData is defined as type char*, so you may
STEER WINNING ROBOTS
WITHOUT SERVOS!
Perform proportional speed, direction, and steering with
only two Radio/Control channels for vehicles using two
separate brush-type electric motors mounted right and left
with our mixing RDFR dual speed control. Used in many
successful competitive robots. Single joystick operation: up
goes straight ahead, down is reverse. Pure right or left twirls
vehicle as motors turn opposite directions. In between stick
positions completely proportional. Plugs in like a servo to
your Futaba, JR, Hitec, or similar radio. Compatible with gyro
steering stabilization. Various volt and amp sizes available.
The RDFR47E 55V 75A per motor unit pictured above.
www.vantec.com
Order at
(888) 929-5055
66 SERVO 01.2007
need to cast the data type. For example, if your image data are
unsigned bytes (the most common input type), you’d cast each
value to unsigned char* before assigning, or otherwise using, it.
If you’re accessing data from a grayscale (single-channel)
image, and the data depth is eight bits (one byte per pixel),
you’d access pixel[row][col] with
pixel[row][col] = ((uchar*)
(pImg->imageData +
row*pImg->widthStep + col));
In multi-channel images, channel values are interlaced.
Here’s a code snippet to access blue, green, and red pixel values:
step = pImg->widthStep;
nChan = pImg->nChannels;
// = 3 for a BGR image
buf = pImg->imageData;
blue[row][col] =
((uchar*)(buf + row*widthStep +
nChan*col);
green[row][col] =
((uchar*)(buf + row*widthStep +
nChan*col + 1);
red[row][col] =
((uchar*)(buf + row*widthStep +
nChan*col + 2);
Finally, if image depth is greater than eight bits (for
example, IPL_DEPTH_32S), you’d need to transfer multiple
bytes for each value and multiply the buffer offset by
the number of data bytes for your image depth. It’s very
unlikely, however, that you’ll encounter a situation in which
you must access multi-byte pixel values directly.
Finding Help
If you have problems installing or using OpenCV, the first
place to turn for help is the FAQ ( faq.htm) in your OpenCV
docs directory. The INSTALL file, at the root of your OpenCV
directory, also contains helpful setup and troubleshooting
tips. If these don’t answer your question, you may want to
post a query to the official Yahoo! user group. The group’s
URL is in the Resources sidebar.
API documentation for each module is in the docs/ref
subdirectory. All reference manuals except the one for
CVAUX are linked from index.htm, in the docs directory.
Coming Up ...
Next month, I’ll show you how to detect faces with
OpenCV and explain the algorithm behind the interface. Be
seeing you! SV
About the Author
Robin Hewitt is an independent software consultant working in
the areas of computer vision and robotics. She has worked as a
Computer Vision Algorithm Developer at Evolution Robotics and
is a member of SO( 3), a computer-vision research group at UC
San Diego. She is one of the original developers of SodaVision, an
experimental face-recognition system at UC San Diego.
SodaVision was built with OpenCV.