Skip to content

Commit 053fa74

Browse files
committed
Add mybuddy expression playing interface
1 parent d6a55c4 commit 053fa74

File tree

9 files changed

+70
-42
lines changed

9 files changed

+70
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ test_test.py
2121
__pycache__/port.cpython-39.pyc
2222
demo/__pycache__/port.cpython-39.pyc
2323
demo/__pycache__/port_setup.cpython-39.pyc
24+
.idea

.idea/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/pymycobot.iml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

pymycobot/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from pymycobot.mybuddysocket import MyBuddySocket
1515
from pymycobot.mira import Mira
1616
from pymycobot.mybuddybluetooth import MyBuddyBlueTooth
17+
from pymycobot.mybuddyemoticon import Emoticon
1718

1819
__all__ = [
1920
"MyCobot",
@@ -28,6 +29,7 @@
2829
"MyBuddySocket",
2930
"MyBuddyBlueTooth",
3031
"Mira",
32+
"Emoticon",
3133
]
3234

3335
__version__ = "2.9.7b1"

pymycobot/mybuddyemoticon.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# coding=utf-8
2+
3+
from __future__ import division
4+
import cv2 as cv
5+
import time
6+
import threading
7+
import pynput.mouse as pm
8+
9+
10+
class Emoticon:
11+
def __init__(self, file_path, window_size: list = [], play_time=5) -> None:
12+
"""API for playing emoticons
13+
14+
Args:
15+
file_path: Absolute path of facial expression video.
16+
window_size: `[Length, width] `Size of the playback window (default is full screen).
17+
play_time: Playback duration. 5 seconds by default
18+
19+
"""
20+
self.file_path = file_path
21+
self.window_size = window_size
22+
self.play_time = play_time
23+
self.quit = False
24+
25+
@property
26+
def window_size(self):
27+
return self.window_size
28+
29+
@property
30+
def play_time(self):
31+
return self.play_time
32+
33+
def on_click(self, x, y, button, pressed):
34+
if pressed:
35+
self.quit = True
36+
return True
37+
else:
38+
return False
39+
40+
def ls_k_thread(self):
41+
while 1:
42+
with pm.Listener(on_click=self.on_click) as pmlistener:
43+
pmlistener.join()
44+
45+
def analyse_pic_thread(self):
46+
r = threading.Thread(target=self.ls_k_thread)
47+
r.setDaemon(True)
48+
r.start()
49+
50+
def play(self):
51+
cap = cv.VideoCapture(self.file_path)
52+
out_win = "frame"
53+
cv.namedWindow(out_win, cv.WINDOW_NORMAL)
54+
if not self.window_size:
55+
cv.setWindowProperty(out_win, cv.WND_PROP_FULLSCREEN, cv.WINDOW_FULLSCREEN)
56+
else:
57+
cv.resizeWindow(out_win, self.window_size[0], self.window_size[1])
58+
t = time.time()
59+
while time.time() - t < self.play_time and self.quit == False:
60+
ret, frame = cap.read()
61+
# print(frame)
62+
if frame is not None:
63+
cv.imshow(out_win, frame)
64+
if ret == False:
65+
cap = cv.VideoCapture(self.file_path)
66+
cap.release()
67+
cv.destroyAllWindows()

0 commit comments

Comments
 (0)