Thursday, March 31, 2011

Different way of accessing pixel using OpenCV


// 1st way of Accesing pixels
for(int row=0;row<p_img->get_height();row++){
for(int col=0;col<p_img->get_width();col++)
{
ptr_data_grey[row*step_grey+col]=
(ptr_data_rgb[row*step_rgb+col*channels_rgb+0]*0.299) +
(ptr_data_rgb[row*step_rgb+col*channels_rgb+1]*0.587)+
(ptr_data_rgb[row*step_rgb+col*channels_rgb+2]*0.114);
}
}
//2nd way of accessing pixels.
for(int row=0;row<p_img->get_height();row++){
uchar* ptr_data_rgb_updated = ptr_data_rgb + row*step_rgb;
uchar* ptr_data_grey_updated = ptr_data_grey+ row*step_grey;
for(int col=0;col<p_img->get_width();col++)
{

//ptr_data_grey[row*step_grey+col]=
ptr_data_grey_updated[col]=
(ptr_data_rgb_updated[channels_rgb*col+0]*0.299) +
(ptr_data_rgb_updated[channels_rgb*col+1]*0.587)+
(ptr_data_rgb_updated[channels_rgb*col+2]*0.114);
}
}

No comments:

Post a Comment

Please ask if anything is not clear enough..........