iphone update uilabel and uiimageview
I have three labels and one uimageview object. The labels displays info about the image. My problem is that I can't update both the labels and image. The code below updates only labels. How to update uiimageview (ARView2) as well?
- (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]];
}
When I use this code:
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
bufferContent = createIplImageFrom开发者_开发知识库SampleBuffer(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];
}
only ARView2 is updated with new image. But labels don't change their values.
FINAL ANSWEAR ok. Somehow I manage to achieve my goal. I don't know if it's correct but it works. I post the code, hope somebody will find it useful.
- (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;
}
- Check if you connected properly ARview2 in UI;
- What is in results.resultImg? Is it a valid image?
精彩评论