Ask Your Question

Video element access

asked 2012-09-04 14:58:58 -0500

bharath422 gravatar image


I am a newbie opencv user, and I wanted to ask how to access the elements of a Mat. This question has been answered before, I am pasting the answer to this which was answered before which is:

You can use template version of Mat:

Mat_<vec3b> bgrMat; bgrMat(y, x) = Vec3b(0,0,0); Vec3b* row = bgrMat[y] // pointer to mat row

However, for this I have to create a template version on Mat. However, I am trying to work on a video streaming problem where I want to operate on 2D images from a video stream as below:

Mat edges;
    Mat frame;
    cap >> frame;
    ............ //work on frame element by element.


I guess i cant use the template version of Mat in this case. I tried using it and I got compiler errors. I also, tried to follow what was given in the documentation that I can refer to the Mat elements using the .at() function provided I know the type, which I did not know. I tried to use the type() function for that, which returned the value 16 which I was not trying to interpret. The documentation only says type() can be used as in the previous versions with IplImage or CvMat, and assumes the user is acquainted with the older versions of opencv, but unfortunately i am not.


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-09-05 03:56:59 -0500

Vladislav Vinogradov gravatar image

VideoCapture returns BGR images, so the type will be Vec3b.

The image type is a combination of depth and channels.

depth - the type of pixel's element
channels - the number of elements in pixel

For depth OpenCV uses constants:

CV_8U - unsigned char
CV_8S - signed char
CV_16U - unsigned short
CV_16S - signed short
CV_32S - int
CV_32F - float
CV_64F - double

So 3-channel 8-bit image will have CV_8UC3 type (CV_8U depth and 3 Channels).

You can use depth() function to know image depth and channels() function to know channels number.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2012-09-04 14:58:58 -0500

Seen: 273 times

Last updated: Sep 05 '12