Mat different channels

asked 2016-08-16 17:02:36 -0500

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.

edit retag flag offensive close merge delete

Comments

1

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.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-08-17 07:18:11 -0500 )edit
1

If you are reading them with imread without specifiers, they will always be 3 channel 8 bit images

Ah, that is good to know, thanks!

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.

This is exactly what I ended up doing :D

Kolibri gravatar imageKolibri ( 2016-08-17 15:15:55 -0500 )edit