So, I'm trying to make a text detector using the CIDetector in swift. When I point my phone to a piece of text, it does not detect it. However, if I turn my phone to the side, it works and detects text. How can I change it so that it detects text with the correct camera orientation? Here is my code:
Prepare the text detector function:
func prepareTextDetector() -> CIDetector {
let options: [String: AnyObject] = [CIDetectorAccuracy: CIDetectorAccuracyHigh, CIDetectorAspectRatio: 1.0]
return CIDetector(ofType: CIDetectorTypeText, context: nil, options: options)
}
Text Detection Function:
func performTextDetection(image: CIImage) -> CIImage? {
if let detector = detector {
let features = detector.featuresInImage(image)
for feature in features as! [CITextFeature] {
resultImage = drawHighlightOverlayForPoints(image, topLeft: feature.topLeft, topRight: feature.topRight,
bottomLeft: feature.bottomLeft, bottomRight: feature.bottomRight)
imagex = cropBusinessCardForPoints(resultImage!, topLeft: feature.topLeft, topRight: feature.topRight, bottomLeft: feature.bottomLeft, bottomRight: feature.bottomRight)
}
}
return resultImage
}
It works when it is oriented as left, but not for the correct one:

source
share