Ask Your Question
0

vector results inconsistent what am I doing?[SOLVED]

asked 2020-01-18 20:54:40 -0500

superfly gravatar image

updated 2020-01-19 20:02:21 -0500

supra56 gravatar image

Hi, I am getting 2 different vector-cross product results, one from OpenCV and different from OpenCV but same with each other from Symbolab Vector-Cross Calculator & the following video 6.17 tutorial on calculating plane equation.

Here are the 2 vectors PQ & PR. Try them initially with OpenCV and Symbolab:

Mat PQ = (Mat_<float>(3, 1) << 1.0, -1.0, 0.0);
Mat PR = (Mat_<float>(3, 1) << 1.0, 0.0, -1.0);

Mat vec_cross_result = (Mat_<float>(3, 1) << 0.0, 0.0, 0.0);
cv::multiply(PR, PQ, vec_cross_result);
std::cerr << PQ << " " << PR << "  " << std::endl << "Result: " << std::endl << vec_cross_result << std::endl;
[1,-0,-0]  //OpenCV result

Using dedicated vectors Vec3f below instead of a 3 x 1 matrix above, and got the same OpenCV as with Mats, to no surprise...

cv::Vec3f A(1.0, -1.0, 0.0), B(1.0, 0.0, -1.0), vector_cross;
std::cerr << A << std::endl;
std::cerr << B << std::endl;
multiply(A, B, vector_cross);
std::cerr << "Vector result:" << vector_cross << std::endl;

Symbolab result is [1,1,1]. Video tutorial the same 6:17.. What am I overlooking?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2020-01-18 22:05:45 -0500

Tetragramm gravatar image

cv::multiply is not a cross product. It is an element-wise product.

You want to do

vec_cross_result = PQ.cross(PR);
edit flag offensive delete link more

Comments

Excellent! Thank you!

std::cout << "by Mat" << std::endl;
    Mat PQ = (Mat_<float>(3, 1) << 1.0, -1.0, 0.0);
    Mat PR = (Mat_<float>(3, 1) << 1.0, 0.0, -1.0); 
    Mat  vec_cross_result = (Mat_<float>(3, 1) << 0.0, 0.0, 0.0);
    vec_cross_result = PQ.cross(PR);
    std::cerr << PQ << " " << PR << "  " << std::endl << "Result: " << std::endl << vec_cross_result << std::endl;

Result [1,1,1] - correct

    std::cout << "by vector";
    cv::Vec3f A(1.0, -1.0, 0.0), B(1.0, 0.0, -1.0), vec_cr_result;
    std::cerr << A << " " << B << " " << vec_cr_result << std::endl;
    vec_cr_result = A.cross(B);
   std::cerr << A << " " << B << "  " << std::endl << "Result: " << vec_cr_result<<std::endl;

Result[1,1,1]-correct

superfly gravatar imagesuperfly ( 2020-01-19 10:50:26 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-01-18 20:50:33 -0500

Seen: 51 times

Last updated: Jan 19