# Accessing pixel pointer

Hi guys

Can you explain to me how the accessing pixel has been done in the double loop ? how do they change rows and cols and pixel's value?

for(int i=0;i<cv_ptr->image.rows;i++)
{
float* ptr_img_A = cv_ptr->image.ptr<float>(i);

for(int j=0;j<cv_ptr->image.cols;j++)
{
*ptr_img_B=255*(*ptr_img_A)/3.5;
ptr_img_A++;
}
}


Thank you.

edit retag close merge delete

ptr_img_B seems to be missing here.

( 2014-07-03 18:59:45 -0500 )edit

how so ?..

( 2014-07-04 02:38:10 -0500 )edit

It is neither declared nor advanced ever.

( 2014-07-04 05:12:12 -0500 )edit

Ya I just pick up this part of code just to understand the accessing pixel

( 2014-07-04 05:28:36 -0500 )edit

Sort by ยป oldest newest most voted

This is fairly normal pointer arithmetic, usually explained in a second or third computer science/C++ course.

The OpenCV Mat Documentation describes how to access data in OpenCV images.

more

I don't want courses in pointer, my question was how we can use pointer to access to pixel. Anyway thank you

( 2014-07-04 02:34:25 -0500 )edit
1

The sample you posed uses pointer arithmetic to access the value of each pixel in row-major order.

( 2014-07-04 03:01:27 -0500 )edit

and what about the cols ? because as I know the image is like a two dimension table we can access to each pixel via i,j.. but using pointer I can't see clearly how we do that !

( 2014-07-04 03:24:23 -0500 )edit
2

Same as in the question you asked here http://answers.ros.org/question/173933/accessing-pixel-image-c/ ptr_img_A = cv_ptr->image.ptr<float>(i); Gives you a pointer to the first element in the i'th row. ptr_img_A++ changes ptr_img_A from pointing to one column to pointing the next column...

( 2014-07-04 04:20:22 -0500 )edit