Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ultra-simple integrated HMS Core ML Kit scene recognition to build a new album management model

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to use ultra-simple integrated HMS Core ML Kit scene recognition to build a new album management model", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use ultra-simple integrated HMS Core ML Kit scene recognition to build a new album management model.

Functional characteristics

Huawei scene recognition service supports classifying and tagging the scene content of pictures, such as food, flowers, greens, cats, dogs, kitchens, peaks, washing machines and other 102 scenes, and based on the identified information, build a more intelligent photo album application experience.

Scene recognition has the following functional features:

Multi-class scene recognition supports 102 kinds of scene recognition, and continues to increase.

High recognition accuracy can identify a variety of objects, scenes, high recognition accuracy.

Identify fast response speed, millisecond response speed, and constantly optimize performance.

The integration is simple and efficient to provide API interface and SDK package, which is convenient for customer integration, easy to operate and reduce development costs.

Application scenario

Scene recognition is not only applied to the establishment of intelligent photo albums, photo retrieval and classification, but also can identify the shooting scene and automatically select the corresponding scene filter and camera parameters to help users take better-looking photos.

Development Code 1 Development preparation 1.1 configure AppGallery Connect.

Before developing the application, you need to configure the relevant information in AppGallery Connect. For specific steps, please refer to the link below: https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides-V5/config-agc-0000001050990353-V5

Configure the Maven warehouse address of HMS Core SDK and complete the SDK integration of this service.

(1) Open the Android Studio project-level "build.gradle" file.

(2) add HUAWEI agcp plug-in and Maven code base.

Configure the Maven warehouse address of HMS Core SDK in "allprojects > repositories".

Configure the Maven warehouse address of HMS Core SDK in "buildscript > repositories".

If the "agconnect-services.json" file is added to App, you need to add the agcp configuration to "buildscript > dependencies".

Buildscript {repositories {google () jcenter () maven {url 'https://developer.huawei.com/repo/'}} dependencies {... Classpath 'com.huawei.agconnect:agcp:1.4.1.300'}} allprojects {repositories {google () jcenter () maven {url' https://developer.huawei.com/repo/'}} 2 development code static image detection 2.1 create scene recognition detector instance. / / method 1: use the default parameter configuration. MLSceneDetectionAnalyzer analyzer = MLSceneDetectionAnalyzerFactory.getInstance () .getSceneDetectionAnalyzer (); / / method 2: create a scene recognition analyzer instance based on custom configuration. MLSceneDetectionAnalyzerSetting setting = new MLSceneDetectionAnalyzerSetting.Factory () / / sets the scene recognition credibility threshold. .setConfidence (confidence) .create (); MLSceneDetectionAnalyzer analyzer = MLSceneDetectionAnalyzerFactory.getInstance () .getSceneDetectionAnalyzer (setting); 2.2 construct MLFrame through android.graphics.Bitmap. Supported image formats include: jpg/jpeg/png/bmp. MLFrame frame = new MLFrame.Creator (). SetBitmap (bitmap). Create (); 2.3 for scene recognition. / / method 1: synchronous identification. SparseArray results = analyzer.analyseFrame (frame); / / Mode 2: asynchronous recognition. Task task = analyzer.asyncAnalyseFrame (frame); task.addOnSuccessListener (new OnSuccessListener () {public void onSuccess (List result) {/ / scene recognition successful processing logic. }}) .addOnFailureListener (new OnFailureListener () {public void onFailure (Exception e) {/ / processing logic for scene recognition failure. / / failure. If (e instanceof MLException) {MLException mlException = (MLException) e; / / get the error code. Developers can deal with the error code and make differential page prompts according to the error code. Int errorCode = mlException.getErrCode (); / / get the error message. Developers can quickly locate the problem by combining the error code. String errorMessage = mlException.getMessage ();} else {/ / other exceptions. 2.4 Detection is complete, stop the analyzer and release the detection resources. If (analyzer! = null) {analyzer.stop ();} Video stream detection

Developers can process the video stream by themselves, convert the video stream into MLFrame objects, and then identify the scene according to the method of still image detection.

If the developer calls the synchronization detection API, you can also use SDK's built-in LensEngine class to identify video stream scenarios. The sample code is as follows:

3.1 create a scene recognition analyzer. You can only create an end-to-side scene recognition analyzer. MLSceneDetectionAnalyzer analyzer = MLSceneDetectionAnalyzerFactory.getInstance (). GetSceneDetectionAnalyzer (); 3.2 developers create the recognition result processing class "SceneDetectionAnalyzerTransactor", which implements the MLAnalyzer.MLTransactor interface, and uses the transactResult method in this interface to obtain the test results and implement the specific business. Public class SceneDetectionAnalyzerTransactor implements MLAnalyzer.MLTransactor {@ Override public void transactResult (MLAnalyzer.Result results) {SparseArray items = results.getAnalyseList (); / / developers process the identification results as needed. Note that only the test results are processed here. / / other detection-related APIs provided by ML Kit cannot be called. } @ Override public void destroy () {/ / detect the end callback method, which is used to release resources, etc. }} 3.3 set the recognition result processor to bind the analyzer to the result processor. Analyzer.setTransactor (new SceneDetectionAnalyzerTransactor ()); / / create a LensEngine, which is provided by ML Kit SDK and is used to capture the camera's dynamic video stream and pass it to the analyzer. Context context = this.getApplicationContext (); LensEngine lensEngine = new LensEngine.Creator (context, this.analyzer) .setLensType (LensEngine.BACK_LENS). ApplyDisplayDimension (1440, 1080) .applyFps (30.0f) .enableAutomaticFocus (true) .create (); 3.4 call the run method, start the camera, read the video stream, and identify it. / / Please implement other logic of the SurfaceView control yourself. SurfaceView mSurfaceView = findViewById (R.id.surface_view); try {lensEngine.run (mSurfaceView.getHolder ());} catch (IOException e) {/ / exception handling logic. } 3.5 Detection is complete, stop the analyzer and release the detection resources. If (analyzer! = null) {analyzer.stop ();} if (lensEngine! = null) {lensEngine.release ();} DEMO display

At this point, I believe you have a deeper understanding of "how to use ultra-simple integrated HMS Core ML Kit scene recognition to build a new album management model". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report