Android和OpenCVCamera2进行并行处理

Android和OpenCVCamera2进行并行处理

本文介绍了使用Camera2 API Android和OpenCVCamera2进行并行处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该程序要处理相机中的每一帧并对其应用一些图像处理算法.我正在onImageAvailable回调中从ImageReader获取图像提要,并将其传递到具有JNI接口的cpp代码中以进行进一步处理.直到我在cpp代码中执行繁重的操作之前,此方法均能正常工作,此后它开始向摄像机预览添加延迟和滞后.是否可以并行处理提要图像,以便获得实时结果?我已经为cameraCaptureSession使用了另一个线程.

I am developing an app where I want to process each frame from the camera and apply some Image processing algorithms on it. I am getting image feed from ImageReader inside onImageAvailable callback and passing it to my cpp code with JNI interface for further processing. This works fine until I perform heavy operations inside my cpp code, after that it starts adding delay and lag to camera preview. is it possible to process on feed images in parallel so I can achieve real-time results? I am already using a different thread for cameraCaptureSession.

推荐答案

增加ImageReader的maxImage计数,以便您可以同时处理多个图像.但是最后,您的吞吐量必须为30fps,以免减慢预览速度.并行处理仅在(例如)花费100毫秒进行处理时才有帮助,但是您可以并行运行3个处理线程(因此,每33毫秒完成一个帧).

Increase the maxImage count for your ImageReader, so that you can be processing multiple images at the same time. But in the end, your throughput has to be 30fps in order to not slow down preview; parallel processing only helps if it (say) takes 100 ms to do your processing, but you can run 3 processing threads side-by-side (so a frame completes every 33 ms).

或者,如果不能跟上,可以跳过处理帧;否则,可以跳过处理帧.只需检查您的处理是否仍在进行中,如果正在进行,请立即释放映像.当然,如果您唯一的输出是已处理的帧,那将无济于事.

Alternatively, you can skip processing frames if you can't keep up; just check if your processing is still underway, and if it is, release the Image immediately. Of course, that won't help if your only output is the processed frame.

这篇关于使用Camera2 API Android和OpenCVCamera2进行并行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 17:45