ovis: make sure entities are oriented by the OpenCV CS conventions

pull/1569/head
Pavel Rojtberg 7 years ago
parent 0520753dc1
commit a62f9c426e
  1. 6
      modules/ovis/samples/ovis_demo.py
  2. 16
      modules/ovis/src/ovis.cpp

@ -7,19 +7,19 @@ cv.ovis.addResourceLocation("packs/Sinbad.zip")
# camera intrinsics
imsize = (800, 600)
K = np.diag([800, 800, 1])
K[:2, 2] = (400, 100) # offset pp
K[:2, 2] = (400, 500) # offset pp
# observer scene
owin = cv.ovis.createWindow("VR", imsize)
cv.ovis.createGridMesh("ground", (10, 10), (10, 10))
owin.createEntity("ground", "ground", rot=(1.57, 0, 0))
owin.createCameraEntity("cam", K, imsize, 5)
owin.createEntity("figure", "Sinbad.mesh", (0, -5, 0)) # externally defined mesh
owin.createEntity("figure", "Sinbad.mesh", tvec=(0, -5, 0), rot=(np.pi, 0, 0)) # externally defined mesh
owin.createLightEntity("sun", (0, 0, -100))
# interaction scene
iwin = cv.ovis.createWindow("AR", imsize, cv.ovis.SCENE_SEPERATE | cv.ovis.SCENE_INTERACTIVE)
iwin.createEntity("figure", "Sinbad.mesh", (0, -5, 0))
iwin.createEntity("figure", "Sinbad.mesh", tvec=(0, -5, 0), rot=(np.pi, 0, 0))
iwin.createLightEntity("sun", (0, 0, -100))
iwin.setCameraIntrinsics(K, imsize)

@ -49,12 +49,14 @@ void _createTexture(const String& name, Mat image)
}
static void _convertRT(InputArray rot, InputArray tvec, Quaternion& q, Vector3& t,
bool invert = false)
bool invert = false, bool init = false)
{
CV_Assert(rot.empty() || rot.rows() == 3 || rot.size() == Size(3, 3),
tvec.empty() || tvec.rows() == 3);
q = Quaternion::IDENTITY;
// make sure the entity is oriented by the OpenCV coordinate conventions
// when initialised
q = init ? Quaternion(toOGRE) : Quaternion::IDENTITY;
t = Vector3::ZERO;
if (!rot.empty())
@ -346,7 +348,7 @@ public:
Quaternion q;
Vector3 t;
_convertRT(rot, tvec, q, t);
_convertRT(rot, tvec, q, t, false, true);
SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q);
node->attachObject(ent);
}
@ -377,7 +379,7 @@ public:
Quaternion q;
Vector3 t;
_convertRT(rot, tvec, q, t);
_convertRT(rot, tvec, q, t, false, true);
SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q);
node->attachObject(cam);
@ -400,7 +402,7 @@ public:
Quaternion q;
Vector3 t;
_convertRT(rot, tvec, q, t);
_convertRT(rot, tvec, q, t, false, true);
SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q);
node->attachObject(light);
}
@ -420,7 +422,7 @@ public:
SceneNode& node = _getSceneNode(sceneMgr, name);
Quaternion q;
Vector3 t;
_convertRT(rot, tvec, q, t, invert);
_convertRT(rot, tvec, q, t, invert, true);
node.setOrientation(q);
node.setPosition(t);
}
@ -488,7 +490,7 @@ public:
SceneNode* node = cam->getParentSceneNode();
Quaternion q;
Vector3 t;
_convertRT(rot, tvec, q, t, invert);
_convertRT(rot, tvec, q, t, invert, true);
if (!rot.empty())
node->setOrientation(q);

Loading…
Cancel
Save