OpenCV Examples Part 1

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

4. Copy an Image

This sample loads an image and copy it to a new file. The program takes 2 parameters: the image name and a new filename.

Listing 3: Copy an image

  1. /* load source image */
  2. IplImage *src = cvLoadImage( argv[1], CV_LOAD_IMAGE_COLOR );
  3.  
  4. /* get properties, needed to create dest image */
  5. int width     = src->width;
  6. int height    = src->height;
  7. int depth     = src->depth;
  8. int nchannels = src->nChannels;
  9.  
  10. /* create destination image */
  11. IplImage *dst = cvCreateImage( cvSize( width, height ),
  12.                                depth, nchannels );
  13.  
  14. /* copy from source to dest */
  15. cvCopy( src, dst, NULL );
  16.  
  17. /* and save to file */
  18. cvSaveImage( argv[2], dst );

Note that I remove all error checking lines from the code above to make things simple.