stream_hacks to main #2
|
@ -1,4 +1,5 @@
|
||||||
import cv2
|
import cv2
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
from . import OutputProcess
|
from . import OutputProcess
|
||||||
from ovtk_track import types
|
from ovtk_track import types
|
||||||
|
@ -14,7 +15,10 @@ class Process(OutputProcess):
|
||||||
super().__init__(*args)
|
super().__init__(*args)
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
pass
|
self.fig = plt.figure()
|
||||||
|
self.axes = self.fig.add_subplot(projection='3d')
|
||||||
|
self.axes.view_init(15, 0, vertical_axis='y')
|
||||||
|
plt.show(block=False)
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
landmarks = self._inputs['landmarks'].get_nowait()
|
landmarks = self._inputs['landmarks'].get_nowait()
|
||||||
|
@ -31,8 +35,15 @@ class Process(OutputProcess):
|
||||||
landmarks.draw(image, frame, label=False, color=(130, 130, 130))
|
landmarks.draw(image, frame, label=False, color=(130, 130, 130))
|
||||||
|
|
||||||
if skeleton is not None:
|
if skeleton is not None:
|
||||||
skeleton.draw(image, frame)
|
skeleton.draw(self.axes)
|
||||||
|
|
||||||
cv2.imshow("face", frame)
|
cv2.imshow("face", frame)
|
||||||
|
plt.draw()
|
||||||
|
|
||||||
|
# event loops
|
||||||
|
plt.pause(0.0001)
|
||||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||||
raise KeyboardInterrupt('User requested stop')
|
raise KeyboardInterrupt('User requested stop')
|
||||||
|
|
||||||
|
for artist in plt.gca().lines + plt.gca().collections:
|
||||||
|
artist.remove()
|
||||||
|
|
|
@ -3,6 +3,7 @@ from enum import Enum
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
from .Type import Type
|
from .Type import Type
|
||||||
from .Point3d import Point3d
|
from .Point3d import Point3d
|
||||||
|
@ -12,22 +13,27 @@ from .Quaternion import Quaternion
|
||||||
class JOINT_TYPES(Enum):
|
class JOINT_TYPES(Enum):
|
||||||
HEAD = 'head'
|
HEAD = 'head'
|
||||||
CHEST = 'chest'
|
CHEST = 'chest'
|
||||||
|
HIPS = 'hips'
|
||||||
|
|
||||||
SHOULDER_L = 'shoulder_l'
|
SHOULDER_L = 'shoulder_l'
|
||||||
ELBOW_L = 'elbow_l'
|
ELBOW_L = 'elbow_l'
|
||||||
WRIST_L = 'wrist_l'
|
|
||||||
HIP_L = 'hip_l'
|
|
||||||
KNEE_L = 'knee_l'
|
KNEE_L = 'knee_l'
|
||||||
FOOT_L = 'foot_l'
|
FOOT_L = 'foot_l'
|
||||||
|
WRIST_L = 'wrist_l'
|
||||||
|
|
||||||
SHOULDER_R = 'shoulder_r'
|
SHOULDER_R = 'shoulder_r'
|
||||||
ELBOW_R = 'elbow_r'
|
ELBOW_R = 'elbow_r'
|
||||||
WRIST_R = 'wrist_r'
|
|
||||||
HIP_R = 'hip_r'
|
|
||||||
KNEE_R = 'knee_r'
|
KNEE_R = 'knee_r'
|
||||||
FOOT_R = 'foot_r'
|
FOOT_R = 'foot_r'
|
||||||
|
WRIST_R = 'wrist_r'
|
||||||
|
|
||||||
|
|
||||||
|
default_colors = [
|
||||||
|
[255, 0, 0], [0, 255, 0], [0, 0, 255],
|
||||||
|
[255, 255, 0], [255, 0, 255], [0, 255, 255],
|
||||||
|
[128, 255, 0], [255, 0, 128], [0, 255, 128],
|
||||||
|
]
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Joint(Type):
|
class Joint(Type):
|
||||||
pos: Point3d
|
pos: Point3d
|
||||||
|
@ -48,14 +54,10 @@ class Skeleton(Type):
|
||||||
# TODO: More intelegent merge
|
# TODO: More intelegent merge
|
||||||
return Skeleton(self.joints + other.joints)
|
return Skeleton(self.joints + other.joints)
|
||||||
|
|
||||||
def draw(self, image, canvas, color=(255, 255, 255)):
|
def draw(self, axes, colors=default_colors):
|
||||||
for i, joint in enumerate(self.joints.values()):
|
xs, ys, zs = zip(*(joint.pos.as_np() for joint in self.joints.values()))
|
||||||
x, y, z = joint.pos.project_to_image(image)
|
color = [[v / 255 for v in color] for color in colors[:len(xs)]]
|
||||||
|
axes.scatter(xs, ys, zs, c=color)
|
||||||
if x > image.width or x < 0 or y > image.height or y < 0:
|
|
||||||
continue
|
|
||||||
|
|
||||||
cv2.circle(canvas, (x, y), 1, color, -1, cv2.LINE_AA)
|
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
return {type.value: joint for type, joint in self.joints.items()}
|
return {type.value: joint for type, joint in self.joints.items()}
|
||||||
|
|
Loading…
Reference in New Issue