当前位置:网站首页>30 lines of code to realize serverless real-time health code recognition -- operation manual

30 lines of code to realize serverless real-time health code recognition -- operation manual

2022-08-02 12:19:00 HUAWEI CLOUD

1 实验介绍    

实验描述:In this experiment, the text recognition service will be usedSDK开发包,Try the text recognition service,and based on thisBuild yousmart applications and systems.无需配置和管理服务器等基础设施,函数以弹性、免运维、高可靠的方式运行.

内容介绍On HUAWEI CLOUD Function Workflow Service,按照指导创建函数,通过OBS桶上Pass the health code截图,The trigger function passes华为云OCR SDK调用通用文字识别服务,识别Health code content.

2 前提条件

This experiment needs to be performed on HUAWEI CLOUD,Therefore, users need to log in with a HUAWEI CLOUD account;

If you don't have a HUAWEI CLOUD account, please do so firstRegister a HUAWEI CLOUD account and complete real-name authentication,Please use it during the experimentChrome浏览器完成相关操作.

Please refer to HUAWEI CLOUD account registration steps

https://support.huaweicloud.com/intl/zh-cn/usermanual-account/account_id_001.html

Please refer to the real-name authentication operation steps

https://support.huaweicloud.com/intl/zh-cn/usermanual-account/zh-cn_topic_0119621533.html

3 操作指导

3.1 登录华为云

Users who already have an account or have completed registration log in to Huawei云官网:【https://www.huaweicloud.com/

Please refer to HUAWEI CLOUD login:

https://support.huaweicloud.com/usermanual-iam/iam_01_0033.html

3.2 获取ak/sk

AK/SK(Access Key ID/Secret Access Key)即访问密钥,Contains the access keyID(AK)和秘密访问密钥(SK)两部分,华为云通过AK识别用户的身份,通过SK对请求数据进行签名验证,用于确保请求的机密性、完整性和请求者身份的正确性.

操作步骤

a) 登录HUAWEI CLOUD management console,Point your mouse to the username in the upper right corner of the page,在下拉列表中单击“我的凭证”.

b) 在“我的凭证”页面中选择“访问密钥”页签.单击“Added access secret”,Follow the instructions to obtain an authentication accountAK/SK,请妥善保管AK/SK信息.

3.3 开通OCR文字识别服务

The mouse points to the upper left corner of the page“服务列表”,Find it after expansion“人工智能”下的“文字识别”点击打开.

In the upper left corner of the page will beThe area switches to“北京四”,找到“通用文字识别”点击“开通服务”.

3.4 Get the health code identification code

浏览器打开https://health-qr-recognition-code.obs.cn-north-4.myhuaweicloud.com/Health-QR-Recognition.txt,下载文件,保存本地,以备后续步骤使用.

3.5 Configure health code recognition函数

3.5.1 创建函数

The mouse points to the upper left corner of the page“服务列表”,Find it after expansion“算”下的“函数工作流(functionGraph)”点击打开.

Navigate on the left展开“函数”菜单,点击选择“函数列表”,Then click the upper right corner of the function list page“创建函数”按钮.

在“Create a function page”Custom input function name(我这里用的是Health-QR-Recognition),其他配置默认,点击“Create a function button”.

3.5.2 修改代码

页面跳转到 函数详情页面,将index.jsThe code inside the file is removed,用3.4Steps get code replacement,点击“部署”按钮进行保存.

3.5.3 添加依赖包

向下滚动页面,点击“添加依赖包”按钮.

按“ocr”搜索依赖包,选择“cloud-ocr-sdk-nodejs-1.0.3”Click after the dependency package“确认”按钮.

3.5.4 Add environment scalars

切换至“设置”页签,选择“环境变量”,点击“Add environment scalars”按钮.

添加键:ocrEndpoint,值:ocr.cn-north-4.myhuaweicloud.com,后点击“保存”按钮.

3.5.5 开通日志服务

切换到“监控”页签,选择“日志”,点击“立即开通”按钮.

3.5.6 创建触发器

还是在“设置”页签,选择点击“触发器”页签,点击“创建触发器”按钮.

on the Create Trigger page,触发器类型选择“对象存储服务(OBS)” 后点击“创建桶”.

跳转到OBSService Create Bucket page,Configure and create as shown belowOBS桶后,点击“立即创建”按钮(If there is a prompt pop-up box,点击“确定”即可),完成OBSbucket creation.

    区域:华北-北京四

    数据冗余存储策略:单AZ存储

    桶名称:自定义(我这里用的是“health-qr-healthsource-img-obs”)

    Other content defaults

点击“立即创建”按钮.

待OBS创建完毕,Return to the Function Create Trigger page,点击按钮刷新,

桶:Select the bucket you just created(That is, the bucket with the custom name in the previous step)

事件:选择Put,Post事件

后缀:jpg(上传图片的后缀,Consistent with the suffix of the subsequently recognized picture)

后点击“确定”按钮,完成OBS触发器创建.

3.6 传图片触发函数执行

回到OBS列表页,Select Open previously createdOBS.

Navigate on the left栏选择“对象”,点击 “上传对象”按钮,Drag and drop the local health code to the red box.

点击“上传”按钮.

3.7 View the function execution log

Enter on the function page“监控”页签,选择“日志”,You can see that the image upload has triggered the function execution(Without logging,You can wait for a while,Log synchronization is slightly delayed),Click to invoke the result as“执行成功”对应的“请求ID”.

Read the log content,可以看到,The uploaded health code content has passedjson格式返回.

4 后续

This experiment was passedOBSBy uploading the health code,The trigger function identifies the content of the health code,Of course, this is the core part of image content recognition,If you want to batch process and store the results,Also need to develop a small program,As the entrance for users to upload health code pictures,The results of image analysis need to be further extracted and stored,And abnormal code timely alarm,Here they are introduced one by one,Let the developers play freely.

原网站

版权声明
本文为[HUAWEI CLOUD]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/214/202208021202218303.html