我有三個標籤和一個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;
}
「ARview2」是什麼意思? – 2011-06-07 15:36:55
它是UIImageView對象,這是我如何聲明它UIImageView * ARview2; – franz 2011-06-07 16:27:24
當你說你不能同時更新時,你是什麼意思? – 2011-06-07 16:36:41