Numerous times I have seen people post on android-developers about some code they got from somewhere to accomplish something, which uses such tricks and will in fact break in the future. In spite of all that effort, if you know the right tricks you can easily subvert those protections - such by using reflection in Java, or copying in a header like here in C++ - which others then see and use without realizing what they are doing. C/C++ codeĪfter that we can read ( copy) pixel data from C/C++ via glReadPixels() and write them back to texture after modification via glTexSubImage2D().We have spent literally months of engineering time trying to clearly define what can be supported and what can't, and setting things up so that developers will as clearly as possible know when they get outside of that supported world. To overcome this restriction we have to perform an OpenGL rendering from this texture to another regular GL_TEXTURE_2D one using FrameBuffer Object (aka FBO). That makes unable sharing it via CL-GL interop ( cl_khr_gl_sharing) and accessing its pixel data via C/C++ code. The details OpenGL ES 2.0 initialization are also quite straightforward and noisy to be quoted here, but the important point here is that the OpeGL texture to be the target for camera preview should be of type GL_TEXTURE_EXTERNAL_OES (not GL_TEXTURE_2D), internally it keeps picture data in YUV format. Let's leave the details of their implementation beyond of this tutorial, please refer the source code to see them. Protected abstract void setCameraPreviewSize( int width, int height) Let's create a base for our application that just configures Android camera to send preview frames to OpenGL texture and displays these frames on display without any processing.Ī minimal Activity class for that purposes looks like following: Having a preview frame in an OpenGL texture is a good deal for using OpenCL because there is an OpenGL-OpenCL Interoperability API (cl_khr_gl_sharing), allowing sharing OpenGL texture data with OpenCL functions without copying (with some restrictions of course). Android API level 21 brings a new Camera2 API that provides much more control over the camera settings and usage modes, it allows several targets for preview frames and OpenGL texture in particular. Starting Android API level 11 (Android 3.0) Camera API allows use of OpenGL texture as a target for preview frames. In particular let's try two ways: direct calls to OpenCL API and recently introduced OpenCV T-API (aka Transparent API) - implicit OpenCL accelerations of some OpenCV algo-s. Let's consider how we can use OpenCL in this scenario. The most popular CV application scenario for an Android operated device is starting camera in preview mode, applying some CV algo to every frame and displaying the preview frames modified by that CV algo. Recently it has become possible on Android OS. image filtering) run much faster on a GPU than on a CPU. Using GPGPU via OpenCL for applications performance enhancements is quite a modern trend now. The related source code is located within OpenCV samples at opencv/samples/android/tutorial-4-opencl directory. This tutorial also assumes you have an Android operated device with OpenCL enabled. If you need help with anything of the above, you may refer to our Introduction into Android Development guide. It also assumes that you are familiar with Android Java and JNI programming basics. ![]() This tutorial assumes you have the following installed and configured: It was written for Eclipse-based ADT tools (deprecated by Google now), but it easily can be reproduced with Android Studio. This guide was designed to help you in use of OpenCL ™ in Android camera preview based CV application. Prev Tutorial: Android Development with OpenCV
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |