6

IDカードを検出するアプリに取り組んでおり、iosに組み込まれたCIDetectorを使用して、ライブプレビューで長方形のオブジェクトを検出しようとしています。このチュートリアルで説明されているソリューションをここで使用しています CoreImage Detectors

私は流れる結果の 画像を取得しています

私の質問:検出された長方形を抽出してトリミングする方法はありますか?

4

2 に答える 2

6
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
}
于 2016-03-30T18:22:51.840 に答える