Page 40 -
P. 40
14 Chapter 1 ■ Practical Aspects of a Vision System
1.4 Interfacing with the AIPCV Library
This book discusses many algorithms, almost all of which are provided in
source code form at the book’s corresponding website. To access the examples
and images on a PC, copy the directory AIPCV to the C: directory. Within
that directory are many C source files that implement the methods discussed
here. These programs are intended to be explanatory rather than efficient, and
represent another way, a very precise way, to explain an algorithm. These
programs comprise a library that uses a specific internal form for storing
image data that was intended for use with grey-level images. It is not directly
compatible with OpenCV, and so a conversion tool is needed.
OpenCV is not only exceptionally valuable for providing infrastructure to a
vision system, but it also provides a variety of image-processing and computer
vision functions. Many of these will be discussed in upcoming chapters (Canny
and Sobel edge detection, for example), but many of the algorithms described
here and provided in code form in the AIPCV library do not come with
OpenCV. How can the two systems be used together?
The key detail when using OpenCV is knowledge of how the image structure
is implemented. Thus, connecting OpenCV with the AIPCV library is largely a
matter of providing a way to convert between the image structures of the two
systems. This turns out to be quite simple for grey-level, one-channel images,
and more complex for color images.
The basic image structure in the AIPCV library consists of two structures: a
header and an image. The image structure, named simply image, consists of
two pointers: one to a header and one to an array of pixel data:
struct image
{
struct header *info; // Pointer to header
unsigned char **data; // Pointer tp pixels
};
The pixel data is stored in the same way as for single-channel byte images
in OpenCV: as a block of bytes addressed in row major order. It is set up to
be indexed as a 2D array, however, so data is an array of pointers to rows.
The variable data[0] is a pointer to the beginning of the entire array, and so
is equivalent to IplImage.imageData.
The header is quite simple:
struct header
{
int nr, nc;
int oi, oj;
};