-
Notifications
You must be signed in to change notification settings - Fork 1
/
opencv2webslides.py
52 lines (37 loc) · 1.16 KB
/
opencv2webslides.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import eel
import cv2 as cv
import base64
current_slide = 0
@eel.expose
def slide_change_event(val):
global current_slide
current_slide = val
def main():
global current_slide
cap = cv.VideoCapture(0)
# EeLフォルダ設定、および起動 #########################################################
eel.init('webslides')
eel.start(
'index.html',
mode='chrome',
cmdline_args=['--start-fullscreen'],
block=False)
while True:
eel.sleep(0.01)
# カメラキャプチャ ########################################################
ret, frame = cap.read()
if not ret:
continue
print(current_slide)
# UI側へ転送 ##############################################################
_, imencode_image = cv.imencode('.jpg', frame)
base64_image = base64.b64encode(imencode_image)
eel.set_base64image("data:image/jpg;base64," +
base64_image.decode("ascii"))
key = cv.waitKey(1)
if key == 27: # ESC
break
if __name__ == '__main__':
main()