【问题标题】:CIPerspectiveCorrection filter returns image flipped and invertedCIPerspectiveCorrection 过滤器返回翻转和倒置的图像
【发布时间】:2015-05-06 07:40:27
【问题描述】:

我正在使用CIPerspectiveCorrection Filter,我的问题是我返回的图像结果是镜像的、倒置的,并且用于透视校正的点似乎引用了错误的轴或轴方向。

为了隔离问题,我一直在使用 1024 x 1024 的测试图像,并且我正在通过一个完美的矩形区域。我仍然以垂直和水平翻转的图像结束。

这是我的函数,它返回给定图像和一组点的裁剪 CIImage 实例:

 private func _getCroppedImageWithImage(image:CIImage, topLeft:CGPoint, topRight:CGPoint, botLeft:CGPoint, botRight:CGPoint) -> CIImage {
    var rectCoords = NSMutableDictionary(capacity: 4)
    rectCoords["inputTopLeft"] = CIVector(CGPoint:topLeft)
    rectCoords["inputTopRight"] = CIVector(CGPoint:topRight)
    rectCoords["inputBottomLeft"] = CIVector(CGPoint:botLeft)
    rectCoords["inputBottomRight"] = CIVector(CGPoint:botRight)
    return image.imageByApplyingFilter("CIPerspectiveCorrection", withInputParameters: rectCoords)
}

这里是我调用这个函数的地方:

func testCrop() {

    let ciInputImage = CIImage(image:UIImage(named:"test-pattern.jpg")!)

    println("source image is \(ciInputImage)") //<CIImage: 0x170212290 extent [0 0 1024 1024]>

    let ptBotLeft = CGPointMake(32.0,992.0)
    let ptBotRight = CGPointMake(992.0,992.0)
    let ptTopRight = CGPointMake(992.0,32.0)
    let ptTopLeft = CGPointMake(32.0,32.0)

    let croppedImage = _getCroppedImageWithImage(ciInputImage, topLeft: ptTopLeft, topRight: ptTopRight, botLeft: ptBotLeft, botRight: ptBotRight)
    println("cropped image \(croppedImage)") //<CIImage: 0x174204a60 extent [0 0 960 960]>

    let croppedImageCG = CIContext(options: nil).createCGImage(croppedImage, fromRect: croppedImage.extent())

    let imageVC = ImageViewController(image: UIImage(CGImage: croppedImageCG))
    presentViewController(imageVC, animated: true, completion: nil)
}

以前有人遇到过这样的问题吗?

这是源图片

这是在 UIImageView 中显示的最终图像,其中 contentMode 设置为 scaleAspectFit

【问题讨论】:

    标签: ios swift core-image cifilter


    【解决方案1】:

    好的,我很确定,我的问题是 CoreImage 使用笛卡尔坐标系。 Y 起来了。 (零,零)在左下角。

    【讨论】:

    • func cartesianForPoint(point:CGPoint,extent:CGRect) -> CGPoint { return CGPoint(x: point.x,y: extent.height - point.y) }
    • 对于最后一个功能,我非常感谢!我知道问题出在哪里,但是在我的项目上花了很多时间,我不知道如何转换它!
    猜你喜欢
    • 1970-01-01
    • 2019-11-28
    • 2014-04-21
    • 2023-03-29
    • 2012-07-27
    • 2013-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多