Skip to content

Commit c944765

Browse files
committed
(tweak) Re-add v4l2, reqs
1 parent 0e601fd commit c944765

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

BabbleApp/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ colorama==0.4.6;
1313
desktop-notifier==6.0.0;
1414
comtypes==1.4.8;
1515
pygrabber==0.2;
16-
psutil==6.1.1;
16+
psutil==7.0.0;
1717
requests==2.32.3;
18+
v4l2py==3.0.0;

BabbleApp/vivefacialtracker/camera.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
from utils.misc_utils import os_type
3232

3333
if os_type == 'Linux':
34-
import v4l2
34+
import v4l2py as v4l
35+
import v4l2py.device as v4ld
3536
elif os_type == 'Windows':
3637
import pygrabber.dshow_graph as pgdsg
3738
import pygrabber.dshow_ids as pgdsi
@@ -49,7 +50,7 @@ class ControlType(Enum):
4950
class Control:
5051
"""Control defined by the hardware."""
5152
def __init__(self: "FTCamera.ControlInfo",
52-
control: int) -> None:
53+
control: v4ld.BaseControl) -> None:
5354
self._control = control
5455
self.name = control.name
5556
self.type = None
@@ -60,17 +61,17 @@ def __init__(self: "FTCamera.ControlInfo",
6061
self.clipping: bool = False
6162
self.choices: dict[int: str] = {}
6263
match control.type:
63-
case v4l2.uapi.V4L2_CTRL_TYPE_INTEGER:
64+
case v4ld.ControlType.INTEGER:
6465
self.type = FTCamera.ControlType.INTEGER
6566
self.minimum = control.minimum
6667
self.maximum = control.maximum
6768
self.step = control.step
6869
self.default = control.default
6970
self.clipping = control.clipping
70-
case v4l2.uapi.V4L2_CTRL_TYPE_BOOLEAN:
71+
case v4ld.ControlType.BOOLEAN:
7172
self.type = FTCamera.ControlType.BOOLEAN
7273
self.default = control.default
73-
case v4l2.uapi.V4L2_CTRL_TYPE_MENU:
74+
case v4ld.ControlType.MENU:
7475
self.type = FTCamera.ControlType.SELECT
7576
self.choices = dict(control.data)
7677
self.default = control.default
@@ -165,7 +166,7 @@ def __init__(self: 'FTCamera', index: int) -> None:
165166
"""
166167
self._index: int = index
167168
if os_type == 'Linux':
168-
self._device: v4l2.VideoDevice = None
169+
self._device: v4l.Device = None
169170
elif os_type == 'Windows':
170171
self._device: pgdsg.VideoInput = None
171172
self._filter_graph: pgdsg.FilterGraph = None
@@ -210,7 +211,7 @@ def open(self: 'FTCamera') -> None:
210211
return
211212
FTCamera._logger.info("FTCamera.open: index {}".format(self._index))
212213
if os_type == 'Linux':
213-
self._device = v4l2.VideoDevice(self._index)
214+
self._device = v4l.Device.from_id(self._index)
214215
self._device.open()
215216
elif os_type == 'Windows':
216217
self._filter_graph = pgdsg.FilterGraph()
@@ -248,7 +249,7 @@ def _find_format(self: 'FTCamera') -> None:
248249
for x in self._device.info.formats:
249250
FTCamera._logger.info("- {}".format(x))
250251
self._format = next(x for x in self._device.info.formats
251-
if x.pixel_format == v4l2.PixelFormat.YUYV)
252+
if x.pixel_format == v4l.PixelFormat.YUYV)
252253
elif os_type == 'Windows':
253254
for x in self._filter_video.get_formats():
254255
FTCamera._logger.info(x)
@@ -291,7 +292,11 @@ def _find_frame_size(self: 'FTCamera') -> None:
291292
def _set_frame_format(self: 'FTCamera') -> None:
292293
"""Activates the found format and size."""
293294
if os_type == 'Linux':
294-
self._device.set_format()
295+
self._device.set_format(
296+
buffer_type=v4ld.BufferType.VIDEO_CAPTURE,
297+
width=self._frame_size.width,
298+
height=self._frame_size.height,
299+
pixel_format=self._format.pixel_format)
295300
elif os_type == 'Windows':
296301
self._filter_video.set_format(self._frame_size.index)
297302

0 commit comments

Comments
 (0)