Mat different channels
Hello everyone, newbie here.
I am trying to put the pixel values of one Mat into another via mat.put(x,y,values)
That does work, but only for Mats of the same type. When they are not, I get an error.
Provided data element number (4) should be multiple of the Mat channels count (3)
The solution to that problem would be to have the Mats share the same type by converting one of them (right?).
The problem with THAT is, that I need to explicitly state in the cvtColor - Method, which channel to convert (and how). But I do not know the exact channel on runtime, channels count should either be 3 or 4...
So, how do I convert one mat to the type of another mat dynamically? Any ideas?
Thank you very much.
With kind regards, David.
I guess you are first collecting them somewhere. If you are reading them with imread without specifiers, they will always be 3 channel 8 bit images. Once an image is loaded you can retrieve its type, which in turn can be compared to for example CV_8UC3 or CV_8UC4 to know how many channels there are.
Ah, that is good to know, thanks!
This is exactly what I ended up doing :D