Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Before API development, you need to make necessary development preparations, ensure that the Maven repository address of the HMS Core SDK has been configured in your project, and the SDK of this service has been integrated.
Your app can directly call the bank card recognition plug-in to obtain the recognition result through the callback function without processing camera streams. For details, please refer to Sample Code.
1. Create the recognition result callback function and reload the onSuccess, onCanceled, onFailure, and onDenied methods.
onCanceled indicates that the user cancels the recognition.
onFailure indicates that the recognition fails.
onDenied indicates that the recognition request is denied, for example, the camera is unavailable.
MLBcrCaptureResult indicates the recognition result.
- private MLBcrCapture.CallBack callback = new MLBcrCapture.CallBack() {
- @Override
- public void onSuccess(MLBcrCaptureResult bankCardResult){
- // Processing for successful recognition.
- }
- @Override
- public void onCanceled(){
- // Processing for recognition request cancelation.
- }
- // Callback method used when no text is recognized or a system exception occurs during recognition.
- // retCode: error code.
- // bitmap: bank card image that fails to be recognized.
- @Override
- public void onFailure(int retCode, Bitmap bitmap){
- // Exception handling.
- }
- @Override
- public void onDenied(){
- // Processing for recognition request deny scenarios, for example, the camera is unavailable.
- }
- };
2. Set the recognition parameters for calling the captureFrame API of the recognizer. The recognition result is returned through the callback function created in step 1.
- private void startCaptureActivity(MLBcrCapture.CallBack callback) {
- MLBcrCaptureConfig config = new MLBcrCaptureConfig.Factory()
- // Set the expected result type of bank card recognition.
- // MLBcrCaptureConfig.SIMPLE_RESULT: Recognize only the card number and effective date.
- // MLBcrCaptureConfig.ALL_RESULT: Recognize information such as the card number, effective date, card issuing bank, card organization, and card type.
- .setResultType(MLBcrCaptureConfig.RESULT_SIMPLE)
- // Set the recognition screen display orientation.
- // MLBcrCaptureConfig.ORIENTATION_AUTO: adaptive mode. The display direction is determined by the physical sensor.
- // MLBcrCaptureConfig.ORIENTATION_LANDSCAPE: landscape mode.
- // MLBcrCaptureConfig.ORIENTATION_PORTRAIT: portrait mode.
- .setOrientation(MLBcrCaptureConfig.ORIENTATION_AUTO)
- .create();
- MLBcrCapture bankCapture = MLBcrCaptureFactory.getInstance().getBcrCapture(config);
- bankCapture.captureFrame(this, callback);
- }
3. In the callback of the recognition button, call the method defined in step 2 to implement bank card recognition.
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- // Detection button.
- case R.id.detect:
- startCaptureActivity(callback);
- break;
- default:
- break;
- }
- }