我在iOS应用上拥有GoogleMobileVision库https://developers.google.com/vision/ios/text-overview,可以读取图像并从图像中提取文本。我要实现的是能够像移动条形码扫描仪一样在移动照相机的同时提取文本。
我尝试从每个Camera框架中提取框架作为UI图像以识别文本,同时移动Camera直到它识别出文本,但一直存在内存问题,并且Camera冻结。
我知道诸如tesseract,SwiftOCR,AbbyySDK之类的库,但是GoogleMobileVision实际上最适合应用外使用
下面是Google桥接到Swift中的样板代码的一部分:
Bridging-Header.h
#import <GoogleMobileVision/GoogleMobileVision.h>
TextRecognitionViewController.swift
import UIKit
class TextRecognitionViewController: UIViewController {
var textDetector: GMVDetector!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.textDetector = GMVDetector.init(ofType: GMVDetectorTypeText, options: nil)
DispatchQueue.main.async {
self.recognize(image: #imageLiteral(resourceName: "sampleo.png"))
}
}
func recognize(image: UIImage) {
let features: [GMVTextBlockFeature]! = self.textDetector.features(in: image, options: nil) as? [GMVTextBlockFeature]
for textBlock: GMVTextBlockFeature? in features {
if let _ = textBlock?.language, let aValue = textBlock?.value {
self.found(recognizedString: aValue)
}
}
}
func found(recognizedString: String) {
print(recognizedString)
}
}
有人抬起头来如何实现这一目标吗?