ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Accessing pixel pointer

asked 2014-07-03 08:32:01 -0500

ROSkinect gravatar image

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 flag offensive close merge delete

Comments

ptr_img_B seems to be missing here.

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

how so ?..

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

It is neither declared nor advanced ever.

dornhege gravatar image dornhege  ( 2014-07-04 05:12:12 -0500 )edit

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

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

1 Answer

Sort by ยป oldest newest most voted
3

answered 2014-07-03 11:39:12 -0500

ahendrix gravatar image

updated 2014-07-04 03:50:01 -0500

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

This page explains it fairly well: http://www.cs.umd.edu/class/sum2003/c...

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

edit flag offensive delete link more

Comments

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

ROSkinect gravatar image ROSkinect  ( 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.

ahendrix gravatar image ahendrix  ( 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 !

ROSkinect gravatar image ROSkinect  ( 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...

Wolf gravatar image Wolf  ( 2014-07-04 04:20:22 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-07-03 08:32:01 -0500

Seen: 390 times

Last updated: Jul 04 '14