当前位置:网站首页>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);
}
边栏推荐
- [OpenGL] note 29 anti aliasing (MSAA)
- 攻防世界 MISC 进阶区 can_has_stdio?
- Install the gold warehouse database of NPC
- UML diagram memory skills
- Set up a website with a sense of ceremony, and post it to 1/2 of the public network through the intranet
- [graph theory] topological sorting
- Taobao commodity review API interface (item_review get Taobao commodity review API interface), tmall commodity review API interface
- Sobel filter
- 攻防世界 MISC 高手进阶区 001 normal_png
- A complete tutorial for getting started with redis: hyperloglog
猜你喜欢

Redis入门完整教程:慢查询分析

Redis introduction complete tutorial: client communication protocol

共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf

Redis getting started complete tutorial: Geo

Redis introduction complete tutorial: List explanation

Redis入门完整教程:客户端通信协议

攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf

SHP data making 3dfiles white film

Attack and defense world misc master advanced zone 001 normal_ png

Attack and defense world misc advanced grace-50
随机推荐
攻防世界 MISC 进阶区 hong
Complete tutorial for getting started with redis: bitmaps
Photoshop batch adds different numbers to different pictures
[OpenGL] note 29 anti aliasing (MSAA)
One of the commonly used technical indicators, reading boll Bollinger line indicators
图片懒加载的原理
Summary of index operations in mongodb
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
cout/cerr/clog的区别
PS style JS webpage graffiti board plug-in
攻防世界 MISC 进阶 glance-50
共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
Notepad++--编辑的技巧
Talk about Middleware
Sword finger offer 67 Convert a string to an integer
[machine learning] handwritten digit recognition
Redis introduction complete tutorial: slow query analysis
[try to hack] wide byte injection
页面关闭前,如何发送一个可靠请求
Analog rocker controlled steering gear