简体   繁体   中英

Capturing one image after processing another on iphone

I am trying to implement some image processing on iPhone. The program should work as following:

  1. User touches a button to start the task;
  2. Take one image from my AVCaptureConnection, process it, do something on camera configuration (like setting the point of interest, letting it refocus then lock the focus) based the processing result;
  3. Take another image, process it;
  4. Depending on the processing result above, go to (3) immediately or wait a few millisecond;
  5. Repeat (3) and (4) until user stops it.

The problem I have in this task is that I don't know how to force these tasks to be run sequentially (taking the next step only after the last one is finished). I can only find the

captureStillImageAsynchronouslyFromConnection()

method to capture an image, which seems to run in the same thread in where it is called. As a result, I cannot call

[NSThread sleepForTimeInterval:sometime]

to wait then check if the processing is completed without "sleeping" the processing as well.

Is there something else I can do to achieve the task, or do I have to use explicit threading myself?

I came up with a solution using notifications, and it works nicely. I post a notification at the end of the handle invoked in captureStillImageAsynchronouslyFromConnection(), so that when the code finishes processing, it calls in the next step through the notification center.

Here are examples on custom notifications and I basically followed it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM