views:

18

answers:

1

img_hsv is a Mat element of an hsv image!

when i give cout<<*img_hsv.data+10; it gives true value of the pixel ie 79 as output. but when i assign uchar * a=img_hsv.data+10; it gives me some other value... can you please explain me why is this the case? thanks!

A: 

In the first case, you are first getting the content of pointer img_hsv.data and then adding 10 to that value and displaying it. In the second case you are just incrementing the pointer by 10 units. This incremented value points to a memory location. So a will contain the address of the location hence it will be different from the printed value. If you meant that *a is giving different value, then it is because of the operator precedence. In the first case, pointer is dereferened first and then 10 is added to the dereferenced value, and in the second case you are incrementing the pointer first and then dereferencing it.

Naveen