简体   繁体   English

在iPhone上处理完另一个图像后捕获一个图像

[英]Capturing one image after processing another on iphone

I am trying to implement some image processing on iPhone. 我正在尝试在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; 从我的AVCaptureConnection拍摄一张图像,对其进行处理,然后根据处理结果对相机配置进行某些操作(例如,设置关注点,使其重新聚焦然后锁定焦点);
  3. Take another image, process it; 拍摄另一张图像,进行处理;
  4. Depending on the processing result above, go to (3) immediately or wait a few millisecond; 根据上面的处理结果,立即转到(3)或等待几毫秒;
  5. Repeat (3) and (4) until user stops it. 重复(3)和(4),直到用户停止它为止。

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. 我在captureStillImageAsynchronouslyFromConnection()中调用的句柄的末尾发布了一个通知,以便在代码完成处理后,它通过通知中心调用下一步。

Here are examples on custom notifications and I basically followed it. 这是有关自定义通知的示例 ,我基本上遵循了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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