简体   繁体   English

使用OpenGL进行图像处理-设置OpenGL上下文

[英]Using OpenGL for Image Processing - Setting up an OpenGL context

I want to do image processing on a raw image without displaying it on screen (I want to do some calculations based on the image data and display some results on screen based on these calculations.) I found an interesting answer to this question , shown here: 我想对原始图像进行图像处理而不将其显示在屏幕上(我想根据图像数据进行一些计算,并根据这些计算在屏幕上显示一些结果。)我找到了这个问题的有趣答案,如下所示:

Do your actual processing on the GPU: Set up an OpenGL context (OpenGL ES 2 tutorial), and create a SurfaceTexture object in that context. 在GPU上进行实际处理:设置OpenGL上下文(OpenGL ES 2教程),并在该上下文中创建SurfaceTexture对象。 Then pass that object to setPreviewTexture, and start preview. 然后将该对象传递给setPreviewTexture,然后开始预览。 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. 然后,在OpenGL代码中,可以调用SurfaceTexture.updateTexImage,与SurfaceTexture关联的纹理ID将更新为相机的最新预览帧。 You can also read back the RGB texture data to the CPU for further processing using glReadPixels, if desired. 如果需要,还可以使用glReadPixels将RGB纹理数据读回CPU,以进行进一步处理。

I have a question on how to go about implementing it though. 我有一个关于如何实施它的问题。

Do I need to create a GLSurfaceView and a Renderer , I don't actually want to use OpenGL to draw anything on screen so I am not sure if I need them? 我是否需要创建GLSurfaceViewRenderer ,实际上我不想使用OpenGL在屏幕上绘制任何东西,所以不确定是否需要它们? From what I have read online though it seems very essential to have these in order to setup an OpenGL context? 从我在线阅读的内容来看,为了设置OpenGL上下文而拥有这些内容似乎非常重要? Any pointers anybody can give me on this? 有人可以给我任何指示吗?

You don't have to use a GLSurfaceView . 不必使用 GLSurfaceView GLSurfaceView is a convenience class written purely in Java. GLSurfaceView是一个纯粹用Java编写的便利类。 It simplifies the setup part for applications that want to use OpenGL rendering in Android, but all of its functionality is also available through lower level interfaces in the Android frameworks. 它简化了想要在Android中使用OpenGL渲染的应用程序的设置部分,但其所有功能也可以通过Android框架中的较低级接口使用。

For purely offscreen rendering, you can use the EGL interfaces to create contexts, surfaces, etc. Somewhat confusingly, there are two versions in completely different parts of the Android frameworks: 对于纯屏幕外渲染,您可以使用EGL接口创建上下文,表面等。有些令人困惑的是,Android框架的完全不同的部分有两个版本:

  • EGL10 and EGL11 in the javax.microedition.khronos.egl package, available since API level 1. 从API级别1开始提供的javax.microedition.khronos.egl软件包中的EGL10EGL11
  • EGL14 in the android.opengl package, available since API level 17. android.opengl包中的EGL14 ,自API级别17起可用。

They are fairly similar, but the newer EGL14 obviously has some more features. 它们相当相似,但是较新的EGL14显然具有更多功能。 If you're targeting at least API level 17, I would go with the newer version. 如果您的目标至少是API级别17,那么我会选择较新的版本。

Using the methods in the EGL14 class, you can then create contexts, surfaces, etc. For offscreen rendering, one option is to create a Pbuffer surface for rendering. 然后,使用EGL14类中的方法,您可以创建上下文,表面等。对于屏幕外渲染,一种选择是创建用于渲染的Pbuffer表面。 To complete the setup, you will typically use functions like: 要完成设置,通常将使用以下功能:

eglInitialize
eglChooseConfig
eglCreatePbufferSurface
eglCreateContext
eglMakeCurrent

The Android documentation does not really describe these functions, but you can find the actual documentation at the Khronos web site: https://www.khronos.org/registry/egl/sdk/docs/man/ . Android文档并未真正描述这些功能,但是您可以在Khronos网站上找到实际的文档: https : //www.khronos.org/registry/egl/sdk/docs/man/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM