| @@ -45,8 +45,8 @@ dependencies { | |||
| implementation fileTree(dir: 'libs', excludes: ['rt.jar', 'lefaceSDK-multiatt-0814_enc.aar'],include: ['*.jar', '*.aar']) | |||
| //implementation 'com.android.support:design:28.0.0' | |||
| //implementation 'com.android.support:support-v13:28.0.0' | |||
| implementation 'org.pytorch:pytorch_android:1.8.0' | |||
| implementation 'org.pytorch:pytorch_android_torchvision:1.8.0' | |||
| //implementation 'org.pytorch:pytorch_android:1.8.0' | |||
| //implementation 'org.pytorch:pytorch_android_torchvision:1.8.0' | |||
| implementation project(':base') | |||
| //implementation project(':api') | |||
| //annotationProcessor project(':processor') | |||
| @@ -173,6 +173,7 @@ dependencies { | |||
| api project(path: ':dsbridge') | |||
| api project(path: ':base') | |||
| implementation project(path: ':andServer') | |||
| implementation 'androidx.core:core-ktx:1.3.1' | |||
| implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0' | |||
| implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1' | |||
| @@ -108,7 +108,7 @@ public class FaceManager implements ChatMode { | |||
| mNormalChatMode = mFaceChatCloseName; | |||
| mFaceCheckInterface = ArcSoftFaceCheckManager.getInstance(); | |||
| mFaceCheckInterface = KSFaceCheckManager.getInstance(); | |||
| mFaceCheckInterface = TEngineFaceCheckManager.Companion.getInstance(); | |||
| //mFaceCheckInterface = TEngineFaceCheckManager.Companion.getInstance(); | |||
| } | |||
| public static FaceManager getInstance() { | |||
| @@ -733,6 +733,7 @@ public class FaceManager implements ChatMode { | |||
| } | |||
| if (KSCheck && mFaceCheckInterface != null) { | |||
| mFaceCheckInterface.init(); | |||
| //TEngineFaceCheckManager.Companion.getInstance().init(); | |||
| if (MainActivity.instance != null) { | |||
| //KSFaceCheckManager.getInstance().init(); | |||
| } | |||
| @@ -10,11 +10,13 @@ import android.graphics.Bitmap; | |||
| import android.graphics.BitmapFactory; | |||
| import android.graphics.Matrix; | |||
| import android.net.Uri; | |||
| import android.text.TextUtils; | |||
| import android.util.Log; | |||
| import androidx.exifinterface.media.ExifInterface; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.nio.ByteBuffer; | |||
| @@ -84,4 +86,8 @@ public class ImageUtils { | |||
| final float scale = context.getResources().getDisplayMetrics().density; | |||
| return (int) (dpValue * scale + 0.5f); | |||
| } | |||
| public static boolean isFileExists(String path) { | |||
| return TextUtils.isEmpty(path) || new File(path).exists(); | |||
| } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.aispeech.nativedemo.tengine | |||
| import android.app.Activity | |||
| import android.graphics.Bitmap | |||
| import android.util.Log | |||
| import com.aispeech.nativedemo.MainActivity | |||
| @@ -72,13 +73,30 @@ class TEngineFaceCheckManager : FaceCheckInterface { | |||
| // } | |||
| override fun init() { | |||
| val sdkConfig = SdkConfig() | |||
| //TengineKitSdk.getInstance().initSdk(PROGRAM_ROOT_PATH, sdkConfig, AppContext.getInstance()) | |||
| TengineKitSdk.getInstance().initSdk(AppContext.getInstance().externalCacheDir!!.absolutePath, sdkConfig, AppContext.getInstance()) | |||
| TengineKitSdk.getInstance().initFaceDetect() | |||
| copyModel(MainActivity.instance) | |||
| Log.i(LOG_TAG, "init Success") | |||
| } | |||
| fun copyModel(activity: Activity) { | |||
| activity.assets.copyAssetFolder( | |||
| "model", | |||
| activity.externalCacheDir?.absolutePath ?: "", | |||
| object : ModelCopyCallback { | |||
| override fun copyFinish() { | |||
| Log.i(LOG_TAG, "copyModel Success") | |||
| //modelCopyFinished = true | |||
| val sdkConfig = SdkConfig() | |||
| //TengineKitSdk.getInstance().initSdk(PROGRAM_ROOT_PATH, sdkConfig, AppContext.getInstance()) | |||
| TengineKitSdk.getInstance().initSdk(activity.externalCacheDir!!.absolutePath, sdkConfig, activity) | |||
| TengineKitSdk.getInstance().initFaceDetect() | |||
| } | |||
| override fun copyFail() { | |||
| Log.i(LOG_TAG, "copyModel fail") | |||
| } | |||
| }) | |||
| } | |||
| override fun bitmapDetected(bitmap: Bitmap?, personInfo: PersonInfo) { | |||
| if (!KSFaceCheckManager.needKSCheck || !KSFaceCheckManager.hasInitKs) { | |||
| @@ -0,0 +1,68 @@ | |||
| package com.aispeech.nativedemo.tengine | |||
| import android.content.res.AssetManager | |||
| import com.aispeech.nativedemo.tengine.ImageUtils.isFileExists | |||
| import com.shareopen.library.helper.util.FileUtils | |||
| import java.io.File | |||
| import java.io.File.separator | |||
| import java.io.FileOutputStream | |||
| import java.io.IOException | |||
| import java.io.OutputStream | |||
| fun AssetManager.copyAssetFolder( | |||
| srcName: String, | |||
| dstName: String, | |||
| callback: ModelCopyCallback? | |||
| ): Boolean { | |||
| return try { | |||
| var result = true | |||
| val fileList = this.list(srcName) ?: return false | |||
| if (fileList.isEmpty()) { | |||
| result = copyAssetFile(srcName, dstName) | |||
| } else { | |||
| val file = File(dstName) | |||
| result = file.mkdirs() | |||
| for (filename in fileList) { | |||
| result = result and copyAssetFolder( | |||
| srcName + separator.toString() + filename, | |||
| dstName + separator.toString() + filename, | |||
| null | |||
| ) | |||
| } | |||
| } | |||
| callback?.copyFinish() | |||
| result | |||
| } catch (e: IOException) { | |||
| e.printStackTrace() | |||
| callback?.copyFail() | |||
| false | |||
| } | |||
| } | |||
| fun AssetManager.copyAssetFile(srcName: String, dstName: String): Boolean { | |||
| return try { | |||
| if (!isFileExists(dstName)) { | |||
| val inStream = this.open(srcName) | |||
| val outFile = File(dstName) | |||
| val out: OutputStream = FileOutputStream(outFile) | |||
| val buffer = ByteArray(1024) | |||
| var read: Int | |||
| while (inStream.read(buffer).also { read = it } != -1) { | |||
| out.write(buffer, 0, read) | |||
| } | |||
| inStream.close() | |||
| out.close() | |||
| } | |||
| true | |||
| } catch (e: IOException) { | |||
| e.printStackTrace() | |||
| false | |||
| } | |||
| } | |||
| interface ModelCopyCallback { | |||
| fun copyFinish() | |||
| fun copyFail() | |||
| } | |||