Ask Your Question
0

Opencv sum()[]

asked 2013-06-04 22:14:02 -0600

xiaojidan gravatar image

I am new to opencv , I do not understand the function "sum".

Mat img=(Mat_<double>(3,3)<<0,-1,0,-1,5,-1,2,-1,0); double rr=sum(img)[0]; cout<<"rr"<<rr&lt;<endl;< p="">

waitKey(0);
return 0;

What is the meaning of this function "sum", sum(img)[0] is standing for?? sum(img)[1] is standing for ? sum(img)[2] is stranding for??

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-06-05 02:41:19 -0600

berak gravatar image

sum() returns a Scalar with the sum of all pixels per channel

so, for a 3channel img (think a color image),

Scalar s = sum(img);
// s[0] is the sum of the 1st channel (B probably)
// s[1] is the sum of the 2nd channel (G probably)
// s[2] ...

in your case, the Mat only has one channel, so double s = sum(mat)[0] is the way to access it.

edit flag offensive delete link more

Comments

Thank you

xiaojidan gravatar imagexiaojidan ( 2013-06-05 06:29:20 -0600 )edit

Question Tools

Stats

Asked: 2013-06-04 22:14:02 -0600

Seen: 4,233 times

Last updated: Jun 05 '13