Android camera onpreviewframe callback and rotation sensor callback synchronization

这一生的挚爱 提交于 2020-01-04 05:38:05

问题


I have been developing an android app which requires camera preview data for each frames,with addition to that I want pitch (Angle) values (From Rotation sensor) while capturing frame.I want to map the pitch values while capturing frames in real time, for now ,I have been mapping the pitch values in onpreviewframe, but I am not getting the correct results because of delay due to frame getting delivered to onpreviewframe callback.

I have registered the previewcallbackwithbuffer callback to get each frames data in onpreviewframe method.And I have been getting the sensor value from onSensorChanged callback.

Is there a way to map the pitch values while capturing the frame?.

If the above question is not understandable ,I am ready to post the code also..


回答1:


One of the common pitfalls with onPreviewFrame() callbacks is that by default these callbacks will arrive on the main UI thread, and thus can be unpredictably delayed by something else happening on the UI thread. I have explained how to easily switch to using a separate Handler Thread for camera callbacks elsewhere. Also, push the onSensorChanged() callbacks off the UI thread.

In my experience, attributing pitch to preview frames is quite reliable with the above setup. I should confess that my current app throttles the preview stream to ~5 FPS. We don't need higher frame rate, and have quite heavy CV on each frame that we accept.



来源:https://stackoverflow.com/questions/34372994/android-camera-onpreviewframe-callback-and-rotation-sensor-callback-synchronizat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!