First time here? Check out the FAQ!

Ask Your Question
2

Mat element access

asked Sep 4 '12

mrgloom gravatar image

updated Dec 27 '15

I read this article, but I can't find how to access Mat element like this

img[y][x]=100;

is it possible? And another question is how can I don't omit type of Mat, but check types on compilation time.

instead of

img.at<uchar>(i,j)

something like this

img[i][j]
Preview: (hide)

1 answer

Sort by » oldest newest most voted
5

answered Sep 4 '12

Vladislav Vinogradov gravatar image

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
Preview: (hide)

Comments

So I can access pixel like bgrMat(y, x) = Vec3b(B,G,R); ?

mrgloom gravatar imagemrgloom (Sep 5 '12)edit

Yes, for Mat_<Vec3b>.

Question Tools

Stats

Asked: Sep 4 '12

Seen: 3,475 times

Last updated: Sep 04 '12