-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
68 lines (48 loc) · 1.99 KB
/
app.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import cv2
import time
import PySimpleGUI as sg
from labeler import Labeler
import yaml
def main():
labeler = Labeler()
# Load settings from yaml
with open('settings.yaml', 'r') as input_file:
settings = yaml.load(input_file, yaml.FullLoader)
# Camera Settings
frameSize = (settings["camera"]["width"], settings["camera"]["height"])
video_capture = cv2.VideoCapture(0, cv2.CAP_DSHOW)
time.sleep(1.0)
# Init Windows Manager
sg.theme(settings["window"]["sg_theme"])
# Capture button logo
img_path = settings["window"]["button_img_path"]
capture_btn = sg.Button(button_color=sg.TRANSPARENT_BUTTON,
image_filename=img_path, image_size=(50, 50), image_subsample=2,
border_width=0, key="_capture_")
colwebcam1_layout = [[sg.Text("Camera View", size=(60, 1), justification="center")],
[sg.Image(filename="", key="cam1")], [capture_btn]]
colwebcam1 = sg.Column(colwebcam1_layout, element_justification='center')
colslayout = [colwebcam1]
layout = [colslayout]
window = sg.Window("Labeler demo", layout,
no_titlebar=False, alpha_channel=1, grab_anywhere=False,
return_keyboard_events=True, location=(100, 100), icon="img/camera.ico")
while True:
event, values = window.read(timeout=20)
if event == sg.WIN_CLOSED:
break
# Get camera frame
ret, frameOrig = video_capture.read()
frame = cv2.resize(frameOrig, frameSize)
# If you want to procces an image not from the camera
# frame = cv2.imread("PATH_TO_IMAGE")
# Update webcam
imgbytes = cv2.imencode(".png", frame)[1].tobytes()
window["cam1"].update(data=imgbytes)
# If the capture button was pressed
if event == "_capture_":
labeler.label_image(frame)
video_capture.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()