Ask Your Question

Revision history [back]

fixed point arithmetic

Hi, I wonder if anyone can help me with a basic question about the way openCV calculates pixel values.

I want to implement alpha masking, using CV_8U4 matrices.

So, if there are 2 input images in1 and in2,

out.R=(in1.R*(255-in2.A))+(in2.R*in2.A)

out.G=(in1.G*(255-in2.A))+(in2.R*in2.A)

out.B=(in1.B*(255-in2.A))+(in2.R*in2.A)

in other words- I want to use a fixed point arithmetic in the same way openGL does, where 0 represents 0.0f and 255 represents 1.0f..

or in other words:

0*0=0
128*128=64
255*255=255

however, in2.R.mul(in2.A) doesn't work like this - and in2.R.mul(in2.A,1.0/255.0) doesn't either.

Is there any way to easily do openGL style pixel operations in openCV?

Thanks

Tim Redfern