-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_camera.py
49 lines (40 loc) · 1.49 KB
/
play_camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import cv2 as cv
import numpy as np
from camera_librealsense import Camera
camera = Camera()
camera.start()
offset = np.array([0.8, 0.75, 0.4]) # robot base relative to the origin in simulator
origin_offset = np.array([0.29, 0.22]) # Offset of Reference Marker to Dynamic Marker
obst_rel_robot = np.array(
[[0.5, -0.15, 0.05], [0.5, 0.05, 0.05]]) # middle pose relative to robot base
def get_obs_pose(dists):
# get obstacle pose
dyn_obstacles = []
for i in range(len(obst_rel_robot)):
dyn_obstacle = np.array(obst_rel_robot[i] + offset)
dyn_obstacles.append(dyn_obstacle)
for i in range(len(dists)):
dyn_obstacles[i][0] += dists[i] # - self.pos_dif
return np.array(dyn_obstacles)
def add_obs_pose(poses, centers, frame):
for i in range(len(poses)):
cv.putText(frame, str(poses[i]),
(centers[i * 2][0] - 50, centers[i * 2][1] - 50),
cv.FONT_HERSHEY_SIMPLEX, 0.5,
(0, 0, 255), 2)
return frame
while True:
frame = camera.get_frame()
distance, frame = camera.get_distance(frame, add_to_frame=True)
centers, frame = camera.get_centers(frame, add_to_frame=True)
distance -= origin_offset # relative to origin
dyn_obstacles = get_obs_pose(distance)
# print(centers)
# print(dyn_obstacles)
frame = add_obs_pose(dyn_obstacles, centers, frame)
cv.imshow('frame', frame)
key = cv.waitKey(1)
if key == ord('q'):
break
cv.destroyAllWindows()
camera.stop()