1

I am developing an android application in which I can do high level image processing and I used custom camera preview to capture images, but when I check logcat after launching the application, I found this message from Choreographer Skipped 440 frames! The application may be doing too much work on its main thread.

My log is as bellow

05-07 10:04:11.480: I/CameraPreview(28340): Orientation Changed
05-07 10:04:11.990: I/Choreographer(28340): Skipped 145 frames!  The application    may be doing too much work on its main thread.
05-07 10:04:15.620: I/Choreographer(28340): Skipped 212 frames!  The application      may be doing too much work on its main thread.
05-07 10:04:20.590: I/CameraPreview(28340): +++++++++++++++++++++++++++++++++++++++
05-07 10:04:20.590: I/CameraPreview(28340): starting recognition process
05-07 10:04:22.490: I/FaceDetector(28340): Number of faces found: 1
05-07 10:04:22.490: I/Value X(28340): 273
05-07 10:04:22.500: I/Value Y(28340): 106
05-07 10:04:22.500: I/Bitmap Width :(28340): 640
05-07 10:04:22.510: I/Bitmap Height :(28340): 480
05-07 10:04:22.520: I/CameraPreview(28340): Bitmap Size : 205 : 201
05-07 10:04:22.520: I/Face Recognition(28340):        ===========================================
05-07 10:04:22.520: I/Face Recognition(28340): recognizeFace (single face)
05-07 10:04:22.550: I/CameraPreview(28340): Previwe Stoped Face Detected....
05-07 10:04:22.550: I/CameraPreview(28340): Stopping preview in SurfaceDestroyed().
05-07 10:04:22.720: I/CameraPreview(28340): Total Recognition process took:       2.127638333
05-07 10:04:22.720: I/Choreographer(28340): Skipped 440 frames!  The application may    be doing too much work on its main thread.
  • I used custom camera preview in onFramePreview() method to frequently capture buffer images and if it contains a "Human Face" then send it for processing.
  • When the image processing part is executed, it's frame is skipped by Choreographer and im not getting expected result.
  • I used OpenCV for the image processing

Please help me to solve this stuff. I searched many times in StackOverflow but not getting a proper answer.

Thanks

Lal
  • 14,726
  • 4
  • 45
  • 70
Bhadresh
  • 115
  • 2
  • 3
  • 13
  • You can use AsyncTask to solve this issue.. – Lal May 07 '14 at 05:16
  • but i all-ready try using AsyncTask,AsyncTaskLoader,Runnable,Thread class but not any improvement and when i launch application first time on device then work proper with expected result but second time it skipped frame there is any garbage collection issue? – Bhadresh May 07 '14 at 06:00

3 Answers3

4

Use more threading, Run intensive processes on the background thread, either AsyncTask or use this.

    public Runnable NameOfRunnable = new Runnable()
    {
        @Override
        public void run()
        {
            while (true)
            {
            // TODO add code to refresh in background
                try
                {

                    Thread.sleep(1000);// sleeps 1 second
                    //Do Your process here.
                } catch (InterruptedException e){
            // TODO Auto-generated catch block
            e.printStackTrace();
            }
        }

    }
};

then call

    NameOfRunnable.start();

or

    NameOfRunnable.run();

depends on what you want to do with it, either ui or just back ground info, plus callbacks will help do what you need to do

Adam
  • 126
  • 1
  • 5
  • Also check out this answer, http://stackoverflow.com/questions/7714299/android-background-thread – Adam May 07 '14 at 05:14
  • 2
    it's mandatory to call `NameOfRunnable.start();` because `run()` will just call the method `run()` synchronously without actually starting the thread! – msysmilu Mar 12 '15 at 20:49
0

Is the image processing part being done on the main thread ? If yes then try to do all heavy processing in another thread and after processing is done pass it back to the Main thread. A better alternative would be to use AyncTask and perform the image processing in the doInBackground() method.

Refer to the following tutorial : tutorial

Kakarot
  • 4,252
  • 2
  • 16
  • 18
0

Its like u r doing lot of processing in main thread.You should use a separate thread or asynctask for doing processing or buffering of images and after that can update ui . If using asychtask do background operation in doinBackground() and update ui in onPostExecute and If u use thread then for updating ui u need to call runOnUithread to update the UI

user1969053
  • 1,750
  • 1
  • 12
  • 12