Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
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 - Fatal编程技术网

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 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

您可能正在将有符号字节值转换为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*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] << " ";