pyobs-v4l 2.0.0.dev4__tar.gz → 2.0.0.dev6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyobs_v4l-2.0.0.dev6/.github/dependabot.yml +15 -0
- pyobs_v4l-2.0.0.dev6/.github/workflows/dependabot-automerge.yml +24 -0
- pyobs_v4l-2.0.0.dev6/.github/workflows/pyrefly.yml +23 -0
- pyobs_v4l-2.0.0.dev6/.github/workflows/pytest.yml +25 -0
- pyobs_v4l-2.0.0.dev6/PKG-INFO +12 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/pyobs_v4l/gui.py +22 -4
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/pyobs_v4l/v4lcamera.py +39 -20
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/pyproject.toml +13 -6
- pyobs_v4l-2.0.0.dev6/tests/test_import.py +19 -0
- pyobs_v4l-2.0.0.dev6/tests/test_v4lcamera.py +45 -0
- pyobs_v4l-2.0.0.dev6/uv.lock +3154 -0
- pyobs_v4l-2.0.0.dev4/PKG-INFO +0 -12
- pyobs_v4l-2.0.0.dev4/uv.lock +0 -2464
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/.github/workflows/pypi.yml +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/.github/workflows/ruff.yml +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/.pre-commit-config.yaml +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/.readthedocs.yml +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/LICENSE +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/README.md +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/docs/Makefile +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/docs/make.bat +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/docs/requirements.txt +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/docs/source/_static/pyobs.gif +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/docs/source/conf.py +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/docs/source/index.rst +0 -0
- {pyobs_v4l-2.0.0.dev4 → pyobs_v4l-2.0.0.dev6}/pyobs_v4l/__init__.py +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Dependabot auto-merge
|
|
2
|
+
|
|
3
|
+
on: pull_request
|
|
4
|
+
|
|
5
|
+
permissions:
|
|
6
|
+
contents: write
|
|
7
|
+
pull-requests: write
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
dependabot:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
|
|
13
|
+
steps:
|
|
14
|
+
- name: Fetch Dependabot metadata
|
|
15
|
+
id: metadata
|
|
16
|
+
uses: dependabot/fetch-metadata@v2
|
|
17
|
+
with:
|
|
18
|
+
compat-lookup: true
|
|
19
|
+
- name: Enable auto-merge for patch and minor updates
|
|
20
|
+
if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor' }}
|
|
21
|
+
run: gh pr merge --auto --merge "$PR_URL"
|
|
22
|
+
env:
|
|
23
|
+
PR_URL: ${{ github.event.pull_request.html_url }}
|
|
24
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: pyrefly
|
|
2
|
+
on: push
|
|
3
|
+
|
|
4
|
+
jobs:
|
|
5
|
+
pyrefly:
|
|
6
|
+
runs-on: ubuntu-latest
|
|
7
|
+
timeout-minutes: 10
|
|
8
|
+
|
|
9
|
+
steps:
|
|
10
|
+
- name: Check out repository code
|
|
11
|
+
uses: actions/checkout@v4
|
|
12
|
+
|
|
13
|
+
- name: Set up Python
|
|
14
|
+
uses: astral-sh/setup-uv@v5
|
|
15
|
+
with:
|
|
16
|
+
enable-cache: true
|
|
17
|
+
python-version: "3.13"
|
|
18
|
+
|
|
19
|
+
- name: Install packages
|
|
20
|
+
run: uv sync --all-extras --dev
|
|
21
|
+
|
|
22
|
+
- name: Run pyrefly
|
|
23
|
+
run: uv run pyrefly check
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: PyTest
|
|
2
|
+
on: push
|
|
3
|
+
|
|
4
|
+
jobs:
|
|
5
|
+
test:
|
|
6
|
+
runs-on: ubuntu-latest
|
|
7
|
+
timeout-minutes: 10
|
|
8
|
+
|
|
9
|
+
steps:
|
|
10
|
+
- name: Check out repository code
|
|
11
|
+
uses: actions/checkout@v4
|
|
12
|
+
|
|
13
|
+
- name: Set up Python
|
|
14
|
+
uses: astral-sh/setup-uv@v5
|
|
15
|
+
with:
|
|
16
|
+
enable-cache: true
|
|
17
|
+
python-version: "3.13"
|
|
18
|
+
|
|
19
|
+
- name: Install packages
|
|
20
|
+
run: uv sync --all-extras --dev
|
|
21
|
+
|
|
22
|
+
- name: Run tests
|
|
23
|
+
run: uv run pytest tests
|
|
24
|
+
env:
|
|
25
|
+
CI: true
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pyobs-v4l
|
|
3
|
+
Version: 2.0.0.dev6
|
|
4
|
+
Summary: pyobs module for V4L cameras
|
|
5
|
+
Author-email: Tim-Oliver Husser <thusser@uni-goettingen.de>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: opencv-python<6,>=4.0
|
|
10
|
+
Requires-Dist: pyobs-core<3,>=2.0.0.dev48
|
|
11
|
+
Provides-Extra: gui
|
|
12
|
+
Requires-Dist: pyobs-core[gui]<3,>=2.0.0.dev48; extra == 'gui'
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import sys
|
|
3
|
+
import threading
|
|
3
4
|
from pathlib import Path
|
|
4
5
|
from typing import Any
|
|
5
6
|
|
|
@@ -15,7 +16,9 @@ class MainWindow(QtWidgets.QMainWindow):
|
|
|
15
16
|
super().__init__()
|
|
16
17
|
self.setWindowTitle(f"V4L Camera — /dev/video{device}")
|
|
17
18
|
|
|
18
|
-
self.
|
|
19
|
+
self._device = device
|
|
20
|
+
self._camera: cv2.VideoCapture | None = None
|
|
21
|
+
self._lock = threading.Lock()
|
|
19
22
|
self._last_frame: cv2.typing.MatLike | None = None
|
|
20
23
|
self._preview_task: asyncio.Task[None] | None = None
|
|
21
24
|
|
|
@@ -37,10 +40,21 @@ class MainWindow(QtWidgets.QMainWindow):
|
|
|
37
40
|
|
|
38
41
|
self._preview_task = asyncio.ensure_future(self._live_preview())
|
|
39
42
|
|
|
43
|
+
async def _open_camera(self) -> cv2.VideoCapture:
|
|
44
|
+
loop = asyncio.get_running_loop()
|
|
45
|
+
return await loop.run_in_executor(None, cv2.VideoCapture, self._device)
|
|
46
|
+
|
|
47
|
+
def _read_frame(self) -> tuple[bool, Any]:
|
|
48
|
+
with self._lock:
|
|
49
|
+
if self._camera is None:
|
|
50
|
+
return False, None
|
|
51
|
+
return self._camera.read()
|
|
52
|
+
|
|
40
53
|
async def _live_preview(self) -> None:
|
|
41
54
|
loop = asyncio.get_running_loop()
|
|
55
|
+
self._camera = await self._open_camera()
|
|
42
56
|
while True:
|
|
43
|
-
ret, frame = await loop.run_in_executor(None, self.
|
|
57
|
+
ret, frame = await loop.run_in_executor(None, self._read_frame)
|
|
44
58
|
if ret:
|
|
45
59
|
self._last_frame = frame
|
|
46
60
|
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
|
@@ -54,7 +68,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|
|
54
68
|
self.expose.start_exposure(0.0)
|
|
55
69
|
for _ in range(count):
|
|
56
70
|
loop = asyncio.get_running_loop()
|
|
57
|
-
ret, frame = await loop.run_in_executor(None, self.
|
|
71
|
+
ret, frame = await loop.run_in_executor(None, self._read_frame)
|
|
58
72
|
if ret:
|
|
59
73
|
self._last_frame = frame
|
|
60
74
|
gray = cv2.cvtColor(self._last_frame, cv2.COLOR_BGR2GRAY)
|
|
@@ -64,7 +78,11 @@ class MainWindow(QtWidgets.QMainWindow):
|
|
|
64
78
|
def closeEvent(self, event: Any) -> None:
|
|
65
79
|
if self._preview_task is not None:
|
|
66
80
|
self._preview_task.cancel()
|
|
67
|
-
|
|
81
|
+
# take the same lock _read_frame() uses so release() can't race an in-flight read()
|
|
82
|
+
# still running on the executor thread (task.cancel() only requests cancellation)
|
|
83
|
+
with self._lock:
|
|
84
|
+
if self._camera is not None:
|
|
85
|
+
self._camera.release()
|
|
68
86
|
super().closeEvent(event)
|
|
69
87
|
|
|
70
88
|
|
|
@@ -43,11 +43,17 @@ class v4lCamera(BaseVideo):
|
|
|
43
43
|
loop = asyncio.get_running_loop()
|
|
44
44
|
future: asyncio.Future[None] = loop.create_future()
|
|
45
45
|
|
|
46
|
+
def _finish() -> None:
|
|
47
|
+
# wait_for cancels the future on timeout, so guard set_result to avoid an
|
|
48
|
+
# InvalidStateError from the loop thread once the orphaned call finally ends.
|
|
49
|
+
if not future.done():
|
|
50
|
+
future.set_result(None)
|
|
51
|
+
|
|
46
52
|
def _wrapper() -> None:
|
|
47
53
|
try:
|
|
48
54
|
func()
|
|
49
55
|
finally:
|
|
50
|
-
loop.call_soon_threadsafe(
|
|
56
|
+
loop.call_soon_threadsafe(_finish)
|
|
51
57
|
|
|
52
58
|
threading.Thread(target=_wrapper, daemon=True).start()
|
|
53
59
|
try:
|
|
@@ -59,11 +65,23 @@ class v4lCamera(BaseVideo):
|
|
|
59
65
|
async def _open_camera(self) -> Any:
|
|
60
66
|
"""Open the V4L2 camera device, without blocking the event loop."""
|
|
61
67
|
result: list[Any] = []
|
|
68
|
+
lock = threading.Lock()
|
|
69
|
+
timed_out = False
|
|
62
70
|
|
|
63
71
|
def _open() -> None:
|
|
64
|
-
|
|
72
|
+
camera = cv2.VideoCapture(self._device)
|
|
73
|
+
with lock:
|
|
74
|
+
if timed_out:
|
|
75
|
+
# timed out while still opening; release the handle nobody will use
|
|
76
|
+
camera.release()
|
|
77
|
+
else:
|
|
78
|
+
result.append(camera)
|
|
65
79
|
|
|
66
80
|
if not await self._run_blocking(_open):
|
|
81
|
+
with lock:
|
|
82
|
+
timed_out = True
|
|
83
|
+
if result:
|
|
84
|
+
result.pop().release()
|
|
67
85
|
raise TimeoutError(f"Timed out opening camera device after {_SDK_CALL_TIMEOUT}s.")
|
|
68
86
|
return result[0]
|
|
69
87
|
|
|
@@ -88,25 +106,26 @@ class v4lCamera(BaseVideo):
|
|
|
88
106
|
# open camera
|
|
89
107
|
camera = await self._open_camera()
|
|
90
108
|
|
|
91
|
-
# loop until
|
|
109
|
+
# loop until the background task is cancelled on close
|
|
92
110
|
last = time.time()
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
try:
|
|
112
|
+
while True:
|
|
113
|
+
# read frame
|
|
114
|
+
frame = await self._read_frame(camera)
|
|
115
|
+
if frame is None:
|
|
116
|
+
continue
|
|
117
|
+
|
|
118
|
+
# if time since last image is too short, wait a little
|
|
119
|
+
if time.time() - last < self._interval:
|
|
120
|
+
await asyncio.sleep(0.01)
|
|
121
|
+
continue
|
|
122
|
+
last = time.time()
|
|
123
|
+
|
|
124
|
+
# process it
|
|
125
|
+
await self._set_image(frame)
|
|
126
|
+
finally:
|
|
127
|
+
# release camera
|
|
128
|
+
camera.release()
|
|
110
129
|
|
|
111
130
|
|
|
112
131
|
__all__ = ["v4lCamera"]
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pyobs-v4l"
|
|
3
|
-
version = "2.0.0.
|
|
3
|
+
version = "2.0.0.dev6"
|
|
4
4
|
description = "pyobs module for V4L cameras"
|
|
5
5
|
authors = [{ name = "Tim-Oliver Husser", email = "thusser@uni-goettingen.de" }]
|
|
6
|
-
requires-python = ">=3.11
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
7
|
license = "MIT"
|
|
8
8
|
dependencies = [
|
|
9
|
-
"opencv-python>=4.0,<
|
|
10
|
-
"pyobs-core>=2.0.0.
|
|
9
|
+
"opencv-python>=4.0,<6",
|
|
10
|
+
"pyobs-core>=2.0.0.dev48,<3",
|
|
11
11
|
]
|
|
12
12
|
|
|
13
13
|
[project.optional-dependencies]
|
|
14
14
|
gui = [
|
|
15
|
-
"pyobs-core[gui]>=2.0.0.
|
|
15
|
+
"pyobs-core[gui]>=2.0.0.dev48,<3",
|
|
16
16
|
]
|
|
17
17
|
|
|
18
18
|
[project.scripts]
|
|
@@ -20,10 +20,12 @@ v4l-gui = "pyobs_v4l.gui:main"
|
|
|
20
20
|
|
|
21
21
|
[dependency-groups]
|
|
22
22
|
dev = [
|
|
23
|
-
"black>=25.1.0,<
|
|
23
|
+
"black>=25.1.0,<27",
|
|
24
24
|
"ruff>=0.9.0",
|
|
25
25
|
"pyrefly>=1.1.1",
|
|
26
26
|
"pre-commit>=4.2.0,<5",
|
|
27
|
+
"pytest>=8.0.0",
|
|
28
|
+
"pytest-asyncio>=0.24.0",
|
|
27
29
|
]
|
|
28
30
|
|
|
29
31
|
[build-system]
|
|
@@ -43,3 +45,8 @@ select = ["E", "F", "W", "I", "UP", "G"]
|
|
|
43
45
|
|
|
44
46
|
[tool.pyrefly]
|
|
45
47
|
python-version = "3.11"
|
|
48
|
+
replace-imports-with-any = ["cv2"]
|
|
49
|
+
project-excludes = ["pyobs_v4l/gui.py"]
|
|
50
|
+
|
|
51
|
+
[tool.pytest.ini_options]
|
|
52
|
+
asyncio_mode = "strict"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Smoke tests: import the driver and instantiate it without hardware, asserting it
|
|
2
|
+
advertises the interfaces it claims.
|
|
3
|
+
|
|
4
|
+
The V4L2 device is only opened inside the capture loop (after open()), so
|
|
5
|
+
instantiation is safe. ``pyobs_v4l.gui`` is deliberately not imported here -- it pulls
|
|
6
|
+
in PySide6/qasync at module load and needs a display.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from pyobs.interfaces import IImageType, IVideo
|
|
10
|
+
from pyobs.modules import Module
|
|
11
|
+
|
|
12
|
+
from pyobs_v4l import v4lCamera
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_instantiate_camera() -> None:
|
|
16
|
+
camera = v4lCamera()
|
|
17
|
+
assert isinstance(camera, Module)
|
|
18
|
+
assert isinstance(camera, IVideo)
|
|
19
|
+
assert isinstance(camera, IImageType)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Unit tests for the non-hardware logic in v4lCamera: constructor state and the
|
|
2
|
+
_run_blocking timeout wrapper.
|
|
3
|
+
|
|
4
|
+
Opening the V4L2 device and reading frames is out of scope here.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import asyncio
|
|
8
|
+
import threading
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
from pyobs_v4l import v4lCamera
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_constructor_defaults() -> None:
|
|
16
|
+
camera = v4lCamera()
|
|
17
|
+
assert camera._device == 0
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_constructor_device() -> None:
|
|
21
|
+
camera = v4lCamera(device=3)
|
|
22
|
+
assert camera._device == 3
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.mark.asyncio
|
|
26
|
+
async def test_run_blocking_runs_func_and_returns_true() -> None:
|
|
27
|
+
ran: list[bool] = []
|
|
28
|
+
|
|
29
|
+
def fast() -> None:
|
|
30
|
+
ran.append(True)
|
|
31
|
+
|
|
32
|
+
assert await v4lCamera._run_blocking(fast) is True
|
|
33
|
+
assert ran == [True]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@pytest.mark.asyncio
|
|
37
|
+
async def test_run_blocking_times_out() -> None:
|
|
38
|
+
done = threading.Event()
|
|
39
|
+
|
|
40
|
+
def slow() -> None:
|
|
41
|
+
done.wait()
|
|
42
|
+
|
|
43
|
+
assert await v4lCamera._run_blocking(slow, timeout=0.01) is False
|
|
44
|
+
done.set()
|
|
45
|
+
await asyncio.sleep(0.05) # let the daemon thread drain before the loop closes
|