Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

the CV_IMAGE_ELEM was a macro in the old C opencv api in order to obtain the pixel value of an image. Assume a gray-scale image, access to the row i, column j pixel can be:

CV_IMAGE_ELEM (image, type, i, j);

or in case of a colour image:

CV_IMAGE_ELEM (image, type, i, Nc * j + c);
CV_IMAGE_ELEM (image, type, i, Nc * j + c);
CV_IMAGE_ELEM (image, type, i, Nc * j + c);

, where

  • Nc: The total number of channels
  • c: The channel you're interested in (varies from 0 to 3)

Now if you want to transform this into the new C++ api you can do it different ways:

You use the at method to access the value at a particular position (i, j):

type elem_a= matrix.at<type>[c](i,j); //access element aij, with i from 0 to rows-1 and j from 0 to cols-1

Instead of specifying the position with i and j, you can use a Point object:

Point p=Point(x,y);
type elem_a= matrix.at<type>[c](p); //Warning: y ranges from 0 to rows-1 and x from 0 to cols-1

or you can use the ptr method to obtain a pointer to a particular row. Then you use the [] to access a particular pixel in a particular channel:

type elem = matrix.ptr<type>(i)[Nc * j + c]

, where

  • type: The datatype (float, int, uchar, etc)
  • i: The row you're interested in
  • Nc: The number of channels
  • j: The column you're interested in
  • c: The channel you're interested in (varies from 0 to 3, in case of single channel this can be omitted)

the CV_IMAGE_ELEM was a macro in the old C opencv api in order to obtain the pixel value of an image. Assume a gray-scale image, access to the row i, column j pixel can be:

CV_IMAGE_ELEM (image, type, i, j);

or in case of a colour image:

CV_IMAGE_ELEM (image, type, i, Nc * j + c);
CV_IMAGE_ELEM (image, type, i, Nc * j + c);
CV_IMAGE_ELEM (image, type, i, Nc * j + c);

, where

  • Nc: The total number of channels
  • c: The channel you're interested in (varies from 0 to 3)

For example, for a colour image:

CV_IMAGE_ELEM (image, uchar, i, 3 * j)
CV_IMAGE_ELEM (image, uchar, i, 3 * j +1)
CV_IMAGE_ELEM (image, uchar, i, 3 * j +2)

Now if you want to transform this into the new C++ api you can do it different ways:

You use the at method to access the value at a particular position (i, j):

type elem_a= matrix.at<type>[c](i,j); //access element aij, with i from 0 to rows-1 and j from 0 to cols-1

Instead of specifying the position with i and j, you can use a Point object:

Point p=Point(x,y);
type elem_a= matrix.at<type>[c](p); //Warning: y ranges from 0 to rows-1 and x from 0 to cols-1

or you can use the ptr method to obtain a pointer to a particular row. Then you use the [] to access a particular pixel in a particular channel:

type elem = matrix.ptr<type>(i)[Nc * j + c]

, where

  • type: The datatype (float, int, uchar, etc)
  • i: The row you're interested in
  • Nc: The number of channels
  • j: The column you're interested in
  • c: The channel you're interested in (varies from 0 to 3, in case of single channel this can be omitted)

the CV_IMAGE_ELEM was a macro in the old C opencv api in order to obtain the pixel value of an image. Assume a gray-scale image, access to the row i, column j pixel can be:

CV_IMAGE_ELEM (image, type, i, j);

or in case of a colour image:

CV_IMAGE_ELEM (image, type, i, Nc * j + c);

, where

  • Nc: The total number of channels
  • c: The channel you're interested in (varies from 0 to 3)

For example, for a colour image:example:

CV_IMAGE_ELEM (image, uchar, i, 3 * j)
CV_IMAGE_ELEM (image, uchar, i, 3 * j +1)
CV_IMAGE_ELEM (image, uchar, i, 3 * j +2)

Now if you want to transform this into the new C++ api you can do it different ways:

You use the at method to access the value at a particular position (i, j):

type elem_a= matrix.at<type>[c](i,j); //access element aij, with i from 0 to rows-1 and j from 0 to cols-1

Instead of specifying the position with i and j, you can use a Point object:

Point p=Point(x,y);
type elem_a= matrix.at<type>[c](p); //Warning: y ranges from 0 to rows-1 and x from 0 to cols-1

or you can use the ptr method to obtain a pointer to a particular row. Then you use the [] to access a particular pixel in a particular channel:

type elem = matrix.ptr<type>(i)[Nc * j + c]

, where

  • type: The datatype (float, int, uchar, etc)
  • i: The row you're interested in
  • Nc: The number of channels
  • j: The column you're interested in
  • c: The channel you're interested in (varies from 0 to 3, in case of single channel this can be omitted)

the CV_IMAGE_ELEM was a macro in the old C opencv api in order to obtain the pixel value of an image. Assume a gray-scale image, access to the row i, column j pixel can be:

CV_IMAGE_ELEM (image, type, i, j);

or in case of a colour image:

CV_IMAGE_ELEM (image, type, i, Nc * j + c);

, where

  • Nc: The total number of channels
  • c: The channel you're interested in (varies from 0 to 3)

For example:

CV_IMAGE_ELEM (image, uchar, i, 3 * j)
CV_IMAGE_ELEM (image, uchar, i, 3 * j +1)
CV_IMAGE_ELEM (image, uchar, i, 3 * j +2)

Now if you want to transform this into the new C++ api you can do it different ways:

You use the at method to access the value at a particular position (i, j):

type elem_a= matrix.at<type>[c](i,j); //access element aij, with i from 0 to rows-1 and j from 0 to cols-1

Instead of specifying the position with i and j, you can use a Point object:

Point p=Point(x,y);
type elem_a= matrix.at<type>[c](p); //Warning: y ranges from 0 to rows-1 and x from 0 to cols-1

or you can use the ptr method to obtain a pointer to a particular row. Then you use the [] to access a particular pixel in a particular channel:

type elem = matrix.ptr<type>(i)[Nc * j + c]

, where

  • type: The datatype (float, int, uchar, etc)
  • i: The row you're interested in
  • Nc: The total number of channels
  • j: The column you're interested in
  • c: The channel you're interested in (varies from 0 to 3, in case of single channel this can be omitted)