Ask Your Question

Java equivalent for Vec and Matx?

asked 2013-03-14 22:23:57 -0500

rylexr gravatar image


I'm doing a project with OpenCV 2.4.4 Java wrappers and I need to know what is the equivalent for Vec and Matx classes. Thanks in advance.


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-03-15 03:52:42 -0500

Vec and Mat are just for small vector/matrix where the size is known at compile time. You could use Point/Point2f/Point3f/Scalar depending on the needed size.

But you should probably used Mat for other size, I've seen nothing in Java doc, maybe because this class are template for the compilation, therefore not binded in Java... Or you can create your templated class in Java for usual size (2x2,3x3,4x4,...).

edit flag offensive delete link more


It that means I can replace them with native Java arrays? Like for instance:

Vec2i -> int[2]
Vec6d -> double[6]
Matx31f -> float[3][1]
Matx66d -> double[6][6]

Or it's better to create a generic class for each one, like:

public class Vec<T> {
  private int size;
  private Object[] data;

  public Vec(int size) {
    this.size = size; = new Object[size];

  // other methods

so Vec2i could be represented like: Vec<Integer> v = new Vec<Integer>(2) ?

rylexr gravatar imagerylexr ( 2013-03-15 14:22:56 -0500 )edit

Question Tools


Asked: 2013-03-14 22:23:57 -0500

Seen: 686 times

Last updated: Mar 15 '13