-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_camera_info.py
75 lines (57 loc) · 1.89 KB
/
get_camera_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import platform
from camera_info import CameraInfo
from ndi import NDICapture
from sc_logging import logger
# This file contains the code to get the camera information for the current OS
def get_camera_info_windows():
from win32DeviceEnum import enum_devices_dshow
device_info = []
cameras = enum_devices_dshow.enumerate_video_devices_dshow()
for camera in cameras:
device_info.append(
CameraInfo(
camera[1], str(camera[0]), camera[0], CameraInfo.CameraType.OPENCV
)
)
return device_info
def get_camera_info_mac():
import AVFoundation as AV
device_info = []
devices = AV.AVCaptureDevice.devicesWithMediaType_(AV.AVMediaTypeVideo)
for i, device in enumerate(devices):
device_info.append(
CameraInfo(
device.localizedName(),
device.uniqueID(),
i,
CameraInfo.CameraType.OPENCV,
)
)
# sort by the ID, since opencv sorts by ID
device_info.sort(key=lambda x: x.uuid)
# update the ID
for i, camera in enumerate(device_info):
camera.id = i
return device_info
def get_camera_info_linux():
# Basic method using /dev/video* enumeration
import glob
device_info = glob.glob("/dev/video*")
device_info = [
CameraInfo(f"Camera {i}", dev, i, CameraInfo.CameraType.OPENCV)
for i, dev in enumerate(device_info)
]
return device_info
def get_camera_info() -> list[CameraInfo]:
logger.info("Getting cameras info")
os_name = platform.system()
cameras = []
if os_name == "Windows":
cameras += get_camera_info_windows()
elif os_name == "Darwin":
cameras += get_camera_info_mac()
elif os_name == "Linux":
cameras += get_camera_info_linux()
# Add NDI cameras
cameras += NDICapture.get_camera_info_ndi()
return cameras