本文介绍了Android的SDK:获取原料preVIEW摄像机图像不显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的图像处理与原始图像不显示在屏幕,这显然会降低性能上。

I want to do image processing with a raw image without showing it on the screen, which obviously reduces performance.

据未经preVIEW 的答案,这个线程 Android摄像头这是不可能的了Android 1.5,但没有任何人知道是否有可能在的Andr​​oid 4.0(API等级15)?

According to the answers to this thread Android Camera without Preview it was not possible in Android 1.5, but does anybody know if it is possible in Android 4 (API level 15)?

推荐答案

在安卓4.0,最简单的选项,以接收原始图像数据没有显示在屏幕上它是使用<一个href="http://developer.android.com/reference/android/hardware/Camera.html#set$p$pviewTexture%28android.graphics.SurfaceTexture%29">Camera.set$p$pviewTexture()调用路由preVIEW帧到GPU。

In Android 4, the simplest option to receiving raw image data without displaying it on screen is to use the Camera.setPreviewTexture() call to route the preview frames to the GPU.

您可以使用此方法有两种:

You can use this in two ways:

  1. 请在GPU上的实际加工:设置OpenGL上下文(的OpenGL ES 2教程),并创建一个SurfaceTexture对象在这种情况下。然后通过该对象设置previewTexture,并开始preVIEW。然后,在你的OpenGL code,你可以打电话SurfaceTexture.updateTexImage,并与相关的表面纹理质地的ID将被更新,以从相机最新preVIEW框架。也可以使用glReadPixels,如果需要读回的RGB纹理数据到CPU,以便进一步处理。
  2. 请您处理CPU上:你可以简单地创建一个没有任何OpenGL上下文设置虚拟物体表面纹理。传递你想要的纹理ID的任意整数,且表面纹理连接到使用一套previewTexture相机。只要你不叫updateTexImage时,将表面纹理简单地丢弃传递给它的相机中的所有数据。然后,使用设置了preVIEW回调<一href="http://developer.android.com/reference/android/hardware/Camera.html#set$p$pviewCallback%28android.hardware.Camera.$p$pviewCallback%29">set$p$pviewCallback,和使用该数据(通常以YUV格式),用于CPU处理。这可能是比#1的效率较低,但不需要知道的OpenGL。
  1. Do your actual processing on the GPU: Set up an OpenGL context (OpenGL ES 2 tutorial), and create a SurfaceTexture object in that context. Then pass that object to setPreviewTexture, and start preview. Then, in your OpenGL code, you can call SurfaceTexture.updateTexImage, and the texture ID associated with the SurfaceTexture will be updated to the latest preview frame from the camera. You can also read back the RGB texture data to the CPU for further processing using glReadPixels, if desired.
  2. Do your processing on the CPU: You can simply create a dummy SurfaceTexture object without any OpenGL context set up. Pass any integer you want as the texture ID, and connect the SurfaceTexture to the camera using setPreviewTexture. As long as you don't call updateTexImage, the SurfaceTexture will simply discard all data passed into it by the camera. Then set up preview callbacks using setPreviewCallback, and use that data (typically in a YUV format) for CPU processing. This is probably less efficient than #1, but does not require knowing OpenGL.

这篇关于Android的SDK:获取原料preVIEW摄像机图像不显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 03:53