Image stretch contrast with openCV

I am trying to stretch the contrast of an image in the range of 0-255 using cvNormalize. But when I print the output pixel values, some negative numbers display as the pixel value. I appreciate if you can help me figure out where the problem arose. This is the code:

cvNormalize(srcImage, dstImage, 0, 255, CV_MINMAX );

for ( int pixel = 0; pixel < dstImage->height * dstImage->width; pixel++ ) {
    printf("%d\t",*(dstImage->imageData + pixel));
}
+5
source share
1 answer

Because the type imageData char*and charmay be nagativnym (range [-128, 127]). Try casting on unsigned char.

See docs .

+5
source

All Articles