英文:
Android camera2: how ho to get Image from a defined cameraId?
问题
我使用以下 Android 代码中的 CameraManager
服务:
CameraManager cameraManager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
String[] cameraIdList = cameraManager.getCameraIdList();
现在,我想要从此列表中的一个 cameraId
获取图像,以便能够对该图像执行以下代码:
ShortBuffer shortDepthBuffer = image.getPlanes()[0].getBuffer().asShortBuffer();
我如何根据指定的 cameraId
获取这个图像呢?
谢谢!
英文:
I use the following android code CameraManager
service:
CameraManager cameraManager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
String[] cameraIdList = cameraManager.getCameraIdList();
Now, I want to get the image from one of the cameraIds
in this list in order to be able to execute the following code on this image:
ShortBuffer shortDepthBuffer = image.getPlanes()[0].getBuffer().asShortBuffer();
How can I get this Image from a defined cameraId
?
Thanks !
答案1
得分: 1
使用Camera2
API 没有快捷简单的方法来完成这个任务。对于特定的 cameraId
,您需要:
- 打开相机设备:
cameraManager.openCamera(...)
- 一旦设备被打开,使用它创建捕获会话:
cameraDevice.createCaptureSession(...)
- 为输出配置
ImageReader
并创建捕获请求:cameraDevice.createCaptureRequest(...)
- 使用
captureSession
处理您的捕获请求:captureSession.capture(...)
- 作为结果,您将从为捕获输出配置的
ImageReader
获取一个Image
。
因此,对于简单的相机应用,我建议您查看 CameraX
。1
英文:
There is no fast and easy way to do this with the Camera2
API. For a particular cameraId
you need to:
- Open camera device:
cameraManager.openCamera(...)
- Once the device is opened, use it to create capture session:
cameraDevice.createCaptureSession(...)
- Configure
ImageReader
for output and create capture request::cameraDevice.createCaptureRequest(...)
- Use
captureSession
to process your capture request:captureSession.capture(...)
- As the result you will obtain an
Image
fromImageReader
that you have configured for capture output.
Therefore, for simple camera app I would suggest to look at CameraX
instead.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论