opencv 中读取RGB像素值 .

1. 直接定位到imageData,用数组的形式读取

    unsigned char  b=(unsigned char )m_image.GetImage()->imageData[0];
    unsigned char  g=(unsigned char )m_image.GetImage()->imageData[1];
    unsigned char  r=(unsigned char )m_image.GetImage()->imageData[2];

 

2. 使用CvScalar

 

    IplImage *img=cvLoadImage("c://kobe.bmp",1);
    CvScalar s;
    for(int i=0; iheight; i++)

    {
        for(int j=0; jwidth; j++)

        {
             s=cvGet2D(img,i,j);     // get the (i,j) pixel value
             printf("B=%f, G=%f, R=%f ",s.val[0],s.val[1],s.val[2]);
             s.val[0]=111;
             s.val[1]=111;
             s.val[2]=111;
             cvSet2D(img,i,j,s);       //set the (i,j) pixel value
        }
    }

你可能感兴趣的:(opencv)