Camera2可以连续访问相机预览图像 [英] Camera2 get continuous access to camera preview images

查看:277
本文介绍了Camera2可以连续访问相机预览图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据API将应用程序从Camera1扩展到Camera2.该应用程序的一种核心机制是以每秒约20张图片的速度拍摄预览图片.使用Camera1,我意识到,通过创建SurfaceView,在其支架上添加回调,并在创建表面之后通过定期的setOneShotPreviewCallbacks访问预览图片.那是非常容易和可靠的.

I want to extend an app from Camera1 to Camera2 depending on the API. One core mechanism of the app consists in taking preview pictures at a rate of about 20 pics per second. With Camera1 I realized that by creating a SurfaceView, adding a Callback on its holder and after creation of the surface accessing the preview pics via periodic setOneShotPreviewCallbacks. That was pretty easy and reliable.

现在,在学习Camera2时,我从头开始"并设法将YUV420_888转换为位图(请参阅 YUV420_888转换为位图).但是,我现在正在为捕获技术"而苦苦挣扎.从Google的示例中,我看到您需要使用CameraDevice.TEMPLATE_PREVIEW进行"setRepeating" CaptureRequest以显示预览,例如在表面上看.那样就好.但是,为了拍摄实际照片,我需要使用(这次)builder.addTarget(imageReader.getSurface())发出另一个捕获请求. IE.数据将在imageReader的onImageAvailable方法中可用.

Now, when studying Camera2, I came "from the end" and managed to convert YUV420_888 to Bitmap (see YUV420_888 to Bitmap Conversion ). However I am struggling now with the "capture technique". From the Google example I see that you need to make a "setRepeating" CaptureRequest with CameraDevice.TEMPLATE_PREVIEW for displaying the preview e.g. on a surface view. That is fine. However, in order to take an actual picture I need to make another capture request with (this time) builder.addTarget(imageReader.getSurface()). I.e. data will be available within the onImageAvailable method of the imageReader.

问题:captureRequest的创建是一项相当繁重的操作,在我的设备上大约需要200毫秒.因此,根据我的需要,使用捕获请求(无论是模板STILL_CAPTUR还是PREVIEW)都不可能是每秒捕获20张图像的可行方法.我在SO上找到的建议主要基于(教育程度适中的)Google示例,我并不十分了解...

The problem: the creation of the captureRequest is a rather heavy operation taking about 200ms on my device. Therefore, the usage of a capture request (whether with Template STILL_CAPTUR nor PREVIEW) can impossibly be a feasible approach for capturing 20 images per second, as I need it. The proposals I found here on SO are primarily based on the (educationally moderately efficient) Google example, which I don't really understand...

我认为解决方案必须是向ImageReader提供连续的预览图片流,可以从那里以给定的频率选择预览图片.有人可以提供一些实施指导吗?非常感谢.

I feel the solution must be to feed the ImageReader with a contiuous stream of preview pics, which can be picked from there in a given frequency. Can someone please give some guidance on how to implement this? Many thanks.

推荐答案

如果要为每个帧将缓冲区发送到预览SurfaceView和YUV ImageReader,只需将两个Surface添加到重复的预览请求中作为目标.

If you want to send a buffer to both the preview SurfaceView and to your YUV ImageReader for every frame, simply add both Surfaces to the repeating preview request as targets.

通常,捕获请求可以定位到 会话的已配置输出目标.

Generally, a capture request can target any subset (or all) of the session's configured output targets.

此外,如果您确实只想使用.capture()将偶尔的帧捕获到YUV ImageReader,则不必每次都重新创建捕获请求构建器;只需在同一构建器上再次调用.build()即可;如果您不更改任何设置,则只需重用实际构造的CaptureRequest即可.

Also, if you do want to only capture an occasional frame to your YUV ImageReader with .capture(), you don't have to recreate the capture request builder each time; just call .build() again on the same builder, or just reuse the actual constructed CaptureRequest if you're not changing any settings.

即使偶尔进行捕获,您也可能希望在YUV捕获请求中包括Surface预览作为目标,以便在显示的预览中没有跳过的帧.

Even with this occasional capture, you probably want to include the preview Surface as a target in the YUV capture request, so that there's no skipped frame in the displayed preview.

这篇关于Camera2可以连续访问相机预览图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆