Get the App
SLTechnology News&Howtos  ›  Development  › 

How to develop a smile capture artifact on Android in Android

Shulou Source: shulou.com Published: 2022-06-02 15:19:44 09月30日 Update

This article mainly introduces "how to develop a smile capture artifact in Android on Android". In daily operation, I believe that many people have doubts about how to develop a smile capture artifact on Android in Android. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to develop a smile capture artifact on Android in Android"! Next, please follow the editor to study!

1. Development preparation

   Huawei HMS's kit pre-development preparations are similar, nothing more than adding maven dependencies and introducing SDK.

1.1 add Huawei maven warehouse to project-level gradle

The    increment adds the following maven address:

Buildscript {repositories {maven {url 'http://developer.huawei.com/repo/'} allprojects {repositories {maven {url' http://developer.huawei.com/repo/'} 1.2 add SDK dependencies to the application-level build.gradle

   introduces SDK and basic SDK of face recognition:

Dependencies {/ / introduce basic SDK implementation 'com.huawei.hms:ml-computer-vision:1.0.2.300' / / introduce face detection capability package implementation' com.huawei.hms:ml-computer-vision-face-recognition-model:1.0.2.300'} 1.3 add models incrementally in AndroidManifest.xml file to download automatically

   is mainly used to update the model. With the optimization of the later algorithm, it can be automatically downloaded to the phone to update.

FaceSparseArray.size () * smilingRate & & safeToTakePicture) {safeToTakePicture = false; mHandler.sendEmptyMessage (TAKE_PHOTO);}});}

   photo storage part:

Private void takePhoto () {this.mLensEngine.photograph (null, new LensEngine.PhotographListener () {@ Override public void takenPhotograph (byte [] bytes) {mHandler.sendEmptyMessage (STOP_PREVIEW); Bitmap bitmap = BitmapFactory.decodeByteArray (bytes, 0, bytes.length); saveBitmapToDisk (bitmap) Create a vision engine that captures the camera's dynamic video stream and passes it to the analyzer private void createLensEngine () {Context context = this.getApplicationContext () / / Create LensEngine this.mLensEngine = new LensEngine.Creator (context, this.analyzer) .setLensType (this.lensType) .applyDisplayDimension (640,480) .applyFps (25.0f) .enableAutomaticFocus (true) .create ();} 2.3 dynamic permission application, hitch parser and vision engine creation code @ Overridepublic void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState) This.setContentView (R.layout.activity_live_face_analyse); if (savedInstanceState! = null) {this.lensType = savedInstanceState.getInt ("lensType");} this.mPreview = this.findViewById (R.id.preview); this.createFaceAnalyzer (); this.findViewById (R.id.facingSwitch) .setOnClickListener (this) / / Checking Camera Permissions if (ActivityCompat.checkSelfPermission (this, Manifest.permission.CAMERA) = = PackageManager.PERMISSION_GRANTED) {this.createLensEngine ();} else {this.requestCameraPermission ();}} private void requestCameraPermission () {final String [] permissions = new String [] {Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE} If (! ActivityCompat.shouldShowRequestPermissionRationale (this, Manifest.permission.CAMERA)) {ActivityCompat.requestPermissions (this, permissions, LiveFaceAnalyseActivity.CAMERA_PERMISSION_CODE); return;}} @ Overridepublic void onRequestPermissionsResult (int requestCode, @ NonNull String [] permissions, @ NonNull int [] grantResults) {if (requestCode! = LiveFaceAnalyseActivity.CAMERA_PERMISSION_CODE) {super.onRequestPermissionsResult (requestCode, permissions, grantResults) Return;} if (grantResults.length! = 0 & & grantResults [0] = = PackageManager.PERMISSION_GRANTED) {this.createLensEngine (); return;}} this is the end of the study on "how to develop a smile capture artifact in Android on Android", hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Development smile Analyzer Analysis face artifact Android Learning Detection Code Dynamics parameters Foundation Increment engine File more permissions Model camera Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno MySQL Linux Redmi