2016-01-21 6 views
5

मैंने छवि पर आयताकारों का पता लगाने के लिए अपने ऐप में CIDetector लागू किया है, लेकिन अब मैं छवि को फसल करने के लिए लौटा CGPoint का उपयोग कैसे कर सकता हूं ताकि मैं इसे वापस प्रदर्शित कर सकूं?स्विफ्ट में CIDetector परिप्रेक्ष्य और फसल

परिप्रेक्ष्य के लिए मैंने CIPerspectiveCorrection फ़िल्टर को लागू करने का प्रयास किया है, लेकिन इसे काम नहीं कर सका।

मैंने चारों ओर खोज की है और कुछ सुराग पाए हैं लेकिन स्विफ्ट में समाधान नहीं मिला।

परिप्रेक्ष्य को ठीक करने और मेरी छवि को फसल करने के लिए CIDetector (पता आयताकार) द्वारा प्रदान किए गए डेटा का उपयोग कैसे किया जाए?

किसी भी व्यक्ति जो CIDetectorTypeRectangle रिटर्न से परिचित नहीं हो सकता है: यह 4 CGPoint के निचले स्तर, नीचे की ओर, टॉप लेफ्ट, टॉप राइट देता है।

उत्तर

8

यहाँ क्या काम किया है:

UIGraphicsBeginImageContext(CGSize(width: flattenedImage!.extent.size.height, height: flattenedImage!.extent.size.width)) 

UIImage(ciImage:resultImage!,scale:1.0,orientation:.right).draw(in: CGRect(x: 0, y: 0, width: resultImage!.extent.size.height, height: resultImage!.extent.size.width)) 

let image = UIGraphicsGetImageFromCurrentImageContext() 
UIGraphicsEndImageContext() 
:

func flattenImage(image: CIImage, topLeft: CGPoint, topRight: CGPoint,bottomLeft: CGPoint, bottomRight: CGPoint) -> CIImage { 

    return image.applyingFilter("CIPerspectiveCorrection", withInputParameters: [ 

     "inputTopLeft": CIVector(cgPoint: topLeft), 
     "inputTopRight": CIVector(cgPoint: topRight), 
     "inputBottomLeft": CIVector(cgPoint: bottomLeft), 
     "inputBottomRight": CIVector(cgPoint: bottomRight) 


     ]) 

} 

आप कहीं भी अपने आयत का पता लगाने के

संबंधित मुद्दे