Ask Your Question
1

android: how to put a column into Mat

asked 2012-08-06 09:22:24 -0600

darKoram gravatar image

updated 2012-08-07 09:31:41 -0600

Andrey Pavlenko gravatar image

According to the best practices page we want to use the fewest calls to the JNI as possible to get the job done.

In my application, I want to add a column of data (held in a List<double> or double[] to a Mat column. Rather than doing this

public void putColumn(int colIndex, List<Double> colData, MatOfDouble mat) {
    for( int i=0; i<colData.size(); i++) {
         mat.put(i, colIndex, colData[i]);
    }

I'd prefer to do something like this:

mat.putColumn(List<Double> colData);

Thus reducing the number of JNI calls from colData.size() to 1 call. Is there such a function in the Android API that does this, or do I have to build one with the JNI?

MatOfDouble has nice calls for exporting Mat data to java:
List<Double> mat.toList()
double[] mat.toArray()
but the fromArray(double...a) only seems to be for the constructor.

By the way, why the difference in declarations for float and double versions of put in MatOfDouble?

   public int put(int row, int col, double... data)

   public int put(int row, int col, float[] data)

I'm a c++ programmer and "double...a" is not something i'm familiar with. What does it mean?

edit retag flag offensive close merge delete

Comments

1

I think this post is useful for you http://answers.opencv.org/question/5/how-to-get-and-modify-the-pixel-of-mat-in-java/ . It explains how to modify your data in Java and update it at once in native

sammy gravatar imagesammy ( 2012-08-06 09:31:45 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2012-08-07 09:43:38 -0600

Andrey Pavlenko gravatar image

updated 2012-08-07 09:44:30 -0600

There is no Mat::putColumn() method. But be aware that neither of Mat::put() methods can change the Mat size - instead they can change values of one or more sequential pixels in the Mat.

Another note is that MatOfXxx types are introduced to represent in Java std::vector<Xxx> from C++ side. It means in particular that MatOfDouble should be of either 1xN or Nx1 size.

All the MatOfXxx types have fromArray(Xxx... aX) and fromList(List<Xxx> lX) methods that discard their existing content, allocate a new native buffer of 1xN size and fill it with the provided values.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-08-06 09:22:24 -0600

Seen: 3,114 times

Last updated: Aug 07 '12