Skip to content

Commit c850bc3

Browse files
committed
(feat) VFT candidate
1 parent 8a9b82a commit c850bc3

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

BabbleApp/requirements.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ torch==2.6.0;
55
torchvision==0.21.0;
66
opencv_python==4.11.0.86;
77
pillow==11.0.0;
8-
freesimplegui==5.1.1;
8+
FreeSimpleGUI==5.1.1;
99
python_osc==1.9.0;
1010
pydantic==2.10.6;
1111
pyserial==3.5;
@@ -15,6 +15,4 @@ comtypes==1.4.8;
1515
pygrabber==0.2;
1616
psutil==6.1.1;
1717
requests==2.32.3;
18-
cpython==3.0.11;
19-
pyv4l2; platform_system == "Linux"
20-
PyV4L2Camera; platform_system == "Linux"
18+
git+https://github.com/tomba/pyv4l2.git; platform_system == "Linux"

BabbleApp/vivefacialtracker/camera.py

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

3333
if os_type == 'Linux':
34-
import v4l2py as v4l
35-
import v4l2py.device as v4ld
34+
import v4l2
3635
elif os_type == 'Windows':
3736
import pygrabber.dshow_graph as pgdsg
3837
import pygrabber.dshow_ids as pgdsi
@@ -50,7 +49,7 @@ class ControlType(Enum):
5049
class Control:
5150
"""Control defined by the hardware."""
5251
def __init__(self: "FTCamera.ControlInfo",
53-
control: v4ld.BaseControl) -> None:
52+
control: int) -> None:
5453
self._control = control
5554
self.name = control.name
5655
self.type = None
@@ -61,18 +60,17 @@ def __init__(self: "FTCamera.ControlInfo",
6160
self.clipping: bool = False
6261
self.choices: dict[int: str] = {}
6362
match control.type:
64-
case v4ld.ControlType.INTEGER:
63+
case v4l2.uapi.V4L2_CTRL_TYPE_INTEGER:
6564
self.type = FTCamera.ControlType.INTEGER
6665
self.minimum = control.minimum
6766
self.maximum = control.maximum
6867
self.step = control.step
6968
self.default = control.default
7069
self.clipping = control.clipping
71-
case v4ld.ControlType.BOOLEAN:
70+
case v4l2.uapi.V4L2_CTRL_TYPE_BOOLEAN:
7271
self.type = FTCamera.ControlType.BOOLEAN
7372
self.default = control.default
74-
75-
case v4ld.ControlType.MENU:
73+
case v4l2.uapi.V4L2_CTRL_TYPE_MENU:
7674
self.type = FTCamera.ControlType.SELECT
7775
self.choices = dict(control.data)
7876
self.default = control.default
@@ -167,7 +165,7 @@ def __init__(self: 'FTCamera', index: int) -> None:
167165
"""
168166
self._index: int = index
169167
if os_type == 'Linux':
170-
self._device: v4l.Device = None
168+
self._device: v4l2.VideoDevice = None
171169
elif os_type == 'Windows':
172170
self._device: pgdsg.VideoInput = None
173171
self._filter_graph: pgdsg.FilterGraph = None
@@ -212,7 +210,7 @@ def open(self: 'FTCamera') -> None:
212210
return
213211
FTCamera._logger.info("FTCamera.open: index {}".format(self._index))
214212
if os_type == 'Linux':
215-
self._device = v4l.Device.from_id(self._index)
213+
self._device = v4l2.VideoDevice(self._index)
216214
self._device.open()
217215
elif os_type == 'Windows':
218216
self._filter_graph = pgdsg.FilterGraph()
@@ -250,8 +248,7 @@ def _find_format(self: 'FTCamera') -> None:
250248
for x in self._device.info.formats:
251249
FTCamera._logger.info("- {}".format(x))
252250
self._format = next(x for x in self._device.info.formats
253-
if x.pixel_format == v4l.PixelFormat.YUYV
254-
and x.type == v4ld.BufferType.VIDEO_CAPTURE)
251+
if x.pixel_format == v4l2.PixelFormat.YUYV)
255252
elif os_type == 'Windows':
256253
for x in self._filter_video.get_formats():
257254
FTCamera._logger.info(x)
@@ -273,7 +270,7 @@ def _find_frame_size(self: 'FTCamera') -> None:
273270
for x in self._device.info.frame_sizes:
274271
FTCamera._logger.info("- {}".format(x))
275272
self._frame_size = next(x for x in self._device.info.frame_sizes
276-
if x.pixel_format == v4l.PixelFormat.YUYV
273+
if x.pixel_format == v4l2.PixelFormat.YUYV
277274
and x.min_fps >= 30)
278275
elif os_type == 'Windows':
279276
fsize = next(x for x in self._filter_video.get_formats()
@@ -294,11 +291,7 @@ def _find_frame_size(self: 'FTCamera') -> None:
294291
def _set_frame_format(self: 'FTCamera') -> None:
295292
"""Activates the found format and size."""
296293
if os_type == 'Linux':
297-
self._device.set_format(
298-
buffer_type=v4ld.BufferType.VIDEO_CAPTURE,
299-
width=self._frame_size.width,
300-
height=self._frame_size.height,
301-
pixel_format=self._format.pixel_format)
294+
self._device.set_format()
302295
elif os_type == 'Windows':
303296
self._filter_video.set_format(self._frame_size.index)
304297

@@ -364,7 +357,7 @@ def device_index(self: 'FTCamera') -> int:
364357

365358
if os_type == 'Linux':
366359
@property
367-
def device(self: 'FTCamera') -> v4l.Device:
360+
def device(self: 'FTCamera') -> v4l2.VideoDevice:
368361
"""Video4Linux device if open or None if closed."""
369362
return self._device
370363
elif os_type == 'Windows':
@@ -457,7 +450,7 @@ def _async_grabber(self: 'FTCamera', image: np.ndarray) -> None:
457450
self._process_frame(image)
458451

459452
if os_type == 'Linux':
460-
def _process_frame(self: 'FTCamera', frame: v4l.Frame) -> None:
453+
def _process_frame(self: 'FTCamera', frame) -> None:
461454
"""Process captured frames.
462455
463456
Operates only on YUV422 format right now. Calls _decode_yuv422
@@ -472,7 +465,7 @@ def _process_frame(self: 'FTCamera', frame: v4l.Frame) -> None:
472465

473466
try:
474467
match frame.pixel_format:
475-
case v4l.PixelFormat.YUYV:
468+
case v4l2.PixelFormat.YUYV:
476469
self._decode_yuv422(frame.data)
477470
case _:
478471
FTCamera._logger.error(

0 commit comments

Comments
 (0)