Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Multiply vector by matrix

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 build it, I've got the error:

/home/roman/CLionProjects/opencv_tests/cmake-build-debug/test_e
[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.

Multiply vector by matrix

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 build run it, I've got the error:

/home/roman/CLionProjects/opencv_tests/cmake-build-debug/test_e
[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.

Multiply vector by matrix

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:

/home/roman/CLionProjects/opencv_tests/cmake-build-debug/test_e
[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.