翻译Camera2 API

来源:互联网 发布:javascript书 编辑:程序博客网 时间:2024/05/17 20:01

android.hardware.camera2

The android.hardware.camera2 package provides an interface to individual camera devices connected to an Android device. It replaces the deprecated Camera class.

camera2包提供对连接到Android 设备相机的接口,该包替代弃用的Camera类。

This package models a camera device as a pipeline, which takes in input requests for capturing a single frame, captures the single image per the request, and then outputs one capture result metadata packet, plus a set of output image buffers for the request. The requests are processed in-order, and multiple requests can be in flight at once. Since the camera device is a pipeline with multiple stages, having multiple requests in flight is required to maintain full framerate on most Android devices.

该包将Camera设备当作一个管道,负责处理应用一系列抓去单帧的请求。该包将对每一次请求进行抓去图像,并针对每一次请求返回给应用对应抓去图像结果的元数据,并附带输出一组缓存这些请求对应图像的缓冲区。请求是按顺序处理的,并且多个请求能并行处理。因为该Camera设备拥有多级流水线,所以该特性能满足大多数Android设备对保持满帧的要求。

To enumerate, query, and open available camera devices, obtain a CameraManager instance.

通过获取CameraManager的单例,来枚举、查询、打开可用的Camera设备。

Individual CameraDevices provide a set of static property information that describes the hardware device and the available settings and output parameters for the device. This information is provided through the CameraCharacteristics object, and is available through getCameraCharacteristics(String)

各个相机设备都有相关的参数来描述各自的特性,这些特性有部分可以进行配置。特性的信息是由CameraCharacteristics 的对象来提供,可以通过方法getCameraCharacteristics(String)来获得该特性。

To capture or stream images from a camera device, the application must first create a camera capture session with a set of output Surfaces for use with the camera device, with createCaptureSession(List, CameraCaptureSession.StateCallback, Handler). Each Surface has to be pre-configured with an appropriate size and format (if applicable) to match the sizes and formats available from the camera device. A target Surface can be obtained from a variety of classes, including SurfaceView, SurfaceTexture via Surface(SurfaceTexture),MediaCodec, MediaRecorder, Allocation, and ImageReader.

要想从相机补获图像流信息,应用必须先创建一个Camera抓去图像的会话,同时这个会话必须带有一组可以用来输出Camera 设备数据的Surfaces。会话的创建方法是createCaptureSession(List, CameraCaptureSession.StateCallback, Handler)。Surfaces 组中的每一个Surface大小和格式都必须提前配置成所用的Camera设备支持的大小和格式。Surfaces 组可以通过很多类的对象来获取,包括SurfaceView类,SurfaceTexture类以Surface(SurfaceTexture)方式,MediaCodec类,MediaRecorde类,Allocation类,ImageReader类。

Generally, camera preview images are sent to SurfaceView or TextureView (via its SurfaceTexture). Capture of JPEG images or RAW buffers for DngCreator can be done with ImageReader with the JPEG and RAW_SENSOR formats. Application-driven processing of camera data in RenderScript, OpenGL ES, or directly in managed or native code is best done through Allocation with a YUV Type, SurfaceTexture, and ImageReader with a YUV_420_888 format, respectively.

一般,Camera图像都通过SurfaceView或者TextureView(通过其SurfaceTexture 提供 Surfaces)的方式来预览图像。如果是获取JPEG图像或者是动态内存中缓冲区的数据的话,可以用ImageReader,不过要配置ImageReader格式为JPEG和RAW_SENSOR格式。如果是用在渲染脚步、OpenGL ES处理方面,或者是套直接用本地C/C++代码来处理的话,建议配置AllocationYUV格式使用,或者使用 SurfaceTexture ,或者用ImageReader,但是配置其格式为YUV_420_888。

The application then needs to construct a CaptureRequest, which defines all the capture parameters needed by a camera device to capture a single image. The request also lists which of the configured output Surfaces should be used as targets for this capture. The CameraDevice has a factory method for creating a request builder for a given use case, which is optimized for the Android device the application is running on.

创建完会话后,应用然后就需要构造一个抓去请求,这个请求中包含了相机需要抓去图像对应的所有配置。同时,该请求也列出了相机设备输出数据对应的目标Surfaces组。这个相机设备有为了简化该请求的配置,用一个对应的工厂方法来生成该请求。

Once the request has been set up, it can be handed to the active capture session either for a one-shot capture or for an endlessly repeatinguse. Both methods also have a variant that accepts a list of requests to use as a burst capture / repeating burst. Repeating requests have a lower priority than captures, so a request submitted through capture() while there's a repeating request configured will be captured before any new instances of the currently repeating (burst) capture will begin capture.

一旦请求建立好了,它就可以传给会话以便用来单次抓去图像或者一直抓取图像。每一个方法都有对应一个变体(burst capture 和repeating burst)。一直抓取的这个模式优先级比单次抓取要低,因此在两种模式同时村子啊的时候,单次抓取要先执行。

After processing a request, the camera device will produce a TotalCaptureResult object, which contains information about the state of the camera device at time of capture, and the final settings used. These may vary somewhat from the request, if rounding or resolving contradictory parameters was necessary. The camera device will also send a frame of image data into each of the output Surfaces included in the request. These are produced asynchronously relative to the output CaptureResult, sometimes substantially later.

处理完请求后,Camera设会产生一个TotalCaptureResult.对象,该对象包含来在摘取图像过程中Camera的状态消息,和相机的最后配置信息。这些信息随着请求的不同而不同。Camera设备会发送帧图像到对应配置好的输出Surfaces组中。这些过程相对与抓取结果是异步进行的,有时相对落后些。





原创粉丝点击