java - 我的应用无法识别 USB 外接摄像头(可以识别前后摄像头,即使我可以使用它们),我正在使用 Android Camera2 API
问题描述
我的应用无法识别 USB 外接摄像头(可以识别前后摄像头,即使我可以使用它们),我正在使用 Android Camera2 API。我没有使用它(ICameraProvider 接口),因为我真的不知道如何使用它。我已经在motorola one action (Android 10.0) 和 LG 3 stylus (Android 7.0) 上对其进行了测试。
第一个问题:我需要使用ICameraProvider接口吗,怎么用? https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/master/camera/provider/2.4/ICameraProvider.hal
第二个问题:“External USB Cameras”Android 文档的实现部分是针对开发者的,还是我应该做一些步骤?https://source.android.com/devices/camera/external-usb-cameras
第三个问题:我应该根我的手机吗?
我的一些代码(此代码仅识别前后摄像头,但不识别 USB 摄像头):
package com.example.camera10;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.hardware.usb.UsbManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraManager;
import java.util.HashMap;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class IdCameras extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_id_cameras);
Intent intent = getIntent();
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
String[] idList = manager.getCameraIdList();
Log.d("Available Cameras", String.valueOf(idList.length));
TextView textView = findViewById(R.id.textView);
textView.setText(String.valueOf(idList.length));
int maxCameraCnt = idList.length;
for (int index = 0; index < maxCameraCnt; index++) {
String cameraId = manager.getCameraIdList()[index];
Log.d("Camera", cameraId);
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
}
} catch (CameraAccessException e) {
e.printStackTrace();
}
// Capture the layout's TextView and set the string as its text
}
}
解决方案
Android 手机不强制支持外部网络摄像头。您找到的说明适用于制造商,以帮助他们使网络摄像头显示在 camera2 API 中。
如果制造商没有决定支持网络摄像头,您的选择是使用 USB API 并在您的应用程序中实现完整的 UVC 网络摄像头堆栈(有可用的库)。或者,如果您只关心特定的 Android 设备,并且可以为其制作自定义图像,则可以按照您找到的说明在设备上启用网络摄像头支持。
推荐阅读
- excel - Excel 计算字段未返回正确值
- r - dplyr 与 str_locate_all 发生变异
- javascript - 将我的类组件转换为功能组件的方法是什么?
- r - 在R中按条件对多行求和
- python - 使用 pandas.DataFrame.to_csv 写入 csv 文件时如何强制执行分类整数 dtype
- python - Python Pandas 如何从命令行读取 C++ 结构二进制文件
- node.js - 如何在节点包内解析相对路径?
- internet-explorer - 在 IE 中的 FontAwesome 图标上显示标题
- mysql - 为什么 docker compose 创建名称错误的 mysql 容器?
- python - 如何使用目录的每个子目录中的文件数创建一个python列表