title: Camera live scanning iOS
body: <p>I am developing an iOS application where I need to do some object live scanning. For this I need to take 3 or 4 frames per second in example. Here is my code for creating capture session: </p>
  
  <pre><code>// 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:&amp;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];
  </code></pre>
  
  <p>And delegate method which is called on queue: </p>
  
  <pre><code>-(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];
      }
  }
  </code></pre>
  
  <p>The problem is that I cannot see the image on a screen, no errors and warnings, but image is not shown. My question is - am I on the right path, what needs to be fixed in my code to show the image on the screen?</p>