flutter_tencent_ocr 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new60

flutter_tencent_ocr #

身份证识别 #

  Future idCardOCR() async {
    final ByteData imageBytes =
        await rootBundle.load('assets/images/image6.png');

    FlutterTencentOcr.iDCardOCR(
      SecretId,
      SecretKey,
      IDCardOCRRequest.fromParams(
          config: IDCardOCRConfig.fromParams(reshootWarn: true),
          imageBase64: base64Encode(imageBytes.buffer.asUint8List())),
    ).then((onValue) {
      setState(() {
        _message = onValue.toString();
      });
    }).catchError(
      (error) {
        setState(() {
          _message = error;
        });
      },
    );
  }

银行卡识别 #

  Future bankOCR() async {
    final ByteData imageBytes =
        await rootBundle.load('assets/images/bank.jpeg');

    FlutterTencentOcr.bankCardOCR(
      SecretId,
      SecretKey,
      GeneralOCRRequest.fromParams(
          imageBase64: base64Encode(imageBytes.buffer.asUint8List())),
    ).then((onValue) {
      setState(() {
        _message = onValue.toString();
      });
    }).catchError(
      (error) {
        setState(() {
          _message = error;
        });
      },
    );
  }

营业执照 #

  Future bizLicenseOCR() async {
    final ByteData imageBytes = await rootBundle.load('assets/images/biz.png');

    FlutterTencentOcr.bizLicenseOCR(
      SecretId,
      SecretKey,
      GeneralOCRRequest.fromParams(
          imageBase64: base64Encode(imageBytes.buffer.asUint8List())),
    ).then((onValue) {
      setState(() {
        _message = onValue.toString();
      });
    }).catchError(
      (error) {
        setState(() {
          _message = error;
        });
      },
    );
  }

统一调用的方法 #

  Future otherOCR() async {
    
    final ByteData imageBytes = await rootBundle.load('assets/images/biz.png');

    Map map = {"ImageBase64": base64Encode(imageBytes.buffer.asUint8List())};

    FlutterTencentOcr.ocrRequest(
            SecretId, SecretKey, "BizLicenseOCR", jsonEncode(map))
        .then((onValue) {
      setState(() {
        _message = onValue.toString();
      });
    }).catchError(
      (error) {
        setState(() {
          _message = error;
        });
      },
    );
  }

运行examle #

在 main.dart 同级目录下新建文件: local_config.dart

/// 腾讯OCR生成的秘钥串
const String SecretId = "xxxxxx"; 
const String SecretKey = "xxxxxxx"; 

0.1.2 #

  • clean findProxy.

0.1.1 #

  • clean warning.

0.1.0 #

  • Initial version.

example/lib/main.dart

import 'dart:convert';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_tencent_ocr/flutter_tencent_ocr.dart';
import 'package:flutter_tencent_ocr/IDCardOCR.dart';
import 'package:flutter_tencent_ocr/GeneralOCRRequest.dart';

import 'local_config.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _message = '';

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('腾讯OCR'),
          ),
          body: Column(children: <Widget>[
            Expanded(flex: 1, child: Text(_message)),
            Expanded(
              flex: 1,
              child: ListView(children: <Widget>[
                OutlineButton(
                  onPressed: idCardOCR,
                  child: Text("身份证识别"),
                ),
                OutlineButton(
                  onPressed: bankOCR,
                  child: Text("银行卡"),
                ),
                OutlineButton(
                  onPressed: bizLicenseOCR,
                  child: Text("营业执照"),
                ),
                OutlineButton(
                  onPressed: otherOCR,
                  child: Text("其他识别"),
                ),
              ]),
            )
          ])),
    );
  }

  Future idCardOCR() async {
    final ByteData imageBytes =
        await rootBundle.load('assets/images/image6.png');

    FlutterTencentOcr.iDCardOCR(
      SecretId,
      SecretKey,
      IDCardOCRRequest.fromParams(
          config: IDCardOCRConfig.fromParams(reshootWarn: true),
          imageBase64: base64Encode(imageBytes.buffer.asUint8List())),
    ).then((onValue) {
      setState(() {
        _message = onValue.toString();
      });
    }).catchError(
      (error) {
        setState(() {
          _message = error;
        });
      },
    );
  }

  Future bankOCR() async {
    final ByteData imageBytes =
        await rootBundle.load('assets/images/bank.jpeg');

    FlutterTencentOcr.bankCardOCR(
      SecretId,
      SecretKey,
      GeneralOCRRequest.fromParams(
          imageBase64: base64Encode(imageBytes.buffer.asUint8List())),
    ).then((onValue) {
      setState(() {
        _message = onValue.toString();
      });
    }).catchError(
      (error) {
        setState(() {
          _message = error;
        });
      },
    );
  }

  Future bizLicenseOCR() async {
    final ByteData imageBytes = await rootBundle.load('assets/images/biz.png');

    FlutterTencentOcr.bizLicenseOCR(
      SecretId,
      SecretKey,
      GeneralOCRRequest.fromParams(
          imageBase64: base64Encode(imageBytes.buffer.asUint8List())),
    ).then((onValue) {
      setState(() {
        _message = onValue.toString();
      });
    }).catchError(
      (error) {
        setState(() {
          _message = error;
        });
      },
    );
  }

  Future otherOCR() async {
    
    final ByteData imageBytes = await rootBundle.load('assets/images/biz.png');

    Map map = {"ImageBase64": base64Encode(imageBytes.buffer.asUint8List())};

    FlutterTencentOcr.ocrRequest(
            SecretId, SecretKey, "BizLicenseOCR", jsonEncode(map))
        .then((onValue) {
      setState(() {
        _message = onValue.toString();
      });
    }).catchError(
      (error) {
        setState(() {
          _message = error;
        });
      },
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_tencent_ocr: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_tencent_ocr/flutter_tencent_ocr.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
21
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

We analyzed this package on Mar 26, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
crypto ^2.1.3 2.1.4
dio ^3.0.9 3.0.9
flutter 0.0.0
hex ^0.1.2 0.1.2
Transitive dependencies
charcode 1.1.3
collection 1.14.11 1.14.12
convert 2.1.1
http_parser 3.1.4
meta 1.1.8
path 1.6.4
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test