From 56d77d8e73474212f314adee44c382b0a2e62ef5 Mon Sep 17 00:00:00 2001 From: kujirahand Date: Sat, 11 May 2024 12:23:15 +0900 Subject: [PATCH] add OpenCV camera test --- docs/TkEasyGUI/version-py.md | 2 +- tests/opencv_camera.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/opencv_camera.py diff --git a/docs/TkEasyGUI/version-py.md b/docs/TkEasyGUI/version-py.md index 63fd80b..31ed31d 100644 --- a/docs/TkEasyGUI/version-py.md +++ b/docs/TkEasyGUI/version-py.md @@ -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) diff --git a/tests/opencv_camera.py b/tests/opencv_camera.py new file mode 100644 index 0000000..e31edce --- /dev/null +++ b/tests/opencv_camera.py @@ -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()