tags:

views:

46

answers:

3

Hi there! Im using openCV C++

Im need to convert a single channel image to 3 channels image. So i can use this: cvCvtColor(result,gray,CV_BGR2GRAY);

I cannot do that because the result img is a single channel image. Any ideas?

+2  A: 

Hm, shouldn't you use CV_GRAY2BGR instead of CV_BGR2GRAY?

Vadim Shender
that gives me the same error:Bad number of channels (Incorrect number of channels for this conversion code) in cvCvtColor
Harry
You also must change order of the first two arguments: cvCvtColor(gray, result, CV_GRAY2BGR). Read docs carefully: void cvCvtColor(const CvArr* src, CvArr* dst, int code);
Vadim Shender
A: 

Try merging gray,gray,gray into a BGR.

Utkarsh Sinha
+1  A: 

Try this

CvSize dim = cvSize(int width, int height);

IplImage* dst = cvCreateImage( dim, 8, 3 );\

IplImage* gray = cvCreateImage(dim, , 8 , 1);

// Load the gray scale image

cvMerge(gray , NULL, NULL, NULL, dst);

cvShowImage("gray",gray);

cvShowImage("dst",dst);

cvWaitKey(0);

Both dst and gray must have their data types same. You cant simply merge a float in a uint matrix. You will have to use cvScale for that.

Wajih