OpenCV Android - Calculate the average of a column of Mat

What I'm trying is to calculate the average of a column using openCV in android.

The initial idea was to copy each column to a temp matrix, then use Core.mean() to get the average value. But the problem is : To use Mat.put(), it is expected to have a row, column and a Array[] data and Core.Mean() returns a scalar, so I can't do something like:

myMat.put(row,1,Core.Mean(myTempColumn)).

So how this operation can be done?

I'm wondering that I'll need to get each element from myMat using get and then sum. But the problem is get returns also a Array[] data (that I think is the RGB value), and to sum it, will be necessary another for structure (which I don't think it is the easiest way).

Thank you in advance.

Upvotes: 0

Views: 1148

Answers (1)

Ok solve it: Core.reduce(imageMat,averageMat,0,Core.REDUCE_AVG);

Where: 0 means that the matrix is reduced to a single row. 1 means that the matrix is reduced to a single column.

Core.REDUCE_AVG - does the average

Upvotes: 1

Related Questions