使用Unity3D的solvePnP [英] solvePnP with Unity3D

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

问题描述

我有一个装有红外摄像机的真实/物理棒,并有一些IR LED形成了我正在使用的图案,以使虚拟棒以与物理棒相同的方式移动.

I have a real/physical stick with an IR camera attached to it and some IR LED that forms a pattern that I'm using in order to make a virtual stick move in the same way as the physical one.

为此,我在Python中使用OpenCV,并将由solvePnP计算的旋转和平移矢量发送到Unity.

For that, I'm using OpenCV in Python and send a rotation and translation vector calculated by solvePnP to Unity.

我正努力了解如何将SolvePnP函数给出的结果用于我的3D世界.

I'm struggling to understand how I can use the results given by the solvePnP function into my 3D world.

到目前为止,我所做的是:使用solvePnP函数获取旋转和平移矢量.然后使用此旋转矢量在3d世界中移动我的棍子

So far what I did is: using the solvePnP function to get the rotation and translation vectors. And then use this rotation vector to move my stick in the 3d World

transform.rotation = Quaternion.Euler(new Vector3(x, z, y));

当我的摇杆以一定角度放置并且移动缓慢时,这似乎还可以.但是大多数情况下,它到处都是.

It seems to work okay when my stick is positioned at a certain angle and if I move slowly...but most of the time it moves everywhere.

通过在线寻找答案,大多数人在solvePnP之后又要执行几个步骤-据我了解:

By looking for answers online, most of people are doing several more steps after solvePnP - from what I understand:

  1. 使用Rodrigues将旋转矢量转换为旋转矩阵

  1. Using Rodrigues to convert the rotation vector to a rotation matrix

将旋转矩阵复制并平移 vector 到外部矩阵

Copy the rotation matrix and translation vector into a extrinsic matrix

我知道,如果我像在OpenGL中那样使用矩阵,则必须执行这些步骤-但是Unity3D呢?这些额外步骤是否必要?或者我可以直接使用由solvePnP函数提供的向量(我怀疑,到目前为止我得到的结果不好).

I understand that these steps are necessary if I was working with matrix like in OpenGL - but what about Unity3D? Are these extra steps necessary? Or can I directly use the vectors given by the solvePnP function (which I doubt as the results I'm having so far aren't good).

推荐答案

这很旧,但是答案是关于Unity3D的问题?这些额外的步骤是否必要?或者我可以直接使用由solvePnP函数提供的向量吗? "

This is old, but the answer to the question "what about Unity3D? Are these extra steps necessary? Or can I directly use the vectors given by the solvePnP function"

是:

-不,您不能直接使用它们.我尝试使用Quaternion.Euler转换rvec,正如您所发布的,结果很糟糕.

-No, you can't directly use them. I tried to convert rvec using Quaternion.Euler and as you've posted, the results were bad.

-是的,您必须使用Rodrigues,它可以将rvec正确地转换为旋转矩阵.

-Yes, you have to use Rodrigues, which converts rvec correctly into a rotation matrix.

-关于外在矩阵的求逆:这要视情况而定. 如果您的对象位于世界空间中的(0,0,0),并且您想放置相机,则必须反转tvec和rvec所产生的变换,以便获得所需的结果. 另一方面,如果您的摄像头具有固定的位置,并且想要相对于该对象定位对象,则必须将摄像头的localToWorld矩阵应用于rvec和tvec产生的变换,以获得所需的结果

-About inversing the extrinsic matrix: it depends. If your object is at (0,0,0) in world space and you want to place the camera, you have to invert the transform resulting from tvec and rvec, in order to get the desired result. If on the other hand your camera has a fixed position and you want to position the object relatively to it, you have to apply the camera's localToWorld matrix to your transform resulting from rvec and tvec, in order to get the desired result

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

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