2 Star 1 Fork 0

满建涛 / OpenCVForAndroid

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

说明

运行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>

XML

<com.kongqw.view.CameraFaceDetectionView
        android:id="@+id/cameraFaceDetectionView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

Activity

添加人脸检测监听

CameraFaceDetectionView cameraFaceDetectionView = (CameraFaceDetectionView) findViewById(R.id.cameraFaceDetectionView);
cameraFaceDetectionView.setOnFaceDetectorListener(new CameraFaceDetectionView.OnFaceDetectorListener() {
    @Override
    public void onFace(Mat mat, Rect rect) {

    }
});

添加加载OpenCV的监听

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: ");
    }
});

加载OpenCV

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);

空文件

简介

目标检测&目标追踪&人脸检测&人脸识别 展开 收起
Java
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/manjiantao/OpenCVForAndroid.git
git@gitee.com:manjiantao/OpenCVForAndroid.git
manjiantao
OpenCVForAndroid
OpenCVForAndroid
master

搜索帮助