tencent cloud

Feedback

Deploying OCR-based Text Recognition Application

Last updated: 2020-09-04 15:55:38

    Based on Tencent Cloud's industry-leading deep learning technology, Tencent Cloud OCR is capable of intelligently recognizing words on images and converting them into editable text. It can recognize printed text and handwriting, meeting the text recognition needs in different scenarios.
    By using Serverless Framework Component and OCR SDK, you can quickly deploy a general OCR application based on COS + API + SCF, which contains the following key components:

    • Serverless RESTful API: you can use the Express framework constructed by SCF and API Gateway to implement RESTful API.
    • Serverless static website: the frontend hosts React static pages in COS.
    • COS: you can create a bucket to store target images.

    Prerequisites

    • You have installed Node.js (v8.6 or above; v10.0 or above is recommended).
    • You have activated OCR.

    Directions

    Installation

    Use npm to install Serverless Framework globally:

    $ npm install -g serverless

    If you have already installed Serverless Framework, you can run the following command to upgrade it to the latest version:

    $ npm update -g serverless

    After the installation is completed, run the serverless -v command to view the version information of Serverless Framework and make sure that the version information is as follows or displays higher versions:

    $ serverless –v
    Framework Core: 1.74.1 (standalone)
    Plugin: 3.6.14
    SDK: 2.3.1
    Components: 2.31.6

    Configuration

    1. Create a local folder and run the serverless init command to download the relevant template.
    $ serverless init ocr-app
    1. Find the .env.example file in the template, rename it to .env, and enter your account, key information, and specified bucket (used to store uploaded images) in it.
    # .env
    TENCENT_APP_ID=xxx
    TENCENT_SECRET_ID=xxx
    TENCENT_SECRET_KEY=xxx
    
    # region of bucket
    REGION=ap-guangzhou
    1. Download all npm dependencies.
    $ npm run bootstrap

    Local debugging

    1. Run the following command to launch the server:
      $ cd server && npm run start
    2. Run the following command to start the frontend:
      $ cd frontend && npm run start
    3. Log in to the frontend page at http://localhost:3000 for local debugging.

    Deployment

    1. Run the following command for deployment:
    $ sls deploy --all
    
    serverless ⚡ framework
    
    backend: 
      region: ap-guangzhou
      apigw: 
        serviceId:   service-4i62q1pg
        subDomain:   service-4i62q1pg-1258834142.gz.apigw.tencentcs.com
        environment: release
        url:         https://service-4i62q1pg-1258834142.gz.apigw.tencentcs.com/release/
      scf: 
        functionName: serverless-ocr
        runtime:      Nodejs10.15
        namespace:    default
    
    frontend: 
      region:  ap-guangzhou
      website: https://serverless-ocr-1258834142.cos-website.ap-guangzhou.myqcloud.com
    
    38s › serverless-ocr › Success
    

    After the deployment succeeds, you can use a browser to access the website link generated by the project to view the generated website. Click Upload Image, and the project can implement OCR with the OCR SDK.

    1. You can run sls remove --all to remove the project.
    $  sls remove --all
    
    serverless ⚡ framework
    
    38s › tencent-fullstack › Success
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support