开发者

How to convert colour to greyscale image in openCV?

Hi I have read the openCV reference from this site and using the following code:

VideoCapture mCap;
Mat mcolImage, mbwImage;

           mCap >> mcolImage; // New frames from the camera

          cvtColor( mcolImage, mcolImage, CV_BGR2RGB);
          cvtColor( mcolImage, mbwImage, CV_RGB2GRAY);

           QImage colImagetmp( (uchar*)mcolImage.data, mcolImage.cols, mcolImage.rows, mcolImage.step,
                              QImage::Format_RGB888 ); //Colour

           QImage bwImagetmp ( (uchar*)mbwImage.data, mbwImage.cols, mbwImage.rows, mbwImage.step,
                              QImage::Format_Ind开发者_如何学JAVAexed8); //Greyscale. I hope

           ui.bwDisplay->setPixmap(QPixmap::fromImage(bwImagetmp));
           ui.colDisplay->setPixmap( QPixmap::fromImage(colImagetmp ));

I'm trying to convert one of the output into greyscale. Unfortunately they're still both in colour and I can't see that I've missed a step somewhere. Thanks for the help.


You need to explicitly set a gray color table for bwImagetmp:

QVector<QRgb> colorTable;
for (int i = 0; i < 256; i++) colorTable.push_back(qRgb(i, i, i));
bwImagetmp.setColorTable(colorTable); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜