Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv_contrib
Commits
768deade
Commit
768deade
authored
Mar 30, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1593 from paroj:ovisup
parents
fbaa1a16
7a35ae96
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
37 deletions
+29
-37
aruco_ar_demo.py
modules/ovis/samples/aruco_ar_demo.py
+2
-2
meshes.cpp
modules/ovis/src/meshes.cpp
+2
-2
ovis.cpp
modules/ovis/src/ovis.cpp
+25
-33
No files found.
modules/ovis/samples/aruco_ar_demo.py
View file @
768deade
...
...
@@ -14,8 +14,8 @@ cv.ovis.addResourceLocation("packs/Sinbad.zip") # shipped with Ogre
win
=
cv
.
ovis
.
createWindow
(
"arucoAR"
,
imsize
,
flags
=
0
)
win
.
setCameraIntrinsics
(
K
,
imsize
)
win
.
createEntity
(
"figure"
,
"Sinbad.mesh"
,
(
0
,
0
,
-
5
),
(
-
1.57
,
0
,
0
))
win
.
createLightEntity
(
"sun"
,
(
0
,
0
,
-
100
))
win
.
createEntity
(
"figure"
,
"Sinbad.mesh"
,
(
0
,
0
,
5
),
(
1.57
,
0
,
0
))
win
.
createLightEntity
(
"sun"
,
(
0
,
0
,
100
))
# video capture
cap
=
cv
.
VideoCapture
(
0
)
...
...
modules/ovis/src/meshes.cpp
View file @
768deade
...
...
@@ -28,9 +28,9 @@ void createPlaneMesh(const String& name, const Size2f& size, InputArray image)
}
// plane
MovablePlane
plane
(
Vector3
::
UNIT_Z
,
0
);
MovablePlane
plane
(
-
Vector3
::
UNIT_Z
,
0
);
MeshPtr
mesh
=
MeshManager
::
getSingleton
().
createPlane
(
name
,
RESOURCEGROUP_NAME
,
plane
,
size
.
width
,
size
.
height
,
1
,
1
,
true
,
1
,
1
,
1
,
Vector3
::
UNIT_Y
);
name
,
RESOURCEGROUP_NAME
,
plane
,
size
.
width
,
size
.
height
,
1
,
1
,
true
,
1
,
1
,
1
,
-
Vector3
::
UNIT_Y
);
mesh
->
getSubMesh
(
0
)
->
setMaterialName
(
name
);
}
...
...
modules/ovis/src/ovis.cpp
View file @
768deade
...
...
@@ -23,8 +23,7 @@ static const char* RENDERSYSTEM_NAME = "OpenGL 3+ Rendering Subsystem";
static
std
::
vector
<
String
>
_extraResourceLocations
;
// convert from OpenCV to Ogre coordinates:
// rotation by 180° around x axis
static
Matrix3
toOGRE
=
Matrix3
(
1
,
0
,
0
,
0
,
-
1
,
0
,
0
,
0
,
-
1
);
static
Quaternion
toOGRE
(
Degree
(
180
),
Vector3
::
UNIT_X
);
static
Vector2
toOGRE_SS
=
Vector2
(
1
,
-
1
);
WindowScene
::~
WindowScene
()
{}
...
...
@@ -48,15 +47,12 @@ void _createTexture(const String& name, Mat image)
texMgr
.
loadImage
(
name
,
RESOURCEGROUP_NAME
,
im
);
}
static
void
_convertRT
(
InputArray
rot
,
InputArray
tvec
,
Quaternion
&
q
,
Vector3
&
t
,
bool
invert
=
false
,
bool
init
=
false
)
static
void
_convertRT
(
InputArray
rot
,
InputArray
tvec
,
Quaternion
&
q
,
Vector3
&
t
,
bool
invert
=
false
)
{
CV_Assert
(
rot
.
empty
()
||
rot
.
rows
()
==
3
||
rot
.
size
()
==
Size
(
3
,
3
),
tvec
.
empty
()
||
tvec
.
rows
()
==
3
);
// make sure the entity is oriented by the OpenCV coordinate conventions
// when initialised
q
=
init
?
Quaternion
(
toOGRE
)
:
Quaternion
::
IDENTITY
;
q
=
Quaternion
::
IDENTITY
;
t
=
Vector3
::
ZERO
;
if
(
!
rot
.
empty
())
...
...
@@ -74,7 +70,7 @@ static void _convertRT(InputArray rot, InputArray tvec, Quaternion& q, Vector3&
Matrix3
R
;
_R
.
copyTo
(
Mat_
<
Real
>
(
3
,
3
,
R
[
0
]));
q
=
Quaternion
(
toOGRE
*
R
);
q
=
Quaternion
(
R
);
if
(
invert
)
{
...
...
@@ -85,7 +81,6 @@ static void _convertRT(InputArray rot, InputArray tvec, Quaternion& q, Vector3&
if
(
!
tvec
.
empty
())
{
tvec
.
copyTo
(
Mat_
<
Real
>
(
3
,
1
,
t
.
ptr
()));
t
=
toOGRE
*
t
;
if
(
invert
)
{
...
...
@@ -124,6 +119,10 @@ static SceneNode& _getSceneNode(SceneManager* sceneMgr, const String& name)
try
{
mo
=
sceneMgr
->
getMovableObject
(
name
,
"Camera"
);
// with cameras we have an extra CS flip node
if
(
mo
)
return
*
mo
->
getParentSceneNode
()
->
getParentSceneNode
();
}
catch
(
ItemIdentityException
&
)
{
...
...
@@ -281,12 +280,14 @@ public:
cam
->
setNearClipDistance
(
0.5
);
cam
->
setAutoAspectRatio
(
true
);
camNode
=
sceneMgr
->
getRootSceneNode
()
->
createChildSceneNode
();
camNode
->
setOrientation
(
toOGRE
);
camNode
->
attachObject
(
cam
);
if
(
flags
&
SCENE_INTERACTIVE
)
{
camman
.
reset
(
new
OgreBites
::
CameraMan
(
camNode
));
camman
->
setStyle
(
OgreBites
::
CS_ORBIT
);
camNode
->
setFixedYawAxis
(
true
,
Vector3
::
NEGATIVE_UNIT_Y
);
}
if
(
!
app
->
sceneMgr
)
...
...
@@ -356,7 +357,7 @@ public:
Quaternion
q
;
Vector3
t
;
_convertRT
(
rot
,
tvec
,
q
,
t
,
false
,
true
);
_convertRT
(
rot
,
tvec
,
q
,
t
);
SceneNode
*
node
=
sceneMgr
->
getRootSceneNode
()
->
createChildSceneNode
(
t
,
q
);
node
->
attachObject
(
ent
);
}
...
...
@@ -387,8 +388,10 @@ public:
Quaternion
q
;
Vector3
t
;
_convertRT
(
rot
,
tvec
,
q
,
t
,
false
,
true
);
_convertRT
(
rot
,
tvec
,
q
,
t
);
SceneNode
*
node
=
sceneMgr
->
getRootSceneNode
()
->
createChildSceneNode
(
t
,
q
);
node
=
node
->
createChildSceneNode
();
node
->
setOrientation
(
toOGRE
);
// camera mesh is oriented by OGRE conventions by default
node
->
attachObject
(
cam
);
RealRect
ext
=
cam
->
getFrustumExtents
();
...
...
@@ -410,7 +413,7 @@ public:
Quaternion
q
;
Vector3
t
;
_convertRT
(
rot
,
tvec
,
q
,
t
,
false
,
true
);
_convertRT
(
rot
,
tvec
,
q
,
t
);
SceneNode
*
node
=
sceneMgr
->
getRootSceneNode
()
->
createChildSceneNode
(
t
,
q
);
node
->
attachObject
(
light
);
}
...
...
@@ -430,7 +433,7 @@ public:
SceneNode
&
node
=
_getSceneNode
(
sceneMgr
,
name
);
Quaternion
q
;
Vector3
t
;
_convertRT
(
rot
,
tvec
,
q
,
t
,
invert
,
true
);
_convertRT
(
rot
,
tvec
,
q
,
t
,
invert
);
node
.
setOrientation
(
q
);
node
.
setPosition
(
t
);
}
...
...
@@ -539,40 +542,33 @@ public:
void
fixCameraYawAxis
(
bool
useFixed
,
InputArray
_up
)
{
Vector3
up
=
Vector3
::
UNIT_Y
;
Vector3
up
=
Vector3
::
NEGATIVE_
UNIT_Y
;
if
(
!
_up
.
empty
())
{
_up
.
copyTo
(
Mat_
<
Real
>
(
3
,
1
,
up
.
ptr
()));
up
=
toOGRE
*
up
;
}
Camera
*
cam
=
sceneMgr
->
getCamera
(
title
);
cam
->
getParentSceneNode
()
->
setFixedYawAxis
(
useFixed
,
up
);
camNode
->
setFixedYawAxis
(
useFixed
,
up
);
}
void
setCameraPose
(
InputArray
tvec
,
InputArray
rot
,
bool
invert
)
{
Camera
*
cam
=
sceneMgr
->
getCamera
(
title
);
SceneNode
*
node
=
cam
->
getParentSceneNode
();
Quaternion
q
;
Vector3
t
;
_convertRT
(
rot
,
tvec
,
q
,
t
,
invert
,
true
);
_convertRT
(
rot
,
tvec
,
q
,
t
,
invert
);
if
(
!
rot
.
empty
())
node
->
setOrientation
(
q
);
camNode
->
setOrientation
(
q
*
toOGRE
);
if
(
!
tvec
.
empty
())
n
ode
->
setPosition
(
t
);
camN
ode
->
setPosition
(
t
);
}
void
getCameraPose
(
OutputArray
R
,
OutputArray
tvec
,
bool
invert
)
{
Camera
*
cam
=
sceneMgr
->
getCamera
(
title
);
SceneNode
*
node
=
cam
->
getParentSceneNode
();
Matrix3
_R
;
node
->
getOrientation
().
ToRotationMatrix
(
_R
);
// toOGRE.Inverse() == toOGRE
(
camNode
->
getOrientation
()
*
toOGRE
).
ToRotationMatrix
(
_R
);
if
(
invert
)
{
...
...
@@ -581,20 +577,18 @@ public:
if
(
tvec
.
needed
())
{
Vector3
_tvec
=
n
ode
->
getPosition
();
Vector3
_tvec
=
camN
ode
->
getPosition
();
if
(
invert
)
{
_tvec
=
_R
*
-
_tvec
;
}
_tvec
=
toOGRE
.
Transpose
()
*
_tvec
;
Mat_
<
Real
>
(
3
,
1
,
_tvec
.
ptr
()).
copyTo
(
tvec
);
}
if
(
R
.
needed
())
{
_R
=
toOGRE
.
Transpose
()
*
_R
;
Mat_
<
Real
>
(
3
,
3
,
_R
[
0
]).
copyTo
(
R
);
}
}
...
...
@@ -607,7 +601,6 @@ public:
void
setCameraLookAt
(
const
String
&
target
,
InputArray
offset
)
{
SceneNode
*
cam
=
sceneMgr
->
getCamera
(
title
)
->
getParentSceneNode
();
SceneNode
*
tgt
=
sceneMgr
->
getEntity
(
target
)
->
getParentSceneNode
();
Vector3
_offset
=
Vector3
::
ZERO
;
...
...
@@ -615,10 +608,9 @@ public:
if
(
!
offset
.
empty
())
{
offset
.
copyTo
(
Mat_
<
Real
>
(
3
,
1
,
_offset
.
ptr
()));
_offset
=
toOGRE
*
_offset
;
}
cam
->
lookAt
(
tgt
->
_getDerivedPosition
()
+
_offset
,
Ogre
::
Node
::
TS_WORLD
);
cam
Node
->
lookAt
(
tgt
->
_getDerivedPosition
()
+
_offset
,
Ogre
::
Node
::
TS_WORLD
);
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment