working in pixels in Mat structure

asked 2014-07-25 04:26:06 -0500

jamesnzt gravatar image

updated 2014-07-25 04:30:02 -0500

Siegfried gravatar image

I would like to know how can we work in pixels in the image using MAT structure. I learnt from the forum how to read the RGB value of oixel by the following

for (int i=0;i<img.rows;i++)
  {
    for(int j=0;j<img.cols;j++)
    {
      Vec3f intensity = img.at<Vec3f>(j, i);
      float blue=intensity.val[0];
      float green=intensity.val[1];
      float red=intensity.val[2];
    }
  }

Now i want to copy the value in red,green & blue variables in another MAT structure which same size of img in the same for loop above. How can i edit a value in a pixel?

Thanks in advance :)

edit retag flag offensive close merge delete

Comments

tutorials

also, your code above does the classic noob error of swapping j and i.

it's row-col world in opencv, so if i goes over rows, it should be img.at<Vec3f>(i, j);

berak gravatar imageberak ( 2014-07-25 04:28:59 -0500 )edit

how to make this program line by line. When i typed it, it comes in a single line?

jamesnzt gravatar imagejamesnzt ( 2014-07-25 04:34:21 -0500 )edit
FLY gravatar imageFLY ( 2014-07-25 06:59:35 -0500 )edit