6

Is there any easy way to multiplicate Mat and Vec_? (Provided, that they have proper sizes, e.g.:

Mat_<double> M = Mat(3,3,CV_32F);
Vec3f V=(1,2,3);
result = M*V //?

Maybe there is some easy method of creating row (or col) Mat based on Vec3?

Szał Pał
  • 306
  • 1
  • 7
  • 20

1 Answers1

7

You can't just multiply Mat and Vec (or, more generally, Matx_) elements. Cast the Vec object to Mat:

Mat_<float> M = Mat::eye(3,3,CV_32F);
Vec3f V=(1,2,3);
Mat result = M*Mat(V);

Also, I noticed an error in your code: when constructing M, the type CV_32F corresponds to float elements, not double. This is also corrected in my code example.

Hope that it helps.

Яois
  • 3,838
  • 4
  • 28
  • 50
  • 2
    Minor detail, but this isn't a "cast". It is actually invoking the `Mat` constructor that accepts a single `Vec` as an argument. https://docs.opencv.org/3.4.6/d3/d63/classcv_1_1Mat.html#a507e01fb48b34a3e5c45f9f5b00725e8 – Matt Apr 17 '19 at 16:14