ios - 如何使用 CIDetector 和 Swift 在图像中裁剪检测到的矩形

标签 ios swift avcapturesession cidetector

我正在开发一个检测身份证的应用程序,我正在尝试使用 ios 内置的 CIDetector 在实时预览中检测矩形形状的对象。我在这里使用本教程中解释的解决方案 CoreImage Detectors

我得到了流畅的结果 image

我的问题:有没有办法提取和裁剪检测到的矩形?

最佳答案

func cropBusinessCardForPoints(image: CIImage, topLeft: CGPoint, topRight: CGPoint, bottomLeft: CGPoint, bottomRight: CGPoint) -> CIImage {

    var businessCard: CIImage
    businessCard = image.imageByApplyingFilter(
        "CIPerspectiveTransformWithExtent",
        withInputParameters: [
            "inputExtent": CIVector(CGRect: image.extent),
            "inputTopLeft": CIVector(CGPoint: topLeft),
            "inputTopRight": CIVector(CGPoint: topRight),
            "inputBottomLeft": CIVector(CGPoint: bottomLeft),
            "inputBottomRight": CIVector(CGPoint: bottomRight)])
    businessCard = image.imageByCroppingToRect(businessCard.extent)

    return businessCard
}

关于ios - 如何使用 CIDetector 和 Swift 在图像中裁剪检测到的矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36197051/

相关文章:

无需打开应用程序的 iOS 通知操作

ios - html5 视频结束时触发 .changePage(),iOS

ios - UISplitViewController 共享相同的标题

ios - Swift - UITableView 中的标题 block 按钮交互

ios - 苹果的AVCamera夜间模式

ios - 在相机预览 View 上添加按钮 [BESwiftCamera lib]

ios - 错误 : _handleNonLaunchSpecificActions in iOS9

ios - 在 Xcode 中打开我的 React Native 项目,我的代码在哪里?

ios - 如何在 NSUserDefaults 中保存任何类

ios - CALayer - 将子层放在 Storyboard UIButtons 下方?