Skip to content

Commit

Permalink
après video
Browse files Browse the repository at this point in the history
  • Loading branch information
serge committed Apr 26, 2021
1 parent 18f9eb6 commit 58c5200
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 242 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ La documentation sur le Wiki de La Labomedia

* Xubuntu 18.04
* libboost 1.65
* Blender 2.79b et BGE pour une visualisation
* Blender 2.79b et BGE pour une visualisation sur Debian 10
* oscpy
* numpy
* OpenCV python
Expand Down
Binary file modified blender-skeleton/blender_skeleton.blend
Binary file not shown.
58 changes: 29 additions & 29 deletions blender-skeleton/scripts/always.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from bge import events
from mathutils import Vector, Quaternion, Matrix

from scripts.utils import get_all_objects, JOINTS
from scripts.rs_utils import get_points
from scripts.utils import JOINTS


def apply_objet_position_orientation(objet_point_1, objet_point_2, objet):
Expand Down Expand Up @@ -44,18 +43,6 @@ def apply_objet_position_orientation(objet_point_1, objet_point_2, objet):
objet.worldPosition = objet_point_1.worldPosition


def set_sphere_position_scale():
for i in range(14): # gl.nombre):
if gl.points[i]:
v = Vector(gl.points[i])*gl.scale
gl.spheres[i].worldPosition = [ v[0] + gl.left_right,
v[1] + gl.av_ar,
v[2] + gl.up_down]
gl.spheres[i].worldScale = [1.5*gl.scale,
1.5*gl.scale,
1.5*gl.scale]


def set_body_position_orientation():
""" Le point '18' est au centre de [8, 11] soit au centre du bassin.
Il ne vient pas de COCO !
Expand Down Expand Up @@ -96,16 +83,6 @@ def set_head_location():
gl.spheres[19].worldScale = [1.5*gl.scale, 1.5*gl.scale, 1.5*gl.scale]


def set_cubes_position_orientation_scale():
"""Matérialisation des os par des cubes allongés."""

for bone, [p1, p2] in gl.pairs.items():
bone_cube_obj = gl.all_obj[bone]
apply_objet_position_orientation(gl.spheres[p1],
gl.spheres[p2],
bone_cube_obj)


def keyboard():

if gl.keyboard.events[events.UPARROWKEY] == gl.KX_INPUT_JUST_ACTIVATED:
Expand Down Expand Up @@ -145,6 +122,7 @@ def keyboard():
elif gl.keyboard.events[events.HKEY] == gl.KX_INPUT_JUST_ACTIVATED:
visible_or_not()


def visible_or_not():
"""Visibilité soit du personnage, soit la matérialisation des os"""

Expand All @@ -171,24 +149,46 @@ def visible_or_not():
gl.body_visible = 1


def set_cubes_position_orientation_scale():
"""Matérialisation des os par des cubes allongés."""

for bone, [p1, p2] in gl.pairs.items():
bone_cube_obj = gl.all_obj[bone]
apply_objet_position_orientation(gl.spheres[p1],
gl.spheres[p2],
bone_cube_obj)


def set_sphere_position_scale():
for i in range(14): # gl.nombre):
if gl.points[i]:
v = Vector(gl.points[i])*gl.scale
gl.spheres[i].worldPosition = [ v[0] + gl.left_right,
v[1] + gl.av_ar,
v[2] + gl.up_down]
# Les sphères sont aggrandies pour être mieux vues
gl.spheres[i].worldScale = [1.5*gl.scale,
1.5*gl.scale,
1.5*gl.scale]


def main():

gl.fps += 1
if time() - gl.t > 10:
gl.t = time()
# #print(int(gl.fps/10))
print("FPS =", int(gl.fps/10), "Body n°:", gl.body)
gl.fps = 0
print("Body n°:", gl.body)

keyboard()

if gl.points:

# #print("Maj")
set_sphere_position_scale()
set_cubes_position_orientation_scale()
set_body_position_orientation()
set_head_location() # pour COCO

# #set_head_location()
# On repasse par ici si nouveaux poins
gl.points = None

gl.metarig.update()
Expand Down
10 changes: 4 additions & 6 deletions blender-skeleton/scripts/once.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from oscpy.server import OSCThreadServer

from bge import logic as gl
from scripts.utils import get_all_objects, add_object
from scripts.utils import get_all_objects, add_object, get_points_blender
from scripts.utils import JOINTS, PAIRS_COCO, PAIRS_MPI
from scripts.rs_utils import Filtre, get_points
from scripts.sound import EasyAudio


Expand All @@ -20,8 +19,8 @@ def on_points(*args):
gl.body = args[-1]
# J'ôte le body
args = args[:-1]

gl.points = get_points(args)
# Les points reçus sont au format cubemos*1000
gl.points = get_points_blender(args)


def on_note(i):
Expand All @@ -34,8 +33,7 @@ def on_note(i):

def osc_server_init():
gl.server = OSCThreadServer()
gl.server.listen('0.0.0.0', port=8003, default=True)

gl.server.listen(b'localhost', port=8003, default=True)

# Les callbacks du serveur
gl.server.default_handler = default_handler
Expand Down
126 changes: 0 additions & 126 deletions blender-skeleton/scripts/rs_utils.py

This file was deleted.

33 changes: 33 additions & 0 deletions blender-skeleton/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,36 @@ def add_object(obj, position, life):
shoulder.L, upper_arm.L, forearm.L, hand.L, shoulder.R, upper_arm.R,
forearm.R, hand.R, pelvis.L, pelvis.R, thigh.L, shin.L, thigh.R, shin.R]
"""


def get_points_blender(data):
"""frame_data = list(coordonnées des points empilés d'une frame
soit 3*18 items avec:
mutipliées par 1000
les None sont remplacés par (-1000000, -1000000, -1000000)
le numéro du body (dernier de la liste) doit être enlevé
Conversion:
Les coords sont multipliées par 1000 avant envoi en OSC
Permutation de y et z, z est la profondeur pour RS et OpenCV
et inversion de l'axe des y en z
Conversion de cubemos en blender
"""

# Réception de 54=3*18 ou 45=3*15
if len(data) == 54 or len(data) == 45:
nombre = int(len(data)/3)
points = []
for i in range(nombre):
# Reconstruction par 3
val = [ data[(3*i)],
data[(3*i)+1],
data[(3*i)+2]]
if val == [-1000000, -1000000, -1000000]:
points.append(None)
else:
# Conversion
points.append([val[0]/1000, val[2]/1000, -val[1]/1000])
else:
points = None

return points
Loading

0 comments on commit 58c5200

Please sign in to comment.