OpenCV Examples Part 1

Nov 4, 2008 | Tags: OpenCV | del.icio.us del.icio.us | digg Digg

3. Retrieve Image Properties

At times we need to retrieve the properties of an image like: width, height, number of channels, etc. Listing 2 shows the code snippet to retrieve image properties. The full source code is in imgprop.c.

Listing 2: Retrieve image properties

  1. /* load the image */
  2. IplImage *img = cvLoadImage( argv[1], CV_LOAD_IMAGE_COLOR );
  3.  
  4. /* print some properties */
  5. printf( "Filename:    %s\n",        argv[1] );
  6. printf( "# channels:  %d\n",        img->nChannels );
  7. printf( "Pixel depth: %d bits\n",   img->depth );
  8. printf( "width:       %d pixels\n", img->width );
  9. printf( "height:      %d pixels\n", img->height );
  10. printf( "Image size:  %d bytes\n",  img->imageSize );
  11. printf( "Width step:  %d bytes\n",  img->widthStep );

Consult OpenCV Reference Manuals for details of IplImage data structure.