当前位置:网站首页>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);
}
边栏推荐
- 攻防世界 MISC 高手进阶区 001 normal_png
- Redis démarrer le tutoriel complet: Pipeline
- Unity vscode emmylua configuration error resolution
- Photoshop批量给不同的图片添加不同的编号
- Hit the core in the advanced area of misc in the attack and defense world
- 【室友用一局王者荣耀的时间学会了用BI报表数据处理】
- Create Ca and issue certificate through go language
- Google collab trample pit
- Google Earth engine (GEE) - tasks upgrade enables run all to download all images in task types with one click
- Redis getting started complete tutorial: Geo
猜你喜欢
Google Earth engine (GEE) - globfire daily fire data set based on mcd64a1
【图论】拓扑排序
Unity vscode emmylua configuration error resolution
Detailed explanation of heap sort code
Advanced area of attack and defense world misc 3-11
[Jianzhi offer] 6-10 questions
Tweenmax emoticon button JS special effect
Advanced area a of attack and defense world misc Masters_ good_ idea
A complete tutorial for getting started with redis: transactions and Lua
P2181 对角线和P1030 [NOIP2001 普及组] 求先序排列
随机推荐
A complete tutorial for getting started with redis: redis usage scenarios
Google collab trample pit
MySQL Architecture - user rights and management
图片懒加载的原理
Attack and defense world misc advanced grace-50
攻防世界 MISC 高手进阶区 001 normal_png
Attack and defense world misc advanced zone 2017_ Dating_ in_ Singapore
攻防世界 MISC 进阶 glance-50
Redis入门完整教程:初识Redis
【ODX Studio编辑PDX】-0.2-如何对比Compare两个PDX/ODX文件
攻防世界 MISC 进阶区 can_has_stdio?
Redis introduction complete tutorial: slow query analysis
9 - class
Redis入门完整教程:键管理
A complete tutorial for getting started with redis: transactions and Lua
常用技术指标之一文读懂BOLL布林线指标
Photoshop批量给不同的图片添加不同的编号
Analog rocker controlled steering gear
Redis入门完整教程:客户端通信协议
【ODX Studio編輯PDX】-0.2-如何對比Compare兩個PDX/ODX文件