当前位置:网站首页>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);
}
边栏推荐
- [odx Studio Edit pdx] - 0.2 - Comment comparer deux fichiers pdx / odx
- A complete tutorial for getting started with redis: Pipeline
- Gnawing down the big bone - sorting (II)
- ETCD数据库源码分析——处理Entry记录简要流程
- Redis démarrer le tutoriel complet: Pipeline
- Redis入门完整教程:列表讲解
- Excel 快捷键-随时补充
- MySQL Architecture - logical architecture
- Erik baleog and Olaf, advanced area of misc in the attack and defense world
- Duplicate ADMAS part name
猜你喜欢
![P2181 对角线和P1030 [NOIP2001 普及组] 求先序排列](/img/79/36c46421bce08284838f68f11cda29.png)
P2181 对角线和P1030 [NOIP2001 普及组] 求先序排列

Redis入门完整教程:发布订阅

Set up a website with a sense of ceremony, and post it to 1/2 of the public network through the intranet

colResizable. JS auto adjust table width plug-in

The overview and definition of clusters can be seen at a glance

Excel 快捷键-随时补充

LabVIEW中比较两个VI

Tweenmax emoticon button JS special effect

Install the gold warehouse database of NPC

OSEK标准ISO_17356汇总介绍
随机推荐
Redis入门完整教程:事务与Lua
页面关闭前,如何发送一个可靠请求
Google collab trample pit
A complete tutorial for getting started with redis: Pipeline
Redis入门完整教程:Redis使用场景
Sobel filter
Mongodb aggregation operation summary
【taichi】用最少的修改将太极的pbf2d(基于位置的流体模拟)改为pbf3d
UML diagram memory skills
Duplicate ADMAS part name
Redis getting started complete tutorial: Key Management
【图论】拓扑排序
C语言快速解决反转链表
企业如何跨越数字化鸿沟?尽在云原生2.0
Set up a website with a sense of ceremony, and post it to 1/2 of the public network through the intranet
Hit the core in the advanced area of misc in the attack and defense world
Redis入门完整教程:列表讲解
Sword finger offer 67 Convert a string to an integer
The solution to the lack of pcntl extension under MAMP, fatal error: call to undefined function pcntl_ signal()
[try to hack] wide byte injection