关于图像内的 AWS iOS 文本识别的文档似乎很少甚至没有。我已经完成了 AWS 创建 IAM 并具有执行 Rekognition 等权限的过程,我从该配置文件在 AWS 上创建了我的“移动应用程序”,并且我获得了一个包含在我的项目中的 json 文件。
我正在初始化 AWS“堆栈”,在 App Delegate 中也没有出现任何问题
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
AWSDDLog.sharedInstance.logLevel = .info
return AWSMobileClient.sharedInstance().interceptApplication(
application,
didFinishLaunchingWithOptions: launchOptions)
}
我的 ViewController 崩溃了:
override func viewDidLoad() {
super.viewDidLoad()
let rekognitionClient = AWSRekognition.default() // CRASH HERE BOOM
let sourceImage = UIImage(named: "corolla")
let image = AWSRekognitionImage()
image!.bytes = UIImageJPEGRepresentation(sourceImage!, 0.7)
guard let request = AWSRekognitionDetectLabelsRequest() else {
puts("Unable to initialize AWSRekognitionDetectLabelsRequest.")
return
}
request.image = image
request.maxLabels = 3
request.minConfidence = 90
rekognitionClient.detectLabels(request) { (response:AWSRekognitionDetectLabelsResponse?, error:Error?) in
if error == nil {
print(response!)
}
}
}
崩溃表明:
2018-07-27 11:22:10.064126-0400 Plater[13491:5229604] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The service configuration is `nil`. You need to configure `awsconfiguration.json`, `Info.plist` or set `defaultServiceConfiguration` before using this method.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000110d3e1e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x000000010d7d4031 objc_exception_throw + 48
2 AWSRekognition 0x000000010caf19ac __36+[AWSRekognition defaultRekognition]_block_invoke + 492
3 libdispatch.dylib 0x0000000111dc97ec _dispatch_client_callout + 8
4 libdispatch.dylib 0x0000000111dcad64 dispatch_once_f + 285
5 AWSRekognition 0x000000010caf1794 +[AWSRekognition defaultRekognition] + 84
6 Plater 0x000000010bd6c5ec _T06Plater14ViewControllerC11viewDidLoadyyF + 124
7 Plater 0x000000010bd6d364 _T06Plater14ViewControllerC11viewDidLoadyyFTo + 36
8 UIKit 0x000000010e214131 -
据我所知,我似乎应该在 json 文件中配置 Rekognition?在 AWS 网站上创建 json 文件时,我没有看到该选项...
有什么想法吗?
最佳答案
我在尝试使用不同的 AWS 服务时遇到了同样的问题。将服务添加到我的 awsconfiguration.json
文件中,如下所示:
"Rekognition": {
"Default": {
"Region": "us-east-1"
}
}
来源:我在文档中找不到这个,但 SDK 是 open source
关于ios - aws Rekognition 未在 iOS 上初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51561234/