Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does openCV's convertto function not work?

I have an image which has 4 channels and is in 4 * UINT8 format.

I am trying to convert it to 3 channel float and I am using this code:

images.convertTo(images,CV_32FC3,1/255.0);

After the conversion, the image is in a float format but still has 4 channels. How can I get rid of 4th (alpha) channel in OpenCV?

like image 404
mans Avatar asked Mar 04 '14 13:03

mans


1 Answers

As @AldurDisciple said, Mat::convertTo() is intended to be used for changing the data type of a Mat, not for changing the number of channels.

To work out, you should split it into two steps:

cvtColor(image, image, CV_BGRA2BGR);       // 1. change the number of channels
image.convertTo(image, CV_32FC3, 1/255.0); // 2. change type to float and scale
like image 166
herohuyongtao Avatar answered Sep 18 '22 07:09

herohuyongtao