2015-03-05 21 views
5

CIPerspectiveCorrection Filter kullanıyorum ve benim sorunum, döndürülen resim sonuçlarının yansıtılmış, baş aşağı ve perspektif düzeltmesi için kullanılan noktaların yanlış eksene veya eksen yönüne referans olarak görünmesiydi .CIPerspectiveCorrection filtresi döndürülen görüntüyü döndürür ve ters çevrilmiş

Konuyu izole etmek için 1024 x 1024 boyutunda bir test görüntüsü ile çalışıyorum ve mükemmel bir dikdörtgen alanda geçiyorum. Hala dikey ve yatay olarak çevrilmiş resimlerle bitiyorum. İşte

bir görüntü verilmiş ve puan set kırpılmış bir CIImage örneği döndüren benim fonksiyonudur:

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) 
} 

Ve burada bu işlevi arıyorum nerede:

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) 
} 

kimse sorunlarla karşılaştı Has daha önce böyle mi yaptın? İşte

kaynak imajını

enter image description here

Ve burada

enter image description here

cevap

7

Tamam scaleAspectFit ayarlı contentMode bir UIImageView görüntülenen son görüntü ise, sorunum, ben güzelim Emin, CoreImage, Kartezyen koordinat sistemini kullanıyor. Y yukarıda. (sıfır, sıfır) sol altta.

+4

fonk cartesianForPoint (noktası: CGPoint, kapsamı: CGRect) -> CGPoint { dönüş CGPoint (x: point.x, y: extent.height - point.y) } – nwales

+0

Bunun için kadar teşekkür olabilir son işlev! Sorunun ne olduğunu biliyordum ama projemde çok fazla zaman geçirdim, nasıl dönüştüreceğimi anlayamadım! – Fengson

+0

@nwales Teşekkürler! – Zeotyn

İlgili konular