Skip to content

Commit

Permalink
add OpenCV camera test
Browse files Browse the repository at this point in the history
  • Loading branch information
kujirahand committed May 11, 2024
1 parent dea19d9 commit 56d77d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/TkEasyGUI/version-py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Module TkEasyGUI.version

# TkEasyGUI version 0.2.67
# TkEasyGUI version 0.2.68

- audo generated by [pyproject.toml](https://github.com/kujirahand/tkeasygui-python/blob/main/pyproject.toml)

Expand Down
35 changes: 35 additions & 0 deletions tests/opencv_camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
OpenCV Camera Test
Please install OpenCV
```
pip install opencv-python
pip install opencv-contrib-python
```
"""

import cv2 as cv
import TkEasyGUI as sg
# import PySimpleGUI as sg

# camera
vc = cv.VideoCapture(0)
# layout
layout = [
[sg.Button("Exit")],
[sg.Image(key="-image-", size=(400, 300))],
]
# event loop
window = sg.Window("Camera Test", layout)
while True:
event, values = window.read(timeout=1)
if event in (sg.WIN_CLOSED, "Exit"):
break
# capture
ret, frame = vc.read()
if ret:
frame = cv.resize(frame, (400, 300), fx=0, fy=0)
img = cv.imencode(".png", frame)[1].tobytes()
window["-image-"].update(img)

vc.release()
window.close()

0 comments on commit 56d77d8

Please sign in to comment.