百度智能(文本识别),API传图OC代码与SDK使用

甘林梦 2021-01-14 16:38:21
百度 API 智能 识别 文本


 

百度智能中的文本识别中的身份证识别,有API方式和SDK方式

API方式

百度智能(文本识别),百度API传图没有提供OC的示例,这里提供一下

- (void)OCTest:(NSString*)token {
//***********post请求********************//
 NSString *testURL =[NSString stringWithFormat:@"https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token=%@",token];
testURL = [testURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString:testURL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
//设置请求方法
request.HTTPMethod = @"POST";
//设置请求体
UIImage *testImage = [UIImage imageNamed:@"test.jpg"];
NSData *imageData = UIImagePNGRepresentation(testImage);
NSString *baseStr = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSString *urlEncode= (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
NULL,
(__bridge CFStringRef)baseStr,
NULL,
(CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
 CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)));
NSLog(@"urlEncode is %@",urlEncode);
NSString *str =[NSString stringWithFormat:@"image=%@&id_card_side=%@",urlEncode,@"front"];
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPBody = data;
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//
 if (error) {
NSLog(@"error is %@",error);
}else
{
NSLog(@"data is %@",data);
NSDictionary *dic= [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(@"解析得出的dic is %@",dic);
}
}];
[dataTask resume];
}

如果UI没设计拍照UI,这里建议大家使用SDK,稳定性好,效率高。

SDK方式

真机运行报错的话,把lib中的模拟器都移掉。

真机运行报错、Archive/IPA/Upload AppStore 时报错"Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]..."

为了方便开发者调试,AipBase.framework合并了模拟器和真机架构,上线前,使用lipo工具移除相关架构即可,参考:

cd lib
# 使用lipo -info 可以查看包含的架构
lipo -info AipBase.framework/AipBase # Architectures in the fat file: AipBase are: i386 x86_64 armv7 armv7s arm64
# 移除x86_64, i386
lipo -remove x86_64 AipBase.framework/AipBase -o AipBase.framework/AipBase
lipo -remove i386 AipBase.framework/AipBase -o AipBase.framework/AipBase
lipo -remove x86_64 AipOcrSdk.framework/AipOcrSdk -o AipOcrSdk.framework/AipOcrSdk
lipo -remove i386 AipOcrSdk.framework/AipOcrSdk -o AipOcrSdk.framework/AipOcrSdk
# 再次查看
lipo -info AipBase.framework/AipBase # Architectures in the fat file: AipBase are: armv7 armv7s arm64

如果想修改SDK的UI,可以使用AipOrcSdk中的源码,站在巨人的肩膀上编程,也很香!






版权声明
本文为[甘林梦]所创,转载请带上原文链接,感谢
https://www.cnblogs.com/ljcgood66/p/14278009.html

  1. Rocketmq CPP client visual studio 2019 compilation
  2. Usage of data custom attribute in jquery
  3. Common decompression in Linux
  4. Upload large files in Java
  5. Sentry (v20.12.1) k8s cloud native architecture exploration, sentry for JavaScript manual capture event basic usage
  6. Sentry (v20.12.1) k8s cloud native architecture exploration, sentry for JavaScript manual capture event basic usage
  7. Docker + MySQL Cluster + read / write separation + MYCAT Management + vertical sub database + load balancing
  8. Docker + MySQL Cluster + read / write separation + MYCAT Management + vertical sub database + load balancing
  9. Java use interceptor infinite forwarding / redirection infinite loop / redirection times too many error (stack overflow error) solution
  10. Java use interceptor infinite forwarding / redirection infinite loop / redirection times too many error (stack overflow error) solution
  11. 010_ MySQL
  12. 010_ MySQL
  13. Fast integration of imsdk and Huawei offline push
  14. 消息队列之RabbitMQ
  15. Rabbitmq of message queue
  16. 初学java进制转换方面补充学习
  17. Learn java base conversion supplementary learning
  18. 了解一下RPC,为何诞生RPC,和HTTP有什么不同?
  19. 了解一下RPC,为何诞生RPC,和HTTP有什么不同?
  20. 初学java进制转换方面补充学习
  21. Learn about RPC, why RPC was born, and what's the difference between RPC and HTTP?
  22. Learn about RPC, why RPC was born, and what's the difference between RPC and HTTP?
  23. Learn java base conversion supplementary learning
  24. JDBC测试连接数据库
  25. JDBC test connection database
  26. 大厂面试官竟然这么爱问Kafka,一连八个Kafka问题把我问蒙了?
  27. The interviewers of big factories love to ask Kafka so much. I'm blinded by eight Kafka questions in a row?
  28. 安卓开发和java开发有什么区别!2021年BATJ30套大厂Android经典高频面试题,面试必问
  29. Spring Security OAuth2.0認證授權四:分散式系統認證授權
  30. What's the difference between Android development and java development! 2021 batj30 Android classic high frequency interview questions
  31. Spring security oauth2.0 authentication and authorization 4: distributed system authentication and authorization
  32. Java微服务 vs Go微服务,究竟谁更强!?
  33. 大厂面试官竟然这么爱问Kafka,一连八个Kafka问题把我问蒙了?
  34. Who is stronger, Java microservice vs go microservice!?
  35. Java微服务 vs Go微服务,究竟谁更强!?
  36. The interviewers of big factories love to ask Kafka so much. I'm blinded by eight Kafka questions in a row?
  37. Who is stronger, Java microservice vs go microservice!?
  38. springboot异常处理之404
  39. Spring boot exception handling 404
  40. Spring Boot Security 国际化 多语言 i18n 趟过巨坑
  41. springboot异常处理之404
  42. Spring boot security international multilingual I18N
  43. Spring boot exception handling 404
  44. Netty系列化之Google Protobuf编解码
  45. Netty之编解码
  46. Java编解码
  47. Netty解码器
  48. Netty与TCP粘包拆包
  49. Netty开发入门
  50. Java集合遍历时遇到的坑
  51. Spring IOC 源码解析(下)
  52. Spring IoC源码解析(上)
  53. Google protobuf codec of netty serialization
  54. Encoding and decoding of netty
  55. Java codec
  56. Netty decoder
  57. Netty and TCP packet sticking and unpacking
  58. Introduction to netty development
  59. Problems encountered in Java collection traversal
  60. Spring IOC source code analysis (2)