开发者

How to manually display frames from Camera.PreviewCallback after processing, without Camera.Preview

开发者 https://www.devze.com 2023-01-28 21:49 出处:网络
I have built a face detection app where I get the frames from onPreviewFrame, do the face detection and then draw a circle on a canvas above my surfaceView. The problem is frames are automatically dis

I have built a face detection app where I get the frames from onPreviewFrame, do the face detection and then draw a circle on a canvas above my surfaceView. The problem is frames are automatically disp开发者_Go百科layed using the surfaceview thread when Camera.StartPreview() is started. This is obviously necessary for the PreviewCallback to kick in. As the processing, face detection and drawing, is done in a separate thread(I am assuming here), there is a 2 second delay between the frame being displayed and the result of that frame being processed and drawn on the canvas.

What I want to do is stop the camera preview displaying the frames and display them myself after processing. I believe this has three benefits:

The delay with disappear.

I can draw straight to the bitmap instead of on a canvas which is useless as you can not undo what you have done.

It will help keep memory comsumption low by not having two threads using the same image.

I've read that it is possible to display frames from the previewCallback, does anybody know how and how to stop the frames being displayed automatically?

Many thanks in advance.


James, Here I found a solution, if you want to stop the camera preview, just comment out tow lines( I suppose you used the CameraPreview.java as the start) // Camera.setPreviewDisplay(holder); // setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); These means camera won't use the surface to display preview, so you can use the callback data to show directly, but the efficiency is very low, there is only 1fps on the emulator, but however, I think this is a solution, and then you can consider how to draw frames more efficiently next

Good luck, and I wish to know if it's OK for you after this solution :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号