First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered Jun 13 '19

berak gravatar image

it's not really an opencv problem, more a basic java one --

java's byte type is actually signed (-127..127) ! (and there is no unsigned char equivalent in java, so your array gets "silently" casted to signed char under the hood.

please try NOT to iterate over pixels over a whole image from java, it's quite an opencv - antipattern, slow & error prone.

if you absolutely HAVE to do arithmetics on that data, you need to convert EVERY SINGLE BYTE to uchar before your operation, and back to signed afterwards

click to hide/show revision 2
No.2 Revision

it's not really an opencv problem, more a basic java one --

java's byte type is actually signed (-127..127) ! (and there is no unsigned char equivalent in java, so your array gets "silently" casted to signed char under the hood.

please try NOT to iterate over pixels over a whole image from java, it's quite an opencv - antipattern, slow & error prone.

if you absolutely HAVE to do arithmetics on that data, using manual loops (again, don't !), you need to convert EVERY SINGLE BYTE to uchar before your operation, and back to signed afterwards