Ask Your Question

How to run slow video processing algorithms in background while showing camera output?

asked 2012-10-03 02:12:48 -0500

CV_Max gravatar image

In more detail, on my iPad I'm trying to

  • start the videoCamera;
  • take a frame and process it in background (say object detection, which is quite slow)
  • in the meanwhile, continuing to show the video output (e.g. at 15 fps)
  • when the algorithm terminates on the frame previously taken, take the current frame and run again;
  • always show the video output
  • when the algorithm terminates, take the current frame...

... and so on.

I tried with dispatch_queues but it gives me errors, I think because I'm not able to say to the processing algorithm "Take the current frame only when you have finished with the frame previously taken".

How can I do that?


edit retag flag offensive close merge delete



Learn to use multithreading. boost::thread is a good starting point. Follow some of the tutorials there, then start to work on your own solution. boost::asio is a very nice solution, but you may need more time to grasp it. If you work on iOS (which seems to be the case) learn how to use dispatch_queues or other multithreading mechanisms for iOS. Did you complete a tutorial on iOS multithreading? Are you able to write a simple multithreaded app?

sammy gravatar imagesammy ( 2012-10-03 02:46:48 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2012-10-03 10:49:49 -0500

karlphillip gravatar image

updated 2012-10-03 10:52:29 -0500

It's not clear if you want to display the processed frames in the video window. So I'll assume you just want to show the original video to the user, and do something else with the processed frame.

The most obvious approach is creating a 2nd thread to do your custom processing.

The idea is that on every iteration of the main loop, your application will perform 2 tasks:

  • display the frame on the screen;
  • and check if the 2nd thread is alive: if it's not, you will start the 2nd thread and pass a copy of the current frame for it to process. When the processing finishes on the 2nd thread the thread will automatically die, but on the next iteration of the main loop it will be started again with a new frame to process.

On this post I share 2 similar solutions, one using Linux pthreads and the other using Windows threads.

edit flag offensive delete link more

answered 2013-01-24 16:55:45 -0500

Utilize dispatch. Place your background stuff in the dispatch and let processImage continue on

Here is a great link with a nice code example. Just fill in the blanks:

edit flag offensive delete link more

Question Tools


Asked: 2012-10-03 02:12:48 -0500

Seen: 1,981 times

Last updated: Jan 24 '13