# OCR 识别

# 官方文档

OCR 识别官方文档

# 源码

TNWX 中 OCR 识别相关接口源码

# 示例

app.get('/ocr', async (req: any, res: any) => {

    let type: string = req.query.type;

    console.log('to ocr...' + type);

    switch (parseInt(type)) {
        case 1:
            OCRApi.ocrByUrl(OCRType.IDCARD,'https://up.enterdesk.com/edpic_360_360/28/bc/80/28bc80d62c84ea7797197a6d7cb03394.jpg')
                .then((data) => {
                    res.send(data);
                })
                .catch((error) => console.log(error))
            break;
        case 2:
            OCRApi.ocrByUrl(OCRType.PRINTEDTEXT,'https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1724603202,554806693&fm=26&gp=0.jpg')
                .then((data) => {
                    res.send(data);
                })
                .catch((error) => console.log(error))
            break;
        case 3:
            OCRApi.ocrByFile(OCRType.PRINTEDTEXT,'/Users/Javen/Downloads/miniprogram_qrcode2.png')
                .then((data) => {
                    res.send(data);
                })
                .catch((error) => console.log(error))
            break;
        default:
            break
    }

});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33