Android camera2: 如何从指定的 cameraId 获取图像?

huangapple go评论83阅读模式
英文:

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,您需要:

  1. 打开相机设备:cameraManager.openCamera(...)
  2. 一旦设备被打开,使用它创建捕获会话:cameraDevice.createCaptureSession(...)
  3. 为输出配置 ImageReader 并创建捕获请求:cameraDevice.createCaptureRequest(...)
  4. 使用 captureSession 处理您的捕获请求:captureSession.capture(...)
  5. 作为结果,您将从为捕获输出配置的 ImageReader 获取一个 Image

因此,对于简单的相机应用,我建议您查看 CameraX1

英文:

There is no fast and easy way to do this with the Camera2 API. For a particular cameraId you need to:

  1. Open camera device: cameraManager.openCamera(...)
  2. Once the device is opened, use it to create capture session: cameraDevice.createCaptureSession(...)
  3. Configure ImageReader for output and create capture request:: cameraDevice.createCaptureRequest(...)
  4. Use captureSession to process your capture request: captureSession.capture(...)
  5. As the result you will obtain an Image from ImageReader that you have configured for capture output.

Therefore, for simple camera app I would suggest to look at CameraX instead.

huangapple
  • 本文由 发表于 2020年9月18日 16:37:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/63952187.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定