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
f0d30f2c
Commit
f0d30f2c
authored
Jun 23, 2019
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2160 from dnandha:ovis-add-animation
parents
8acc8aaf
6810e6c8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
11 deletions
+109
-11
ovis.hpp
modules/ovis/include/opencv2/ovis.hpp
+27
-2
ovis_demo.cpp
modules/ovis/samples/ovis_demo.cpp
+8
-4
ovis_demo.py
modules/ovis/samples/ovis_demo.py
+7
-2
ovis.cpp
modules/ovis/src/ovis.cpp
+67
-3
No files found.
modules/ovis/include/opencv2/ovis.hpp
View file @
f0d30f2c
...
...
@@ -45,7 +45,8 @@ enum EntityProperty
{
ENTITY_MATERIAL
,
ENTITY_SCALE
,
ENTITY_AABB_WORLD
ENTITY_AABB_WORLD
,
ENTITY_ANIMBLEND_MODE
};
/**
...
...
@@ -77,7 +78,7 @@ public:
CV_WRAP
virtual
void
setCompositors
(
const
std
::
vector
<
String
>&
names
)
=
0
;
/**
* place an entity of a
n
mesh in the scene
* place an entity of a mesh in the scene
*
* the mesh needs to be created beforehand. Either programmatically
* by e.g. @ref createPointCloudMesh or by placing an Ogre .mesh file in a resource location.
...
...
@@ -164,6 +165,30 @@ public:
CV_WRAP
virtual
void
setEntityPose
(
const
String
&
name
,
InputArray
tvec
=
noArray
(),
InputArray
rot
=
noArray
(),
bool
invert
=
false
)
=
0
;
/**
* get a list of available entity animations
* @param name entity name
* @param out the animation names
*/
CV_WRAP
virtual
void
getEntityAnimations
(
const
String
&
name
,
std
::
vector
<
String
>&
out
)
=
0
;
/**
* play entity animation
* @param name entity name
* @param animname animation name
* @param loop enable or disable animation loop
* @see getEntityAnimations
*/
CV_WRAP
virtual
void
playEntityAnimation
(
const
String
&
name
,
const
String
&
animname
,
bool
loop
=
true
)
=
0
;
/**
* stop entity animation
* @param name enitity name
* @param animname animation name
*/
CV_WRAP
virtual
void
stopEntityAnimation
(
const
String
&
name
,
const
String
&
animname
)
=
0
;
/**
* read back the image generated by the last call to @ref waitKey
*/
...
...
modules/ovis/samples/ovis_demo.cpp
View file @
f0d30f2c
...
...
@@ -2,7 +2,6 @@
#include <opencv2/videoio.hpp>
#include <opencv2/ovis.hpp>
#include <opencv2/aruco.hpp>
#include <iostream>
...
...
@@ -35,12 +34,17 @@ int main()
ovis
::
createGridMesh
(
"ground"
,
Size2i
(
10
,
10
),
Size2i
(
10
,
10
));
owin
->
createEntity
(
"ground"
,
"ground"
,
Vec3f
(
1.57
,
0
,
0
));
owin
->
createCameraEntity
(
"cam"
,
K
,
imsize
,
5
);
owin
->
createEntity
(
"
figure
"
,
"Sinbad.mesh"
,
Vec3i
(
0
,
0
,
5
),
Vec3f
(
CV_PI
/
2.0
,
0.0
,
0.0
));
// externally defined mesh
owin
->
createEntity
(
"
sinbad
"
,
"Sinbad.mesh"
,
Vec3i
(
0
,
0
,
5
),
Vec3f
(
CV_PI
/
2.0
,
0.0
,
0.0
));
// externally defined mesh
owin
->
createLightEntity
(
"sun"
,
Vec3i
(
0
,
0
,
-
100
));
// setup and play idle animation
owin
->
setEntityProperty
(
"sinbad"
,
ovis
::
EntityProperty
::
ENTITY_ANIMBLEND_MODE
,
Scalar
(
1
));
// 1 = cumulative
owin
->
playEntityAnimation
(
"sinbad"
,
"IdleBase"
);
owin
->
playEntityAnimation
(
"sinbad"
,
"IdleTop"
);
//interaction scene
Ptr
<
ovis
::
WindowScene
>
iwin
=
ovis
::
createWindow
(
String
(
"AR"
),
imsize
,
ovis
::
SCENE_SEPERATE
|
ovis
::
SCENE_INTERACTIVE
);
iwin
->
createEntity
(
"
figure
"
,
"Sinbad.mesh"
,
Vec3i
(
0
,
-
5
,
0
),
Vec3f
(
CV_PI
,
0.0
,
0.0
));
iwin
->
createEntity
(
"
sinbad
"
,
"Sinbad.mesh"
,
Vec3i
(
0
,
-
5
,
0
),
Vec3f
(
CV_PI
,
0.0
,
0.0
));
iwin
->
createLightEntity
(
"sun"
,
Vec3i
(
0
,
0
,
-
100
));
iwin
->
setCameraIntrinsics
(
K
,
imsize
);
...
...
@@ -50,5 +54,5 @@ int main()
owin
->
setEntityPose
(
"cam"
,
t
,
R
);
}
return
0
;
return
1
;
}
modules/ovis/samples/ovis_demo.py
View file @
f0d30f2c
...
...
@@ -14,12 +14,17 @@ 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"
,
tvec
=
(
0
,
-
5
,
0
),
rot
=
(
np
.
pi
,
0
,
0
))
# externally defined mesh
owin
.
createEntity
(
"
sinbad
"
,
"Sinbad.mesh"
,
tvec
=
(
0
,
-
5
,
0
),
rot
=
(
np
.
pi
,
0
,
0
))
# externally defined mesh
owin
.
createLightEntity
(
"sun"
,
(
0
,
0
,
-
100
))
# setup and play idle animation
owin
.
setEntityProperty
(
"sinbad"
,
cv
.
ovis
.
ENTITY_ANIMBLEND_MODE
,
1
)
# 1 = cumulative
owin
.
playEntityAnimation
(
"sinbad"
,
"IdleBase"
)
owin
.
playEntityAnimation
(
"sinbad"
,
"IdleTop"
)
# interaction scene
iwin
=
cv
.
ovis
.
createWindow
(
"AR"
,
imsize
,
cv
.
ovis
.
SCENE_SEPERATE
|
cv
.
ovis
.
SCENE_INTERACTIVE
)
iwin
.
createEntity
(
"
figure
"
,
"Sinbad.mesh"
,
tvec
=
(
0
,
-
5
,
0
),
rot
=
(
np
.
pi
,
0
,
0
))
iwin
.
createEntity
(
"
sinbad
"
,
"Sinbad.mesh"
,
tvec
=
(
0
,
-
5
,
0
),
rot
=
(
np
.
pi
,
0
,
0
))
iwin
.
createLightEntity
(
"sun"
,
(
0
,
0
,
-
100
))
iwin
.
setCameraIntrinsics
(
K
,
imsize
)
...
...
modules/ovis/src/ovis.cpp
View file @
f0d30f2c
...
...
@@ -277,6 +277,7 @@ class WindowSceneImpl : public WindowScene
RenderWindow
*
rWin
;
Ptr
<
OgreBites
::
CameraMan
>
camman
;
Ptr
<
Rectangle2D
>
bgplane
;
std
::
unordered_map
<
String
,
Controller
<
Real
>*>
frameCtrlrs
;
Ogre
::
RenderTarget
*
depthRTT
;
int
flags
;
...
...
@@ -495,7 +496,8 @@ public:
node
->
attachObject
(
ent
);
}
void
removeEntity
(
const
String
&
name
)
CV_OVERRIDE
{
void
removeEntity
(
const
String
&
name
)
CV_OVERRIDE
{
SceneNode
&
node
=
_getSceneNode
(
sceneMgr
,
name
);
node
.
getAttachedObject
(
name
)
->
detachFromParent
();
...
...
@@ -576,6 +578,52 @@ public:
node
.
setPosition
(
t
);
}
void
getEntityAnimations
(
const
String
&
name
,
std
::
vector
<
String
>&
out
)
CV_OVERRIDE
{
SceneNode
&
node
=
_getSceneNode
(
sceneMgr
,
name
);
Entity
*
ent
=
dynamic_cast
<
Entity
*>
(
node
.
getAttachedObject
(
name
));
CV_Assert
(
ent
&&
"invalid entity"
);
for
(
auto
const
&
anim
:
ent
->
getAllAnimationStates
()
->
getAnimationStates
())
{
out
.
push_back
(
anim
.
first
);
}
}
void
playEntityAnimation
(
const
String
&
name
,
const
String
&
animname
,
bool
loop
=
true
)
CV_OVERRIDE
{
SceneNode
&
node
=
_getSceneNode
(
sceneMgr
,
name
);
Entity
*
ent
=
dynamic_cast
<
Entity
*>
(
node
.
getAttachedObject
(
name
));
CV_Assert
(
ent
&&
"invalid entity"
);
AnimationState
*
animstate
=
ent
->
getAnimationState
(
animname
);
animstate
->
setTimePosition
(
0
);
animstate
->
setEnabled
(
true
);
animstate
->
setLoop
(
loop
);
if
(
frameCtrlrs
.
find
(
animname
)
!=
frameCtrlrs
.
end
())
return
;
frameCtrlrs
.
insert
({
animname
,
Ogre
::
ControllerManager
::
getSingleton
().
createFrameTimePassthroughController
(
Ogre
::
AnimationStateControllerValue
::
create
(
animstate
,
true
)
)
});
}
void
stopEntityAnimation
(
const
String
&
name
,
const
String
&
animname
)
CV_OVERRIDE
{
SceneNode
&
node
=
_getSceneNode
(
sceneMgr
,
name
);
Entity
*
ent
=
dynamic_cast
<
Entity
*>
(
node
.
getAttachedObject
(
name
));
CV_Assert
(
ent
&&
"invalid entity"
);
AnimationState
*
animstate
=
ent
->
getAnimationState
(
animname
);
if
(
!
animstate
->
getEnabled
())
return
;
animstate
->
setEnabled
(
false
);
animstate
->
setTimePosition
(
0
);
Ogre
::
ControllerManager
::
getSingleton
().
destroyController
(
frameCtrlrs
[
animname
]);
frameCtrlrs
.
erase
(
animname
);
}
void
setEntityProperty
(
const
String
&
name
,
int
prop
,
const
String
&
value
)
CV_OVERRIDE
{
CV_Assert
(
prop
==
ENTITY_MATERIAL
);
...
...
@@ -598,9 +646,25 @@ public:
void
setEntityProperty
(
const
String
&
name
,
int
prop
,
const
Scalar
&
value
)
CV_OVERRIDE
{
CV_Assert
(
prop
==
ENTITY_SCALE
);
SceneNode
&
node
=
_getSceneNode
(
sceneMgr
,
name
);
node
.
setScale
(
value
[
0
],
value
[
1
],
value
[
2
]);
switch
(
prop
)
{
case
ENTITY_SCALE
:
{
node
.
setScale
(
value
[
0
],
value
[
1
],
value
[
2
]);
break
;
}
case
ENTITY_ANIMBLEND_MODE
:
{
Entity
*
ent
=
dynamic_cast
<
Entity
*>
(
node
.
getAttachedObject
(
name
));
CV_Assert
(
ent
&&
"invalid entity"
);
ent
->
getSkeleton
()
->
setBlendMode
(
static_cast
<
Ogre
::
SkeletonAnimationBlendMode
>
(
value
[
0
]));
break
;
}
default
:
CV_Error
(
Error
::
StsBadArg
,
"unsupported property"
);
}
}
void
getEntityProperty
(
const
String
&
name
,
int
prop
,
OutputArray
value
)
CV_OVERRIDE
...
...
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