MCPcopy Create free account
hub / github.com/RustCV/RustCV / list_devices

Function list_devices

rustcv-backend-v4l2/src/device.rs:15–41  ·  view source on GitHub ↗

枚举系统中的摄像头设备

()

Source from the content-addressed store, hash-verified

13
14/// 枚举系统中的摄像头设备
15pub fn list_devices() -> Result<Vec<DeviceInfo>> {
16 let mut devices = Vec::new();
17
18 // 遍历 /dev/video* 节点
19 let node_iter = v4l::context::enum_devices();
20
21 for node in node_iter {
22 // 尝试打开设备查询能力
23 let path = node.path().to_string_lossy().to_string();
24 if let Ok(dev) = v4l::Device::with_path(&path) {
25 if let Ok(caps) = dev.query_caps() {
26 // 过滤:必须支持 Video Capture (0x00000001)
27 // 忽略 Metadata 设备或 Output 设备
28 if caps.capabilities.contains(Flags::VIDEO_CAPTURE) {
29 devices.push(DeviceInfo {
30 name: node.name().unwrap_or_else(|| "Unknown Camera".into()),
31 id: path, // /dev/video0
32 backend: "V4L2".to_string(),
33 bus_info: Some(caps.bus),
34 });
35 }
36 }
37 }
38 }
39
40 Ok(devices)
41}
42
43/// 打开设备并初始化流
44pub fn open(id: &str, config: CameraConfig) -> Result<(Box<dyn Stream>, DeviceControls)> {

Callers 1

list_devicesMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected