()
| 17 | """ |
| 18 | |
| 19 | def 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 | |
| 44 | main() |
no test coverage detected