MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_OpenCV_Draw_On_Webcam_Image.py:19–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17"""
18
19def main():
20 layout = [[sg.Graph((600,450),(0,450), (600,0), key='-GRAPH-', enable_events=True, drag_submits=True)],],
21
22 window = sg.Window('Demo Application - OpenCV Integration', layout)
23 graph_elem = window['-GRAPH-'] # type: sg.Graph
24 a_id = None
25 # ---===--- Event LOOP Read and display frames, operate the GUI --- #
26 cap = cv2.VideoCapture(0)
27 while True:
28 event, values = window.read(timeout=0)
29 if event in ('Exit', None):
30 break
31
32 ret, frame = cap.read()
33 imgbytes=cv2.imencode('.ppm', frame)[1].tobytes() # on some ports, will need to change to png
34 if a_id:
35 graph_elem.delete_figure(a_id) # delete previous image
36 a_id = graph_elem.draw_image(data=imgbytes, location=(0,0)) # draw new image
37 graph_elem.send_figure_to_back(a_id) # move image to the "bottom" of all other drawings
38
39 if event == '-GRAPH-':
40 graph_elem.draw_circle(values['-GRAPH-'], 5, fill_color='red', line_color='red')
41
42 window.close()
43
44main()

Calls 6

readMethod · 0.95
closeMethod · 0.95
delete_figureMethod · 0.80
draw_imageMethod · 0.80
send_figure_to_backMethod · 0.80
draw_circleMethod · 0.80

Tested by

no test coverage detected