title: Capture an image using openCV without image detection iOS
body: <p>I've run into a few problems that I've found answers to but none of them are working for me.</p>
  
  <p>Goal: After 60 seconds of trying to detect 3 QR codes, provide an option to manually capture the image and send that image to an email. Something like: 60 seconds has passed --> UIAlertController with an "OK" button that leads to a image capture view --> User captures image, that image is then added as an attachment to an email that they can then send</p>
  
  <p>Problem: Cannot find a way to capture an image using the opencv library described in <a href="https://www.toptal.com/machine-learning/real-time-object-detection-using-mser-in-ios" rel="nofollow">https://www.toptal.com/machine-learning/real-time-object-detection-using-mser-in-ios</a></p>
  
  <p>Things I've tried:</p>
  
  <ul>
  <li><p>Taking a screenshot while video is playing (worked, however I'm looking for a more intricate way to do this  </p>
  
  <pre><code>(UIImage *)capture {
      UIGraphicsBeginImageContext(self.view.bounds.size);
      [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
      UIImage *imageView = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      return imageView;
  }
  </code></pre></li>
  <li><p>Use UIImagePickerController (Could not get the MFMailComposeViewController to display. Also kept getting "snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.")</p>
  
  <pre><code>(IBAction)takePhoto:(id)sender {
      UIImagePickerController *picker = [[UIImagePickerController alloc] init];
      picker.allowsEditing = NO;
      picker.modalPresentationStyle = UIModalPresentationCurrentContext;
      picker.sourceType = UIImagePickerControllerSourceTypeCamera;
      [self presentViewController:picker animated:YES completion:nil];
  }
  
  (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
      UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
      [self dismissViewControllerAnimated:YES completion:nil];
      [self emailImage:image];
   }
  
  (void)emailImage:(UIImage *)image {
      if ([MFMailComposeViewController canSendMail]) {
          MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
          mailComposeViewController.mailComposeDelegate = self;
          mailComposeViewController.navigationBar.barStyle = UIBarStyleDefault;
          mailComposeViewController.modalPresentationStyle = UIModalPresentationPageSheet;
          NSString *messageBody = @"";
          messageBody = [messageBody stringByAppendingFormat:@"Image Attached"];
          NSArray *recipients = [NSArray arrayWithObjects: @"x@x.com", nil];
          [mailComposeViewController setMessageBody:messageBody isHTML:NO];
          [mailComposeViewController setToRecipients:recipients];
  
          NSData *data = UIImagePNGRepresentation(image);
          [mailComposeViewController addAttachmentData:data mimeType:@"image/png" fileName:@"Photo"];
  
          NSString *messageSubject = [NSString stringWithFormat:@"Cannot Scan"];
          [mailComposeViewController setSubject:messageSubject];
  
          [self presentViewController:mailComposeViewController animated:YES completion:nil];
      }
  }
  (void)mailComposeController:(MFMailComposeViewController*)controller
    didFinishWithResult:(MFMailComposeResult)result
                  error:(NSError*)error {
      NSString *msg1;
      switch (result)
      {
          case MFMailComposeResultCancelled:
              msg1 =@"Sending Mail is cancelled";
              break;
          case MFMailComposeResultSaved:
              msg1=@"Sending Mail is Saved";
              break;
          case MFMailComposeResultSent:
              msg1 =@"Your Mail has been sent successfully. We will be responding shortly with your results.";
              break;
          case MFMailComposeResultFailed:
              msg1 =@"Message sending failed";
              break;
          default:
              msg1 =@"Your Mail is not Sent";
              break;
      }
      UIAlertView *mailResultAlert = [[UIAlertView alloc]initWithFrame:CGRectMake(10, 170, 300, 120)];
      mailResultAlert.message=msg1;
      mailResultAlert.title=@"Message";
      [mailResultAlert addButtonWithTitle:@"OK"];
      [mailResultAlert show];
  
      dispatch_async(dispatch_get_main_queue(), ^{
          [self dismissViewControllerAnimated:YES completion:nil];
          [self dismissViewControllerAnimated:YES completion:nil];
      }); 
  }
  </code></pre></li>
  </ul>
  
  <p>Would anyone know a way to just use the openCV videoCamera method to capture an image manually? 
  Or how to fix UIImagePickerController?
  Or any other alternative solutions?</p>
  
  <p>Thanks!</p>