本文介绍了为什么convertto在opencv不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个有4个频道并且处于 4 * UINT8
格式的图片。
I have an image which has 4 channels and is in 4 * UINT8
format.
将其转换为3通道浮动和我使用这个代码:
I am trying to convert it to 3 channel float and I am using this code:
images.convertTo(images,CV_32FC3,1/255.0);
但转换后,Image是一个浮点数,但仍有4个通道。
But after conversion, Image is a float but still has 4 channels. How can I get ride of 4th (alpha) channel in OpenCV?
推荐答案
如@AldurDisciple说,用于更改 Mat
的数据类型,而不是更改频道数量。
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
这篇关于为什么convertto在opencv不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!