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
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
2 | No.2 Revision |
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
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
3 | No.3 Revision |
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
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
4 | No.4 Revision |
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
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