[PD-dev] opencv rgba/gray output

Loic Kessous loic.kessous at gmail.com
Mon Feb 23 20:35:31 CET 2009


I try to develop some code in opencv in the pix_opencv's style. To  
start, I tried to convert rgba to gray using opencv ( cvCvtColor(orig,  
gray, CV_BGRA2GRAY); )

but I can't get a gray picture of the same size at the output. If I  
just copy the gray image, I get just 4 small gray copy of the original  
on one line on the top of the image.

If I try to convert from grey to rgba before to output the data, I get  
a monochrome but yellow picture.

I wonder if there's a relation with the fact that I am working on a  
mac, is it possible ? because of a difference coding of rgba on mac  
and others?

do someone know how I can solve this?

here is the code of the one which give me a yellow monochromatic  

///////////////// processImage /////////////////////////
void pix_opencv_mytest :: processRGBAImage(imageStruct &image) {
   if ((this->comp_xsize!=image.xsize)||(this->comp_ysize! 
=image.ysize)||(!orig)) {
	this->comp_xsize = image.xsize; 	this->comp_ysize = image.ysize;

	cvReleaseImage(&orig);			cvReleaseImage(&gray);		 

		//create the orig image with new size
         orig = cvCreateImage(cvSize(image.xsize,image.ysize),  
     	gray = cvCreateImage(cvSize(orig->width,orig->height),  
     // Here we make a copy of the pixel data from image to orig- 
 >imageData, orig is a IplImage struct
	    memcpy( orig->imageData, image.data, image.xsize*image.ysize*4 );
		cvCvtColor(orig, gray, CV_BGRA2GRAY);  // Convert to grayscale		
	cvCvtColor(gray, orig, CV_GRAY2BGRA);
     //copy back the processed frame to image
     memcpy( image.data, orig->imageData, image.xsize*image.ysize*4 );



More information about the Pd-dev mailing list