问题
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