[OpenCV-Users] Converting an image in grayscale

Marco Paladini paladini at dcs.qmul.ac.uk
Wed Feb 13 14:10:41 GMT 2008


Dear All,

I can't figure out how to convert an image to
greyscale while having still 3 channels to plot
color points over it.
Is there a way to do it?

Thanks.

What I've tried to do is to copy the grayscale data over the image data
and I get the greyscale image repeated 9 times (3 rows and 3 columns)


// image has been created with depth 8, 3 channels
image = cvCreateImage( cvGetSize(frame), 8, 3 );
// grey has depth 8, 1 channel
grey = cvCreateImage( cvGetSize(frame), 8, 1 );
cvCvtColor( image, grey, CV_BGR2GRAY );
// make image greyscale
for(i=0;i<image->imageSize;i++)
{
   image->imageData[i] = grey->imageData[i%grey->imageSize];
}

-- 
Marco Paladini     Room :  329      Phone : +44 (0) 207 882 8019
Department of Computer Science      email: paladini at dcs.qmul.ac.uk
Queen Mary, University of London    http://www.dcs.qmul.ac.uk/~paladini
London E1 4NS.  UK



More information about the OpenCV-Users mailing list