当前位置:网站首页>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);
}
边栏推荐
- Qt个人学习总结
- Summary of wechat applet display style knowledge points
- 浅聊一下中间件
- Sword finger offer 65 Add without adding, subtracting, multiplying, dividing
- Serial port data frame
- 【剑指offer】1-5题
- Excel 快捷键-随时补充
- Complete tutorial for getting started with redis: bitmaps
- LIst 相关待整理的知识点
- 共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
猜你喜欢
Google Earth engine (GEE) - tasks upgrade enables run all to download all images in task types with one click
Attack and defense world misc advanced grace-50
小程序vant tab组件解决文字过多显示不全的问题
Redis introduction complete tutorial: Collection details
VIM editor knowledge summary
攻防世界 MISC 进阶 glance-50
攻防世界 MISC 进阶区 hit-the-core
A complete tutorial for getting started with redis: transactions and Lua
位运算符讲解
攻防世界 MISC 高手进阶区 001 normal_png
随机推荐
为什么信息图会帮助你的SEO
[ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
LabVIEW中比较两个VI
Redis入门完整教程:列表讲解
Async await used in map
Attack and Defense World MISC Advanced Area Erik baleog and Olaf
攻防世界 MISC 进阶区 Ditf
云服务器设置ssh密钥登录
Google collab trample pit
微信公众号解决从自定义菜单进入的缓存问题
colResizable. JS auto adjust table width plug-in
Gnawing down the big bone - sorting (II)
浅聊一下中间件
攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf
攻防世界 MISC 进阶区 hit-the-core
共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
[sword finger offer] questions 1-5
Redis getting started complete tutorial: publish and subscribe
Sobel filter
UML图记忆技巧