2

I'm developing an image processing app on Android phones, which is expected to run 24/7. I've managed to do the following:

  • Use Camera2 interface to gain better fps.
  • Grab raw frames, using renderscript to convert to rgb and do image processing using opencv in a background service( no preview ). I got around 20fps after conversion to rgb at 1280x960 on LG G4.

So my questions are:

  • Is there anything else I need to optimize to minimize the memory and CPU usage?
  • Any chance that this application can run 24/7? Is delegating all the camera operations and processing to the background service sufficient to allow it run 24/7? When I leave it running, I can still feel the heat from the camera and its surrounding area.

Any suggestion would be appreciated. Thanks.

UPDATE 1

The app runs on LG G4 using Camera2 interface and do image processing in the background with the screen off, got too hot and the phone turned off itself after a few hours. What can I do to overcome this?

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
VB4EVA
  • 81
  • 2
  • 17

3 Answers3

1

about the second question. I think the app can not run 24/7 because the phone will close itself because of the heat.

GBoz
  • 11
  • 1
  • Can you elaborate more on this? Is this based on your personal experiment or is it a solid proof documented some where? Thanks. – VB4EVA Mar 22 '17 at 04:20
  • 2
    Okay, when your phone is overheating​, the CPU will slow down itself to decrease the temperature of the phone and sometimes it can close all apps that are currently running. This means it will close your app when it is overheated. – GBoz Mar 22 '17 at 05:49
  • so is there anyway to avoid that overheating running the camera in the background? – VB4EVA Mar 22 '17 at 06:07
  • 1
    I think if you manage to run the app under lockscreen maybe it works. – GBoz Mar 22 '17 at 20:54
1

Before answering to your question i must say that i am also new to image processing with android (but not to image processing field).

For the question one:
May be yes. Because image processing tasks are much memory intensive you may need to optimize your app in order to avoid things like memory leak(even if the android runtime perform routine garbage collection) . check the following links

link one

may be useful

when it comes to pixel level operation ( when you avoid using inbuilt functions of opencv or what ever the library you are using and do access and process pixels manually) it will be too slow. I am saying this based on my experience on my laptop. Hoping that you are using opencv for your app just take a look at the following opencv site ( it is for python but you can get the idea)

take an idea from this

and also this SO answer: SO answer

A tip i can remember: try to reduce Mat variable copying (copying Mat objects to other Mat objects) as much as you can

Question number two:
I will go with answer given by user7746903. This answer also linked with the memory that will be consumed by your background app. There will be much more memory intensive app running on background so it depends. Thank you.

Community
  • 1
  • 1
d91
  • 83
  • 1
  • 8
  • Thanks for your reply. What about if I only run 1 single app? Is it still impossible? – VB4EVA Mar 22 '17 at 06:41
  • 1
    you welcome. and it depends. how can we say that your app is not consuming all the memory that your phone can give? because performance of phones are varies from device to device. so you have to think about that..a consider about acceleration of app using GPU. i don't know opencv for android allow this or not. – d91 Mar 22 '17 at 06:48
  • Ok, I think I will try my best and tested it out first. The good thing is that I can choose any device to work with. Plus it only runs 1 single app, so I do hope if I could optimize the memory usage to the best, it can run 24/7. Thanks. – VB4EVA Mar 22 '17 at 06:54
  • And make sure to test the app on real device. not in a virtual device or simulator. good luck. :) – d91 Mar 22 '17 at 07:14
0

For the first question: I feel its worth mentioning that you should by pass java as much as possible. Ie. using Java as the interfacial layer, then using JNI C as the call loop.

eg: Get texture from camera2 > supply texture to C function > call render script/ compute shaders from C and other processing functions > call java function to render to screen.

This speeds up CPU performance and reduces memory warnings (especially when rapid allocation and freeing of memory).

Wy th
  • 33
  • 5