update interfaces and add interface examples (speech, openpose, asus xtion)

This commit is contained in:
Brian Delhaisse
2019-06-22 00:02:33 +02:00
parent fb35ddd6dc
commit 7b876780fc
12 changed files with 570 additions and 341 deletions
+8 -3
View File
@@ -4,8 +4,13 @@ In this folder, you will find examples on what interfaces you can use and on how
You will also be able to connect an interface with an element of the world (in this case, a robot) using bridges,
and see that different bridges can lead to different behaviors while getting the data from the same interface.
Here are few examples that depict the various interfaces:
Here are few examples that depict the various interfaces available to the user:
1. `mouse_keyboard.py`: use the mouse keyboard interface
2. `webcam.py`: use the webcam interface
3. `playstation.py`: use the Playstation joystick controller interface
4. `xbox.py`: use the Xbox joystick controller interface
3. `playstation.py`: use the Playstation game controller interface
4. `xbox.py`: use the Xbox game controller interface
5. `asus_xtion.py`: use the Asus Xtion interface
6. `openpose.py`: use the Openpose interface
7. `speech.py`: use the speech (recognizer/translator) interface
**Note**: some interfaces require to install different libraries, and possibly to configure them. Check the raised errors.
+73
View File
@@ -0,0 +1,73 @@
#!/usr/bin/env python
"""Run the Asus Xtion interface.
Make sure that the `openni` library is installed with all the correct environment variables set, and that the Asus
Xtion is connected before running this code. Note that it can take some time to initialize the interface.
"""
import argparse
import matplotlib.pyplot as plt
from pyrobolearn.tools.interfaces.camera.asus_xtion import AsusXtionInterface
# create parser
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--use_thread', help='If we should run the webcam interface in a thread.', type=bool,
default=False)
parser.add_argument('-r', '--use_rgb', help='If we should get RGB images. Note that RGB and IR images can not be '
'captured at the same time.', type=bool,
default=True)
parser.add_argument('-d', '--use_depth', help='If we should get depth images.', type=bool,
default=True)
parser.add_argument('-i', '--use_ir', help='If we should get IR images. Note that RGB and IR images can not be '
'captured at the same time.', type=bool,
default=False)
args = parser.parse_args()
# get which pictures to capture
use_rgb, use_depth, use_ir = args.use_rgb, args.use_depth, args.use_ir
if use_rgb and use_ir:
use_ir = False
# create Asus Xtion interface
interface = AsusXtionInterface(use_rgb=use_rgb, use_depth=use_depth, use_ir=use_ir)
# plotting using matplotlib in interactive mode
fig, axes = plt.subplots(1, 2)
plots = [None]*2
titles = []
if use_rgb:
titles.append('RGB')
if use_ir:
titles.append('IR')
if use_depth:
titles.append('Depth')
plt.ion() # interactive mode on
while True:
# if don't use thread call `step` or `run`
data = interface.run()
# get the frame and plot it with matplotlib
if plots[0] is None:
for i in range(len(plots)):
plots[i] = axes[i].imshow(data[i])
axes[i].set_title(titles[i])
else:
for plot, img in zip(plots, data):
plot.set_data(img)
# pause a bit
plt.pause(0.01)
# check if the figure is closed, and if so, get out of the loop
if not plt.fignum_exists(fig.number):
break
plt.ioff() # interactive mode off
plt.show()
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env python
"""Run the Openpose interface.
Make sure that the webcam is connected, and that the openpose framework has been installed before running this code.
For this code to work, you have to specify the path to the openpose framework, or set the `OPENPOSE_PATH` environment
variable. Note that it can take some time to initialize the interface.
"""
import cv2
import argparse
from pyrobolearn.tools.interfaces.camera.openpose import OpenPoseInterface
# create parser
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--path', help='Absolute path to the openpose framework. If not specified, it will check '
'for the environment variable `OPENPOSE_PATH`.', type=str, default='')
parser.add_argument('-t', '--use_thread', help='If we should run the openpose interface in a thread.', type=bool,
default=False)
parser.add_argument('-f', '--detect_face', help='If we should detect the face with openpose.', type=bool,
default=True)
parser.add_argument('-a', '--detect_hands', help='If we should detect the hands with openpose.', type=bool,
default=False)
args = parser.parse_args()
path = None if args.path == '' else args.path
# create openpose interface
if args.use_thread:
# create and run interface in a thread
interface = OpenPoseInterface(openpose_path=path, detect_face=args.detect_face, detect_hands=args.detect_hands,
use_thread=True, sleep_dt=1. / 10, verbose=True)
raw_input('Press key to stop the openpose interface')
else:
# create interface
interface = OpenPoseInterface(openpose_path=path, detect_face=args.detect_face, detect_hands=args.detect_hands)
# run interface
while True:
frame, keypoints = interface.run()
cv2.imshow("OpenPose 1.4.0 - Tutorial Python API", frame)
# quit display if 'esc' button is pressed
key = cv2.waitKey(15) & 0xFF
if key == 27:
cv2.destroyWindow('frame')
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env python
"""Run the speech interface.
This will perform speech recognition, translation, and synthesization. Make sure that your computer has a microphone
connected.
In the future, interfaces using the Google assistant, Alexa, or a similar tool will be implemented.
"""
import argparse
from pyrobolearn.tools.interfaces.audio.speech import SpeechRecognizerInterface, SpeechTranslatorInterface
# get the available languages.
languages = SpeechRecognizerInterface.available_languages
print("Available languages are: {}".format(languages))
# create parser
parser = argparse.ArgumentParser()
# parser.add_argument('-t', '--use_thread', help='If we should run the webcam interface in a thread.', type=bool,
# default=False)
parser.add_argument('-l', '--lang', help='The language that needs to be recognized.', type=str, choices=languages,
default='english')
parser.add_argument('-a', '--target_lang', help='If we should get depth images.', type=str, choices=languages,
default='english')
args = parser.parse_args()
# create speech recognizer/translator interface
# interface = SpeechRecognizerInterface(verbose=True, lang=args.lang)
interface = SpeechTranslatorInterface(verbose=True, from_lang=args.lang, target_lang=args.target_lang)
# run the interface
while True:
data = interface.run()
+41 -23
View File
@@ -1,34 +1,52 @@
#!/usr/bin/env python
"""Load the Webcam interface.
"""Run the Webcam interface.
Make sure that the webcam is connected before running this code. Note that it can take some time to initialize
the interface.
"""
from itertools import count
import argparse
import matplotlib.pyplot as plt
from pyrobolearn.tools.interfaces.camera.webcam import WebcamInterface
# create interface
interface = WebcamInterface(use_thread=True, sleep_dt=1./10, verbose=False)
# plotting using matplotlib in interactive mode
fig = plt.figure()
plot = None
plt.ion() # interactive mode on
# create parser
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--use_thread', help='If we should run the webcam interface in a thread.', type=bool,
default=False)
args = parser.parse_args()
for _ in count():
# # if don't use thread call `step` or `run` (note that `run` returns the frame but not
# interface.step()
# get the frame and plot it with matplotlib
frame = interface.frame
if plot is None:
plot = plt.imshow(frame)
else:
plot.set_data(frame)
plt.pause(0.01)
# create webcam interface
if args.use_thread:
# create and run interface in a thread
interface = WebcamInterface(use_thread=True, sleep_dt=1./10, verbose=True)
raw_input('Press key to stop the webcam interface')
else:
# create interface
interface = WebcamInterface()
# check if the figure is closed, and if so, get out of the loop
if not plt.fignum_exists(fig.number):
break
# plotting using matplotlib in interactive mode
fig = plt.figure()
plot = None
plt.ion() # interactive mode on
plt.ioff() # interactive mode off
plt.show()
while True:
# if don't use thread call `step` or `run` (note that `run` returns the frame but not
interface.step()
# get the frame and plot it with matplotlib
frame = interface.frame
if plot is None:
plot = plt.imshow(frame)
else:
plot.set_data(frame)
plt.pause(0.01)
# check if the figure is closed, and if so, get out of the loop
if not plt.fignum_exists(fig.number):
break
plt.ioff() # interactive mode off
plt.show()