Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A correct answer has been given by berak.


Below is just an explanation of the historical context.

convertTo cannot be used to change the number of channels. Simply speaking, convertTo will only read the "depth" part of the enum and ignore the "channel" part of the enum.


In the documentation, this is explained as follows: (emphasis added)

rtype – desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.

What this means is that your code is equivalent to calling convertTo with a enum of CV_8U, while keeping the number of channels unchanged at 4.


I agree that this is very confusing to OpenCV users, but it is one of the many rough edges that can't be fixed anymore due to backwards compatibility.