使用旋转矩阵opencv [英] Using a rotation matrix opencv

查看:153
本文介绍了使用旋转矩阵opencv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在opencv中有功能Core.Rodrigues的旋转矩阵.我想通过此旋转矩阵围绕原点旋转一个位于(0,0,1)的点.我该如何获取该点的新位置?

I have a rotation matrix from the function Core.Rodrigues in opencv. I want to rotate a point located at (0, 0, 1) about the origin by this rotation matrix. How do I do this to get the new location of the point?

   Mat rmat= new Mat();
   Calib3d.Rodrigues(rvec, rmat); //rvec is the rotation vector from solvepnp
   double[] p= {0, 0, 1};
   Scalar scalar= new Scalar(p);
   Mat point= new Mat(1, 3, CvType.CV_64F, scalar);
   Mat newpoint= new Mat();
   Mat empty= new Mat();
   Core.gemm(point, rmat, 1, empty, 0, newpoint);

当我知道那是错误的时候,newpoint的结果为0、0、0

newpoint has 0, 0, 0 for the result, when I know that that is wrong

任何帮助将不胜感激.

推荐答案

围绕原点旋转点的方法是将其与旋转矩阵预乘.我对Core.gemm不熟悉.这是一种更透明的方法.

The way to rotate a point about the origin is to premultiply it with the rotation matrix. I am not familiar with Core.gemm. Here is a more transparent way of doing this.

Mat rmat= new Mat();
Calib3d.Rodrigues(rvec, rmat); //rvec is the rotation vector from solvepnp
Matx33f rotation_matrix = rmat;
Matx31f original_point(0,0,1);
Matx31f rotated_point = rotation_matrix*original_point;

这应该更容易调试.检查存储在rotation_matrix中的值,确保将它们初始化为合理的值(在调试器中可以看到Matx的内容).您可以查看这些值,然后自己进行乘法以仔细检查是否愿意.这个过程应该是完全透明的.

This should be much easier to debug. Check the values stored in rotation_matrix, make sure they are initialized to reasonable values (the contents of Matx can be seen in debugger). You can look at the values and do the multiplication yourself to double check if you like. The process should be entirely transparent.

这篇关于使用旋转矩阵opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆