Appery Text Recognition Plugin

Copy to Clipboard

Text Recognition Cordova Plugin


TextRecognizer.recognizeText

Parameters

  • {string} filePath - path to image
  • {function} success - callback function which takes a parameter data which will be invoked on success
  • {function} error - callback function which takes a parameter err which will be invoked on failure
Supported Options
propertyvaluedescription
useBase64false (default) / trueWhether or not filePath is a base64 encoded string.

Example:

window.ApperyioMLCordovaPlugin.TextRecognizer.recognizeText('filePath', successCallback, errorCallback)

Realtime text recognition from camera

TextRecognizer.startRealTimeRecognition

Parameters
  • {function} success - callback function which takes a parameter data which will be invoked on success
  • {function} error - callback function which takes a parameter err which will be invoked on failure
  • {object} options - options for face detector
Supported Options
propertyvaluedescription
showDetectedTexttrue (default) / falseWhether or not show detected text on video overlay
frameImageDatatrue (default) / falseWhether include base64 of captured text photo or not
frameImageResultTypeCameraResultType.BASE64_STRING (default) / CameraResultType.DATA_URLinclude captured photo as only base64 string or as full data url
delay500 (default)Time interval in msec, for performing recognition each interval value
encodingTypeEncodingType.JPEG (default) / EncodingType.PNGformat of output image
cameraDirectionCameraDirection.BACK (default) / CameraDirection.FRONTUse back or front camera of device during text recognition
detectedTextImageDatatrue (default) / falsereturn or not cropped text image data in base64 format depends on frameImageResultType option value for every detected text block; if true, each item of response "textBlocks" array contains "textBlockImage" field with the data

Example:

window.ApperyioMLCordovaPlugin.TextRecognizer.startRealTimeRecognition(successCallback, errorCallback, {
   showDetectedText: true,
   frameImageData: true,
   frameImageResultType: 0, // BASE64_STRING: 0 (default), DATA_URL: 1
   encodingType: 1, // JPEG : 0 (default) Return JPEG encoded image, PNG : 1 Return PNG encoded image
   cameraDirection: 1, // BACK : 0 (default) Use the back-facing camera, FRONT : 1 Use the front-facing camera
   delay: 100,
   detectedTextImageData: true
})

Sample JSON callback:

{
  "text": "Firebase Docs Guides\nRecognize Text in Images with ML Kit on Android\nYou can use ML Kit to recognize text in images. ML Kit\nhas both a general-purpose APl suitable for recognizing\ntext in images, such as the text of a street sign, and an\nAPl optimized for recognizing the text of documents. The\ngeneral-purpose APl has both on-device and cloud-based\nmodels. Document text recognition is available only as a\ncloud-based model. See the overview for a comparison of\nthe cloud and on-device models.\nRecognize Textin Images with ML K.\nCess\nFirecasts\nFor Firebase Developers\nSee the ML Kit quickstart sample on GitHub for an\nexample of this APl in use, or try the codelab .\nBefore you begin\n1. If you haven't already, add Firebase to your Android project.\n2. In your project-level build.gradle file, make sure to include Google's Maven repository in both your\nbuildscript and allprojects sections.\n3. Add the dependencies for the ML Kit Android libraries to your module (app-level) Gradle file (usually\napp\/build.gradle):",
  "textBlocks": [
    {
      "text": "Firebase Docs Guides",
      "boundingBox": {
        "left": 36,
        "right": 209,
        "top": 41,
        "bottom": 56
      },
      "cornerPoints": [
        {
          "pointX": 36,
          "pointY": 41
        },
        {
          "pointX": 209,
          "pointY": 41
        },
        {
          "pointX": 209,
          "pointY": 56
        },
        {
          "pointX": 36,
          "pointY": 56
        }
      ],
      "lines": [
        {
          "text": "Firebase Docs Guides",
          "boundingBox": {
            "left": 36,
            "right": 209,
            "top": 41,
            "bottom": 56
          },
          "cornerPoints": [
            {
              "pointX": 36,
              "pointY": 41
            },
            {
              "pointX": 209,
              "pointY": 41
            },
            {
              "pointX": 209,
              "pointY": 56
            },
            {
              "pointX": 36,
              "pointY": 56
            }
          ]
        }
      ]
    }
  ]
}

TextRecognizer.stopRealTimeRecognition

Parameters
  • {function} success - callback function which takes a parameter data which will be invoked on success
  • {function} error - callback function which takes a parameter err which will be invoked on failure

Example:

window.ApperyioMLCordovaPlugin.TextRecognizer.stopRealTimeRecognition(successCallback, errorCallback)

Invocation example using toPromise helper method

let result = await this.$a.toPromise(window.ApperyioMLCordovaPlugin?.TextRecognizer?.recognizeText, {
        beginParameters: ['IMAGE BASE64'],
        endParameters: [{
            useBase64: true
        }]
    })

πŸ‘

YouTube Video: Text Recognition Plugin

You can also check this Appery.io YouTube video that shows how to create an app with the Text Recognition feature: