Ask Your Question
2

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

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

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?

Thanks

edit retag flag offensive close merge delete

Comments

1

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 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
3

answered 2012-10-03 10:49:49 -0600

karlphillip gravatar image

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

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
0

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

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: http://stackoverflow.com/questions/3869217/iphone-ios-running-in-separate-thread

edit flag offensive delete link more

Question Tools

Stats

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

Seen: 2,389 times

Last updated: Jan 24 '13