C++ 访问负像素值OpenCV IplImage*pRGBImg=cvLoadImage(input_file.c_str(),CV_LOAD_IMAGE_不变); int width=pRGBImg->width; int height=pRGBImg->height; int bpp=pRGBImg->nChannels; 对于(int i=0;i
您可能正在将有符号字节值转换为int,而int可能会给出负值。请尝试以下代码:C++ 访问负像素值OpenCV IplImage*pRGBImg=cvLoadImage(input_file.c_str(),CV_LOAD_IMAGE_不变); int width=pRGBImg->width; int height=pRGBImg->height; int bpp=pRGBImg->nChannels; 对于(int i=0;i,c++,opencv,C++,Opencv,您可能正在将有符号字节值转换为int,而int可能会给出负值。请尝试以下代码: 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*heigh
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] << " ";
}
std::cout使用uchar对我很有效
std::cout << std::dec << "R:" << (unsigned int) pRGBImg->imageData[i] <<
" G:" << (unsigned int) pRGBImg->imageData[i+1] <<
" B:" << (unsigned int) pRGBImg->imageData[i+2] << " ";
std::cout
std::cout << std::dec << "R:" << (uchar) pRGBImg->imageData[i] <<
"G:" << (uchar) pRGBImg->imageData[i+1] <<
"B:" << (uchar) pRGBImg->imageData[i+2] << " ";