身份证相机
- 在相机视图中检测身份证,并返回身份证的解扭曲图像。
- 扫描身份证背面的 PDF417 条形码。
安装
CocoaPods
使用在您的 Podfile 中添加以下 pod 并运行 pod install
。
pod 'ID-Card-Camera', '~> 1.0'
Swift Package Manager
使用- 在 Xcode 中,从顶部的菜单中选择 文件 -> 添加包 ...。
- 在搜索栏中输入
https://github.com/AppliedRecognition/ID-Card-Camera.git
。 - 单击 添加包 按钮。
使用方法
import UIKit
import IDCardCamera
class ViewController: UIViewController, CardDetectionViewControllerDelegate {
@IBOutlet var imageView: UIImageView!
func scanIDCard() {
// Set the scan settings
// In this example the aspect ratio is that of a typical credit card
// The width and height units are not important
let settings = CardDetectionSettings(width: 85.6, height: 53.98)
// Create the view controller
let controller = CardDetectionViewController()
// Set the delegate that will receive the result
controller.delegate = self
// Present the card detection view controller
self.present(controller, animated: true, completion: nil)
}
func cardDetectionViewController(_ viewController: CardDetectionViewController, didDetectCard image: CGImage, withSettings settings: CardDetectionSettings) {
// The card has been scanned
// Display the image in the image view
self.imageView.image = UIImage(cgImage: image)
}
}