opencv converting gray to rgb

asked 2014-03-19 20:21:57 -0500

Jack123 gravatar image

updated 2014-03-20 04:07:55 -0500

berak gravatar image

Hello, I am trying to convert an image into a grayscale image, But I need 3 channels and the grayscale image has only one. Is there a function in opencv to replicate 1 channel into 3?

My code is:

IplImage* GetGrayImage(IplImage* frame, IplImage* imgHSV){
    IplImage* imgGray = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
    IplImage* imgBW = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
    cvCvtColor(frame, imgGray, CV_BGR2GRAY);
    CvScalar s3;
    s3 = cvGet2D(imgHSV, i1, i2);

    cvInRangeS(imgHSV, cvScalar(s3.val[0] - a, s3.val[1] - 50, s3.val[2] - 50), cvScalar(s3.val[0] + a, s3.val[1] + 50, s3.val[2] + 50), imgBW);

    cvCopy(frame, imgGray, imgBW);//here it breaks because the dimensions are different

    cvReleaseImage(&imgBW);
    return imgGray;
}
edit retag flag offensive close merge delete

Comments

Use cvCvtColor(gray, bgr, CV_GRAY2BGR);

Haris gravatar imageHaris ( 2014-03-20 00:22:49 -0500 )edit