iphone обновляет uilabel и uiimageview - PullRequest
0 голосов
/ 07 июня 2011

У меня есть три метки и один объект uimageview. На этикетках отображается информация об изображении. Моя проблема в том, что я не могу обновить как ярлыки, так и изображение. Код ниже обновляет только метки. Как обновить uiimageview (ARView2)?

- (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 обновляется новым изображением. Но метки не меняют своих значений.

ЗАКЛЮЧИТЕЛЬНЫЙ ОТВЕТ Хорошо. Каким-то образом мне удается достичь своей цели. Я не знаю, правильно ли это, но это работает. Я публикую код, надеюсь, кто-нибудь найдет его полезным.

- (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;

}

1 Ответ

0 голосов
/ 07 июня 2011
  • Проверьте, правильно ли вы подключили ARview2 в пользовательском интерфейсе;
  • Что находится в results.resultImg?Это действительное изображение?
...