K1 muse pi pro烧写OpenHarmony后是否能通过APP调用USB摄像头?我通过hdc查看了一下是有识别到USB摄像头的,具体日志如下:
# dmesg | grep -i camera
[26788.044150] usb 2-1.3: Found UVC 1.00 device 2K USB Camera (2bdf:028a)
[28053.971551] usb 2-1.2: Found UVC 1.00 device 2K USB Camera (2bdf:028a)
[28054.185208] hid-generic 0003:2BDF:028A.0001: hiddev96,hidraw0: USB HID v1.01 Device [SN0002 2K USB Camera] on usb-xhci-hcd.1.auto-1.2/input6
[28786.634780] usb 2-1.1: Found UVC 1.00 device 2K USB Camera (2bdf:028a)
[28786.959148] hid-generic 0003:2BDF:028A.0002: hiddev96,hidraw0: USB HID v1.01 Device [SN0002 2K USB Camera] on usb-xhci-hcd.1.auto-1.1/input6
[28796.874821] usb 2-1.3: Found UVC 1.00 device 2K USB Camera (2bdf:028a)
[28886.986818] usb 2-1.3: Found UVC 1.00 device 2K USB Camera (2bdf:028a)
[28887.176370] hid-generic 0003:2BDF:028A.0003: hiddev96,hidraw0: USB HID v1.01 Device [SN0002 2K USB Camera] on usb-xhci-hcd.1.auto-1.3/input6
# ls /dev/video*
/dev/video0 /dev/video1 /dev/video2 /dev/video23 /dev/video24
接入USB摄像头后ls video多输出的是video1和video2。
我通过CameraKit来访问USB摄像头代码如下:
private preferUsbBackCamera(): camera.CameraDevice | undefined {
const manager = this.getManager();
if (!manager) return undefined;
const list: camera.CameraDevice[] = manager.getSupportedCameras();
// 详细日志:打印所有相机设备信息
console.info(`Total cameras: ${list?.length || 0}`);
list?.forEach((cam, index) => {
console.info(`Camera ${index}:`);
console.info(` ID: ${cam?.cameraId}`);
console.info(` ConnectionType: ${cam?.connectionType}`);
console.info(` Position: ${cam?.cameraPosition}`);
console.info(` Type: ${cam?.cameraType}`);
});
if (!list || list.length === 0) {
console.error('No cameras available');
return undefined;
}
// 放宽选择条件,尝试所有可能的 USB 摄像头
let target = list.find((d: camera.CameraDevice) =>
d?.connectionType === 2 && d?.cameraPosition !== camera.CameraPosition.CAMERA_POSITION_FRONT
);
if (!target) {
console.info('No USB camera found with connectionType=2, trying all cameras...');
// 尝试所有非前置相机
target = list.find((d: camera.CameraDevice) =>
d?.cameraPosition !== camera.CameraPosition.CAMERA_POSITION_FRONT
);
}
if (!target) {
console.info('No non-front camera found, using first available camera');
target = list[0];
}
console.info(`Selected camera: ${target?.cameraId}, connectionType: ${target?.connectionType}`);
return target;
}
有没有大佬能帮忙看一下?
