gpt4 book ai didi

c++ - 访问负像素值 OpenCV

转载 作者:行者123 更新时间:2023-11-28 08:19:45 27 4
gpt4 key购买 nike

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] << " ";
}

这段代码给出了不同的像素值,我在 matlab 中得到的值是正值,而 open cv 给出的值是负值。

最佳答案

您可能正在将一个带符号的字节值转换为 int,它可以给出负值。试试这个代码:

  std::cout << std::dec << "R:" << (unsigned int) pRGBImg->imageData[i] <<  
" G:" << (unsigned int) pRGBImg->imageData[i+1] <<
" B:" << (unsigned int) pRGBImg->imageData[i+2] << " ";

关于c++ - 访问负像素值 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6292081/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com