我目前正在研究一個涉及AVCaptureVideoDataOutputSampleBufferDelegate
的項目以進行眨眼檢測。使用AVCaptureVideoDataOutputSampleBufferDelegate方法執行dispatch_async塊的延遲
我在委託方法
(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{
//Initialisation of buffer and UIImage and CIDetector, etc.
dispatch_async(dispatch_get_main_queue(), ^(void) {
if(features.count > 0){
CIFaceFeature *feature = [features objectAtIndex:0];
if([feature leftEyeClosed]&&[feature rightEyeClosed]){
flag = TRUE;
}else{
if(flag){
blinkcount++;
//Update UILabel containing blink count. The count variable is incremented from here.
}
flag = FALSE;
}
}
}
上面示出的方法被稱爲連續並處理來自相機的視頻饋入以下dispatch_async
塊。 flag
布爾值跟蹤在最後一幀中眼睛是關閉還是打開,以便可以檢測到閃爍。有相當數量的幀被丟棄,但仍然可以正確檢測到閃爍,所以我猜想處理的fps是足夠的。
我的問題是UILabel
在執行眨眼後大幅延遲(〜1秒)後得到更新。這使得該應用程序看起來很遲鈍並且不直觀。我試圖在沒有調度的情況下編寫UI更新代碼,但這是不行的。有什麼我可以做的,以便UILabel
瞬時更新閃爍後執行?