pyobs-v4l 2.0.0.dev5__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/workflows/dependabot-automerge.yml +24 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/PKG-INFO +1 -1
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/pyobs_v4l/gui.py +22 -4
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/pyobs_v4l/v4lcamera.py +39 -20
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/pyproject.toml +1 -1
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/uv.lock +1 -1
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/.github/dependabot.yml +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/.github/workflows/pypi.yml +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/.github/workflows/pyrefly.yml +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/.github/workflows/pytest.yml +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/.github/workflows/ruff.yml +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/.pre-commit-config.yaml +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/.readthedocs.yml +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/LICENSE +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/README.md +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/docs/Makefile +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/docs/make.bat +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/docs/requirements.txt +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/docs/source/_static/pyobs.gif +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/docs/source/conf.py +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/docs/source/index.rst +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/pyobs_v4l/__init__.py +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/tests/test_import.py +0 -0
- {pyobs_v4l-2.0.0.dev5 → pyobs_v4l-2.0.0.dev6}/tests/test_v4lcamera.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 }}
|
|
@@ -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"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|