Better camera control for droid
This commit is contained in:
parent
fa24ab4607
commit
68a0c79d1a
3 changed files with 77 additions and 23 deletions
35
DemoPrograms/PyDroid3/Demo_OpenCV_Webcam_Minimal.py
Normal file
35
DemoPrograms/PyDroid3/Demo_OpenCV_Webcam_Minimal.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import tkinter
|
||||
import PySimpleGUI as sg
|
||||
import cv2
|
||||
|
||||
"""
|
||||
Demo of using OpenCV to show your webcam in a GUI window.
|
||||
This demo will run on tkinter, Qt, and Web(Remi). The web version flickers at the moment though
|
||||
To exit, right click and choose exit. If on Qt, you'll have to kill the program as there are no right click menus
|
||||
in PySimpleGUIQt (yet).
|
||||
"""
|
||||
|
||||
CAMERA_FRONT = 1
|
||||
CAMERA_REAR = 0
|
||||
sg.change_look_and_feel('Dark Black 1')
|
||||
|
||||
# define the window layout
|
||||
layout = [[sg.Image(filename='', key='-IMAGE-', tooltip='Right click for exit menu')],
|
||||
[sg.Exit()],]
|
||||
|
||||
# create the window and show it without the plot
|
||||
window = sg.Window('Demo Application - OpenCV Integration', layout, location=(0,0),
|
||||
no_titlebar=True, grab_anywhere=True,
|
||||
right_click_menu=['&Right', ['E&xit']], ) # if trying Qt, you will need to remove this right click menu
|
||||
|
||||
# ---===--- Event LOOP Read and display frames, operate the GUI --- #
|
||||
cap = cv2.VideoCapture(CAMERA_REAR) # Setup the OpenCV capture device (webcam)
|
||||
while True:
|
||||
event, values = window.read(timeout=20)
|
||||
if event in ('Exit', None):
|
||||
break
|
||||
ret, frame = cap.read() # Read image from capture device (camera)
|
||||
imgbytes=cv2.imencode('.png', frame)[1].tobytes() # Convert the image to PNG Bytes
|
||||
window['-IMAGE-'].update(data=imgbytes) # Change the Image Element to show the new image
|
||||
|
||||
window.close()
|
Loading…
Add table
Add a link
Reference in a new issue