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:
- Log in to CMS Partner with the username/password provided (https://fcloud-partner-cms.ftech.ai)
- Buy a service package
- Create App
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
- With Gradle v1.x - v5.x
Open
build.grade
file and addmaven
line like below
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } <- add this line
}
}
- With Gradle v6.x+
Open
setting.gradle
file and addmaven
line like below
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
- Java
@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
...
OCRManager.init(getApplicationContext());
}
- Kotlin
override fun onCreate() {
super.onCreate()
...
OCRManager.init(applicationContext)
}
SDK Android Feature
Init
Param | Type | Description |
---|---|---|
appId | String | Application id |
secretKey | String | IOE secret key |
- Java
OCRManager.initGateway(appId, secretKey, new IInitGatewayCallback() {
@Override
public void onSuccess() {
}
@Override
public void onFail(@Nullable AppException error) {
}
});
- Kotlin
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 |
- Java
OCRManager.registerOCRCallback(new IOCRCallback() {
@Override
public void onStart() {
}
@Override
public void onFail(@Nullable AppException error) {
}
@Override
public void onSuccess(@NonNull OCRData result) {
}
});
- Kotlin
OCRManager.registerOCRCallback(object : IOCRCallback {
override fun onStart() {
}
override fun onFail(error: AppException?) {
}
override fun onSuccess(result: OCRData) {
})
})
Get config
- Get list config used to ocr param
- When sucess, result is
listConfig
, it will be called ononSuccess()
in callback When fail, it will called on
onFail()
in callbackJava
OCRManager.getConfig(new IOCRConfigCallback() {
@Override
public void onSuccess(@NonNull List<OCRConfigData> listConfig) {
}
@Override
public void onFail(@Nullable AppException error) {
}
});
- Kotlin
OCRManager.getConfig(object : IOCRConfigCallback {
override fun onSuccess(listConfig: List<OCRConfigData>) {
}
override fun onFail(error: AppException?) {
}
})
Start
- Used to start OCR
- When successful start, it will be called on
onStart()
in callback - When have result
result
will be return ononSuccess()
in callback When fails, it will be processed at callback
onFail()
in callback.Java
//use file
OCRManager.startOCR(documentType, responseFormat, toMathMl, file);
...
//use file path
OCRManager.startOCR(documentType, responseFormat, toMathMl, absoluteFilePath);
- Kotlin
//use file
OCRManager.startOCR(documentType, responseFormat, toMathMl, file)
...
//use file path
OCRManager.startOCR(documentType, responseFormat, toMathMl, absoluteFilePath)
Export data
- Used to export data OCR to csv or excel file
- When export success
data
will be return ononSuccess()
in callback - When fails, it will be processed at callback
onFail()
in callback
Param | Description |
---|---|
requestId | Request id |
exportType | Type export (OCRExportType.CSV, OCRExportType.EXCEL) |
- Java
OCRManager.export(requestId, exportType, new IExportCallback() {
@Override
public void onSuccess(@NonNull String data) {
}
@Override
public void onFail(@Nullable AppException error) {
}
});
- Kotlin
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
- Get list config mode used to ocr param
- When sucess, result is
ConfigData
, it will be called ononSuccess()
in callback - When fail, it will called on
onFailure()
in callback
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
- Implement
FOCRViewController
with inputOCRData
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. |