31
31
from utils .misc_utils import os_type
32
32
33
33
if os_type == 'Linux' :
34
- import v4l2py as v4l
35
- import v4l2py .device as v4ld
34
+ import v4l2
36
35
elif os_type == 'Windows' :
37
36
import pygrabber .dshow_graph as pgdsg
38
37
import pygrabber .dshow_ids as pgdsi
@@ -50,7 +49,7 @@ class ControlType(Enum):
50
49
class Control :
51
50
"""Control defined by the hardware."""
52
51
def __init__ (self : "FTCamera.ControlInfo" ,
53
- control : v4ld . BaseControl ) -> None :
52
+ control : int ) -> None :
54
53
self ._control = control
55
54
self .name = control .name
56
55
self .type = None
@@ -61,18 +60,17 @@ def __init__(self: "FTCamera.ControlInfo",
61
60
self .clipping : bool = False
62
61
self .choices : dict [int : str ] = {}
63
62
match control .type :
64
- case v4ld . ControlType . INTEGER :
63
+ case v4l2 . uapi . V4L2_CTRL_TYPE_INTEGER :
65
64
self .type = FTCamera .ControlType .INTEGER
66
65
self .minimum = control .minimum
67
66
self .maximum = control .maximum
68
67
self .step = control .step
69
68
self .default = control .default
70
69
self .clipping = control .clipping
71
- case v4ld . ControlType . BOOLEAN :
70
+ case v4l2 . uapi . V4L2_CTRL_TYPE_BOOLEAN :
72
71
self .type = FTCamera .ControlType .BOOLEAN
73
72
self .default = control .default
74
-
75
- case v4ld .ControlType .MENU :
73
+ case v4l2 .uapi .V4L2_CTRL_TYPE_MENU :
76
74
self .type = FTCamera .ControlType .SELECT
77
75
self .choices = dict (control .data )
78
76
self .default = control .default
@@ -167,7 +165,7 @@ def __init__(self: 'FTCamera', index: int) -> None:
167
165
"""
168
166
self ._index : int = index
169
167
if os_type == 'Linux' :
170
- self ._device : v4l . Device = None
168
+ self ._device : v4l2 . VideoDevice = None
171
169
elif os_type == 'Windows' :
172
170
self ._device : pgdsg .VideoInput = None
173
171
self ._filter_graph : pgdsg .FilterGraph = None
@@ -212,7 +210,7 @@ def open(self: 'FTCamera') -> None:
212
210
return
213
211
FTCamera ._logger .info ("FTCamera.open: index {}" .format (self ._index ))
214
212
if os_type == 'Linux' :
215
- self ._device = v4l . Device . from_id (self ._index )
213
+ self ._device = v4l2 . VideoDevice (self ._index )
216
214
self ._device .open ()
217
215
elif os_type == 'Windows' :
218
216
self ._filter_graph = pgdsg .FilterGraph ()
@@ -250,8 +248,7 @@ def _find_format(self: 'FTCamera') -> None:
250
248
for x in self ._device .info .formats :
251
249
FTCamera ._logger .info ("- {}" .format (x ))
252
250
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 )
255
252
elif os_type == 'Windows' :
256
253
for x in self ._filter_video .get_formats ():
257
254
FTCamera ._logger .info (x )
@@ -273,7 +270,7 @@ def _find_frame_size(self: 'FTCamera') -> None:
273
270
for x in self ._device .info .frame_sizes :
274
271
FTCamera ._logger .info ("- {}" .format (x ))
275
272
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
277
274
and x .min_fps >= 30 )
278
275
elif os_type == 'Windows' :
279
276
fsize = next (x for x in self ._filter_video .get_formats ()
@@ -294,11 +291,7 @@ def _find_frame_size(self: 'FTCamera') -> None:
294
291
def _set_frame_format (self : 'FTCamera' ) -> None :
295
292
"""Activates the found format and size."""
296
293
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 ()
302
295
elif os_type == 'Windows' :
303
296
self ._filter_video .set_format (self ._frame_size .index )
304
297
@@ -364,7 +357,7 @@ def device_index(self: 'FTCamera') -> int:
364
357
365
358
if os_type == 'Linux' :
366
359
@property
367
- def device (self : 'FTCamera' ) -> v4l . Device :
360
+ def device (self : 'FTCamera' ) -> v4l2 . VideoDevice :
368
361
"""Video4Linux device if open or None if closed."""
369
362
return self ._device
370
363
elif os_type == 'Windows' :
@@ -457,7 +450,7 @@ def _async_grabber(self: 'FTCamera', image: np.ndarray) -> None:
457
450
self ._process_frame (image )
458
451
459
452
if os_type == 'Linux' :
460
- def _process_frame (self : 'FTCamera' , frame : v4l . Frame ) -> None :
453
+ def _process_frame (self : 'FTCamera' , frame ) -> None :
461
454
"""Process captured frames.
462
455
463
456
Operates only on YUV422 format right now. Calls _decode_yuv422
@@ -472,7 +465,7 @@ def _process_frame(self: 'FTCamera', frame: v4l.Frame) -> None:
472
465
473
466
try :
474
467
match frame .pixel_format :
475
- case v4l .PixelFormat .YUYV :
468
+ case v4l2 .PixelFormat .YUYV :
476
469
self ._decode_yuv422 (frame .data )
477
470
case _:
478
471
FTCamera ._logger .error (
0 commit comments