2016-10-26 4 views
0

CIDetector (Using CIDetectorTypeText) 텍스트 주위에 직사각형을 그릴 수 있지만 텍스트 방향을 감지 할 수있는 방법을 찾을 수 없습니다. 누구든지 Swift로 텍스트 방향을 감지하는 방법을 알고 있습니까?텍스트 방향 감지

+0

CIDetectorImageOrientation을 사용하여 텍스트가 이미 없으면 이미지로 검색 할 수 있습니다. – Callam

+0

'CIDetectorImageOrientation' 만 방향을 설정하는 데 사용할 수 있다고 생각했습니다. [이 답변] (http://stackoverflow.com/questions/36199572/how-to-change-cidetector-orientation) – Daniel

+0

https : //developer.apple.com/reference/coreimage/citextfeature#overview – Callam

답변

2

인식 된 텍스트 방향이 인쇄됩니다.

guard let image = CIImage(image: imageView.image!) else { return } 

let detector = CIDetector(ofType: CIDetectorTypeText, context: nil, options: [ 
    CIDetectorAccuracy: CIDetectorAccuracyHigh 
]) 

let orientations = [Int](1..<9).flatMap { 
    detector?.features(in: image, options: [ 
     CIDetectorImageOrientation: $0 
    ]).count ?? 0 > 0 ? $0 : nil 
} 

if orientations.filter({ $0 < 5 }).count == 4 { 
    print("text has horizontal orientation") 
} else if orientations.filter({ $0 > 4 }).count == 4 { 
    print("text has vertical orientation") 
} else { 
    print("text has mixed orientation") 
} 
+0

수평 값이 주어 지더라도 수직 텍스트를 감지하기 때문에이 방법은 효과가 없습니다. . – Daniel