Search code examples
imagevideoopencvpixel

How do I access a pixel in OpenCV?


I have an x,y point coordinate, how would I use this to access a specific point on an IplImage?

Thanks


Solution

  • 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))