First, plug-in recommendation

  • Cross-platform Office documents, pictures online preview, video playback native plug-in
  • Android and IOS image preview online, video playback native plugin

Second, preparation

1. Prepare Android and IOS certificates

  • Android: Generate the Android packaged keystore certificate file and obtain MD5 (very important), refer to the documentation: Android platform signing certificate (.keystore) generation guide – DCloud Q&A
  • IOS: Apply for an IOS certificate in Windows and an IOS certificate in Mac

2. Baidu materials preparation

  • Enter baidu AI open platform

  • Click the console in the upper right corner to log in. If you have no account, please register your account first

  • After login, if there is no real name authentication, please authenticate first. Enterprise real name authentication is recommended (you can use more functions).

  • Select Text Recognition – to create the application

  • Obtain the API Key, Secret Key, and License file

  • Baidu OCR interface charge details, there are free times, for development and debugging, please view the overview in baidu console, or directly view the product pricing document

Three, quick start

  • Step1: download this plug-in sample project, or download GitHub – silianpan/Seal- uniplugin-demo

  • Step2: open manifest.json – basic configuration – and obtain the DCloud AppID again

  • Step3: Click try it out

  • Step4: Open manifest.json – App Native Plug-in Configuration – Select cloud plug-in

  • Step5: create the nativeplugins/ seal-ocr /android/assets folder in the root directory of the project, and create the nativeplugins/ seal-ocr/IOS directory on the IOS end

  • Step6: place the downloaded aip.license file on the Android terminal (change the file name to the same one if the file name is different) in the assets directory created above. Place the downloaded aip.license file on the IOS terminal directly in the IOS directory

  • Step7: make a custom debugging base: click “run to mobile phone or simulator” in the HBuilderX menu to make a custom debugging base, and fill in the steps and matters for attention as shown in the figure below

    Attached: debug.keystore download link, used for testing only

    Keystore name: “debug. Keystore” Keystore password: “Android” Key alias: “AndroidDebugKey” Key password: “Android”

    Md5: A5:61-77:2 e: AA: 63:15:18:47: D6:5 b: EC: 6 a: FA: F4:0 a

  • Step8: Select a custom debugging base: Click Run – “Run to mobile phone or emulator” – “Base Run Selection -” Custom debugging base

  • Step9: Debug and run: Click Run — “Run to mobile phone or simulator” — “run to Android App base”

Iv. Interface manual

  • Plug-in method: OCR
  • OCR method parameters
parameter type The default value If required instructions
ak string null no Baidu AI Open Platform console application Api Key. The License file is recommended for official release
sk string null no Baidu AI open platform console application Secret Key is officially released. You are advised to use the License file
ocrType string null is The identification type is described as follows
resultType int 0 no Result type: 0: only recognition result, 1: only recognized image, 2: recognition result + recognized image
scaleWidth double 0.2 no The width of the clipping box displayed after taking a picture ranges from 0.05 to 0.2. The smaller the value is, the larger the clipping box is, and 0.05 is the maximum. The width and height can be set differently
scaleHeight double 0.2 no The height of the clipping frame displayed after the photo is taken ranges from 0.05 to 0.2. The smaller the value is, the larger the clipping frame is, and 0.05 is the maximum. The width and height can be set differently
albumEnable bool true no Whether to enable album selection, default: true (yes)
backgroundColor string # 000000 no Recognize page background color, default: #000000 (black)
hintTextEnable bool true no Whether to display bottom text prompt, default: true (yes)
hintText string null no Customize the text prompt at the bottom. If you do not fill in the text prompt, use the default text prompt
hintTextColor string #FFFFFF no Prompt text color, default: #FFFFFF (white)
hintTextBackgroundColor string # 000000 no Prompt text background color, default: #000000 (black)
hintTextSize int 14 no Prompt text size, default: 14px
templateSign string null no ID of a custom template
  • OcrType specifies

    The field values instructions
    general General Character Recognition (including position information version)
    general_basic Universal character recognition
    accurate_basic General Character Recognition (High Precision Version)
    accurate General character Recognition (with high precision version of position information)
    general_enhanced For general character recognition (including rare character version), the service has been discontinued and the high precision version has been used
    general_webimage Network image recognition
    bankcard Bank card identification
    bankcard_scan Bank card scanning collection
    vehicle_license Identification of driving license
    driving_license Driver’s license recognition
    license_plate License plate recognition
    business_license Business license identification
    receipt General bill identification
    passport Passport identification
    numbers Digital recognition
    qrcode Two-dimensional code recognition
    businesscard Business card recognition
    lottery Lottery recognition
    vatinvoice VAT invoice identification
    taxireceipt Taxi fare
    vincode VIN code
    trainticket The train ticket
    trip_ticket itinerary
    car_sell_invoice Motor vehicle sales invoice
    vihicle_sertification Vehicle certificate
    example_doc_reg Test paper analysis and identification
    written_text Handwritten character recognition
    hukou_page Identification of household register
    normal_machine_invoice Ordinary machine invoice identification
    weight_note Pounds single recognition
    medical_detail Identification of medical expenses
    online_taxi_itinerary Ride-hailing itinerary recognition
    idcard_front Id card front photo identification
    idcard_back The reverse side of the ID card is photographed for identification
    idcard_front_scan Front scan of ID card (embedded quality control + cloud recognition)
    idcard_back_scan Reverse scanning of ID card (embedded quality control + cloud recognition)
    custom Custom Templates
  • Code sample

    Sealocrmodule. OCR ({// ak: ", // sk: ", ocrType, scaleWidth: 0.1, scaleHeight: 0.1, albumEnable: False}, res => {uni.showModal({content: 'Get recognition result:' + json.stringify (res)})})Copy the code
  • Description of the status code of the interface callback result

    Status code instructions
    200 Identify the successful
    301 Failed to obtain the Token. Check whether the baidu cloud application package name, AK, and SK are the same
    302 Failed to obtain the Token. Check whether the baidu cloud application package name and license file are consistent
    303 Local quality control initialization error
    304 Baidu OCR error information, including error codes, can be viewed by referring to baidu official documents
    1001 The SDK is initialized
    1002 The SDK initialization is complete
    1003 Start extracting results
    1004 Extraction results completed

5. Follow-up plan

  • The IOS side support