How to access image Data from a RGB image (3channel image) in opencv

前端 未结 5 818
予麋鹿
予麋鹿 2021-01-21 14:55

I am trying to take the imageData of image in this where w= width of image and h = height of image

for (int i = x; i < x+h; i++) //height of frame pixels
{
          


        
5条回答
  •  甜味超标
    2021-01-21 15:32

    See good explanation here on multiple methods for accessing pixels in an IplImage in OpenCV.

    From the code you've posted your problem lies in your position variable, you'd want something like int pos = i*w*Channels + j*Channels, then you can access the RGB pixels at

    unsigned char r = data->imageData[pos];

    unsigned char g = data->imageData[pos+1];

    unsigned char b = data->imageData[pos+2];

    (assuming RGB, but on some platforms I think it can be stored BGR).

提交回复
热议问题