Sunday, May 22, 2011

OpenCV - Convert image to grayscale

  1. /* load image */
  2. IplImage *src = cvLoadImage( argv[1], CV_LOAD_IMAGE_COLOR );
  3.  
  4. /* get image properties */
  5. width  = src->width;
  6. height = src->height;
  7.  
  8. /* create new image for the grayscale version */
  9. IplImage *dst = cvCreateImage( cvSize( width, height ), IPL_DEPTH_8U, 1 );
  10.  
  11. /* CV_RGB2GRAY: convert RGB image to grayscale */
  12. cvCvtColor( src, dst, CV_RGB2GRAY );

No comments:

Post a Comment