Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to access alpha value at pixel using Mat.data?

I found the following piece of code in this In which there is a piece of code to acces the alpha value that looks like this:

double opacity = (double)image.data[y*image.step + x * image.channels () +3]

I can't understand how this piece of code works, from what I have found, Mat.data is used to access a pixel at some location, and I can't understand why x*image.channels () is in the code.

Hopefully someone can explain me the code.

Thanks in advance.

How to access alpha value at pixel using Mat.data?

I found the following piece of code in this question. In which there is a piece of code to acces the alpha value that looks like this:

double opacity = (double)image.data[y*image.step + x * image.channels () +3]

I can't understand how this piece of code works, from what I have found, Mat.data is used to access a pixel at some location, and I can't understand why x*image.channels () is in the code.

Hopefully someone can explain me the code.

Thanks in advance.