mirror of
https://github.com/wassname/pyrobolearn.git
synced 2026-09-09 11:31:38 +08:00
update interfaces and add interface examples (speech, openpose, asus xtion)
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user