Page 29 -
P. 29

Chapter 1 ■ Practical Aspects of a Vision System    3


                                     image = cvLoadImage( ˝ C:\AIPCV\image1.jpg˝, 1 );
                                     if( image )
                                     {
                                         cvNamedWindow(  ˝ Input Image˝, 1 );
                                         cvShowImage(  ˝ Input Image˝, image );
                                         printf(  ˝ Press a key to exit\n˝);
                                         cvWaitKey(0);
                                         cvDestroyWindow( ˝ String˝);
                                     }
                                     else
                                         fprintf( stderr,  ˝ Error reading image\n˝ );
                                     return 0;
                                 }

                                 This is similar to many example programs on the Internet. It reads in an
                               image (C:\AIPCV\image1.jpg is a string giving the path name of the image)
                               and displays it in a window on the screen. When the user presses a key, the
                               program terminates after destroying the display window.
                                 Before anyone can modify this code in a knowledgeable way, the data
                               structures and functions need to be explained.


                               1.2.1 The IplImage Data Structure

                               The IplImage structure is the in-memory data organization for an image.
                               Images in IplImage form can be converted into arrays of pixels, but IplImage
                               also contains a lot of structural information about the image data, which can
                               have many forms. For example, an image read from a GIF file could be 256
                               grey levels with an 8-bit pixel size, or a JPEG file could be read into a 24-bit
                               per pixel color image. Both files can be represented as an IplImage.
                                 An IplImage is much like other internal image representations in its basic
                               organization. The essential fields are as follows:



                               width       An integer holding the width of the image in pixels

                               height      An integer holding the height of the image in pixels
                               imageData   A pointer to an array of characters, each one an actual pixel or color value


                                 If each pixel is one byte, this is really all we need. However, there are many
                               data types for an image within OpenCV; they can be bytes, ints, floats, or
                               doubles in type, for instance. They can be greys (1 byte) or 3-byte color (RGB),
                               4 bytes, and so on. Finally, some image formats may have the origin at the
                               upper left (most do, in fact) and some use the lower left (only Microsoft).
   24   25   26   27   28   29   30   31   32   33   34