Convert binary image into RGB in OpenCV

12,913

You probably should not mix C and C++ notations.

Try to use cv::CvtColor instead of cvCvtColor

Concerning your second question, are you using cv::CvtColor with both input and output having three channels?

Share:
12,913
E_learner
Author by

E_learner

Updated on June 05, 2022

Comments

  • E_learner
    E_learner almost 2 years

    I am using OpenCV 2.4.3 to do foreground detection. I want to convert the result foreground which is binary into RGB image. My code is like this:

    cv::VideoCapture cap;
    cap.open ( "test.avi " );
    cv::Mat img;
    cv::Mat finalForeground;
    cv::Mat element( 3, 3, CV_8U, cv::Scalar(1) );
    cv::gpu::GMG_GPU gmgGpu
    
    gmgGpu.initialize ( cv::Size ( 1600, 1200 ) );
    cv::gpu::GpuMat gpuForeground;
    cv::Mat rgbForeground;
    
    for ( int i = 0; i < 500; i ++ )
    {
        cap >> img; 
        cv::gpu::GpuMat gpuImg ( img );    
        gmgGpu.operator()(gpuImg, gpuForeground);
        gpuForeground.download ( finalForeground);
        cv::morphologyEx ( finalForeground, finalForeground, CV::MORPH_CLOSE, element );
        cvCvtColor ( finalForeground, rgbForeground, CV_GRAY2BGR );
     }
    

    Then I got an error like this:

    error C2664: 'cvCvtColor' : cannot convert parameter 2 from 'cv::Mat' to 'CvArr *'

    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

    Could someone give any suggestion for handling this error? Thanks.

  • E_learner
    E_learner over 11 years
    Thank you, I used it as "cv::cvtColor" and that error is solved.
  • jlengrand
    jlengrand over 11 years
    Another question closed on SO :)