Reputation: 1
IplImage* pRGBImg = cvLoadImage(input_file.c_str(), CV_LOAD_IMAGE_UNCHANGED);
int width = pRGBImg->width;
int height = pRGBImg->height;
int bpp = pRGBImg->nChannels;
for (int i=0; i < width*height*bpp; i+=bpp)
{
if (!(i % (width*bpp))) // print empty line for better readability
std::cout << std::endl;
std::cout << std::dec << "R:" << (int) pRGBImg->imageData[i] <<
" G:" << (int) pRGBImg->imageData[i+1] <<
" B:" << (int) pRGBImg->imageData[i+2] << " ";
}
this code is giving different pixel values what i got in matlab is in positive and open cv give value in negative.
Upvotes: 0
Views: 658
Reputation: 1586
using uchar worked for me
std::cout << std::dec << "R:" << (uchar) pRGBImg->imageData[i] <<
"G:" << (uchar) pRGBImg->imageData[i+1] <<
"B:" << (uchar) pRGBImg->imageData[i+2] << " ";
Upvotes: 0
Reputation: 15154
You are probably converting a signed byte value to int which can give negative values. Try this code:
std::cout << std::dec << "R:" << (unsigned int) pRGBImg->imageData[i] <<
" G:" << (unsigned int) pRGBImg->imageData[i+1] <<
" B:" << (unsigned int) pRGBImg->imageData[i+2] << " ";
Upvotes: 1