2011-06-09 8 views
0
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] << " "; 
} 

ce code donne différentes valeurs de pixels ce que j'ai obtenu dans matlab est positif et ouvert cv donne une valeur négative.Accès aux valeurs de pixels négatifs OpenCV

Répondre

1

Vous convertissez probablement une valeur d'octet signée en int pouvant donner des valeurs négatives. Essayez ce 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] << " "; 
0

utilisant uchar a fonctionné pour moi

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