0

I have been working on a Mobile application that analyzes the frame looking for specific objects. The processing was to heavy, and I keep getting

05-08 17:44:24.909: I/Choreographer(31606): Skipped 114 frames!  The application may be doing too much work on its main thread.

So i switched the image processing to threads, now it is much faster but I am not able to recognize any object . The data(the different frames) is not updating and I don't know why. Here is what I'm doing in pseudocode( SurfaceHolder.Callback ,Camera.PreviewCallback and camera.addCallbackBuffer(data) are implemented )

public void onPreviewFrame(byte[] data, Camera camera)
{
  Imageprocessor np = new ImageProcessor(data);
  np.start()
  results = np.getResults();
 }

From the debugging I have done so far I know that start is analyzing the whole frame, but . the data is not updating it keeps stacked at the very first frame. This does not happen if I do it in the main Thread like this,

public void onPreviewFrame(byte[] data, Camera camera)
{
  Imageprocessor np = new ImageProcessor();
  np.process(data)
  results = np.getResults();
 }

This works but it force me to skip many frames. The answer may be easy, but I could not find it online.

Forgive me if I am posting a very noob question

Thanks in advance

1 Answers1

0

That's because in the single threaded case, the np.process() is complete before you execute results=..., but in the threaded case, the results=... follows immediately after starting the threads. Unless getResults() waits for all the threads to finish??

Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189
  • yes you are right i am not waiting for the thread to finish. But the issue is still not resolved the `byte[]` remains the same . Before i start the thread I compare the frames and I always get `old_frame = new_frame`, I do not understand why it's always the same... The comparison is done checking the brightness value of every pixel, `if a pixel_brigthness_old_frame != pixel_brigthness_new_frame return false`. Sadly it returns always true.. – Ignacio Ferrero May 09 '14 at 03:51
  • Is it because you are not synchronizing properly between threads? Without proper synchronization your threads will not see memory changes made by another thread. See [this answer](http://stackoverflow.com/a/3519736/8946) for a fairly detailed overview. – Lawrence Dol May 09 '14 at 04:15