wysaid / android-gpuimage-plus

Android Image & Camera Filters Based on OpenGL.
MIT License
1.8k stars 473 forks source link

How to do real-time face tracking? #160

Open storewaladotcom opened 7 years ago

storewaladotcom commented 7 years ago

Is there a better way to generate a bmp other than the code below:

bufferTexID = Common.genBlankTextureID(mRecordWidth, mRecordHeight);
                    frameBufferObject.bindTexture(bufferTexID);
                    GLES20.glViewport(0, 0, mRecordWidth, mRecordHeight);
                    mFrameRecorder.drawCache();
                    buffer = IntBuffer.allocate(mRecordWidth * mRecordHeight);
                    GLES20.glReadPixels(0, 0, mRecordWidth, mRecordHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buffer);
                    bmp = Bitmap.createBitmap(mRecordWidth, mRecordHeight, Bitmap.Config.ARGB_8888);
                    bmp.copyPixelsFromBuffer(buffer);
                    Log.i(LOG_TAG, String.format("w: %d, h: %d", mRecordWidth, mRecordHeight));

The code is causing a minor lag in the UI. My use case = While the video is recording, take a BMP periodically and check if there is a face in the BMP. If there is another cleaner way of doing this, please suggest.

storewaladotcom commented 7 years ago

any pointers on how to incorporate CGEFaceTracker into CGEFrameRecorder? That may address my issue as well.

wysaid commented 7 years ago

You may need to do this in another thread. Just use CGESharedGLContext to create another context( shared with the view) And put your all code in the background thread.

wysaid commented 7 years ago

The CGEFaceTracker is not so correct when doing real-time processing. I will add a new case for this issue later.

storewaladotcom commented 7 years ago

thank you, I will look forward to that code.

storewaladotcom commented 7 years ago

Could you provide some code on using the sharedcontext please?

wysaid commented 7 years ago

https://github.com/wysaid/android-gpuimage-plus/blob/master/cgeDemo/src/main/java/org/wysaid/cgeDemo/TestCaseActivity.java#L151

storewaladotcom commented 7 years ago

Thank you. I did see that piece of code. how can i get a Bitmap from the shared context?

wysaid commented 7 years ago

You should not use the Bitmap. It's extremely slow. I will do this issue later. And you should change the title to How to do real-time face tracking.

storewaladotcom commented 7 years ago

Thank you @wysaid . I will look forward to this when you get a chance to implement. I went ahead and changed the title.

storewaladotcom commented 7 years ago

@wysaid could you point me to do face recognition at the c++ layer?

wysaid commented 7 years ago

You may take look at the pr I'm very busy recently, and I will do that later.