簡體   English   中英

如何使用CIDetector和Swift裁剪圖像中檢測到的矩形

[英]How to crop detected rectangle in Image with CIDetector and Swift

我正在開發可檢測身份證的應用程序,並且嘗試使用ios中內置的CIDetector在實時預覽中檢測矩形對象。 我正在使用本教程中在此處解釋的解決方案CoreImage Detectors

我正在得到流動的結果圖像

我的問題:有沒有辦法提取和裁剪檢測到的矩形?

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
}

Swift 3,簡單的解決方案

讓faceScanningArea = CGRect(x:0,y:0,寬度:50,高度:50)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM