Ask Your Question
1

Multiply vector by matrix

asked 2018-02-28 06:41:36 -0500

psi gravatar image

updated 2018-02-28 06:43:35 -0500

Please, teach me how to multiply a matrix to a vector. I have really no idea. This is my code

#include <iostream>
#include <opencv2/opencv.hpp>

int main()
{

    cv::Mat_<float> rotation_matrix = cv::Mat::eye(3, 3, CV_32FC1);

    rotation_matrix(0, 0) = 2;
/* Translation vector */
    cv::Vec3f current_translation(1.2,
                              2.3,
                              3.1);
/* Rotation */

    std::cout << current_translation << std::endl;
    std::cout << rotation_matrix << std::endl;
    std::cout << rotation_matrix.dot(current_translation) << std::endl;

    return 0;
}

When I run it, I've got the error:

[1.2, 2.3, 3.1]
[2, 0, 0;
0, 1, 0;
0, 0, 1]
OpenCV Error: Assertion failed (mat.size == size) in dot, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/matmul.cpp, line 3383
terminate called after throwing an instance of 'cv::Exception'
what():  /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/matmul.cpp:3383: error: (-215) mat.size == size in function dot


Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

I've also tried with '*' operator instead of .dot(), but it crashes even in compiling time. So, help me please.

edit retag flag offensive close merge delete

Comments

LBerger gravatar imageLBerger ( 2018-02-28 07:18:03 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-02-28 07:13:12 -0500

LBerger gravatar image

to multiply a matrix to a vector use * :

cv::Mat_<float> rotation_matrix = cv::Mat::eye(3, 3, CV_32FC1);

rotation_matrix(0, 0) = 2;
/* Translation vector */
cv::Vec3f current_translation(1.2,
    2.3,
    3.1);
std::cout << current_translation << std::endl;
std::cout << rotation_matrix << std::endl;
std::cout << rotation_matrix*Mat(current_translation) << std::endl;
edit flag offensive delete link more

Comments

1

Thank you very much!

psi gravatar imagepsi ( 2018-03-01 05:20:27 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-02-28 06:41:36 -0500

Seen: 3,161 times

Last updated: Feb 28 '18