NAV
javascript

Introduction

The OCR module is an Fcloud service developed by Ftech. The module use of technology to distinguish printed or handwritten text characters inside digital images of physical documents, such as a scanned paper document. To integrate and use this service, you must use Fcloud's SDK. And here are instructions for integrating the SDK.

Authentication

To call the APIs, we will have to init the SDK with the parameters ClientID and SecretKey taken when you create the Application on CMS for partners according to the following instructions:

Server Integrator

After integrating the SDK, the Fcloud service supports server-server callbacks to help get request information as quickly and accurately as possible.

Web SDK

Android SDK

Install SDK Android

Setup gradle maven

allprojects {
    repositories {
        google()  
        mavenCentral()
        maven { url 'https://jitpack.io' } <- add this line
    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' } <- add this line
    }
}

Open file app/build.grade then add sdk

dependencies {
...
   implementation 'com.github.FTechMobile:focr-android:1.0.1'
}

Init in file Application

@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
    super.onCreate(savedInstanceState, persistentState);
    ...
    OCRManager.init(getApplicationContext());
}
override fun onCreate() {
  super.onCreate()
  ...
  OCRManager.init(applicationContext)
}

SDK Android Feature

Init

Param Type Description
appId String Application id
secretKey String IOE secret key
OCRManager.initGateway(appId, secretKey, new IInitGatewayCallback() {
  @Override
  public void onSuccess() {

  }

  @Override
  public void onFail(@Nullable AppException error) {

  }
});
OCRManager.initGateway(appId, secretKey, object : IInitGatewayCallback {
  override fun onSuccess() {

  }

  override fun onFail(error: AppException?) {

  }
})

Register callback

After registration, the SDK will return the corresponding status in the callback

Status Description
onStart Called at start OCR
onSuccess Called when return result
onFail Called when an error occurs in process
OCRManager.registerOCRCallback(new IOCRCallback() {
  @Override
  public void onStart() {

  }

  @Override
  public void onFail(@Nullable AppException error) {

  }

  @Override
  public void onSuccess(@NonNull OCRData result) {

  }
});
OCRManager.registerOCRCallback(object : IOCRCallback {
  override fun onStart() {

  }


  override fun onFail(error: AppException?) {

  }

  override fun onSuccess(result: OCRData) {

  })
})

Get config

OCRManager.getConfig(new IOCRConfigCallback() {
    @Override
    public void onSuccess(@NonNull List<OCRConfigData> listConfig) {

    }

    @Override
    public void onFail(@Nullable AppException error) {

    }
});
OCRManager.getConfig(object : IOCRConfigCallback {
    override fun onSuccess(listConfig: List<OCRConfigData>) {

    }

    override fun onFail(error: AppException?) {

    }
})

Start

//use file
OCRManager.startOCR(documentType, responseFormat, toMathMl, file); 
...
//use file path
OCRManager.startOCR(documentType, responseFormat, toMathMl, absoluteFilePath);
//use file
OCRManager.startOCR(documentType, responseFormat, toMathMl, file) 
...
 //use file path
OCRManager.startOCR(documentType, responseFormat, toMathMl, absoluteFilePath)

Export data

Param Description
requestId Request id
exportType Type export (OCRExportType.CSV, OCRExportType.EXCEL)
OCRManager.export(requestId, exportType, new IExportCallback() {
    @Override
    public void onSuccess(@NonNull String data) {

    }

    @Override
    public void onFail(@Nullable AppException error) {

    }
});
OCRManager.export(requestId, exportType, object : IExportCallback {
    override fun onSuccess(data: String) {

    }

    override fun onFail(error: AppException?) {

    }
})

UI Preview OCR data

<ai.ftech.focrsdk.sdk.FOCRView
    android:id="@+id/ocrView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Then set OCRData from onSuccess to view

ocrView.setData(ocrData)

IOS SDK

Install SDK IOS

[IOS] FOCR SDK Supports devices with Apple Neural Engine in iOS 14 and iPadOS 14 and requires a device with a TrueDepth camera on iOS 13 and iPadOS 13 and earlier

Add package dependencies

https://github.com/FTechMobile/focr-sdk-ios.git

SDK IOS Integration

Init

Param Type Description
appId String Application id
key String Secret key
 FtechOCRManager.instance().initSDK(appID: "103211", key: "dbfabc2ebf87889ec1e580e5de07b85e") {
           //Handle success
        } onFailure: { error in
            // Handle Failure
        }

SDK IOS Feature

Get config

FtechOCRManager.instance().getConfig { listConfig in
            //Handle success
        } onFailure: { error in
            //Handle Failure
        }

Start OCR

Param Type Description
file URL The URL should point to a resource that the OCR manager can access and read
config ConfigMode The exact type and values that this parameter can take would depend on the implementation of the OCR
FtechOCRManager.instance().startOCR(with: URL, config) { data in

        } onFailure: { error in
            //Handle Failure
        }

Export file

Param Type Description
requestID String Taken from CORData
fileType String Supports two formats csv, excel
FtechOCRManager.instance().export(with: requestID, fileType: String) { data in
            // Handle success
        } onFailure: { error in
            //Handle Failure
        }

UI Preview OCR data

Errors

The Kittn API uses the following error codes:

Error Code Meaning
400 Bad Request -- Your request is invalid.
401 Unauthorized -- Your API key is wrong.
403 Forbidden -- The kitten requested is hidden for administrators only.
404 Not Found -- The specified kitten could not be found.
405 Method Not Allowed -- You tried to access a kitten with an invalid method.
406 Not Acceptable -- You requested a format that isn't json.
429 Too Many Requests -- You're requesting too many kittens! Slow down!
500 Internal Server Error -- We had a problem with our server. Try again later.
503 Service Unavailable -- We're temporarily offline for maintenance. Please try again later.