diff --git a/examples/qt/widget.py b/examples/qt/widget.py index b11ff09..b72e529 100644 --- a/examples/qt/widget.py +++ b/examples/qt/widget.py @@ -4,8 +4,11 @@ # Copyright (c) 2021 Tiago Coutinho # Distributed under the GPLv3 license. See LICENSE for more info. -# install requirements: pip install cv2 qtpy pyqt6 -# run with: QT_API=pyqt6 python widget.py +# install extra requirements: +# python3 -m pip install opencv-python qtpy pyqt6 + +# run from this directory with: +# QT_API=pyqt6 python widget.py import cv2 from qtpy import QtCore, QtGui, QtWidgets diff --git a/examples/web.py b/examples/web.py index 4fc9a5b..4b6cd76 100644 --- a/examples/web.py +++ b/examples/web.py @@ -4,6 +4,9 @@ # Copyright (c) 2021 Tiago Coutinho # Distributed under the GPLv3 license. See LICENSE for more info. +# Extra dependency required to run this example: +# python3 -m pip install flask + # run from this directory with: FLASK_APP=web flask run -h 0.0.0.0 import flask diff --git a/examples/web/async.py b/examples/web/async.py index cac586e..e0cd1fe 100644 --- a/examples/web/async.py +++ b/examples/web/async.py @@ -5,7 +5,8 @@ # Distributed under the GPLv3 license. See LICENSE for more info. # Extra dependencies required to run this example: -# pip install fastapi jinja2 python-multipart cv2 pillow uvicorn +# python3 -m pip install fastapi jinja2 python-multipart opencv-python \ +# pillow uvicorn # run from this directory with: # uvicorn async:app @@ -88,7 +89,7 @@ def cameras() -> list[Camera]: global CAMERAS if CAMERAS is None: cameras = {} - for device in iter_video_capture_devices(): + for device in iter_video_capture_devices(legacy_controls=True): cameras[device.index] = Camera(device) CAMERAS = cameras return CAMERAS diff --git a/examples/web/common.py b/examples/web/common.py index 9e87cfc..2245995 100644 --- a/examples/web/common.py +++ b/examples/web/common.py @@ -4,12 +4,6 @@ # Copyright (c) 2023 Tiago Coutinho # Distributed under the GPLv3 license. See LICENSE for more info. -# Extra dependencies required to run this example: -# pip install fastapi jinja2 python-multipart cv2 pillow uvicorn - -# run from this directory with: -# uvicorn async:app - """Common tools for async and sync web app examples""" import io @@ -35,22 +29,21 @@ def __init__(self, device: Device) -> None: def frame_to_image(frame, output="jpeg"): - match frame.pixel_format: - case PixelFormat.JPEG | PixelFormat.MJPEG: - if output == "jpeg": - return to_image_send(frame.data, type=output) - else: - buff = io.BytesIO() - image = PIL.Image.open(io.BytesIO(frame.data)) - case PixelFormat.GREY: - data = frame.array - data.shape = frame.height, frame.width, -1 - image = PIL.Image.frombuffer("L", (frame.width, frame.height), data) - case PixelFormat.YUYV: - data = frame.array - data.shape = frame.height, frame.width, -1 - rgb = cv2.cvtColor(data, cv2.COLOR_YUV2RGB_YUYV) - image = PIL.Image.fromarray(rgb) + if frame.pixel_format in (PixelFormat.JPEG, PixelFormat.MJPEG): + if output == "jpeg": + return to_image_send(frame.data, type=output) + else: + buff = io.BytesIO() + image = PIL.Image.open(io.BytesIO(frame.data)) + elif frame.pixel_format == PixelFormat.GREY: + data = frame.array + data.shape = frame.height, frame.width, -1 + image = PIL.Image.frombuffer("L", (frame.width, frame.height), data) + elif frame.pixel_format == PixelFormat.YUYV: + data = frame.array + data.shape = frame.height, frame.width, -1 + rgb = cv2.cvtColor(data, cv2.COLOR_YUV2RGB_YUYV) + image = PIL.Image.fromarray(rgb) buff = io.BytesIO() image.save(buff, output) diff --git a/examples/web/sync.py b/examples/web/sync.py index bbe1601..72a5ef0 100644 --- a/examples/web/sync.py +++ b/examples/web/sync.py @@ -5,7 +5,7 @@ # Distributed under the GPLv3 license. See LICENSE for more info. # Extra dependencies required to run this example: -# pip install pillow cv2 flask gunicorn gevent +# python3 -m pip install pillow opencv-python flask gunicorn gevent # run from this directory with: # gunicorn --bind=0.0.0.0:8000 --log-level=debug --worker-class=gevent sync:app diff --git a/examples/web_async.py b/examples/web_async.py index e7420db..cdf6c49 100644 --- a/examples/web_async.py +++ b/examples/web_async.py @@ -5,7 +5,7 @@ # Distributed under the GPLv3 license. See LICENSE for more info. # install dependencies with: -# pip install uvicorn fastapi +# python3 -m pip install uvicorn fastapi # # run from this directory with: # uvicorn web_async:app