2011-06-07 66 views
0

我有三個標籤和一個uimageview對象。標籤顯示有關圖像的信息。我的問題是我無法更新標籤和圖像。下面的代碼只更新標籤。如何更新uiimageview(ARView2)?iphone更新uilabel和uiimageview

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
     fromConnection:(AVCaptureConnection *)connection 
{ 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 

    bufferContent = createIplImageFromSampleBuffer(sampleBuffer); 
    [self performSelectorOnMainThread:@selector(updateLabels) withObject:nil waitUntilDone:YES]; 

    [pool drain]; 
} 
-(void)updateLabels 
{ 
    results = tracking(bufferContent); 
    labelFPS.text =[NSString stringWithFormat:@"%.2f ms",results.resultTime]; 
    labelKeypoints.text = [NSString stringWithFormat:@" %d",results.noKeypoints]; 
    labelRecognised.text = [NSString stringWithFormat:@"%d",results.resultTime]; 
    [ARview2 setImage:[self UIImageFromIplImage:results.resultImg]]; 

} 

當我使用此代碼:

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
     fromConnection:(AVCaptureConnection *)connection 
{ 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 

    bufferContent = createIplImageFromSampleBuffer(sampleBuffer); 
    results = tracking(bufferContent); 
    labelFPS.text =[NSString stringWithFormat:@"%.2f ms",results.resultTime]; 
    labelKeypoints.text = [NSString stringWithFormat:@" %d",results.noKeypoints]; 
    labelRecognised.text = [NSString stringWithFormat:@"%d",results.resultTime]; 
    [ARView2 performSelectorOnMainThread:@selector(setImage:) withObject:[self UIImageFromIplImage:results.resultImg] waitUntilDone:YES]; 

    [pool drain]; 
} 

僅ARView2與新的圖像更新。但標籤不會改變它們的值。

FINAL ANSWEAR 好的。不知何故,我設法達到我的目標。我不知道這是否正確,但它的工作原理。我發佈代碼,希望有人會發現它有用。

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
     fromConnection:(AVCaptureConnection *)connection 
{ 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 

    bufferContent = createIplImageFromSampleBuffer(sampleBuffer); 
    results = tracking(bufferContent); 

    [arView performSelectorOnMainThread:@selector(setImage:) withObject:[self UIImageFromIplImage:results.resultImg] waitUntilDone:YES]; 
    [self performSelectorInBackground:@selector(updateLabels) withObject:nil]; 

    [pool drain]; 
} 
-(void)updateLabels 
{ 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
    labelFPS.text =[NSString stringWithFormat:@"%.2f ms",results.resultTime]; 
    labelKeypoints.text = [NSString stringWithFormat:@" %d",results.noKeypoints]; 
    labelRecognised.text = [NSString stringWithFormat:@"%d",results.resultTime]; 
    [pool drain]; 
    pool = nil; 

} 
+0

「ARview2」是什麼意思? – 2011-06-07 15:36:55

+0

它是UIImageView對象,這是我如何聲明它UIImageView * ARview2; – franz 2011-06-07 16:27:24

+0

當你說你不能同時更新時,你是什麼意思? – 2011-06-07 16:36:41

回答

0
  • 檢查,如果你在UI正確連接ARview2;
  • results.resultImg是什麼?這是一個有效的圖像?
+0

是的,它是連接,是的,它是有效的圖像。我發佈了更新UIImageView但不更新標籤的代碼。我不知道如何在同一時間更新標籤和UIImageView – franz 2011-06-07 17:09:49