代码拉取完成,页面将自动刷新
运行Demo前请先安装 OpenCV Manager (必须!!) 并给Demo授予CAMERA权限
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.kongqw:FaceDetectLibrary:1.2.1'
}
Step 3. Add it in your app build.gradle
android {
……
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
pickFirst 'org/bytedeco/javacpp/macosx-x86_64/libusb-1.0.dylib'
pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
}
}
Step 4. Set screen orientation in your AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest ……>
<application
……>
<activity
……
android:screenOrientation="landscape">
……
</activity>
</application>
</manifest>
<com.kongqw.view.CameraFaceDetectionView
android:id="@+id/cameraFaceDetectionView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
CameraFaceDetectionView cameraFaceDetectionView = (CameraFaceDetectionView) findViewById(R.id.cameraFaceDetectionView);
cameraFaceDetectionView.setOnFaceDetectorListener(new CameraFaceDetectionView.OnFaceDetectorListener() {
@Override
public void onFace(Mat mat, Rect rect) {
}
});
mCameraFaceDetectionView.setOnOpenCVInitListener(new OnOpenCVInitListener() {
@Override
public void onLoadSuccess() {
Log.i(TAG, "onLoadSuccess: ");
}
@Override
public void onLoadFail() {
Log.i(TAG, "onLoadFail: ");
}
@Override
public void onMarketError() {
Log.i(TAG, "onMarketError: ");
}
@Override
public void onInstallCanceled() {
Log.i(TAG, "onInstallCanceled: ");
}
@Override
public void onIncompatibleManagerVersion() {
Log.i(TAG, "onIncompatibleManagerVersion: ");
}
@Override
public void onOtherError() {
Log.i(TAG, "onOtherError: ");
}
});
mCameraFaceDetectionView.loadOpenCV(getApplicationContext());
mCameraFaceDetectionView.switchCamera();
boolean isSave = FaceUtil.saveImage(Context context, Mat mat, Rect rect, String fileName);
boolean isSave = FaceUtil.deleteImage(Context context, String fileName);
用于显示,对比直接调用 FaceUtil.compare 即可。
Bitmap bitmap = FaceUtil.getImage(Context context, String fileName);
特征文件不存在没有抛异常,返回-1.
double score = FaceUtil.compare(Context context, String fileName1, String fileName2);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。