Videorecording!
This commit is contained in:
@@ -66,6 +66,8 @@ if __name__ == '__main__':
|
|||||||
goal_hsv=cfg['goal'], field_hsv=cfg['field'],
|
goal_hsv=cfg['goal'], field_hsv=cfg['field'],
|
||||||
ball_min_radius=cfg['ball_min_radius'],
|
ball_min_radius=cfg['ball_min_radius'],
|
||||||
)
|
)
|
||||||
|
print('Initialized')
|
||||||
|
striker.mover.stand_up()
|
||||||
|
|
||||||
state = 'init'
|
state = 'init'
|
||||||
init_soll = 0.0
|
init_soll = 0.0
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ except:
|
|||||||
class NaoImageReader(object):
|
class NaoImageReader(object):
|
||||||
|
|
||||||
RESOLUTIONS = {
|
RESOLUTIONS = {
|
||||||
|
0: (120, 160),
|
||||||
1: (240, 320),
|
1: (240, 320),
|
||||||
2: (480, 640),
|
2: (480, 640),
|
||||||
3: (960, 1280)
|
3: (960, 1280)
|
||||||
@@ -26,7 +27,6 @@ class NaoImageReader(object):
|
|||||||
self.fps = fps
|
self.fps = fps
|
||||||
self.vd = ALProxy('ALVideoDevice', ip, port)
|
self.vd = ALProxy('ALVideoDevice', ip, port)
|
||||||
streamer_name = '_'.join(['lower' if cam_id else 'upper', str(res)])
|
streamer_name = '_'.join(['lower' if cam_id else 'upper', str(res)])
|
||||||
print(streamer_name)
|
|
||||||
self.sub = self.vd.subscribeCamera(
|
self.sub = self.vd.subscribeCamera(
|
||||||
streamer_name, cam_id, res, 13, fps
|
streamer_name, cam_id, res, 13, fps
|
||||||
)
|
)
|
||||||
@@ -57,10 +57,11 @@ class NaoImageReader(object):
|
|||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.vd.unsubscribe(self.sub)
|
self.vd.unsubscribe(self.sub)
|
||||||
|
print(self.sub + 'captured %s frames' % len(self.recording))
|
||||||
if self.video_file is not None:
|
if self.video_file is not None:
|
||||||
vf = cv2.VideoWriter(self.video_file,
|
vf = cv2.VideoWriter(self.video_file,
|
||||||
cv2.cv.FOURCC('X', 'V', 'I', 'D'),
|
cv2.cv.FOURCC('X', 'V', 'I', 'D'),
|
||||||
5,
|
self.fps,
|
||||||
(self.res[1], self.res[0]))
|
(self.res[1], self.res[0]))
|
||||||
for frame in self.recording:
|
for frame in self.recording:
|
||||||
vf.write(frame)
|
vf.write(frame)
|
||||||
@@ -70,6 +71,7 @@ class NaoImageReader(object):
|
|||||||
self.sub = self.vd.subscribeCamera(
|
self.sub = self.vd.subscribeCamera(
|
||||||
self.sub, self.cam_id, self.res_id, 13, self.fps
|
self.sub, self.cam_id, self.res_id, 13, self.fps
|
||||||
)
|
)
|
||||||
|
self.recording = []
|
||||||
|
|
||||||
|
|
||||||
class VideoReader(object):
|
class VideoReader(object):
|
||||||
|
|||||||
@@ -16,36 +16,66 @@ class Striker(object):
|
|||||||
|
|
||||||
def __init__(self, nao_ip, nao_port, res, ball_hsv, goal_hsv, field_hsv,
|
def __init__(self, nao_ip, nao_port, res, ball_hsv, goal_hsv, field_hsv,
|
||||||
ball_min_radius):
|
ball_min_radius):
|
||||||
|
|
||||||
|
# Timestamp
|
||||||
self.run_id = strftime('%Y%m%d%H%M%S')
|
self.run_id = strftime('%Y%m%d%H%M%S')
|
||||||
|
|
||||||
|
# Motion
|
||||||
self.mover = NaoMover(nao_ip=nao_ip, nao_port=nao_port)
|
self.mover = NaoMover(nao_ip=nao_ip, nao_port=nao_port)
|
||||||
self.mover.stand_up()
|
self.is_over = False
|
||||||
|
|
||||||
|
# Sight
|
||||||
self.upper_camera = NaoImageReader(
|
self.upper_camera = NaoImageReader(
|
||||||
nao_ip, port=nao_port, res=res, fps=30, cam_id=0,
|
nao_ip, port=nao_port, res=res, fps=30, cam_id=0,
|
||||||
video_file='cam0_' + self.run_id + '.mpg'
|
|
||||||
)
|
)
|
||||||
self.lower_camera = NaoImageReader(
|
self.lower_camera = NaoImageReader(
|
||||||
nao_ip, port=nao_port, res=res, fps=30, cam_id=1,
|
nao_ip, port=nao_port, res=res, fps=30, cam_id=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
# POV
|
||||||
|
self.upper_pov = NaoImageReader(
|
||||||
|
nao_ip, port=nao_port, res=0, fps=15, cam_id=0,
|
||||||
|
video_file='cam0_' + self.run_id + '.mpg'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.lower_pov = NaoImageReader(
|
||||||
|
nao_ip, port=nao_port, res=0, fps=15, cam_id=1,
|
||||||
video_file='cam1_' + self.run_id + '.mpg'
|
video_file='cam1_' + self.run_id + '.mpg'
|
||||||
)
|
)
|
||||||
|
self.pov_thread = Thread(target=self._pov)
|
||||||
|
self.pov_thread.start()
|
||||||
|
|
||||||
|
# Recognition
|
||||||
self.ball_finder = BallFinder(tuple(ball_hsv[0]), tuple(ball_hsv[1]),
|
self.ball_finder = BallFinder(tuple(ball_hsv[0]), tuple(ball_hsv[1]),
|
||||||
ball_min_radius)
|
ball_min_radius)
|
||||||
self.field_finder = FieldFinder(tuple(field_hsv[0]),
|
self.field_finder = FieldFinder(tuple(field_hsv[0]),
|
||||||
tuple(field_hsv[1]))
|
tuple(field_hsv[1]))
|
||||||
self.goal_finder = GoalFinder(tuple(goal_hsv[0]), tuple(goal_hsv[1]))
|
self.goal_finder = GoalFinder(tuple(goal_hsv[0]), tuple(goal_hsv[1]))
|
||||||
|
|
||||||
|
# Talking
|
||||||
self.speaker = ALProxy('ALTextToSpeech', bytes(nao_ip), nao_port)
|
self.speaker = ALProxy('ALTextToSpeech', bytes(nao_ip), nao_port)
|
||||||
|
|
||||||
self.is_over = False
|
|
||||||
|
|
||||||
self.speach_queue = deque(maxlen=4)
|
self.speach_queue = deque(maxlen=4)
|
||||||
self.speach_history = []
|
self.speach_history = []
|
||||||
self.tts_thread = Thread(target=self._speaker)
|
self.tts_thread = Thread(target=self._speaker)
|
||||||
self.tts_thread.start()
|
self.tts_thread.start()
|
||||||
|
|
||||||
self.rotating = False
|
# Debugging
|
||||||
self.rot_dir = 0
|
self._timer_start = 0
|
||||||
self.timer_start = 0
|
self._timer_stop = 0
|
||||||
self.timer_stop = 0
|
|
||||||
self.dy = False
|
def close(self):
|
||||||
|
self.is_over = True
|
||||||
|
|
||||||
|
if self.tts_thread.isAlive():
|
||||||
|
self.tts_thread.join()
|
||||||
|
if self.pov_thread.isAlive():
|
||||||
|
self.pov_thread.join()
|
||||||
|
|
||||||
|
self.upper_camera.close()
|
||||||
|
self.lower_camera.close()
|
||||||
|
self.upper_pov.close()
|
||||||
|
self.lower_pov.close()
|
||||||
|
self.mover.stop_moving()
|
||||||
|
|
||||||
def _speaker(self):
|
def _speaker(self):
|
||||||
while not self.is_over:
|
while not self.is_over:
|
||||||
@@ -53,6 +83,15 @@ class Striker(object):
|
|||||||
self.speaker.say(self.speach_queue.pop())
|
self.speaker.say(self.speach_queue.pop())
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
|
||||||
|
def _pov(self):
|
||||||
|
while not self.is_over:
|
||||||
|
try:
|
||||||
|
self.upper_pov.get_frame()
|
||||||
|
self.lower_pov.get_frame()
|
||||||
|
except RuntimeError as e:
|
||||||
|
print(e)
|
||||||
|
continue
|
||||||
|
|
||||||
def speak(self, text):
|
def speak(self, text):
|
||||||
if not self.speach_history or self.speach_history[-1] != text:
|
if not self.speach_history or self.speach_history[-1] != text:
|
||||||
self.speach_queue.appendleft(text)
|
self.speach_queue.appendleft(text)
|
||||||
@@ -159,7 +198,7 @@ class Striker(object):
|
|||||||
ball_angles = self.get_ball_angles_from_camera(cam)
|
ball_angles = self.get_ball_angles_from_camera(cam)
|
||||||
if ball_angles is not None:
|
if ball_angles is not None:
|
||||||
x, y = ball_angles
|
x, y = ball_angles
|
||||||
self.timer_start = time()
|
self._timer_start = time()
|
||||||
in_sight = True
|
in_sight = True
|
||||||
|
|
||||||
break
|
break
|
||||||
@@ -201,8 +240,8 @@ class Striker(object):
|
|||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
|
||||||
head_yaw, head_pitch = self.mover.get_head_angles()
|
head_yaw, head_pitch = self.mover.get_head_angles()
|
||||||
self.timer_stop = time()
|
self._timer_stop = time()
|
||||||
print('Ball to head', self.timer_stop - self.timer_start)
|
print('Ball to head', self._timer_stop - self._timer_start)
|
||||||
print('Head yaw', head_yaw, end=' ')
|
print('Head yaw', head_yaw, end=' ')
|
||||||
d_yaw = head_yaw - soll
|
d_yaw = head_yaw - soll
|
||||||
print('Head d_yaw', d_yaw)
|
print('Head d_yaw', d_yaw)
|
||||||
@@ -305,15 +344,6 @@ class Striker(object):
|
|||||||
self.mover.wait()
|
self.mover.wait()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def close(self):
|
|
||||||
self.is_over = True
|
|
||||||
if self.tts_thread.isAlive():
|
|
||||||
self.tts_thread.join()
|
|
||||||
self.upper_camera.close()
|
|
||||||
self.lower_camera.close()
|
|
||||||
self.mover.stop_moving()
|
|
||||||
# self.mover.stand_up()
|
|
||||||
|
|
||||||
def goal_search(self):
|
def goal_search(self):
|
||||||
goal_center_x = None
|
goal_center_x = None
|
||||||
positions = [0, pi/6, pi/4, pi/3, pi/2]
|
positions = [0, pi/6, pi/4, pi/3, pi/2]
|
||||||
|
|||||||
Reference in New Issue
Block a user