Get the text count from image iOS swift
Solution:
In iOS it had an option named CIDetector to detect the text count that was appeared in an image.
In iOS it had an option named CIDetector to detect the text count that was appeared in an image.
// MARK: - TextCount
func getTextCount(from img: UIImage?) -> Int {
let detector = CIDetector(ofType: CIDetectorTypeText, context: nil, options: [CIDetectorAccuracy: CIDetectorAccuracyLow])
var ciImage: CIImage? = nil
if let anImage = img?.cgImage {
ciImage = CIImage(cgImage: anImage)
}
// retrive array of CITextFeature
var features: [CIFeature]? = nil
if let anImage = ciImage {
features = detector?.features(in: anImage, options: [CIDetectorReturnSubFeatures: false])
}
return features?.count ?? 0
}
Comments
Post a Comment