1

captureOutput:didOutputSampleBuffer:fromConnection:のデリゲートメソッドを使用していAVCaptureVideoDataOutputます。iPad でテストすると、イメージ バッファのサイズは常に 360x480 で、これは非常に奇妙に思えます。iPad の画面のサイズだと思います。

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { 

    @autoreleasepool {

        CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 
        /*Lock the image buffer*/
        CVPixelBufferLockBaseAddress(imageBuffer,0); 
        /*Get information about the image*/
        uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer); 
        size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); 
        size_t width = CVPixelBufferGetWidth(imageBuffer); 
        size_t height = CVPixelBufferGetHeight(imageBuffer);  

        /*Create a CGImageRef from the CVImageBufferRef*/
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
        CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
        CGImageRef newImage = CGBitmapContextCreateImage(newContext);

        NSLog(@"image size: h %zu, w %zu", height, width);

        /*We unlock the  image buffer*/
        CVPixelBufferUnlockBaseAddress(imageBuffer,0);

        CGRect zoom = CGRectMake(self.touchPoint.y, self.touchPoint.x, 120, 120);
        CGImageRef newImage2 = CGImageCreateWithImageInRect(newImage, zoom);

        /*We release some components*/
        CGContextRelease(newContext); 
        CGColorSpaceRelease(colorSpace);

        UIImage* zoomedImage = [[UIImage alloc] initWithCGImage:newImage2 scale:1.0 orientation:UIImageOrientationUp];
        [self.zoomedView.layer performSelectorOnMainThread:@selector(setContents:) withObject:(__bridge id)zoomedImage.CGImage waitUntilDone:YES];

        CGImageRelease(newImage);
        CGImageRelease(newImage2);

    }

}//end

iPad でも画像バッファが非常に小さい理由はありますか?

4

1 に答える 1

2

の品質はプロパティAVCaptureSessionによって決まります。sessionPresetデフォルトはAVCaptureSessionPresetHighです。キャプチャ デバイスの画面の解像度は気にしません。キャプチャ品質は、デバイスのカメラの機能です。

キャプチャの解像度を画面の解像度により近づけたい場合は、sessionPreset. どのプリセットも画面解像度に直接対応するものではなく、VGA、720p、1080p などの一般的なビデオ形式に対応するものではないことに注意してください。

NSString *const AVCaptureSessionPresetPhoto;
NSString *const AVCaptureSessionPresetHigh;
NSString *const AVCaptureSessionPresetMedium;
NSString *const AVCaptureSessionPresetLow;
NSString *const AVCaptureSessionPreset352x288;
NSString *const AVCaptureSessionPreset640x480;
NSString *const AVCaptureSessionPreset1280x720;
NSString *const AVCaptureSessionPreset1920x1080;
NSString *const AVCaptureSessionPresetiFrame960x540;
NSString *const AVCaptureSessionPresetiFrame1280x720;
于 2012-07-11T23:16:25.287 に答える