所以我正在尝试CIDetector
在 Swift 中使用文本检测器。当我将手机指向一段文字时,它没有检测到它。但是,如果我将手机转到一边,它就会工作并检测到文本。如何更改它以使其在正确的相机方向上检测到文本?这是我的代码:
准备文本检测器功能:
func prepareTextDetector() -> CIDetector {
let options: [String: AnyObject] = [CIDetectorAccuracy: CIDetectorAccuracyHigh, CIDetectorAspectRatio: 1.0]
return CIDetector(ofType: CIDetectorTypeText, context: nil, options: options)
}
文字检测功能:
func performTextDetection(image: CIImage) -> CIImage? {
if let detector = detector {
// Get the detections
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
}
它在像左侧一样定向时起作用,但不适用于右侧: