Merge pull request #4443 from PySimpleGUI/Dev-latest

Switched to ppm format.  Changed tkinter specific call to Graph.send_…
This commit is contained in:
PySimpleGUI 2021-06-20 08:06:23 -04:00 committed by GitHub
commit 5d3b7e1f3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -7,10 +7,15 @@ import cv2
webcam stream, as it's being displayed. To "Draw" simply move your mouse over the image, left click and hold, and
then drag your mouse. You'll see a series of red circles on top of your image.
CURRENTLY ONLY WORKS WITH PySimpleGUI, NOT any of the other ports at this time.
Note also that this demo is using ppm as the image format. This worked fine on all PySimpleGUI ports except
the web port. If you have trouble with the imencode statement, change "ppm" to "png"
Copyright 2021 PySimpleGUI
"""
def main():
layout = [[sg.Graph((600,450),(0,450), (600,0), key='-GRAPH-', enable_events=True, drag_submits=True)],]
layout = [[sg.Graph((600,450),(0,450), (600,0), key='-GRAPH-', enable_events=True, drag_submits=True)],],
window = sg.Window('Demo Application - OpenCV Integration', layout)
graph_elem = window['-GRAPH-'] # type: sg.Graph
@ -23,11 +28,11 @@ def main():
break
ret, frame = cap.read()
imgbytes=cv2.imencode('.ppm', frame)[1].tobytes()
imgbytes=cv2.imencode('.ppm', frame)[1].tobytes() # on some ports, will need to change to png
if a_id:
graph_elem.delete_figure(a_id) # delete previous image
a_id = graph_elem.draw_image(data=imgbytes, location=(0,0)) # draw new image
graph_elem.TKCanvas.tag_lower(a_id) # move image to the "bottom" of all other drawings
graph_elem.send_figure_to_back(a_id) # move image to the "bottom" of all other drawings
if event == '-GRAPH-':
graph_elem.draw_circle(values['-GRAPH-'], 5, fill_color='red', line_color='red')