Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
version 1.0.0
  • Loading branch information
thusser authored Jun 5, 2024
2 parents 8685625 + 84d935c commit fa02d12
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: black
language_version: python3.9
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2022 Tim-Oliver Husser
[email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 12 additions & 9 deletions pyobs_v4l/v4lcamera.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
import asyncio
import time
import logging
from typing import Any
import cv2

from pyobs.modules.camera import BaseVideo
import cv2


log = logging.getLogger(__name__)


class v4lCamera(BaseVideo):
def __init__(self, device: int = 0, *args, **kwargs):
BaseVideo.__init__(self, *args, **kwargs)
def __init__(self, device: int = 0, **kwargs: Any):
BaseVideo.__init__(self, **kwargs)

# store
self._device = device

# thread
self.add_thread_func(self._capture)
self.add_background_task(self._capture)

def _capture(self):
async def _capture(self) -> None:
# open camera
camera = cv2.VideoCapture(self._device)

# loop until closing
last = time.time()
while not self.closing.is_set():
while True:
# read frame
_, frame = camera.read()

# if time since last image is too short, wait a little
if time.time() - last < self._interval:
self.closing.wait(0.01)
await asyncio.sleep(0.01)
continue
last = time.time()

# process it
self._set_image(frame)
await self._set_image(frame)

# release camera
camera.release()


__all__ = ['v4lCamera']
__all__ = ["v4lCamera"]
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.poetry]
name = "pyobs-v4l"
version = "1.0.0"
description = "pyobs module for V4L cameras"
authors = ["Tim-Oliver Husser <[email protected]>"]
license = "MIT"

[tool.poetry.dependencies]
python = ">=3.9,<3.13"

[tool.poetry.dev-dependencies]
black = "^21.12b0"
pre-commit = "^2.16.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 120
target-version = ['py39']

0 comments on commit fa02d12

Please sign in to comment.