Blinkid Android SDK ช่วยให้คุณสร้างประสบการณ์การขึ้นเครื่องที่ยอดเยี่ยมในแอพ Android ของคุณ
ด้วยการสแกนอย่างรวดเร็วเพียงครั้งเดียวผู้ใช้ของคุณจะสามารถดึงข้อมูลจากบัตรประจำตัวของพวกเขาหนังสือเดินทางใบขับขี่และรหัสอื่น ๆ ที่ออกโดยรัฐบาลอื่น ๆ
Blinkid คือ:
หากต้องการดูคุณสมบัติทั้งหมดเหล่านี้ในที่ทำงานดาวน์โหลดแอพสาธิตฟรีของเรา:
รู้สึกพร้อมที่จะแตกด้วยการบูรณาการ? ก่อนอื่นตรวจสอบให้แน่ใจว่าเราสนับสนุนประเภทเอกสารของคุณ➡รายการเต็ม จากนั้นปฏิบัติตามแนวทางด้านล่าง
UISettings )RecognizerRunnerFragment )RecognizerRunnerViewString (การแยกวิเคราะห์)BlinkIdUISettings และ BlinkIdOverlayControllerDocumentUISettingsLegacyDocumentVerificationUISettingsRecognizerRunner และ RecognizerRunnerViewRecognizer และ RecognizerBundleRecognizerRecognizerBundleRecognizer วัตถุระหว่างกิจกรรมlibc++_shared.soYes RecognizerRunnerFragment และตัวควบคุมการซ้อนทับกล้องในกิจกรรมของคุณภายในกิจกรรมของคุณ ใน build.gradle ของคุณเพิ่มที่เก็บ Blinkid Maven ในรายการที่เก็บ
repositories {
maven { url 'https://maven.microblink.com' }
}
เพิ่ม Blinkid เป็นการพึ่งพาและตรวจสอบให้แน่ใจว่าถูกตั้ง transitive เป็น TRUE
dependencies {
implementation('com.microblink:blinkid:6.12.0@aar') {
transitive = true
}
}
Android Studio ควรนำเข้า Javadoc จากการพึ่งพา Maven โดยอัตโนมัติ หากไม่ได้เกิดขึ้นคุณสามารถทำได้ด้วยตนเองโดยทำตามขั้นตอนเหล่านี้:
External Libraries (โดยปกติจะเป็นรายการสุดท้ายในมุมมองโครงการ)blinkid-6.12.0 คลิกขวาที่มันและเลือก Library Properties...Library Properties จะปรากฏขึ้น+ ที่มุมล่างซ้ายของหน้าต่าง (ปุ่มที่มี + กับลูกโลกน้อย)https://blinkid.github.io/blinkid-android/OK จำเป็นต้องใช้คีย์ใบอนุญาตที่ถูกต้องเพื่อเริ่มต้นการสแกน คุณสามารถขอรหัสใบอนุญาตทดลองใช้ฟรีหลังจากที่คุณลงทะเบียนที่ MicroBlink Developer Hub ใบอนุญาตถูกผูกไว้กับชื่อแพ็คเกจของแอปของคุณดังนั้นโปรดตรวจสอบให้แน่ใจว่าคุณป้อนชื่อแพ็คเกจที่ถูกต้องเมื่อถูกถาม
ดาวน์โหลดไฟล์ใบอนุญาตของคุณและใส่ไว้ในโฟลเดอร์ สินทรัพย์ ของแอปพลิเคชันของคุณ ตรวจสอบให้แน่ใจว่าได้ตั้งค่ารหัสใบอนุญาตก่อนใช้คลาสอื่น ๆ จาก SDK มิฉะนั้นคุณจะได้รับข้อยกเว้นรันไทม์
เราขอแนะนำให้คุณขยายคลาสแอปพลิเคชัน Android และตั้งค่าใบอนุญาตในการโทรกลับ onCreate เช่นนี้:
public class MyApplication extends Application {
@ Override
public void onCreate () {
MicroblinkSDK . setLicenseFile ( "path/to/license/file/within/assets/dir" , this );
}
} public class MyApplication : Application () {
override fun onCreate () {
MicroblinkSDK .setLicenseFile( " path/to/license/file/within/assets/dir " , this )
}
} ในกิจกรรมหลักของคุณกำหนดและสร้างกิจกรรม ActivityResultLauncher โดยการเอาชนะวิธีการ onActivityResult ทั้ง OneSideDocumentScan และ TwoSideDocumentScan สามารถใช้แทนกันได้โดยไม่มีความแตกต่างในการใช้งาน ความแตกต่างของฟังก์ชั่นเพียงอย่างเดียวคือ OneSideDocumentScan คือการสแกนเพียงด้านเดียวของเอกสารและ TwoSideDocumentScan สแกนมากกว่าหนึ่งด้านของเอกสาร
ActivityResultLauncher < Void > resultLauncher = registerForActivityResult (
new TwoSideDocumentScan (),
twoSideScanResult -> {
ResultStatus resultScanStatus = twoSideScanResult . getResultStatus ();
if ( resultScanStatus == ResultStatus . FINISHED ) {
// code after a successful scan
// use result.getResult() for fetching results, for example:
String firstName = twoSideScanResult . getResult (). getFirstName (). value ();
} else if ( resultScanStatus == ResultStatus . CANCELLED ) {
// code after a cancelled scan
} else if ( resultScanStatus == ResultStatus . EXCEPTION ) {
// code after a failed scan
}
}
); private val resultLauncher =
registerForActivityResult( TwoSideDocumentScan ()) { twoSideScanResult : TwoSideScanResult ->
when (twoSideScanResult.resultStatus) {
ResultStatus . FINISHED -> {
// code after a successful scan
// use twoSideScanResult.result for fetching results, for example:
val firstName = twoSideScanResult.result?.firstName?.value()
}
ResultStatus . CANCELLED -> {
// code after a cancelled scan
}
ResultStatus . EXCEPTION -> {
// code after a failed scan
}
else -> {}
}
}@Composable
fun createLauncher (): ActivityResultLauncher < Void ?> {
return rememberLauncherForActivityResult( TwoSideDocumentScan ()) { twoSideScanResult : TwoSideScanResult ->
when (twoSideScanResult.resultStatus) {
ResultStatus . FINISHED -> {
// code after a successful scan
// use twoSideScanResult.result for fetching results, for example:
val firstName = twoSideScanResult.result?.firstName?.value()
}
ResultStatus . CANCELLED -> {
// code after a cancelled scan
}
ResultStatus . EXCEPTION -> {
// code after a failed scan
}
else -> {}
}
}
} หลังจากการสแกน result ซึ่งไม่ว่าจะเป็นอินสแตน OneSideScanResult หรือ TwoSideScanResult Object จะได้รับการอัปเดต คุณสามารถกำหนดสิ่งที่เกิดขึ้นกับข้อมูลในการแทนที่ของฟังก์ชัน onActivityResult (รหัส Kotlin ยังแทนที่ฟังก์ชั่นนี้ แต่โดยนัย) ผลลัพธ์สามารถเข้าถึงได้ในวิธี twoSideScanResult.getResult() ( twoSideScanResult.result ใน kotlin)
เริ่มกระบวนการสแกนโดยการเรียก ActivityResultObject และการโทร ActivityResultLauncher.launch :
// method within MyActivity from previous step
public void startScanning () {
// Start scanning
resultLauncher . launch ( null );
} // method within MyActivity from previous step
public fun startScanning () {
// Start scanning
resultLauncher.launch()
} // within @Composable function or setContent block
val resultLauncher = createLauncher()
resultLauncher.launch() ผลลัพธ์จะมีอยู่ในการโทรกลับซึ่งกำหนดไว้ใน ActivityResultObject ซึ่งกำหนดไว้ในขั้นตอนก่อนหน้า
Blinkid ต้องการ Android API ระดับ 21 หรือใหม่กว่า
ความละเอียดดูวิดีโอวิดีโอยังมีความสำคัญเช่นกัน เพื่อที่จะทำการสแกนที่ประสบความสำเร็จความละเอียดดูตัวอย่างกล้องจะต้องมีอย่างน้อย 720p โปรดทราบว่าความละเอียดดูตัวอย่างกล้องไม่เหมือนกับความละเอียดการบันทึกวิดีโอ
Blinkid แจกจ่ายด้วย ARMV7 และ ARM64 Library Binaries
Blinkid เป็นไลบรารีดั้งเดิมที่เขียนด้วย C ++ และพร้อมใช้งานสำหรับหลายแพลตฟอร์ม ด้วยเหตุนี้ Blinkid จึงไม่สามารถทำงานกับอุปกรณ์ที่มีสถาปัตยกรรมฮาร์ดแวร์ที่คลุมเครือได้ เราได้รวบรวมรหัสดั้งเดิม ของ Blinkid สำหรับ Android Abis ที่ได้รับความนิยมมากที่สุดเท่านั้น
ก่อนที่จะตั้งค่ารหัสลิขสิทธิ์คุณควรตรวจสอบว่ารองรับ Blinkid บนอุปกรณ์ปัจจุบัน (ดูส่วนถัดไป: ตรวจสอบความเข้ากันได้ ) การพยายามเรียกใช้วิธีใด ๆ จาก SDK ที่ต้องอาศัยรหัสดั้งเดิมเช่นการตรวจสอบใบอนุญาตบนอุปกรณ์ที่มีสถาปัตยกรรม CPU ที่ไม่ได้รับการสนับสนุนจะทำให้แอปของคุณพัง
หากคุณกำลังรวมไลบรารี Blinkid กับไลบรารีอื่น ๆ ที่มีรหัสเนทีฟลงในแอปพลิเคชันของคุณตรวจสอบให้แน่ใจว่าคุณจับคู่สถาปัตยกรรมของไลบรารีดั้งเดิมทั้งหมด
สำหรับข้อมูลเพิ่มเติมดูส่วนการพิจารณาสถาปัตยกรรมของโปรเซสเซอร์
นี่คือวิธีที่คุณสามารถตรวจสอบได้ว่ารองรับ Blinkid บนอุปกรณ์:
// check if BlinkID is supported on the device,
RecognizerCompatibilityStatus status = RecognizerCompatibility . getRecognizerCompatibilityStatus ( this );
if ( status == RecognizerCompatibilityStatus . RECOGNIZER_SUPPORTED ) {
Toast . makeText ( this , "BlinkID is supported!" , Toast . LENGTH_LONG ). show ();
} else if ( status == RecognizerCompatibilityStatus . NO_CAMERA ) {
Toast . makeText ( this , "BlinkID is supported only via Direct API!" , Toast . LENGTH_LONG ). show ();
} else if ( status == RecognizerCompatibilityStatus . PROCESSOR_ARCHITECTURE_NOT_SUPPORTED ) {
Toast . makeText ( this , "BlinkID is not supported on current processor architecture!" , Toast . LENGTH_LONG ). show ();
} else {
Toast . makeText ( this , "BlinkID is not supported! Reason: " + status . name (), Toast . LENGTH_LONG ). show ();
} // check if _BlinkID_ is supported on the device,
when ( val status = RecognizerCompatibility .getRecognizerCompatibilityStatus( this )) {
RecognizerCompatibilityStatus . RECOGNIZER_SUPPORTED -> {
Toast .makeText( this , " BlinkID is supported! " , Toast . LENGTH_LONG ).show()
}
RecognizerCompatibilityStatus . NO_CAMERA -> {
Toast .makeText( this , " BlinkID is supported only via Direct API! " , Toast . LENGTH_LONG ).show()
}
RecognizerCompatibilityStatus . PROCESSOR_ARCHITECTURE_NOT_SUPPORTED -> {
Toast .makeText( this , " BlinkID is not supported on current processor architecture! " , Toast . LENGTH_LONG ).show()
}
else -> {
Toast .makeText( this , " BlinkID is not supported! Reason: " + status.name, Toast . LENGTH_LONG ).show()
}
}ผู้จดจำบางคนต้องการกล้องที่มีโฟกัสอัตโนมัติ หากคุณลองใช้กับอุปกรณ์ที่ไม่รองรับออโต้โฟกัสคุณจะได้รับข้อผิดพลาด เพื่อป้องกันไม่ให้คุณสามารถตรวจสอบว่าผู้รู้จำได้ว่าต้องใช้โฟกัสอัตโนมัติหรือไม่โดยเรียกใช้วิธีการที่ต้องการ
หากคุณมีอาร์เรย์ของผู้จดทะเบียนอยู่แล้วคุณสามารถกรองผู้จดทะเบียนที่ต้องการโฟกัสอัตโนมัติจากอาร์เรย์โดยใช้รหัสตัวอย่างต่อไปนี้:
Recognizer [] recArray = ...;
if (! RecognizerCompatibility . cameraHasAutofocus ( CameraType . CAMERA_BACKFACE , this )) {
recArray = RecognizerUtils . filterOutRecognizersThatRequireAutofocus ( recArray );
} var recArray : Array < Recognizer > = .. .
if ( ! RecognizerCompatibility .cameraHasAutofocus( CameraType . CAMERA_BACKFACE , this )) {
recArray = RecognizerUtils .filterOutRecognizersThatRequireAutofocus(recArray)
}คุณสามารถรวม Blinkid ลงในแอพของคุณได้ในห้าวิธีที่แตกต่างกันขึ้นอยู่กับกรณีการใช้งานและความต้องการในการปรับแต่ง:
OneSideDocumentScan และ TwoSideDocumentScan ) - SDK จัดการทุกอย่างและคุณเพียงแค่เริ่มกิจกรรมในตัวและจัดการผลลัพธ์ในตัวของเราไม่มีตัวเลือกการปรับแต่งUISettings )-SDK จัดการงานส่วนใหญ่คุณเพียงแค่ต้องกำหนดตัวอักษรการตั้งค่าเริ่มต้นกิจกรรมในตัวและผลลัพธ์ในตัวของเราตัวเลือกการปรับแต่งมี จำกัดRecognizerRunnerFragment )-นำการสแกน UX กลับมาใช้ใหม่จากกิจกรรมในตัวของเราในกิจกรรมของคุณเองRecognizerRunnerView ) - SDK จัดการการจัดการกล้องในขณะที่คุณต้องใช้การสแกน UX ที่กำหนดเองอย่างสมบูรณ์RecognizerRunner ) - SKD จัดการการรับรู้เท่านั้นในขณะที่คุณต้องให้ภาพไม่ว่าจะจากกล้องหรือจากไฟล์ OneSideDocumentScan และ TwoSideDocumentScan ) OneSideDocumentScan และ TwoSideDocumentScan เป็นคลาสที่มีคำจำกัดความการตั้งค่าที่จำเป็นทั้งหมดเพื่อเริ่มกิจกรรมการสแกนในตัวของ SDK อย่างรวดเร็ว ช่วยให้ผู้ใช้สามารถข้ามขั้นตอนการตั้งค่าทั้งหมดเช่น UISettings และ RecognizerBundle และไปสแกนโดยตรง
ดังที่แสดงในการสแกนครั้งแรกของคุณจะต้องใช้คำจำกัดความของผู้ฟังผลลัพธ์เพื่อกำหนดสิ่งที่จะเกิดขึ้นกับผลลัพธ์การสแกนและเรียกฟังก์ชันการสแกนจริง
UISettings ) UISettings เป็นคลาสที่มีการตั้งค่าที่จำเป็นทั้งหมดสำหรับกิจกรรมสแกนในตัวของ SDK มันกำหนดค่าพฤติกรรมการสแกนกิจกรรมสตริงไอคอนและองค์ประกอบ UI อื่น ๆ คุณควรใช้ ActivityRunner เพื่อเริ่มกิจกรรมการสแกนที่กำหนดค่าโดย UISettings ซึ่งแสดงในตัวอย่างด้านล่าง
เราให้บริการชั้นเรียน UISettings หลายคลาสที่เชี่ยวชาญสำหรับสถานการณ์การสแกนที่แตกต่างกัน วัตถุ UISettings แต่ละชิ้นมีคุณสมบัติที่สามารถเปลี่ยนแปลงได้ผ่านวิธีการตั้งค่าที่เหมาะสม ตัวอย่างเช่นคุณสามารถปรับแต่งการตั้งค่ากล้องด้วย setCameraSettings Metod
คลาส UISettings ทั้งหมดที่มีอยู่มีการระบุไว้ที่นี่
ในกิจกรรมหลักของคุณสร้างวัตถุผู้จำแนกที่จะทำการจดจำภาพกำหนดค่าและใส่ลงในวัตถุ RecognizerBundle คุณสามารถดูข้อมูลเพิ่มเติมเกี่ยวกับผู้จดทะเบียนและ RecognizerBundle ได้ที่นี่
ตัวอย่างเช่นในการสแกนเอกสารที่รองรับกำหนดค่าผู้รู้จำของคุณเช่นนี้:
public class MyActivity extends Activity {
private BlinkIdMultiSideRecognizer mRecognizer ;
private RecognizerBundle mRecognizerBundle ;
@ Override
protected void onCreate ( Bundle bundle ) {
super . onCreate ( bundle );
// setup views, as you would normally do in onCreate callback
// create BlinkIdMultiSideRecognizer
mRecognizer = new BlinkIdMultiSideRecognizer ();
// bundle recognizers into RecognizerBundle
mRecognizerBundle = new RecognizerBundle ( mRecognizer );
}
} public class MyActivity : Activity () {
private lateinit var mRecognizer : BlinkIdMultiSideRecognizer
private lateinit var mRecognizerBundle : RecognizerBundle
override fun onCreate ( bundle : Bundle ) {
// setup views, as you would normally do in onCreate callback
// create BlinkIdMultiSideRecognizer
mRecognizer = BlinkIdMultiSideRecognizer ()
// build recognizers into RecognizerBundle
mRecognizerBundle = RecognizerBundle (mRecognizer)
}
} เริ่มกระบวนการรับรู้โดยการสร้าง BlinkIdUISettings และการโทรกิจกรรม ActivityRunner.startActivityForResult :
// method within MyActivity from previous step
public void startScanning () {
// Settings for BlinkIdActivity
BlinkIdUISettings settings = new BlinkIdUISettings ( mRecognizerBundle );
// tweak settings as you wish
// Start activity
ActivityRunner . startActivityForResult ( this , MY_REQUEST_CODE , settings );
} // method within MyActivity from previous step
public fun startScanning () {
// Settings for BlinkIdActivity
val settings = BlinkIdUISettings (mRecognizerBundle)
// tweak settings as you wish
// Start activity
ActivityRunner .startActivityForResult( this , MY_REQUEST_CODE , settings)
} onActivityResult จะถูกเรียกในกิจกรรมของคุณหลังจากการสแกนเสร็จสิ้นที่นี่คุณสามารถรับผลการสแกนได้
@ Override
protected void onActivityResult ( int requestCode , int resultCode , Intent data ) {
super . onActivityResult ( requestCode , resultCode , data );
if ( requestCode == MY_REQUEST_CODE ) {
if ( resultCode == Activity . RESULT_OK && data != null ) {
// load the data into all recognizers bundled within your RecognizerBundle
mRecognizerBundle . loadFromIntent ( data );
// now every recognizer object that was bundled within RecognizerBundle
// has been updated with results obtained during scanning session
// you can get the result by invoking getResult on recognizer
BlinkIdMultiSideRecognizer . Result result = mRecognizer . getResult ();
if ( result . getResultState () == Recognizer . Result . State . Valid ) {
// result is valid, you can use it however you wish
}
}
}
} override protected fun onActivityResult ( requestCode : Int , resultCode : Int , data : Intent ) {
super .onActivityResult(requestCode, resultCode, data);
if (requestCode == MY_REQUEST_CODE ) {
if (resultCode == Activity . RESULT_OK && data != null ) {
// load the data into all recognizers bundled within your RecognizerBundle
mRecognizerBundle.loadFromIntent(data)
// now every recognizer object that was bundled within RecognizerBundle
// has been updated with results obtained during scanning session
// you can get the result by invoking getResult on recognizer
val result = mRecognizer.result
if (result.resultState == Recognizer . Result . State . Valid ) {
// result is valid, you can use it however you wish
}
}
}
} สำหรับข้อมูลเพิ่มเติมเกี่ยวกับผู้จดทะเบียนและ RecognizerBundle มีอยู่ให้ดูที่ Recognizbundle และผู้จดจำที่มีอยู่
RecognizerRunnerFragment ) หากคุณต้องการนำกิจกรรม UX ของเรากลับมาใช้ใหม่ภายในกิจกรรมของคุณเองให้ใช้ RecognizerRunnerFragment กิจกรรมที่จะโฮสต์ RecognizerRunnerFragment จะต้องใช้อินเทอร์เฟซ ScanningOverlayBinder การพยายามเพิ่ม RecognizerRunnerFragment ให้กับกิจกรรมที่ไม่ได้ใช้อินเทอร์เฟซนั้นจะส่งผลให้ ClassCastException
ScanningOverlayBinder มีหน้าที่รับผิดชอบในการส่ง non-null การใช้งาน ScanningOverlay - คลาสที่จะจัดการ UI ที่ด้านบนของ RecognizerRunnerFragment ไม่แนะนำให้สร้างการใช้งาน ScanningOverlay ของคุณเองใช้หนึ่งในการใช้งานของเราที่ระบุไว้ที่นี่แทน
นี่คือตัวอย่างขั้นต่ำสำหรับกิจกรรมที่โฮสต์ RecognizerRunnerFragment :
public class MyActivity extends AppCompatActivity implements RecognizerRunnerFragment . ScanningOverlayBinder {
private BlinkIdMultiSideRecognizer mRecognizer ;
private RecognizerBundle mRecognizerBundle ;
private BlinkIdOverlayController mScanOverlay ;
private RecognizerRunnerFragment mRecognizerRunnerFragment ;
@ Override
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate ();
setContentView ( R . layout . activity_my_activity );
mScanOverlay = createOverlay ();
if ( null == savedInstanceState ) {
// create fragment transaction to replace R.id.recognizer_runner_view_container with RecognizerRunnerFragment
mRecognizerRunnerFragment = new RecognizerRunnerFragment ();
FragmentTransaction fragmentTransaction = getSupportFragmentManager (). beginTransaction ();
fragmentTransaction . replace ( R . id . recognizer_runner_view_container , mRecognizerRunnerFragment );
fragmentTransaction . commit ();
} else {
// obtain reference to fragment restored by Android within super.onCreate() call
mRecognizerRunnerFragment = ( RecognizerRunnerFragment ) getSupportFragmentManager (). findFragmentById ( R . id . recognizer_runner_view_container );
}
}
@ Override
@ NonNull
public ScanningOverlay getScanningOverlay () {
return mScanOverlay ;
}
private BlinkIdOverlayController createOverlay () {
// create BlinkIdMultiSideRecognizer
mRecognizer = new BlinkIdMultiSideRecognizer ();
// bundle recognizers into RecognizerBundle
mRecognizerBundle = new RecognizerBundle ( mRecognizer );
BlinkIdUISettings settings = new BlinkIdUISettings ( mRecognizerBundle );
return settings . createOverlayController ( this , mScanResultListener );
}
private final ScanResultListener mScanResultListener = new ScanResultListener () {
@ Override
public void onScanningDone ( @ NonNull RecognitionSuccessType recognitionSuccessType ) {
// pause scanning to prevent new results while fragment is being removed
mRecognizerRunnerFragment . getRecognizerRunnerView (). pauseScanning ();
// now you can remove the RecognizerRunnerFragment with new fragment transaction
// and use result within mRecognizer safely without the need for making a copy of it
// if not paused, as soon as this method ends, RecognizerRunnerFragments continues
// scanning. Note that this can happen even if you created fragment transaction for
// removal of RecognizerRunnerFragment - in the time between end of this method
// and beginning of execution of the transaction. So to ensure result within mRecognizer
// does not get mutated, ensure calling pauseScanning() as shown above.
}
@ Override
public void onUnrecoverableError ( @ NonNull Throwable throwable ) {
}
};
} package com.microblink.blinkid
class MainActivity : AppCompatActivity (), RecognizerRunnerFragment.ScanningOverlayBinder {
private lateinit var mRecognizer : BlinkIdMultiSideRecognizer
private lateinit var mRecognizerRunnerFragment : RecognizerRunnerFragment
private lateinit var mRecognizerBundle : RecognizerBundle
private lateinit var mScanOverlay : BlinkIdOverlayController
override fun onCreate ( savedInstanceState : Bundle ? ) {
super .onCreate(savedInstanceState)
if ( ! ::mScanOverlay.isInitialized) {
mScanOverlay = createOverlayController()
}
setContent {
this . run {
// viewBinding has to be set to 'true' in buildFeatures block of the build.gradle file
AndroidViewBinding ( RecognizerRunnerLayoutBinding ::inflate) {
mRecognizerRunnerFragment =
fragmentContainerView.getFragment< RecognizerRunnerFragment >()
}
}
}
}
override fun getScanningOverlay (): ScanningOverlay {
return mScanOverlay
}
private fun createOverlay (): BlinkIdOverlayController {
// create BlinkIdMultiSideRecognizer
val mRecognizer = BlinkIdMultiSideRecognizer ()
// bundle recognizers into RecognizerBundle
mRecognizerBundle = RecognizerBundle (mRecognizer)
val settings = BlinkIdUISettings (mRecognizerBundle)
return settings.createOverlayController( this , mScanResultListener)
}
private val mScanResultListener : ScanResultListener = object : ScanResultListener {
override fun onScanningDone ( p0 : RecognitionSuccessType ) {
// pause scanning to prevent new results while fragment is being removed
mRecognizerRunnerFragment !! .recognizerRunnerView !! .pauseScanning()
// now you can remove the RecognizerRunnerFragment with new fragment transaction
// and use result within mRecognizer safely without the need for making a copy of it
// if not paused, as soon as this method ends, RecognizerRunnerFragments continues
// scanning. Note that this can happen even if you created fragment transaction for
// removal of RecognizerRunnerFragment - in the time between end of this method
// and beginning of execution of the transaction. So to ensure result within mRecognizer
// does not get mutated, ensure calling pauseScanning() as shown above.
}
override fun onUnrecoverableError ( p0 : Throwable ) {
}
}
} โปรดดูตัวอย่างแอพที่มาพร้อมกับ SDK สำหรับตัวอย่างที่มีรายละเอียดเพิ่มเติมและตรวจสอบให้แน่ใจว่าการวางแนวกิจกรรมของโฮสต์ของคุณถูกตั้งค่าเป็น nosensor หรือเปิดใช้งานการกำหนดค่าการเปิดใช้งาน (เช่นไม่เริ่มต้นใหม่เมื่อการเปลี่ยนแปลงการกำหนดค่าเกิดขึ้น) สำหรับข้อมูลเพิ่มเติมให้ตรวจสอบส่วนการวางแนวสแกน
RecognizerRunnerViewส่วนนี้กล่าวถึงวิธีการฝัง RecreyizerRunnerView ลงในกิจกรรมการสแกนของคุณและทำการสแกน
RecognizerRunnerView เป็นฟิลด์สมาชิกในกิจกรรมของคุณ สิ่งนี้จำเป็นเพราะคุณจะต้องผ่านกิจกรรมวงจรชีวิตของกิจกรรมทั้งหมดไปยัง RecognizerRunnerViewportrait หรือ landscape การตั้งค่า sensor เป็นการวางแนวของกิจกรรมการสแกนจะทำให้เกิดกิจกรรมรีสตาร์ทอย่างเต็มรูปแบบเมื่อใดก็ตามที่การเปลี่ยนแปลงการวางแนวของอุปกรณ์ สิ่งนี้จะให้ประสบการณ์ผู้ใช้ที่แย่มากเพราะทั้งกล้องและไลบรารีพื้นเมือง Blinkid จะต้องเริ่มต้นใหม่ทุกครั้ง มีมาตรการต่อต้านพฤติกรรมนี้ที่กล่าวถึงในภายหลังcreate onCreate ของกิจกรรมของคุณสร้าง RecognizerRunnerView ใหม่ตั้งค่า RecognizerBundle ที่มีผู้จดจำที่จะใช้โดยมุมมองกำหนด cameraEventsListener ที่จะจัดการเหตุการณ์กล้องบังคับกำหนด ScanResultListener ที่จะได้รับการโทร หลังจากนั้นเพิ่มมุมมองของคุณที่ควรจัดวางที่ด้านบนของมุมมองกล้องsetLifecycle เพื่อเปิดใช้งานการจัดการกิจกรรม Lifeceycle อัตโนมัติ นี่คือตัวอย่างขั้นต่ำของการรวมของ RecognizerRunnerView เป็นมุมมองเดียวในกิจกรรมของคุณ:
public class MyScanActivity extends AppCompatActivity {
private static final int PERMISSION_CAMERA_REQUEST_CODE = 42 ;
private RecognizerRunnerView mRecognizerRunnerView ;
private BlinkIdMultiSideRecognizer mRecognizer ;
private RecognizerBundle mRecognizerBundle ;
@ Override
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
// create BlinkIdMultiSideRecognizer
mRecognizer = new BlinkIdMultiSideRecognizer ();
// bundle recognizers into RecognizerBundle
mRecognizerBundle = new RecognizerBundle ( mRecognizer );
// create RecognizerRunnerView
mRecognizerRunnerView = new RecognizerRunnerView ( this );
// set lifecycle to automatically call recognizer runner view lifecycle methods
mRecognizerRunnerView . setLifecycle ( getLifecycle ());
// associate RecognizerBundle with RecognizerRunnerView
mRecognizerRunnerView . setRecognizerBundle ( mRecognizerBundle );
// scan result listener will be notified when scanning is complete
mRecognizerRunnerView . setScanResultListener ( mScanResultListener );
// camera events listener will be notified about camera lifecycle and errors
mRecognizerRunnerView . setCameraEventsListener ( mCameraEventsListener );
setContentView ( mRecognizerRunnerView );
}
@ Override
public void onConfigurationChanged ( Configuration newConfig ) {
super . onConfigurationChanged ( newConfig );
// changeConfiguration is not handled by lifecycle events so call it manually
mRecognizerRunnerView . changeConfiguration ( newConfig );
}
private final CameraEventsListener mCameraEventsListener = new CameraEventsListener () {
@ Override
public void onCameraPreviewStarted () {
// this method is from CameraEventsListener and will be called when camera preview starts
}
@ Override
public void onCameraPreviewStopped () {
// this method is from CameraEventsListener and will be called when camera preview stops
}
@ Override
public void onError ( Throwable exc ) {
/**
* This method is from CameraEventsListener and will be called when
* opening of camera resulted in exception or recognition process
* encountered an error. The error details will be given in exc
* parameter.
*/
}
@ Override
@ TargetApi ( 23 )
public void onCameraPermissionDenied () {
/**
* Called in Android 6.0 and newer if camera permission is not given
* by user. You should request permission from user to access camera.
*/
requestPermissions ( new String []{ Manifest . permission . CAMERA }, PERMISSION_CAMERA_REQUEST_CODE );
/**
* Please note that user might have not given permission to use
* camera. In that case, you have to explain to user that without
* camera permissions scanning will not work.
* For more information about requesting permissions at runtime, check
* this article:
* https://developer.android.com/training/permissions/requesting.html
*/
}
@ Override
public void onAutofocusFailed () {
/**
* This method is from CameraEventsListener will be called when camera focusing has failed.
* Camera manager usually tries different focusing strategies and this method is called when all
* those strategies fail to indicate that either object on which camera is being focused is too
* close or ambient light conditions are poor.
*/
}
@ Override
public void onAutofocusStarted ( Rect [] areas ) {
/**
* This method is from CameraEventsListener and will be called when camera focusing has started.
* You can utilize this method to draw focusing animation on UI.
* Areas parameter is array of rectangles where focus is being measured.
* It can be null on devices that do not support fine-grained camera control.
*/
}
@ Override
public void onAutofocusStopped ( Rect [] areas ) {
/**
* This method is from CameraEventsListener and will be called when camera focusing has stopped.
* You can utilize this method to remove focusing animation on UI.
* Areas parameter is array of rectangles where focus is being measured.
* It can be null on devices that do not support fine-grained camera control.
*/
}
};
private final ScanResultListener mScanResultListener = new ScanResultListener () {
@ Override
public void onScanningDone ( @ NonNull RecognitionSuccessType recognitionSuccessType ) {
// this method is from ScanResultListener and will be called when scanning completes
// you can obtain scanning result by calling getResult on each
// recognizer that you bundled into RecognizerBundle.
// for example:
BlinkIdMultiSideRecognizer . Result result = mRecognizer . getResult ();
if ( result . getResultState () == Recognizer . Result . State . Valid ) {
// result is valid, you can use it however you wish
}
// Note that mRecognizer is stateful object and that as soon as
// scanning either resumes or its state is reset
// the result object within mRecognizer will be changed. If you
// need to create a immutable copy of the result, you can do that
// by calling clone() on it, for example:
BlinkIdMultiSideRecognizer . Result immutableCopy = result . clone ();
// After this method ends, scanning will be resumed and recognition
// state will be retained. If you want to prevent that, then
// you should call:
mRecognizerRunnerView . resetRecognitionState ();
// Note that reseting recognition state will clear internal result
// objects of all recognizers that are bundled in RecognizerBundle
// associated with RecognizerRunnerView.
// If you want to pause scanning to prevent receiving recognition
// results or mutating result, you should call:
mRecognizerRunnerView . pauseScanning ();
// if scanning is paused at the end of this method, it is guaranteed
// that result within mRecognizer will not be mutated, therefore you
// can avoid creating a copy as described above
// After scanning is paused, you will have to resume it with:
mRecognizerRunnerView . resumeScanning ( true );
// boolean in resumeScanning method indicates whether recognition
// state should be automatically reset when resuming scanning - this
// includes clearing result of mRecognizer
}
};
} หากคุณสมบัติ screenOrientation ของกิจกรรมใน AndroidManifest.xml ถูกตั้งค่าเป็น sensor fullSensor หรือที่คล้ายกันกิจกรรมจะเริ่มต้นใหม่ทุกครั้งที่อุปกรณ์เปลี่ยนทิศทางจากแนวตั้งไปเป็นภูมิทัศน์และในทางกลับกัน ในขณะที่การเริ่มกิจกรรมใหม่จะมีการเรียกใช้วิธี onPause , onStop และ onDestroy และกิจกรรมใหม่จะถูกสร้างขึ้นใหม่ นี่เป็นปัญหาที่อาจเกิดขึ้นสำหรับกิจกรรมการสแกนเนื่องจากในวงจรชีวิตของมันจะควบคุมทั้งกล้องและไลบรารีพื้นเมือง - การรีสตาร์ทกิจกรรมจะกระตุ้นทั้งการรีสตาร์ทของกล้องและไลบรารีพื้นเมือง นี่เป็นปัญหาเนื่องจากการเปลี่ยนทิศทางจากแนวนอนเป็นแนวตั้งและในทางกลับกันจะช้ามากดังนั้นจึงทำให้ประสบการณ์การใช้งานลดลง เราไม่แนะนำการตั้งค่าดังกล่าว
สำหรับเรื่องนั้นเราขอแนะนำให้ตั้งกิจกรรมการสแกนของคุณให้เป็นโหมด portrait หรือโหมด landscape และจัดการการวางแนวอุปกรณ์เปลี่ยนด้วยตนเอง เพื่อช่วยให้คุณได้รับสิ่งนี้ RecognizerRunnerView สนับสนุนการเพิ่มมุมมองเด็กลงไปที่มันจะหมุนโดยไม่คำนึงถึง screenOrientation ของกิจกรรม คุณเพิ่มมุมมองที่คุณต้องการหมุน (เช่นมุมมองที่มีปุ่มข้อความสถานะ ฯลฯ ) เพื่อ RecognizerRunnerView ถึงวิธีการ AddChildView พารามิเตอร์ที่สองของวิธีการคือบูลีนที่กำหนดว่ามุมมองที่คุณกำลังเพิ่มจะหมุนด้วยอุปกรณ์หรือไม่ ในการกำหนดทิศทางที่ได้รับอนุญาตให้ใช้อินเทอร์เฟซ OrientAllowDListener และเพิ่มลงใน RecognizerRunnerView ด้วยวิธีการ setOrientationAllowedListener นี่คือวิธีที่แนะนำในการหมุนของกล้องซ้อนทับ
อย่างไรก็ตามหากคุณต้องการตั้งค่าคุณสมบัติ screenOrientation เป็น sensor หรือคล้ายกันและต้องการ Android เพื่อจัดการกับการเปลี่ยนแปลงการวางแนวของกิจกรรมการสแกนของคุณเราขอแนะนำให้ตั้งค่าคุณสมบัติ configChanges ของกิจกรรมของคุณเพื่อ orientation|screenSize สิ่งนี้จะบอก Android เพื่อไม่ให้รีสตาร์ทกิจกรรมของคุณเมื่อมีการเปลี่ยนแปลงการวางแนวของอุปกรณ์ แต่วิธี onConfigurationChanged ของกิจกรรมจะถูกเรียกเพื่อให้กิจกรรมสามารถแจ้งให้ทราบถึงการเปลี่ยนแปลงการกำหนดค่า ในการใช้วิธีการนี้คุณควรเรียกใช้วิธี changeConfiguration ของ RecognizerView เพื่อให้สามารถปรับมุมมองพื้นผิวของกล้องและเด็กให้เข้ากับการกำหนดค่าใหม่
ส่วนนี้จะอธิบายวิธีการใช้ API โดยตรงเพื่อรับรู้บิตแมป Android โดยไม่จำเป็นต้องใช้กล้อง คุณสามารถใช้ API โดยตรงได้ทุกที่จากแอปพลิเคชันของคุณไม่ใช่แค่จากกิจกรรม
ประสิทธิภาพการจดจำภาพสูงขึ้นอยู่กับคุณภาพของภาพอินพุต เมื่อใช้การจัดการกล้องของเรา (สแกนจากกล้อง) เราพยายามอย่างเต็มที่เพื่อให้ได้เฟรมกล้องด้วยคุณภาพที่ดีที่สุดสำหรับอุปกรณ์ที่ใช้แล้ว ในทางกลับกันเมื่อใช้ API โดยตรงคุณจะต้องให้ภาพคุณภาพสูงโดยไม่ต้องเบลอและแสงจ้าเพื่อการจดจำที่ประสบความสำเร็จ
Bitmaps Android ยังคง ได้รับจากแกลเลอรี่ ใช้ RecoreBitMap หรือ RecorebitMapwithRecognizersImages วิดีโอ ที่สร้างขึ้นจากเฟรมวิดีโอกล้องที่กำหนดเองเช่นเมื่อคุณใช้การจัดการกล้องของคุณเองหรือบุคคลที่สาม การรับรู้จะได้รับการปรับให้เหมาะสมสำหรับความเร็วและจะพึ่งพาความซ้ำซ้อนระหว่างเฟรมวิดีโอติดต่อกันเพื่อให้ได้ผลลัพธ์การรับรู้ที่ดีที่สุดเท่าที่จะเป็นไปได้ ใช้ RecoleDizeVideoImage หรือ RechedizeVideoimagewithRecognizersImages ไม่ได้เป็นส่วนหนึ่งของสตรีมวิดีโอและคุณต้องการให้ได้ผลลัพธ์ที่ดีที่สุดจาก InputImage เดียว ประเภท InputImage มาจาก SDK ของเราหรือสามารถสร้างได้โดยใช้ ImageBuilder ใช้ RecoleZestIllimage หรือ RecredizEstillimagewithRecognizersนี่คือตัวอย่างขั้นต่ำของการใช้ API โดยตรงสำหรับการจดจำ Bitmap Android:
public class DirectAPIActivity extends Activity {
private RecognizerRunner mRecognizerRunner ;
private BlinkIdMultiSideRecognizer mRecognizer ;
private RecognizerBundle mRecognizerBundle ;
@ Override
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate ();
// initialize your activity here
// create BlinkIdMultiSideRecognizer
mRecognizer = new BlinkIdMultiSideRecognizer ();
// bundle recognizers into RecognizerBundle
mRecognizerBundle = new RecognizerBundle ( mRecognizer );
try {
mRecognizerRunner = RecognizerRunner . getSingletonInstance ();
} catch ( FeatureNotSupportedException e ) {
Toast . makeText ( this , "Feature not supported! Reason: " + e . getReason (). getDescription (), Toast . LENGTH_LONG ). show ();
finish ();
return ;
}
mRecognizerRunner . initialize ( this , mRecognizerBundle , new DirectApiErrorListener () {
@ Override
public void onRecognizerError ( Throwable t ) {
Toast . makeText ( DirectAPIActivity . this , "There was an error in initialization of Recognizer: " + t . getMessage (), Toast . LENGTH_SHORT ). show ();
finish ();
}
});
}
@ Override
protected void onResume () {
super . onResume ();
// start recognition
Bitmap bitmap = BitmapFactory . decodeFile ( "/path/to/some/file.jpg" );
mRecognizerRunner . recognizeBitmap ( bitmap , Orientation . ORIENTATION_LANDSCAPE_RIGHT , mScanResultListener );
}
@ Override
protected void onDestroy () {
super . onDestroy ();
mRecognizerRunner . terminate ();
}
private final ScanResultListener mScanResultListener = new ScanResultListener () {
@ Override
public void onScanningDone ( @ NonNull RecognitionSuccessType recognitionSuccessType ) {
// this method is from ScanResultListener and will be called
// when scanning completes
// you can obtain scanning result by calling getResult on each
// recognizer that you bundled into RecognizerBundle.
// for example:
BlinkIdMultiSideRecognizer . Result result = mRecognizer . getResult ();
if ( result . getResultState () == Recognizer . Result . State . Valid ) {
// result is valid, you can use it however you wish
}
}
};
} ScanResultListener.SonsanningDone วิธีการเรียกใช้สำหรับแต่ละภาพอินพุตที่คุณส่งไปยังการรับรู้ คุณสามารถเรียก RecognizerRunner.recognize* วิธีการหลายครั้งด้วยรูปภาพที่แตกต่างกันของเอกสารเดียวกันเพื่อความแม่นยำในการอ่านที่ดีขึ้นจนกว่าคุณจะได้รับผลลัพธ์ที่ประสบความสำเร็จในวิธี onScanningDone ของผู้ฟัง สิ่งนี้มีประโยชน์เมื่อคุณใช้การจัดการกล้องของคุณเองหรือบุคคลที่สาม
String (การแยกวิเคราะห์) ผู้จดจำบางคนสนับสนุนการรับรู้จาก String พวกเขาสามารถใช้ผ่าน API โดยตรงเพื่อแยกวิเคราะห์ String และส่งคืนข้อมูลเช่นเดียวกับเมื่อใช้กับภาพอินพุต เมื่อการรับรู้ดำเนินการกับ String ไม่จำเป็นต้องใช้ OCR String อินพุตถูกใช้ในลักษณะเดียวกับ OCR output ถูกใช้เมื่อรับรู้ภาพ
การรับรู้จาก String สามารถทำได้ในลักษณะเดียวกับการรับรู้จากภาพที่อธิบายไว้ในส่วนก่อนหน้า
ความแตกต่างเพียงอย่างเดียวคือหนึ่งในวิธีการรับรู้ Singleton สำหรับการรับรู้จากสตริงควรเรียกว่า:
Direct API ของ API RecognizerRunner Singleton เป็นเครื่องจักรของรัฐที่สามารถอยู่ในหนึ่งใน 3 รัฐ: OFFLINE READY และ WORKING
RecognizerRunner Singleton มันจะอยู่ในสถานะ OFFLINERecognizerRunner โดยเรียกใช้วิธีการเริ่มต้น หากคุณเรียกใช้วิธี initialize ในขณะที่ RecognizerRunner ไม่ได้อยู่ในสถานะ OFFLINE คุณจะได้รับ IllegalStateExceptionRecognizerRunner จะย้ายไปยังสถานะ READY ตอนนี้คุณสามารถโทรหาวิธี recognize* ใด ๆrecognize* ใด ๆ RecognizerRunner จะย้ายไปยังสถานะ WORKING หากคุณพยายามเรียกใช้วิธีการเหล่านี้ในขณะที่ RecognizerRunner ไม่ได้อยู่ในสถานะ READY คุณจะได้รับ IllegalStateExceptionRecognizerRunner's ทั้งหมดจากเธรด UIRecognizerRunner จะย้ายกลับสู่สถานะ READY ก่อนแล้วจึงเรียกใช้วิธี onscanningdone ของ ScanResultListener ที่ให้ไว้onScanningDone ของ ScanResultListener จะถูกเรียกใช้ในเธรดการประมวลผลพื้นหลังดังนั้นให้แน่ใจว่าคุณไม่ได้ดำเนินการ UI ในการโทรกลับนี้ นอกจากนี้โปรดทราบว่าจนกว่าวิธี onScanningDone จะเสร็จสิ้น RecognizerRunner จะไม่ทำการรับรู้ภาพหรือสตริงอื่นแม้ว่าวิธี recognize* ใด ๆ จะถูกเรียกหลังจากเปลี่ยนเป็นสถานะ READY นี่คือเพื่อให้แน่ใจว่าผลลัพธ์ของผู้จดจำที่รวมอยู่ใน RecognizerBundle ที่เกี่ยวข้องกับ RecognizerRunner จะไม่ได้รับการแก้ไขในขณะที่อาจถูกใช้ภายในวิธี onScanningDoneterminate RecognizerRunner Singleton จะปล่อยทรัพยากรภายในทั้งหมด โปรดทราบว่าแม้หลังจากการโทร terminate คุณอาจได้รับเหตุการณ์ onScanningDone หากมีการทำงานอยู่ระหว่างดำเนินการเมื่อมีการเรียกว่า terminateterminate สามารถเรียกได้จากสถานะของ RecognizerRunner Singleton ใด ๆRecognizerRunner Singleton ด้วยวิธีการ getCurrentState ทั้ง RecreyizerRunnerView และ RecognizerRunner ใช้ซิงเกิลภายในเดียวกันที่จัดการรหัสพื้นเมือง ซิงเกิลนี้จัดการการเริ่มต้นและการสิ้นสุดของห้องสมุดพื้นเมืองและเผยแพร่ผู้จดจำไปยังห้องสมุดพื้นเมือง มีความเป็นไปได้ที่จะใช้ RecognizerRunnerView และ RecognizerRunner ร่วมกันเนื่องจาก Singleton ภายในจะทำให้แน่ใจว่าการซิงโครไนซ์ที่ถูกต้องและการตั้งค่าการจดจำที่ถูกต้องจะถูกใช้ หากคุณพบปัญหาในขณะที่ใช้ RecognizerRunner ร่วมกับ RecognizerRunnerView โปรดแจ้งให้เราทราบ!
เมื่อคุณใช้การจำแนกแบบรวมและรูปภาพของทั้งสองด้านเอกสารคุณต้องเรียก RecognizerRunner.recognize* หลายครั้ง เรียกมันก่อนด้วยภาพของด้านแรกของเอกสารจนกว่าจะอ่านแล้วด้วยภาพของด้านที่สอง ผู้จำแนกแบบรวมจะสลับเป็นการสแกนด้านที่สองโดยอัตโนมัติหลังจากอ่านด้านแรกได้สำเร็จ หากต้องการได้รับแจ้งเมื่อการสแกนด้านแรกเสร็จสมบูรณ์คุณต้องตั้งค่า FirstSiderEcognitionCallback ผ่าน MetadataCallbacks หากคุณไม่ต้องการข้อมูลนั้นเช่นเมื่อคุณมีภาพเดียวสำหรับแต่ละด้านเอกสารอย่าตั้งค่า FirstSideRecognitionCallback และตรวจสอบการรับรู้เรื่องการใช้งานใน ScanResultListener.anningDone หลังจากประมวลผลภาพด้านที่สอง
BlinkIdUISettings และ BlinkIdOverlayController BlinkIdOverlayController ใช้ UI ใหม่สำหรับการสแกนเอกสารประจำตัวซึ่งได้รับการออกแบบมาอย่างเหมาะสมเพื่อใช้กับ BlinkIdMultiSideRecognizer ใหม่และ BlinkIdSingleSideRecognizer ใช้คุณสมบัติใหม่หลายประการ:
UI ใหม่อนุญาตให้ผู้ใช้สแกนเอกสารได้ทุกมุมใด ๆ ในทิศทางใด ๆ เราขอแนะนำให้บังคับให้วางแนวนอนหากคุณสแกนบาร์โค้ดที่ด้านหลังเพราะในอัตราความสำเร็จของการวางแนวนั้นจะสูงขึ้น
ในการเปิดตัวกิจกรรมในตัวที่ใช้ BlinkIdOverlayController ให้ใช้ BlinkIdUISettings
ในการปรับแต่งการซ้อนทับให้จัดหาทรัพยากรสไตล์ที่กำหนดเองของคุณผ่านเมธอด BlinkIdUISettings.setOverlayViewStyle() หรือผ่านตัวสร้าง ReticleOverlayView คุณสามารถปรับแต่งองค์ประกอบที่มีป้ายกำกับบนภาพหน้าจอด้านบนโดยให้คุณลักษณะต่อไปนี้ในสไตล์ของคุณ:
การออก
mb_exitScanDrawable - ไอคอนสามารถวาดได้BlinkIdUISettings.setShowCancelButton(false)คบเพลิง
mb_torchOnDrawable - ไอคอนสามารถวาดได้ที่แสดงเมื่อเปิดใช้งานไฟฉายmb_torchOffDrawable - ไอคอนสามารถวาดได้ที่แสดงเมื่อคบเพลิงถูกปิดใช้งานBlinkIdUISettings.setShowTorchButton(false)คำแนะนำ
mb_instructionsTextAppearance - สไตล์ที่จะใช้เป็น android:textAppearancemb_instructionsBackgroundDrawable - DraWable ใช้สำหรับพื้นหลังmb_instructionsBackgroundColor - สีที่ใช้สำหรับพื้นหลังคำเตือนไฟฉาย
mb_flashlightWarningTextAppearance - สไตล์ที่จะใช้เป็น android:textAppearancemb_flashlightWarningBackgroundDrawable - Drawable ใช้สำหรับพื้นหลังBlinkIdUISettings.setShowFlashlightWarning(false)ไอคอนการ์ด
mb_cardFrontDrawable - ไอคอนที่สามารถวาดได้ในระหว่างภาพเคลื่อนไหวพลิกการ์ดแสดงด้านหน้าของการ์ดmb_cardBackDrawable - ไอคอนที่สามารถวาดได้ในระหว่างการเคลื่อนไหวแบบพลิกการ์ดซึ่งแสดงถึงด้านหลังของการ์ดเส้นเล็ง
mb_reticleDefaultDrawable - drawable แสดงได้เมื่อเรติเคิลอยู่ในสถานะเป็นกลางmb_reticleSuccessDrawable - สามารถทำได้เมื่อมีเส้นซ้ำอยู่ในสถานะความสำเร็จ (การสแกนสำเร็จ)mb_reticleErrorDrawable - Drawable แสดงได้เมื่อเรติเคิลอยู่ในสถานะข้อผิดพลาดmb_reticleColor - สีที่ใช้สำหรับการหมุนรอบองค์ประกอบmb_reticleDefaultColor - สีที่ใช้สำหรับเรติเคิลในสถานะเป็นกลางmb_reticleErrorColor - สีที่ใช้สำหรับเรติเคิลในสถานะข้อผิดพลาดmb_successFlashColor - สีที่ใช้สำหรับเอฟเฟกต์แฟลชในการสแกนที่ประสบความสำเร็จ ในการปรับแต่งการมองเห็นและรูปแบบของกล่องโต้ตอบทั้งสองนี้ให้ใช้วิธีการที่มีให้ใน BlinkIdUISettings
วิธีการควบคุมการมองเห็นของ กล่องโต้ตอบบทนำ คือ BlinkIdUISettings.setShowIntroductionDialog(boolean showIntroductionDialog) และตั้งค่าเป็นจริงโดยค่าเริ่มต้นหมายถึงกล่องโต้ตอบบทนำจะปรากฏขึ้น
วิธีการควบคุมการมองเห็นของ กล่องโต้ตอบ onboarding คือ BlinkIdUISettings.setShowOnboardingInfo(boolean showOnboardingInfo) และตั้งค่าเป็นจริงโดยค่าเริ่มต้นซึ่งหมายถึงกล่องโต้ตอบบทนำจะปรากฏขึ้น
นอกจากนี้ยังมีวิธีการควบคุมความล่าช้าของ "การแสดงความช่วยเหลือ?" คำแนะนำเครื่องมือ ที่แสดงอยู่ด้านบนปุ่มช่วยเหลือ ปุ่มเองจะปรากฏขึ้นหากวิธีการก่อนหน้านี้สำหรับการแสดง onboarding เป็นจริง วิธีการตั้งค่าความยาวหน่วงของคำแนะนำเครื่องมือคือ BlinkIdUISettings.setShowTooltipTimeIntervalMs(long showTooltipTimeIntervalMs) พารามิเตอร์เวลาถูกตั้งค่าเป็นมิลลิวินาที
การตั้งค่าเริ่มต้นของความล่าช้าคือ 12 วินาที (12000 มิลลิวินาที)
การปรับแต่งและการสร้างองค์ประกอบการแนะนำเหล่านี้และการขึ้นเครื่องบินสามารถทำได้ในลักษณะเดียวกับที่อธิบายไว้ในบทก่อนหน้าโดยให้คุณลักษณะดังต่อไปนี้:
ปุ่มช่วยเหลือ
mb_helpButtonDrawable - Drawable ที่แสดงได้เมื่อเปิดใช้งานปุ่มวิธีใช้mb_helpButtonBackgroundColor - สีที่ใช้สำหรับพื้นหลังปุ่มช่วยเหลือmb_helpButtonQuestionmarkColor - สีที่ใช้สำหรับปุ่มช่วยเหลือเบื้องหน้าคำแนะนำเครื่องมือช่วยเหลือ
mb_helpTooltipBackground - ดูได้ที่แสดงเป็นพื้นหลังเมื่อคำแนะนำเครื่องมือช่วยปรากฏขึ้นmb_helpTooltipColor - สีที่ใช้สำหรับพื้นหลังคำแนะนำเครื่องมือช่วยเหลือmb_helpTooltipTextAppearance - สไตล์ที่จะใช้เป็น android:textAppearanceบทนำบทนำ
mb_introductionBackgroundColor - สีที่ใช้สำหรับพื้นหลังหน้าจอบทนำmb_introductionTitleTextAppearance - สไตล์ที่จะใช้เป็น android:textAppearancemb_introductionMessageTextAppearance - สไตล์ที่จะใช้เป็น android:textAppearancemb_introductionButtonTextAppearance - สไตล์ที่จะใช้เป็น android:textAppearanceBlinkIdUISettings.setShowIntroductionDialog(false)กล่องโต้ตอบ onboarding
mb_onboardingBackgroundColor - สีที่ใช้สำหรับพื้นหลังหน้าจอ onboardingmb_onboardingPageIndicatorColor - สีที่ใช้สำหรับตัวบ่งชี้หน้าวงกลมในหน้าจอออนบอร์ดmb_onboardingTitleTextAppearance - สไตล์ที่จะใช้เป็น android:textAppearancemb_onboardingMessageTextAppearance - สไตล์ที่จะใช้เป็น android:textAppearancemb_onboardingButtonTextAppearance - สไตล์ที่จะใช้เป็น android:textAppearanceBlinkIdUISettings.setShowOnboardingInfo(false) กล่องโต้ตอบการแจ้งเตือนที่เรียกโดย SDK มีชุดคุณสมบัติของตัวเองที่สามารถแก้ไขได้ใน styles.xml
MB_alert_dialog เป็นธีมที่ขยาย Theme.AppCompat.Light.Dialog.Alert ธีมและใช้สีเริ่มต้นของธีมแอปพลิเคชัน ในการเปลี่ยนแอตทริบิวต์ในกล่องโต้ตอบการแจ้งเตือนเหล่านี้โดยไม่ต้องเปลี่ยนแอตทริบิวต์อื่น ๆ ในแอปพลิเคชันของผู้ใช้ชุดรูปแบบ MB_alert_dialog จะต้องถูกเขียนทับ
< style name = " MB_alert_dialog " parent = " Theme.AppCompat.Light.Dialog.Alert " >
< item name = " android:textSize " >TEXT_SIZE</ item >
< item name = " android:background " >COLOR</ item >
< item name = " android:textColorPrimary " >COLOR</ item >
< item name = " colorAccent " >COLOR</ item >
</ style >แอตทริบิวต์ที่ไม่ได้เขียนทับกำลังจะใช้สีและขนาดเริ่มต้นของธีมแอปพลิเคชัน
colorAccent attbiers ใช้เพื่อเปลี่ยนสีของปุ่มโต้ตอบการแจ้งเตือน หากแอ็ตทริบิวต์ colorAccent ของธีมแอปพลิเคชันมีการเปลี่ยนแปลงสถานที่อื่นสีปุ่มการแจ้งเตือนนี้จะเปลี่ยนไป อย่างไรก็ตามการเขียนทับชุดรูปแบบ MB_alert_dialog และแอตทริบิวต์นี้ภายในจะมั่นใจได้ว่าเฉพาะสีปุ่มในกล่องโต้ตอบการแจ้งเตือนของ MicroBlink SDK เท่านั้น หากชุดรูปแบบแอปพลิเคชันขยายธีมจากชุด MaterialComponents (เช่น Theme.MaterialComponents.Light.NoActionBar Light.noactionBar) สีปุ่มดังกล่าวอาจเปลี่ยนแปลงได้โดยการเขียนทับแอตทริบิวต์ colorOnPrimary แทนแอตทริบิวต์ colorAccent
DocumentUISettings DocumentUISettings เปิดตัวกิจกรรมที่ใช้ BlinkIdOverlayController พร้อม UI ทางเลือก มันเหมาะที่สุดสำหรับการสแกนด้านเอกสารเดียวของเอกสารการ์ดต่าง ๆ และไม่ควรใช้กับผู้จดจำรวมเนื่องจากไม่มีคำแนะนำของผู้ใช้เมื่อใดที่จะเปลี่ยนไปทางด้านหลัง
LegacyDocumentVerificationUISettings LegacyDocumentVerificationUISettings เปิดตัวกิจกรรมที่ใช้ BlinkIdOverlayController พร้อม UI ทางเลือก มันเหมาะที่สุดสำหรับ ผู้จดทะเบียนที่รวมกัน เพราะมันจัดการการสแกนด้านเอกสารหลายด้านในการเปิดกล้องเดี่ยวและนำทางผู้ใช้ผ่านกระบวนการสแกน นอกจากนี้ยังสามารถใช้สำหรับการสแกนด้านเดียวของบัตรประจำตัวประชาชนหนังสือเดินทางใบขับขี่ ฯลฯ
สตริงที่ใช้ภายในกิจกรรมในตัวและการซ้อนทับสามารถแปลเป็นภาษาท้องถิ่นได้ หากคุณกำลังใช้ RecognizerRunnerView (ดูบทนี้สำหรับข้อมูลเพิ่มเติม) ในกิจกรรมการสแกนที่กำหนดเองของคุณคุณควรจัดการกับการแปลเป็นแอพ Android อื่น ๆ RecognizerRunnerView ไม่ได้ใช้สตริงหรือ drawables แต่ใช้เฉพาะสินทรัพย์จากโฟลเดอร์ assets/microblink สินทรัพย์เหล่านั้นจะต้องไม่แตะต้องตามที่จำเป็นสำหรับการจดจำการทำงานอย่างถูกต้อง
อย่างไรก็ตามหากคุณใช้กิจกรรมหรือการซ้อนทับในตัวของเราพวกเขาจะใช้ทรัพยากรที่บรรจุอยู่ใน LibBlinkID.aar เพื่อแสดงสตริงและรูปภาพที่ด้านบนของมุมมองกล้อง เราได้เตรียมสตริงสำหรับหลายภาษาซึ่งคุณสามารถใช้นอกกรอบได้ นอกจากนี้คุณยังสามารถแก้ไขสตริงเหล่านั้นหรือคุณสามารถเพิ่มภาษาของคุณเอง
ในการใช้ภาษาคุณต้องเปิดใช้งานจากรหัส:
หากต้องการใช้ภาษาที่แน่นอนในการเริ่มต้นแอปพลิเคชันก่อนที่จะเปิดองค์ประกอบ UI ใด ๆ จาก SDK คุณควรเรียกวิธีการ LanguageUtils.setLanguageAndCountry(language, country, context) ตัวอย่างเช่นคุณสามารถตั้งค่าภาษาเป็นโครเอเชียเช่นนี้:
// define BlinkID language
LanguageUtils . setLanguageAndCountry ( "hr" , "" , this ); Blinkid สามารถแปลเป็นภาษาอื่นได้อย่างง่ายดาย โฟลเดอร์ res ใน LibBlinkID.aar Archive มี values โฟลเดอร์ซึ่งมี strings.xml - ไฟล์นี้มีสตริงภาษาอังกฤษ In order to make eg croatian translation, create a folder values-hr in your project and put the copy of strings.xml inside it (you might need to extract LibBlinkID.aar archive to access those files). Then, open that file and translate the strings from English into Croatian.
To modify an existing string, the best approach would be to:
strings.xml in folder res/values-hr of the LibBlinkID.aar archive<string name="MBBack">Back</string>strings.xml in the folder res/values-hr , if it doesn't already exist<string name="MBBack">Natrag</string>RecognizerRunner and RecognizerRunnerViewProcessing events, also known as Metadata callbacks are purely intended for giving processing feedback on UI or to capture some debug information during development of your app using BlinkID SDK. For that reason, built-in activities and fragments handle those events internally. If you need to handle those events yourself, you need to use either RecognizerRunnerView or RecognizerRunner.
Callbacks for all events are bundled into the MetadataCallbacks object. Both RecognizerRunner and RecognizerRunnerView have methods which allow you to set all your callbacks.
We suggest that you check for more information about available callbacks and events to which you can handle in the javadoc for MetadataCallbacks class.
Please note that both those methods need to pass information about available callbacks to the native code and for efficiency reasons this is done at the time setMetadataCallbacks method is called and not every time when change occurs within the MetadataCallbacks object. This means that if you, for example, set QuadDetectionCallback to MetadataCallbacks after you already called setMetadataCallbacks method, the QuadDetectionCallback will not be registered with the native code and you will not receive its events.
Similarly, if you, for example, remove the QuadDetectionCallback from MetadataCallbacks object after you already called setMetadataCallbacks method, your app will crash with NullPointerException when our processing code attempts to invoke the method on removed callback (which is now set to null ). We deliberately do not perform null check here because of two reasons:
null callback, while still being registered to native code is illegal state of your program and it should therefore crash Remember , each time you make some changes to MetadataCallbacks object, you need to apply those changes to to your RecognizerRunner or RecognizerRunnerView by calling its setMetadataCallbacks method.
Recognizer concept and RecognizerBundle This section will first describe what is a Recognizer and how it should be used to perform recognition of the images, videos and camera stream. Next, we will describe how RecognizerBundle can be used to tweak the recognition procedure and to transfer Recognizer objects between activities.
RecognizerBundle is an object which wraps the Recognizers and defines settings about how recognition should be performed. Besides that, RecognizerBundle makes it possible to transfer Recognizer objects between different activities, which is required when using built-in activities to perform scanning, as described in first scan section, but is also handy when you need to pass Recognizer objects between your activities.
List of all available Recognizer objects, with a brief description of each Recognizer , its purpose and recommendations how it should be used to get best performance and user experience, can be found here .
Recognizer concept The Recognizer is the basic unit of processing within the BlinkID SDK. Its main purpose is to process the image and extract meaningful information from it. As you will see later, the BlinkID SDK has lots of different Recognizer objects that have various purposes.
Each Recognizer has a Result object, which contains the data that was extracted from the image. The Result object is a member of corresponding Recognizer object and its lifetime is bound to the lifetime of its parent Recognizer object. If you need your Result object to outlive its parent Recognizer object, you must make a copy of it by calling its method clone() .
Every Recognizer is a stateful object, that can be in two states: idle state and working state . While in idle state , you can tweak Recognizer object's properties via its getters and setters. After you bundle it into a RecognizerBundle and use either RecognizerRunner or RecognizerRunnerView to run the processing with all Recognizer objects bundled within RecognizerBundle , it will change to working state where the Recognizer object is being used for processing. While being in working state , you cannot tweak Recognizer object's properties. If you need to, you have to create a copy of the Recognizer object by calling its clone() , then tweak that copy, bundle it into a new RecognizerBundle and use reconfigureRecognizers to ensure new bundle gets used on processing thread.
While Recognizer object works, it changes its internal state and its result. The Recognizer object's Result always starts in Empty state. When corresponding Recognizer object performs the recognition of given image, its Result can either stay in Empty state (in case Recognizer failed to perform recognition), move to Uncertain state (in case Recognizer performed the recognition, but not all mandatory information was extracted), move to StageValid state (in case Recognizer successfully scanned one part/side of the document and there are more fields to extract) or move to Valid state (in case Recognizer performed recognition and all mandatory information was successfully extracted from the image).
As soon as one Recognizer object's Result within RecognizerBundle given to RecognizerRunner or RecognizerRunnerView changes to Valid state, the onScanningDone callback will be invoked on same thread that performs the background processing and you will have the opportunity to inspect each of your Recognizer objects' Results to see which one has moved to Valid state.
As already stated in section about RecognizerRunnerView , as soon as onScanningDone method ends, the RecognizerRunnerView will continue processing new camera frames with same Recognizer objects, unless paused. Continuation of processing or resetting recognition will modify or reset all Recognizer objects's Results . When using built-in activities, as soon as onScanningDone is invoked, built-in activity pauses the RecognizerRunnerView and starts finishing the activity, while saving the RecognizerBundle with active Recognizer objects into Intent so they can be transferred back to the calling activities.
RecognizerBundle The RecognizerBundle is wrapper around Recognizers objects that can be used to transfer Recognizer objects between activities and to give Recognizer objects to RecognizerRunner or RecognizerRunnerView for processing.
The RecognizerBundle is always constructed with array of Recognizer objects that need to be prepared for recognition (ie their properties must be tweaked already). The varargs constructor makes it easier to pass Recognizer objects to it, without the need of creating a temporary array.
The RecognizerBundle manages a chain of Recognizer objects within the recognition process. When a new image arrives, it is processed by the first Recognizer in chain, then by the second and so on, iterating until a Recognizer object's Result changes its state to Valid or all of the Recognizer objects in chain were invoked (none getting a Valid result state). If you want to invoke all Recognizers in the chain, regardless of whether some Recognizer object's Result in chain has changed its state to Valid or not, you can allow returning of multiple results on a single image.
You cannot change the order of the Recognizer objects within the chain - no matter the order in which you give Recognizer objects to RecognizerBundle , they are internally ordered in a way that provides best possible performance and accuracy. Also, in order for BlinkID SDK to be able to order Recognizer objects in recognition chain in the best way possible, it is not allowed to have multiple instances of Recognizer objects of the same type within the chain. Attempting to do so will crash your application.
Recognizer objects between activities Besides managing the chain of Recognizer objects, RecognizerBundle also manages transferring bundled Recognizer objects between different activities within your app. Although each Recognizer object, and each its Result object implements Parcelable interface, it is not so straightforward to put those objects into Intent and pass them around between your activities and services for two main reasons:
Result object is tied to its Recognizer object, which manages lifetime of the native Result object.Result object often contains large data blocks, such as images, which cannot be transferred via Intent because of Android's Intent transaction data limit. Although the first problem can be easily worked around by making a copy of the Result and transfer it independently, the second problem is much tougher to cope with. This is where, RecognizerBundle's methods saveToIntent and loadFromIntent come to help, as they ensure the safe passing of Recognizer objects bundled within RecognizerBundle between activities according to policy defined with method setIntentDataTransferMode :
STANDARD , the Recognizer objects will be passed via Intent using normal Intent transaction mechanism , which is limited by Android's Intent transaction data limit. This is same as manually putting Recognizer objects into Intent and is OK as long as you do not use Recognizer objects that produce images or other large objects in their Results .OPTIMISED , the Recognizer objects will be passed via internal singleton object and no serialization will take place. This means that there is no limit to the size of data that is being passed. This is also the fastest transfer method, but it has a serious drawback - if Android kills your app to save memory for other apps and then later restarts it and redelivers Intent that should contain Recognizer objects, the internal singleton that should contain saved Recognizer objects will be empty and data that was being sent will be lost. You can easily provoke that condition by choosing No background processes under Limit background processes in your device's Developer options , and then switch from your app to another app and then back to your app.PERSISTED_OPTIMISED , the Recognizer objects will be passed via internal singleton object (just like in OPTIMISED mode) and will additionaly be serialized into a file in your application's private folder. In case Android restarts your app and internal singleton is empty after re-delivery of the Intent , the data will be loaded from file and nothing will be lost. The files will be automatically cleaned up when data reading takes place. Just like OPTIMISED , this mode does not have limit to the size of data that is being passed and does not have a drawback that OPTIMISED mode has, but some users might be concerned about files to which data is being written.onSaveInstanceState and save bundle back to file by calling its saveState method. Also, after saving state, you should ensure that you clear saved state in your onResume , as onCreate may not be called if activity is not restarted, while onSaveInstanceState may be called as soon as your activity goes to background (before onStop ), even though activity may not be killed at later time.OPTIMISED mode to transfer large data and image between activities or create your own mechanism for data transfer. Note that your application's private folder is only accessible by your application and your application alone, unless the end-user's device is rooted. This section will give a list of all Recognizer objects that are available within BlinkID SDK, their purpose and recommendations how they should be used to get best performance and user experience.
The FrameGrabberRecognizer is the simplest recognizer in BlinkID SDK, as it does not perform any processing on the given image, instead it just returns that image back to its FrameCallback . Its Result never changes state from Empty.
This recognizer is best for easy capturing of camera frames with RecognizerRunnerView . Note that Image sent to onFrameAvailable are temporary and their internal buffers all valid only until the onFrameAvailable method is executing - as soon as method ends, all internal buffers of Image object are disposed. If you need to store Image object for later use, you must create a copy of it by calling clone .
Also note that FrameCallback interface extends Parcelable interface, which means that when implementing FrameCallback interface, you must also implement Parcelable interface.
This is especially important if you plan to transfer FrameGrabberRecognizer between activities - in that case, keep in mind that the instance of your object may not be the same as the instance on which onFrameAvailable method gets called - the instance that receives onFrameAvailable calls is the one that is created within activity that is performing the scan.
The SuccessFrameGrabberRecognizer is a special Recognizer that wraps some other Recognizer and impersonates it while processing the image. However, when the Recognizer being impersonated changes its Result into Valid state, the SuccessFrameGrabberRecognizer captures the image and saves it into its own Result object.
Since SuccessFrameGrabberRecognizer impersonates its slave Recognizer object, it is not possible to give both concrete Recognizer object and SuccessFrameGrabberRecognizer that wraps it to same RecognizerBundle - doing so will have the same result as if you have given two instances of same Recognizer type to the RecognizerBundle - it will crash your application.
This recognizer is best for use cases when you need to capture the exact image that was being processed by some other Recognizer object at the time its Result became Valid . When that happens, SuccessFrameGrabber's Result will also become Valid and will contain described image. That image can then be retrieved with getSuccessFrame() method.
Unless stated otherwise for concrete recognizer, single side BlinkID recognizers from this list can be used in any context, but they work best with BlinkIdUISettings and DocumentScanUISettings , with UIs best suited for document scanning.
Combined recognizers should be used with BlinkIdUISettings . They manage scanning of multiple document sides in the single camera opening and guide the user through the scanning process. Some combined recognizers support scanning of multiple document types, but only one document type can be scanned at a time.
The BlinkIdSingleSideRecognizer scans and extracts data from the single side of the supported document. You can find the list of the currently supported documents here. We will continue expanding this recognizer by adding support for new document types in the future. Star this repo to stay updated.
The BlinkIdSingleSideRecognizer works best with the BlinkIdUISettings and BlinkIdOverlayController .
Use BlinkIdMultiSideRecognizer for scanning both sides of the supported document. First, it scans and extracts data from the front, then scans and extracts data from the back, and finally, combines results from both sides. The BlinkIdMultiSideRecognizer also performs data matching and returns a flag if the extracted data captured from the front side matches the data from the back. You can find the list of the currently supported documents here. We will continue expanding this recognizer by adding support for new document types in the future. Star this repo to stay updated.
The BlinkIdMultiSideRecognizer works best with the BlinkIdUISettings and BlinkIdOverlayController .
The MrtdRecognizer is used for scanning and data extraction from the Machine Readable Zone (MRZ) of the various Machine Readable Travel Documents (MRTDs) like ID cards and passports. This recognizer is not bound to the specific country, but it can be configured to only return data that match some criteria defined by the MrzFilter .
You can find information about usage context at the beginning of this section.
The MrtdCombinedRecognizer scans Machine Readable Zone (MRZ) after scanning the full document image and face image (usually MRZ is on the back side and face image is on the front side of the document). Internally, it uses DocumentFaceRecognizer for obtaining full document image and face image as the first step and then MrtdRecognizer for scanning the MRZ.
You can find information about usage context at the beginning of this section.
The PassportRecognizer is used for scanning and data extraction from the Machine Readable Zone (MRZ) of the various passport documents. This recognizer also returns face image from the passport.
You can find information about usage context at the beginning of this section.
The VisaRecognizer is used for scanning and data extraction from the Machine Readable Zone (MRZ) of the various visa documents. This recognizer also returns face image from the visa document.
You can find information about usage context at the beginning of this section.
The IdBarcodeRecognizer is used for scanning barcodes from various ID cards. Check this document to see the list of supported document types.
You can find information about usage context at the beginning of this section.
The DocumentFaceRecognizer is a special type of recognizer that only returns face image and full document image of the scanned document. It does not extract document fields like first name, last name, etc. This generic recognizer can be used to obtain document images in cases when specific support for some document type is not available.
You can find information about usage context at the beginning of this section.
You need to ensure that the final app gets all resources required by BlinkID . At the time of writing this documentation, Android does not have support for combining multiple AAR libraries into single fat AAR. The problem is that resource merging is done while building application, not while building AAR, so application must be aware of all its dependencies. There is no official Android way of "hiding" third party AAR within your AAR.
This problem is usually solved with transitive Maven dependencies, ie when publishing your AAR to Maven you specify dependencies of your AAR so they are automatically referenced by app using your AAR. Besides this, there are also several other approaches you can try:
RecognizerRunnerView ). You can perform custom UI integration while taking care that all resources (strings, layouts, images, ...) used are solely from your AAR, not from BlinkID . Then, in your AAR you should not reference LibBlinkID.aar as gradle dependency, instead you should unzip it and copy its assets to your AAR's assets folder, its classes.jar to your AAR's lib folder (which should be referenced by gradle as jar dependency) and contents of its jni folder to your AAR's src/main/jniLibs folder.BlinkID is distributed with ARMv7 and ARM64 native library binaries.
ARMv7 architecture gives the ability to take advantage of hardware accelerated floating point operations and SIMD processing with NEON. This gives BlinkID a huge performance boost on devices that have ARMv7 processors. Most new devices (all since 2012.) have ARMv7 processor so it makes little sense not to take advantage of performance boosts that those processors can give. Also note that some devices with ARMv7 processors do not support NEON and VFPv4 instruction sets, most popular being those based on NVIDIA Tegra 2, ARM Cortex A9 and older. Since these devices are old by today's standard, BlinkID does not support them. For the same reason, BlinkID does not support devices with ARMv5 ( armeabi ) architecture.
ARM64 is the new processor architecture that most new devices use. ARM64 processors are very powerful and also have the possibility to take advantage of new NEON64 SIMD instruction set to quickly process multiple pixels with a single instruction.
There are some issues to be considered:
LibBlinkID.aar archive contains ARMv7 and ARM64 builds of the native library. By default, when you integrate BlinkID into your app, your app will contain native builds for all these processor architectures. Thus, BlinkID will work on ARMv7 and ARM64 devices and will use ARMv7 features on ARMv7 devices and ARM64 features on ARM64 devices. However, the size of your application will be rather large.
We recommend that you distribute your app using App Bundle. This will defer apk generation to Google Play, allowing it to generate minimal APK for each specific device that downloads your app, including only required processor architecture support.
If you are unable to use App Bundle, you can create multiple flavors of your app - one flavor for each architecture. With gradle and Android studio this is very easy - just add the following code to build.gradle file of your app:
android {
...
splits {
abi {
enable true
reset()
include 'armeabi-v7a', 'arm64-v8a'
universalApk true
}
}
}
With that build instructions, gradle will build two different APK files for your app. Each APK will contain only native library for one processor architecture and one APK will contain all architectures. In order for Google Play to accept multiple APKs of the same app, you need to ensure that each APK has different version code. This can easily be done by defining a version code prefix that is dependent on architecture and adding real version code number to it in following gradle script:
// map for the version code
def abiVersionCodes = ['armeabi-v7a':1, 'arm64-v8a':2]
import com.android.build.OutputFile
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
def filter = output.getFilter(OutputFile.ABI)
if(filter != null) {
output.versionCodeOverride = abiVersionCodes.get(output.getFilter(OutputFile.ABI)) * 1000000 + android.defaultConfig.versionCode
}
}
}
For more information about creating APK splits with gradle, check this article from Google.
After generating multiple APK's, you need to upload them to Google Play. For tutorial and rules about uploading multiple APK's to Google Play, please read the official Google article about multiple APKs.
If you won't be distributing your app via Google Play or for some other reasons want to have single APK of smaller size, you can completely remove support for certain CPU architecture from your APK. This is not recommended due to consequences .
To keep only some CPU architectures, for example armeabi-v7a and arm64-v8a , add the following statement to your android block inside build.gradle :
android {
...
ndk {
// Tells Gradle to package the following ABIs into your application
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
This will remove other architecture builds for all native libraries used by the application.
To remove support for a certain CPU architecture only for BlinkID , add the following statement to your android block inside build.gradle :
android {
...
packagingOptions {
exclude 'lib/<ABI>/libBlinkID.so'
}
}
where <ABI> represents the CPU architecture you want to remove:
exclude 'lib/armeabi-v7a/libBlinkID.so'exclude 'lib/arm64-v8a/libBlinkID.so' You can also remove multiple processor architectures by specifying exclude directive multiple times. Just bear in mind that removing processor architecture will have side effects on performance and stability of your app. Please read this for more information.
Google decided that as of August 2019 all apps on Google Play that contain native code need to have native support for 64-bit processors (this includes ARM64 and x86_64). This means that you cannot upload application to Google Play Console that supports only 32-bit ABI and does not support corresponding 64-bit ABI.
By removing ARMv7 support, BlinkID will not work on devices that have ARMv7 processors.
By removing ARM64 support, BlinkID will not use ARM64 features on ARM64 device
If you are combining BlinkID library with other libraries that contain native code into your application, make sure you match the architectures of all native libraries. For example, if third party library has got only ARMv7 version, you must use exactly ARMv7 version of BlinkID with that library, but not ARM64. Using this architectures will crash your app at initialization step because JVM will try to load all its native dependencies in same preferred architecture and will fail with UnsatisfiedLinkError .
libc++_shared.so BlinkID contains native code that depends on the C++ runtime. This runtime is provided by the libc++_shared.so , which needs to be available in your app that is using BlinkID . However, the same file is also used by various other libraries that contain native components. If you happen to integrate both such library together with BlinkID in your app, your build will fail with an error similar to this one:
* What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
> 2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs:
- <path>/.gradle/caches/transforms-3/3d428f9141586beb8805ce57f97bedda/transformed/jetified-opencv-4.5.3.0/jni/arm64-v8a/libc++_shared.so
- <path>/.gradle/caches/transforms-3/609476a082a81bd7af00fd16a991ee43/transformed/jetified-blinkid-6.12.0/jni/arm64-v8a/libc++_shared.so
If you are using jniLibs and CMake IMPORTED targets, see
https://developer.android.com/r/tools/jniLibs-vs-imported-targets
The error states that multiple different dependencies provide the same file lib/arm64/libc++_shared.so (in this case, OpenCV and BlinkID).
You can resolve this issue by making sure that the dependency that uses newer version of libc++_shared.so is listed first in your dependency list, and then, simply add the following to your build.gradle :
android {
packaging {
jniLibs {
pickFirsts.add("lib/armeabi-v7a/libc++_shared.so")
pickFirsts.add("lib/arm64-v8a/libc++_shared.so")
}
}
}
หมายเหตุสำคัญ
The code above will always select the first libc++_shared.so from your dependency list, so make sure that the dependency that uses the latest version of libc++_shared.so is listed first. This is because libc++_shared.so is backward-compatible, but not forward-compatible. This means that, eg libBlinkID.so built against libc++_shared.so from NDK r24 will work without problems when you package it together with libc++_shared.so from NDK r26, but will crash when you package it together with libc++_shared.so from NDK r21. This is true for all your native dependencies.
In case of problems with SDK integration, first make sure that you have followed integration instructions. If you're still having problems, please contact us at help.microblink.com.
If you are getting "invalid license key" error or having other license-related problems (eg some feature is not enabled that should be or there is a watermark on top of camera), first check the ADB logcat. All license-related problems are logged to error log so it is easy to determine what went wrong.
When you have to determine what is the license-relate problem or you simply do not understand the log, you should contact us help.microblink.com. When contacting us, please make sure you provide following information:
AndroidManifest.xml and/or your build.gradle file)Keep in mind: Versions 5.8.0 and above require an internet connection to work under our new License Management Program.
We're only asking you to do this so we can validate your trial license key. Data extraction still happens offline, on the device itself. Once the validation is complete, you can continue using the SDK in offline mode (or over a private network) until the next check.
If you are having problems with scanning certain items, undesired behaviour on specific device(s), crashes inside BlinkID or anything unmentioned, please do as follows:
enable logging to get the ability to see what is library doing. To enable logging, put this line in your application:
com . microblink . blinkid . util . Log . setLogLevel ( com . microblink . blinkid . util . Log . LogLevel . LOG_VERBOSE );After this line, library will display as much information about its work as possible. Please save the entire log of scanning session to a file that you will send to us. It is important to send the entire log, not just the part where crash occurred, because crashes are sometimes caused by unexpected behaviour in the early stage of the library initialization.
Contact us at help.microblink.com describing your problem and provide following information:
InvalidLicenseKeyException when I construct specific Recognizer object Each license key contains information about which features are allowed to use and which are not. This exception indicates that your production license does not allow using of specific Recognizer object. You should contact support to check if provided license is OK and that it really contains all features that you have purchased.
InvalidLicenseKeyException with trial license key Whenever you construct any Recognizer object or any other object that derives from Entity , a check whether license allows using that object will be performed. If license is not set prior constructing that object, you will get InvalidLicenseKeyException . We recommend setting license as early as possible in your app, ideally in onCreate callback of your Application singleton.
ClassNotFoundExceptionThis usually happens when you perform integration into Eclipse project and you forget to add resources or native libraries into the project. You must alway take care that same versions of both resources, assets, java library and native libraries are used in combination. Combining different versions of resources, assets, java and native libraries will trigger crash in SDK. This problem can also occur when you have performed improper integration of BlinkID SDK into your SDK. Please read how to embed BlinkID inside another SDK.
UnsatisfiedLinkError This error happens when JVM fails to load some native method from native library If performing integration into Android studio and this error happens, make sure that you have correctly combined BlinkID SDK with third party SDKs that contain native code, especially if you need resolving conflict over libc++_shared.so . If this error also happens in our integration sample apps, then it may indicate a bug in the SDK that is manifested on specific device. Please report that to our support team.
libc++_shared.so Please consult the section about resolving libc++_shared.so conflict.
MetadataCallbacks object, but it is not being called Make sure that after adding your callback to MetadataCallbacks you have applied changes to RecognizerRunnerView or RecognizerRunner as described in this section.
MetadataCallbacks object, and now app is crashing with NullPointerException Make sure that after removing your callback from MetadataCallbacks you have applied changes to RecognizerRunnerView or RecognizerRunner as described in this section.
onScanningDone callback I have the result inside my Recognizer , but when scanning activity finishes, the result is gone This usually happens when using RecognizerRunnerView and forgetting to pause the RecognizerRunnerView in your onScanningDone callback. Then, as soon as onScanningDone happens, the result is mutated or reset by additional processing that Recognizer performs in the time between end of your onScanningDone callback and actual finishing of the scanning activity. For more information about statefulness of the Recognizer objects, check this section.
IllegalStateException stating Data cannot be saved to intent because its size exceeds intent limit . This usually happens when you use Recognizer that produces image or similar large object inside its Result and that object exceeds the Android intent transaction limit. You should enable different intent data transfer mode. For more information about this, check this section. Also, instead of using built-in activity, you can use RecognizerRunnerFragment with built-in scanning overlay.
This usually happens when you attempt to transfer standalone Result that contains images or similar large objects via Intent and the size of the object exceeds Android intent transaction limit. Depending on the device, you will get either TransactionTooLargeException, a simple message BINDER TRANSACTION FAILED in log and your app will freeze or your app will get into restart loop. We recommend that you use RecognizerBundle and its API for sending Recognizer objects via Intent in a more safe manner (check this section for more information). However, if you really need to transfer standalone Result object (eg Result object obtained by cloning Result object owned by specific Recognizer object), you need to do that using global variables or singletons within your application. Sending large objects via Intent is not supported by Android.
Direct API When automatic scanning of camera frames with our camera management is used (provided camera overlays or direct usage of RecognizerRunnerView ), we use a stream of video frames and send multiple images to the recognition to boost reading accuracy. Also, we perform frame quality analysis and combine scanning results from multiple camera frames. On the other hand, when you are using the Direct API with a single image per document side, we cannot combine multiple images. We do our best to extract as much information as possible from that image. In some cases, when the quality of the input image is not good enough, for example, when the image is blurred or when glare is present, we are not able to successfully read the document.
Online trial licenses require a public network access for validation purposes. See Licensing issues.
onOcrResult() method in my OcrCallback is never invoked and all Result objects always return null in their OCR result gettersIn order to be able to obtain raw OCR result, which contains locations of each character, its value and its alternatives, you need to have a license that allows that. By default, licenses do not allow exposing raw OCR results in public API. If you really need that, please contact us and explain your use case.
You can find BlinkID SDK size report for all supported ABIs here.
Complete API reference can be found in Javadoc.
For any other questions, feel free to contact us at help.microblink.com.