当前位置:网站首页>HMS core unified scanning service
HMS core unified scanning service
2022-07-04 23:03:00 【Just_ Paranoid】
Unified code scanning service (Scan Kit) Provide convenient barcode and QR code scanning 、 analysis 、 Generative power , Help you quickly build the scanning function in the application . Thanks to Huawei's ability to accumulate in the field of computer vision ,Scan Kit It can realize the detection and automatic amplification of long distance code or small code , At the same time, aiming at common complex code scanning scenarios ( Like reflection 、 Dark light 、 Stain 、 Fuzzy 、 cylinder ) It has done targeted identification optimization , Improve code scanning success rate and user experience .
Scan Kit Support Android and iOS System integration . among ,Android System integration Scan Kit Rear support horizontal screen code scanning capability .
guide :
https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/service-introduction-0000001050041994
codelab:
https://developer.huawei.com/consumer/cn/codelabsPortal/carddetails/ScanKit
Build code scanning function
https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/android-overview-0000001050282308
gradle Add compilation dependency
implementation 'com.huawei.hms:scan:2.6.0.300'
Custom code scanning
Customized View Support developers to customize the code scanning interface , The scanning process and camera control will be controlled by Scan Kit complete .
// Set the code type that supports identification and initialize RemoteView, Set the operation of page elements
// take RemoteView Load into Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_defined);
// Bind camera preview layout .
frameLayout = findViewById(R.id.rim);
// Set the scanning identification area , You can adjust the parameters according to your needs .
DisplayMetrics dm = getResources().getDisplayMetrics();
float density = dm.density;
mScreenWidth = getResources().getDisplayMetrics().widthPixels;
mScreenHeight = getResources().getDisplayMetrics().heightPixels;
// At present Demo The width and height of the scanning frame is 300dp.
final int SCAN_FRAME_SIZE = 300;
int scanFrameSize = (int) (SCAN_FRAME_SIZE * density);
Rect rect = new Rect();
rect.left = mScreenWidth / 2 - scanFrameSize / 2;
rect.right = mScreenWidth / 2 + scanFrameSize / 2;
rect.top = mScreenHeight / 2 - scanFrameSize / 2;
rect.bottom = mScreenHeight / 2 + scanFrameSize / 2;
// initialization RemoteView, And set parameters through the following methods :setContext()( Mandatory ) Pass in context、setBoundingBox() Set the scanning area 、setFormat() Set the identification code system , After setting, call build() Method to complete the creation . adopt setContinuouslyScan( Optional ) Method to set discontinuous scanning mode .
remoteView = new RemoteView.Builder().setContext(this).setBoundingBox(rect).setContinuouslyScan(false).setFormat(HmsScan.QRCODE_SCAN_TYPE, HmsScan.DATAMATRIX_SCAN_TYPE).build();
// Will customize view Load into activity Of frameLayout in .
remoteView.onCreate(savedInstanceState);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
frameLayout.addView(remoteView, params);
}
// Yes RemoteView Set result callback listening , Get the scanning result object HmsScan, See code value analysis for the information contained therein
@Override
protected void onCreate(Bundle savedInstanceState) {
…
// Identify the result callback event subscription
remoteView.setOnResultCallback(new OnResultCallback() {
@Override
public void onResult(HmsScan[] result) {
// Get the code scanning result HmsScan
showResult(result);
}
});
}
// Developers scan the code successfully , If you don't want to end the current “Activity” And continue with other operations , You can call the pause scanning interface .
remoteView.pauseContinuouslyScan();
// You need to resume scanning from the suspended scanning state , You can call the recovery scanning interface , Restore the current “Activity” Receive code scanning results .
remoteView.resumeContinuouslyScan();
// Set discontinuous scanning mode .
// adopt setContinuouslyScan Method setting , The default is true, Continuous scanning mode , At this time, the scanning result will return continuously ; Set to false, Discontinuous scanning mode , At this time, the same code value will only be returned once .
// setContinuouslyScan Set to false, Discontinuous scanning mode .
remoteView = new RemoteView.Builder().setContext(this).setContinuouslyScan(false).build();
// Set whether to return to the original image after successful scanning .
// adopt enableReturnBitmap Method returns to the original image after successfully scanning the code , Do not return by default . Can pass HmsScan Object's getOriginalBitmap To get the results .
remoteView = new RemoteView.Builder().setContext(this).enableReturnBitmap().build();
Picture scanning
//1. Get photo , Convert picture to Bitmap.
// data yes Intent type ,data.getData Is the barcode image to be scanned Uri.
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
//2. initialization HmsScanAnalyzerOptions, Set the code system and settings that support identification Bitmap The mode is picture scanning mode .
// Developers can set optional parameters in the following ways .
//setHmsScanTypes(): Set the code system , Default recognition Scan Kit Supported coding system , Specify a specific code system for scanning , It can improve the scanning speed .
//setPhotoMode(true): Set up Bitmap Pattern , The default is camera scan mode , Set here as picture scanning mode , The value is true.
// “QRCODE_SCAN_TYPE” and “DATAMATRIX_SCAN_TYPE” It means scan only QR and Data Matrix Code of
HmsScanAnalyzerOptions options = new HmsScanAnalyzerOptions.Creator().setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE, HmsScan.DATAMATRIX_SCAN_TYPE).setPhotoMode(true).create();
//3. call ScanUtil Static method of decodeWithBitmap Send a code scanning request and obtain the code scanning result object HmsScan, Please refer to code value analysis for the information contained therein .
// If the developer does not need to specify to detect only a specific code system , Here “options” It can be set to “null”.
HmsScan[] hmsScans = ScanUtil.decodeWithBitmap(BitmapActivity.this, bitmap, options);
// Process scan results
if (hmsScans != null && hmsScans.length > 0) {
// Show scan results
showResult(hmsScans);
}
边栏推荐
猜你喜欢
Set up a website with a sense of ceremony, and post it to 1/2 of the public network through the intranet
攻防世界 MISC 进阶区 hit-the-core
SPH中的粒子初始排列问题(两张图解决)
Install the gold warehouse database of NPC
Advanced area a of attack and defense world misc Masters_ good_ idea
Attack and defense world misc advanced area Hong
Unity vscode emmylua configuration error resolution
Analysis of the self increasing and self decreasing of C language function parameters
A complete tutorial for getting started with redis: redis shell
[sword finger offer] questions 1-5
随机推荐
cout/cerr/clog的区别
攻防世界 MISC 进阶区 Ditf
Redis入门完整教程:GEO
On-off and on-off of quality system construction
Attack and defense world misc advanced grace-50
浅聊一下中间件
The difference between Max and greatest in SQL
A complete tutorial for getting started with redis: redis usage scenarios
PS style JS webpage graffiti board plug-in
Redis入门完整教程:Bitmaps
Mongodb aggregation operation summary
Common methods in string class
S32 Design Studio for ARM 2.2 快速入门
Hit the core in the advanced area of misc in the attack and defense world
Redis入门完整教程:事务与Lua
C语言快速解决反转链表
Advanced area a of attack and defense world misc Masters_ good_ idea
Record: how to scroll screenshots of web pages on Microsoft edge in win10 system?
Install the gold warehouse database of NPC
攻防世界 MISC 进阶区 hit-the-core