1 | initial version |
In Java you can use Mat::get()
and Mat::put()
methods.
One pixel can be read by
double[] Mat::get(int row, int col)
One or few pixels can be written by
Mat::put(int row, int col, double... data)
But if you're going to work with many pixels, it's better to get all the Mat data at once to Java primitive array, work with it in Java, and then put it back to Mat with a single JNI call. The corresponding Java primitive array type depends on the Mat type:
CV_8U and CV_8S -> byte[],
CV_16U and CV_16S -> short[],
CV_32S -> int[],
CV_32F -> float[],
CV_64F-> double[].
So the code will like following:
Mat m = ... // assuming it's of CV_8U type
byte buff[] = new byte[m.total() * m.channels()];
m.get(0, 0, buff);
// working with buff
// ...
m.put(0, 0, buff);
2 | No.2 Revision |
In Java you can use Mat::get()
and Mat::put()
methods.
One pixel can be read by
double[] Mat::get(int row, int col)
One or few pixels can be written by
Mat::put(int row, int col, double... data)
But if you're going to work with many pixels, it's better to get all the Mat data at once to Java primitive array, work with it in Java, and then put it back to Mat with a single JNI call. The corresponding Java primitive array type depends on the Mat type:
CV_8U and CV_8S -> byte[],
CV_16U and CV_16S -> short[],
CV_32S -> int[],
CV_32F -> float[],
CV_64F-> double[].
So the code will look like following:
Mat m = ... // assuming it's of CV_8U type
byte buff[] = new byte[m.total() * m.channels()];
m.get(0, 0, buff);
// working with buff
// ...
m.put(0, 0, buff);