Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Reading pixel values from a frame of a video

Hi,

Is this the right way of reading pixel values from a frame of video?:

IplImage* bgr_frame = cvQueryFrame( capture );
int width, height, nchannels, step;
int i, j, r_ch, b_ch, g_ch;

width = bgr_frame->width;
height = bgr_frame->height;
nchannels = bgr_frame->nChannels;
step = bgr_frame->widthStep;
uchar *data = ( uchar* )bgr_frame->imageData;

for(i = 0 ; i < height ; i++) 
{
  for( j = 0 ; j < width ; j++)
  {
    b_ch = ((uchar *)(bgr_frame->imageData + i*bgr_frame->widthStep))[j*bgr_frame->nChannels + 0];
    g_ch = ((uchar *)(bgr_frame->imageData + i*bgr_frame->widthStep))[j*bgr_frame->nChannels + 1];
    r_ch = ((uchar *)(bgr_frame->imageData + i*bgr_frame->widthStep))[j*bgr_frame->nChannels + 2];       
  }
}

Thanks and regards Himanshu