开发者

How do I access a pixel in OpenCV?

开发者 https://www.devze.com 2023-04-06 21:50 出处:网络
I 开发者_Go百科have an x,y point coordinate, how would I use this to access a specific point on an IplImage?

I 开发者_Go百科have an x,y point coordinate, how would I use this to access a specific point on an IplImage?

Thanks


Use CV_IMAGE_ELEM

CV_IMAGE_ELEM( image_header, elemtype, y, x*N+C )

E.g. given an 8-bit 3 channel (such as RGB) IplImage* img, we want (x,y) on the 2nd channel:

CV_IMAGE_ELEM(img, uchar, y, (x * 3) + 1))


OR, you can do this. for more matrix operation, see here.

http://note.sonots.com/OpenCV/MatrixOperations.html

     int col, row, z;
     uchar b, g, r;
     for( y = 0; row < img->height; y++ )
     {
       for ( col = 0; col < img->width; col++ )
       {
         //for( z = 0; z < img->nChannels; z++ )
         //{
         //   c = img->imageData[img->widthStep * row + col * img->nChannels + z];
         //}
         b = img->imageData[img->widthStep * row + col * 3]
         g = img->imageData[img->widthStep * row + col * 3 + 1];
         r = img->imageData[img->widthStep * row + col * 3 + 2];
       }
     }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号