How do I access a pixel in OpenCV?

拜拜、爱过 提交于 2019-11-30 18:54:45

问题


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

Thanks


回答1:


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



回答2:


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];
       }
     }


来源:https://stackoverflow.com/questions/7535364/how-do-i-access-a-pixel-in-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!