0
私は、ユーザーがボタンを押してから0.1秒ごとに画像を取得するアプリケーションを作成しています。しかし、私は画像間の一貫性のある0.1秒の遅延を得るのに問題があります。captureStillImage特定の時刻に非同期で動作しない
これはcaptureStillImageAsynchronously
が非同期クロージャであるためですか。 AVCapturePhotoOutput
からcapturePhoto
に切り替えるとこの問題は解決しますか?ここに私のコードの要約があります。
var stillImageOutput : AVCaptureStillImageOutput?
// Button action.
@IBAction func takeImage(_ sender: UIButton) {
//take 1 image every 0.1 seconds scheduled using a timer
Timer.scheduledTimer(timeInterval: 0.1,
target: self,
selector: #selector(calldidPressTakePhoto),
userInfo: nil,
repeats: true)
}
// Take image
func didPressTakePhoto(){
if let videoConnection = stillImageOutput?.connection(withMediaType: AVMediaTypeVideo){
videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait
//Capture image. everything in this closure is ASYNCHRONOUS?
stillImageOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: {
(sampleBuffer, error) in
//Do something with the result image...
})
}
}
私の推測では、あなたが示唆したように非同期の問題になると思います。非同期で実行すると、基本的にコードが実行されたときは気にしないで、バックグラウンドで実行するだけです。だから、一貫して時間間隔を取得することはありません。 –
2番目の質問では、 'capturePhoto'はデリゲートメソッドを呼び出します。残念ながら、それはタイミングと一貫しません。 – cuomo456