0

カメラを介して AVFoundation を使用して画像をキャプチャし、UIImageView. viewWillAppear画像サイズは 1936 x 2592 で、 gets が呼び出された後、画面が画像で更新されるまでに 5.5 秒かかります。

これは正常で、単に画像のサイズが原因ですか? これは、iOS6 を実行している iPhone4 上にあります。この遅延は受け入れられないので、おそらく最初に画像を縮小しようとする解決策を見つける必要がありますが、フープを飛び越える前に質問すると思いました.

アップデート

画像サイズを 484 x 648 に縮小するにはさらに時間がかかり、5.6 秒かかります。私が使用しているキャプチャコードのコメントにリクエストがありました。この投稿の一番下にあります。また、画像を 1 つだけキャプチャして表示しています。

// コンソール出力:

画像あり

2013-03-03 11:37:16.741 RPFaceCamera[4867:907] viewWillAppear - 所要時間: 0.000215>

2013-03-03 11:37:22.249 RPFaceCamera[4867:907] viewDidAppear - 所要時間: 5.507458>


//コード

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if (self.faceImage != nil){
        start = [NSDate date];
        printf("have image     \n");
        self.faceImageView.image = self.faceImage;
        NSLog(@"viewWillAppear - time taken: %f", -[start timeIntervalSinceNow]);
    }

}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSLog(@"viewDidAppear - time taken: %f", -[start timeIntervalSinceNow]);
}

//キャプチャ コード - (これは Apple の AVDemo から引用したと思います)。Objective-C の形式は、読みやすさに関して多くのことが望まれています。

- (void)captureImage
{
    AVCaptureConnection *connection;
    connection = [stillImageOutput connectionWithMediaType:AVMediaTypeVideo];

    [stillImageOutput setOutputSettings:[NSDictionary
                                         dictionaryWithObject:[NSNumber numberWithInt:kCMPixelFormat_32BGRA]
                                         forKey:(id)kCVPixelBufferPixelFormatTypeKey]];

    [stillImageOutput captureStillImageAsynchronouslyFromConnection:connection
          completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
              if(error)
                  NSLog(@"captureImage failed");
              else{

                  CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(imageDataSampleBuffer);
                  CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault,
                                                                              imageDataSampleBuffer,
                                                                              kCMAttachmentMode_ShouldPropagate);

                  CIImage *ciImage =
                  [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer
                                                options:(__bridge NSDictionary *)attachments];

                  NSNumber *orientation = (__bridge NSNumber *)(CMGetAttachment(imageDataSampleBuffer,
                                                      kCGImagePropertyOrientation, NULL));

                  printf("original orientation     %d\n", [orientation intValue]);

                  self.faceImage = [UIImage imageWithCIImage:ciImage scale:1.0f orientation:[orientation intValue]];
                  printf("self.faceImage     %d\n", self.faceImage.imageOrientation);
                  printf("self.faceImage    width: %f height: %f\n",  self.faceImage.size.width, self.faceImage.size.height);

                  __weak __typeof__(self) weakSelf = self;
                  [weakSelf performSelectorOnMainThread:@selector(showFaceView) withObject:nil waitUntilDone:NO];
              }                                                      
          }
     ];
}

// キャプチャが完了したときにメイン スレッドで呼び出されるメソッド - (void)showFaceView { NSLog(@"showfaceView");

    [self destroyAVCapture];
    [self.delegate dismissCameraWithImage:self.faceImage];
}
4

1 に答える 1

0

画像エディターで物理的に画像を小さくすると、読み込み時間が短くなると思います。

現在、コメントに従って、スケールを設定しています[UIImage imageWithCIImage:ciImage scale:4.0f orientation:[orientation intValue]

これは実際には画像ファイルを小さくするわけではないので、ロード時間は短くなりません。を使用してサイズを縮小する方法については、このStackoverflow の投稿の回答を確認してください。 この投稿では、プログラムによる. おそらく、それらはよりうまく機能するでしょう。UIImageNSDataUIImage

于 2013-03-03T17:13:36.377 に答える