【发布时间】:2016-09-15 11:16:36
【问题描述】:
我遇到了一些问题,我已经找到了答案,但没有一个对我有用。
目标:在尝试检测 3 个 QR 码 60 秒后,提供手动捕获图像并将该图像发送到电子邮件的选项。类似于:60 秒过去了 --> UIAlertController 带有一个“确定”按钮,该按钮导致图像捕获视图 --> 用户捕获图像,然后将该图像作为附件添加到电子邮件中,然后他们可以发送
问题:找不到使用https://www.toptal.com/machine-learning/real-time-object-detection-using-mser-in-ios中描述的opencv库捕获图像的方法
我尝试过的事情:
-
在播放视频时截取屏幕截图(有效,但我正在寻找一种更复杂的方法来做到这一点
(UIImage *)capture { UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *imageView = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return imageView; } -
使用 UIImagePickerController(无法让 MFMailComposeViewController 显示。还不断收到“对尚未渲染的视图进行快照会导致空快照。确保您的视图在快照或屏幕更新后的快照之前至少渲染一次。” )
(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]; }); }
有人知道使用 openCV videoCamera 方法手动捕获图像的方法吗? 或者如何修复 UIImagePickerController? 还是有其他替代解决方案?
谢谢!
【问题讨论】:
标签: ios objective-c iphone image