【问题标题】:How to crop detected rectangle in Image with CIDetector and Swift如何使用 CIDetector 和 Swift 在图像中裁剪检测到的矩形
【发布时间】:2017-03-15 17:29:52
【问题描述】:

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

我得到了流畅的结果 image

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

【问题讨论】:

  • 嗨@Ayoub 我关注了您共享的链接以检测图像中的矩形,但它不如您的结果准确,除了上面链接中给出的解决方案之外我们还需要做什么?

标签: ios swift avcapturesession cidetector


【解决方案1】:
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
}

【讨论】:

    【解决方案2】:

    Swift 3,简单的解决方案

    让 faceScanningArea = CGRect(x: 0, y: 0, width: 50, height: 50)

    theFaceFrame.image = UIImage( cgImage( orginalImage.image?.cgImage )!.cropping(to: faceScanningArea)!)

    【讨论】:

      猜你喜欢
      • 2018-01-27
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      • 2017-07-30
      相关资源
      最近更新 更多