Skip to content

Commit f991ed8

Browse files
committed
push code
1 parent 053fa74 commit f991ed8

File tree

1 file changed

+47
-28
lines changed

1 file changed

+47
-28
lines changed

pymycobot/mybuddyemoticon.py

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,83 @@
44
import cv2 as cv
55
import time
66
import threading
7-
import pynput.mouse as pm
87

98

109
class Emoticon:
11-
def __init__(self, file_path, window_size: list = [], play_time=5) -> None:
10+
def __init__(self, file_path: list = [], window_size: list = [], play_time=5) -> None:
1211
"""API for playing emoticons
1312
1413
Args:
15-
file_path: Absolute path of facial expression video.
16-
window_size: `[Length, width] `Size of the playback window (default is full screen).
14+
file_path(list): Absolute path of facial expression video.
15+
window_size(list): `[Length, width] `Size of the playback window (default is full screen).
1716
play_time: Playback duration. 5 seconds by default
1817
1918
"""
20-
self.file_path = file_path
21-
self.window_size = window_size
22-
self.play_time = play_time
19+
self.__file_path = file_path
20+
self.__window_size = window_size
21+
self.__play_time = play_time
2322
self.quit = False
23+
self.stop_play = False
24+
25+
@property
26+
def file_path(self):
27+
return self.__file_path
28+
29+
def add_file_path(self, path):
30+
self.__file_path.append(path)
2431

2532
@property
2633
def window_size(self):
27-
return self.window_size
34+
return self.__window_size
35+
36+
@window_size.setter
37+
def window_size(self, data):
38+
self.__window_size = data
2839

2940
@property
3041
def play_time(self):
31-
return self.play_time
32-
33-
def on_click(self, x, y, button, pressed):
34-
if pressed:
42+
return self.__play_time
43+
44+
@play_time.setter
45+
def play_time(self, data):
46+
self.__play_time = data
47+
48+
def mouse_callback(self, event, x, y, flags, param):
49+
if event == cv.EVENT_LBUTTONDOWN:
3550
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()
51+
52+
def stop(self):
53+
self.stop_play = True
54+
55+
def start(self):
56+
self.stop_play = False
57+
58+
def run(self):
59+
t = threading.Thread(target=self.play, daemon=True)
60+
t.start()
4961

5062
def play(self):
51-
cap = cv.VideoCapture(self.file_path)
63+
index = 0
64+
cap = cv.VideoCapture(self.__file_path[index])
5265
out_win = "frame"
5366
cv.namedWindow(out_win, cv.WINDOW_NORMAL)
5467
if not self.window_size:
5568
cv.setWindowProperty(out_win, cv.WND_PROP_FULLSCREEN, cv.WINDOW_FULLSCREEN)
5669
else:
5770
cv.resizeWindow(out_win, self.window_size[0], self.window_size[1])
5871
t = time.time()
72+
cv.setMouseCallback(out_win, self.mouse_callback)
5973
while time.time() - t < self.play_time and self.quit == False:
74+
while self.stop_play:
75+
pass
6076
ret, frame = cap.read()
6177
# print(frame)
6278
if frame is not None:
6379
cv.imshow(out_win, frame)
64-
if ret == False:
65-
cap = cv.VideoCapture(self.file_path)
80+
if cv.waitKey(1) & 0xFF == ord('q') or ret == False:
81+
index += 1
82+
if index >= len(self.__file_path):
83+
index = 0
84+
cap = cv.VideoCapture(self.__file_path[index])
6685
cap.release()
6786
cv.destroyAllWindows()

0 commit comments

Comments
 (0)