我有三个标签和一个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