Ask Your Question
2

convertTo from CV_32f to CV_8U

asked 2012-12-03 03:04:04 -0600

Rex gravatar image

updated 2020-11-15 02:09:57 -0600

I want to do a bilateral filter and my image has to be type CV_8UC1/C3 for this.

To convert it would appear I have to use convertTo, but this is simply not working.

This is what I am doing:

Mat Temp= Mat(CurrentMat.size(),CV_8U);
CurrentMat.convertTo(Temp,CV_8UC3);
Mat Result=Temp.clone();
qDebug()<<CV_8UC1<<CV_8UC3;
qDebug()<<"Type"<<Temp.type()<<Result.type()<<CurrentMat.type();
qDebug()<<"Data"<<Result.data<<CurrentMat.data;     
bilateralFilter ( CurrentMat, Result, 5, 15, 15 );

Via the output I can clearly see that the type of Temp is 24 and not 0 or 16 which it should become.

Appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
6

answered 2012-12-03 04:02:01 -0600

Vladislav Vinogradov gravatar image

updated 2012-12-03 04:03:31 -0600

The output of convertTo will have the same channels count as input. It seem like CurrentMat has CV_32FC4 type, so Result will have CV_8UC4 (CV_8UC4 == 24). If you want to convert your image from 4-channel to 3-channel you should use cvtColor with CV_BGRA2BGR (or CV_BGRA2GRAY for single channel output):

Mat Temp;
CurrentMat.convertTo(Temp, CV_8U);
Mat Result;
cvtColor(Temp, Result, CV_BGRA2BGR);
edit flag offensive delete link more

Comments

Thanks that worked.

Rex gravatar imageRex ( 2012-12-03 04:16:48 -0600 )edit

Question Tools

Stats

Asked: 2012-12-03 03:04:04 -0600

Seen: 60,494 times

Last updated: Dec 03 '12