简体   繁体   中英

Convert binary image into RGB in OpenCV

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM