0
私はいくつかのオブジェクトのライブスキャンを行う必要があるiOSアプリケーションを開発しています。このためには、例では1秒間に3,4フレームを取る必要があります。ここでは、キャプチャセッションを作成するための私のコードは次のとおりです。カメラのライブスキャンiOS
// Create an AVCaptureSession
AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
captureSession.sessionPreset = AVCaptureSessionPresetHigh;
// Find a suitable AVCaptureDevice
AVCaptureDevice *photoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
// Create and add an AVCaptureDeviceInput
NSError *error = nil;
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:photoCaptureDevice error:&error];
if(videoInput){
[captureSession addInput:videoInput];
}
// Create and add an AVCaptureVideoDataOutput
AVCaptureVideoDataOutput *videoOutput = [[AVCaptureVideoDataOutput alloc] init];
// we want BGRA, both CoreGraphics and OpenGL work well with 'BGRA'
NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:kCMPixelFormat_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
[videoOutput setVideoSettings:rgbOutputSettings];
// Configure your output, and start the session
dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
[videoOutput setSampleBufferDelegate:self queue:queue];
if(videoOutput){
[captureSession addOutput:videoOutput];
}
[captureSession startRunning];
// Setting up the preview layer for the camera
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
previewLayer.frame = cameraViewCanvas.bounds;
// ADDING FINAL VIEW layer TO THE MAIN VIEW sublayer
[cameraViewCanvas.layer addSublayer:previewLayer];
とキューで呼び出されるデリゲートメソッド:
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{
if(isCapturing){
NSLog(@"output");
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer options:(NSDictionary *)attachments];
UIImage *newFrame = [[UIImage alloc] initWithCIImage:ciImage];
[self showImage:newFrame];
}
}
問題は、私は、画面上の画像、無エラーと警告を見ることができないということです、画像は表示されません。私の質問は - 私は正しい道のりで、画面上にイメージを表示するためにコード内で修正する必要があるのですか?
あなたは 'cameraViewCanvas'についての詳細情報を提供しますか?どこに定義され、初期化されているかなど... – yinkou
カメラのビデオ出力を表示するのは、@Operty(nonatomic、retain)IBOutlet UIView * cameraViewCanvas;です。他のオブジェクト、つまりUIImageViewを追加して、まだ取り込んだフレームをプレビューすることができます。 – Artem
これをInterfaceBuilderにメインビューに追加しましたか? – yinkou