Repository: opencv
Issue: OpenCV Android: FPS decrease over time with JavaCameraView on Nexus 7
Labels: platform: android


##### System information (version)
<!-- Example
- OpenCV => 3.4.0dev
- Operating System / Platform => Android 
-->

##### Detailed description

 I think I found a bug in the current `JavaCameraView` or the underlying `CameraBridgeViewBase `Implementation.  I compiled the OpenCv library by myself for multiple architectures to get the contrib modules working. My typical OpenCv-Activity creates an instance of a JavaCameraView and receives each frame in the `onCameraFrame()-Method` and delegates the `Mat` information to a background- processing-Thread. 
However, on my Samsung Galaxy S8 i get about 30 FPS at beginning, it drops to 25FPS after some time and then only differs with lighting conditions.  So far so good.
But if I run the Application on my Nexus 7 (it's my customers device, so I really need to get it work there) it starts with 27 - 30 FPS after the `mCamera.startPreview();` got called. Every minute after that i lose about 2 FPS. After some time the camera is running it ends at ~7 FPS and thats not acceptable for my needs. 
If I close the app (I release the camera in onPause() and onDestroy() and free all allocated memory if the app got closed) and restart, it directly starts with the low 8 - 10 FPS in where it ends the Appstart before. It seems like some kind of framebuffer or cached Bitmaps do not get released properly but i really cant find the root of the problem. 

If i remove all code inside the `onCameraFrame()` and only return the incoming frames as RGBA it makes no difference to the observed behaviour. 

I also used the android profiler to check if there is any increase of memory usage. I dont know if it relates to this problem, but the profiler shows that the "java" memory category is about 36MB at beginning and increases over time with ~1MB every few seconds. That looks a bit strange to me since I am not created any Java instances by myself at runtime. 
so IMO the error must be in the JavaCameraView or underlying implementation or something
stable memory usage except increasing "Java"-related allocated memory: 
![android_profiler](https://user-images.githubusercontent.com/14052248/38327035-8b94dadc-3847-11e8-807b-51c19b4d88a7.png)

significant Logcat difference from S8 to Nexus 7 are these kind of messages: 

`04-04 19:22:07.112 194-28680/? I/QCamera3HWI: int qcamera::QCamera3HardwareInterface::translateMetadataToParameters(const camera_metadata_t*, cam_trigger_t&): flash mode after mapping 0
04-04 19:22:07.112 208-28705/? E/mm-camera: linearization_set_params: param_id is not supported in this module
    pca_rolloff_set_params: param_id is not supported in this module
    wb_set_params: param_id is not supported in this module
04-04 19:22:07.113 208-28705/? E/mm-camera: demosaic_set_params: param_id 6, is not supported in this module
    demux_set_params: param_id 6, is not supported in this module
    clf_set_params: param_id 6, is not supported in this module
    mce_set_params: param_id is not supported in this module
    sce_set_params: param_id is not supported in this module
    linearization_set_params: param_id is not supported in this module
    pca_rolloff_set_params: param_id is not supported in this module
    demosaic_set_params: param_id 8, is not supported in this module
    demux_set_params: param_id 8, is not supported in this module
    clf_set_params: param_id 8, is not supported in this module
04-04 19:22:07.113 208-28676/? E/mm-camera-sensor: module_sensor_event_control_set_parm:1084 CAM_INTF_PARM_LED_MODE 0 
04-04 19:22:07.113 208-28676/? E/mm-camera: stats_port_proc_downstream_set_parm AF ROI sent x: 0 ,y: 0 dx: 0 dy: 0, weight: 0 
04-04 19:22:07.114 208-28676/? E/mm-camera: isp_util_set_param_crop_region, No change in crop info, nothing to update
`
which got called for every incoming frame. 

are there any related issues with the Nexus 7 i didnt found yet? 

##### Steps to reproduce
-build opencv 3.4.0 from source with official python build script and include contrib modules and NEON support
-Use JavaCameraView and test on Nexus 7 
-Implement onCameraFrame()
-reuse Mat Objects and release them properly to avoid fps-loss due to high memory allocation



-->