OpenCV Android: Get camera frames in the background without showing on screen

I wrote an optical flow detection application that is based on the OpenCV tutorials for Android and the source code of the Barry Thomas OpenCV Demo 2 application. Now I want to make this application a background task so that I can transfer the discovery result to my main activity through the listener interface.

All sample applications in OpenCV totals extend the Activity and implement the CvCameraViewListener and show the camera input on scrurr. I want to capture camera frames and do optical stream detection on frames in the background without showing them on the screen.

How can I get frames from the camera in the background showing the camera input?

+6
source share
2 answers

There are two ways, but you have to keep Mat in memory in the onCameraFrame method:

 @Override public Mat onCameraFrame(CvCameraViewFrame inputFrame) { mRgba = inputFrame.rgba(); return mRgba; } 

1) make cameraview invisible 2) make onCameraFrame return null

In both cases, you must do additional work in a different view.

+1
source

The only way to find frames in the background is to use a SurfaceTexture instead of a SurfaceView and therefore set it using Camera.setPreviewTexture instead of Camera.setPreviewDisplay .

This answer as well as this one helped.

0
source

Source: https://habr.com/ru/post/969548/


All Articles