android4.0 FaceDetection笔记 .

基于Android平台的人脸识别实现 效果图 先上效果,让大家看看如何 现在有很多人脸识别的技术我们可以拿来使用;但是个人认为还是离线端的SDK比较实用;所以个人一直在搜集人脸识别的SDK;原来使用开源的OpenCV;最近有个好友推荐虹软的ArcFace, 闲来无事就下来测试了一下。个人感觉还不错,效率比OpenCV要好很多,检测速度很快;20ms左右就可以检测出来;获取特征点(人脸比对)的效率也很高,基本上 阅读详情

这几天研究了下andoid4.0.3的FaceDetection这里写一下大致的流程,方便日后查阅。

相关说明可以在这里找到:

frameworks/base/docs/html/guide/topics/media/camera.jd

起始代码可以在camera.jd里找到也可以在

packages/apps/Camera/src/com/android/camera/Camera.java里找到,具体代码我就不说了.

一般起始点是startFaceDetection函数

startFaceDetection函数大致内容如下:

  1. /*Your application must start the face detection function each time you start (or restart) the 
  2. camera preview. Create a method for starting face detection so you can call it as needed, as shown 
  3. in the example code below.*/  
  4.   
  5. public void startFaceDetection(){  
  6.     // Try starting Face Detection   
  7.     ....  
  8.     // start face detection only *after* preview has started   
  9.     if (params.getMaxNumDetectedFaces() > 0){  
  10.         // camera supports face detection, so can start it:   
  11.         mCamera.startFaceDetection();  
  12.     }  
  13. }  
/*Your application must start the face detection function each time you start (or restart) the
camera preview. Create a method for starting face detection so you can call it as needed, as shown
in the example code below.*/

public void startFaceDetection(){
    // Try starting Face Detection
    ....
    // start face detection only *after* preview has started
    if (params.getMaxNumDetectedFaces() > 0){
        // camera supports face detection, so can start it:
        mCamera.startFaceDetection();
    }
}
首先判断硬件是否支持该功能

getMaxNumDetectedFaces函数在

frameworks/base/core/java/android/hardware/Camera.java

内容如下:

  1. /** 
  2.  * Gets the maximum number of detected faces supported. This is the 
  3.  * maximum length of the list returned from {@link FaceDetectionListener}. 
  4.  * If the return value is 0, face detection of the specified type is not 
  5.  * supported. 
  6.  * 
  7.  * @return the maximum number of detected face supported by the camera. 
  8.  * @see #startFaceDetection() 
  9.  */  
  10. public int getMaxNumDetectedFaces() {  
  11.     return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);  
  12. }  
        /**
         * Gets the maximum number of detected faces supported. This is the
         * maximum length of the list returned from {@link FaceDetectionListener}.
         * If the return value is 0, face detection of the specified type is not
         * supported.
         *
         * @return the maximum number of detected face supported by the camera.
         * @see #startFaceDetection()
         */
        public int getMaxNumDetectedFaces() {
            return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);
        }
而KEY_MAX_NUM_DETECTED_FACES_HW一般是在HAL层initDefaultParameters函数里设置的,设置如下
  1. <SPAN style="FONT-SIZE: 12px">p.set(CameraParameters::KEY_MAX_NUM_DETECTED_FACES_HW, "1"); //add by dao set the max face detectctor number </SPAN>  
p.set(CameraParameters::KEY_MAX_NUM_DETECTED_FACES_HW, "1"); //add by dao set the max face detectctor number 
initDefaultParameters里类似这样的代码,其它的我就不贴出来了.

mCamera.startFaceDetection();这个是执行的

frameworks/base/core/java/android/hardware/Camera.java里的startFaceDetection函数,内容如下:

  1. /** 
  2.  * Starts the face detection. This should be called after preview is started. 
  3.  * The camera will notify {@link FaceDetectionListener} of the detected 
  4.  * faces in the preview frame. The detected faces may be the same as the 
  5.  * previous ones. Applications should call {@link #stopFaceDetection} to 
  6.  * stop the face detection. This method is supported if {@link 
  7.  * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0. 
  8.  * If the face detection has started, apps should not call this again. 
  9.  * 
  10.  * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)}, 
  11.  * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)} 
  12.  * have no effect. The camera uses the detected faces to do auto-white balance, 
  13.  * auto exposure, and autofocus. 
  14.  * 
  15.  * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera 
  16.  * will stop sending face callbacks. The last face callback indicates the 
  17.  * areas used to do autofocus. After focus completes, face detection will 
  18.  * resume sending face callbacks. If the apps call {@link 
  19.  * #cancelAutoFocus()}, the face callbacks will also resume.</p> 
  20.  * 
  21.  * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, 
  22.  * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming 
  23.  * preview with {@link #startPreview()}, the apps should call this method 
  24.  * again to resume face detection.</p> 
  25.  * 
  26.  * @throws IllegalArgumentException if the face detection is unsupported. 
  27.  * @throws RuntimeException if the method fails or the face detection is 
  28.  *         already running. 
  29.  * @see FaceDetectionListener 
  30.  * @see #stopFaceDetection() 
  31.  * @see Parameters#getMaxNumDetectedFaces() 
  32.  */  
  33. public final void startFaceDetection() {  
  34.     if (mFaceDetectionRunning) {  
  35.         throw new RuntimeException("Face detection is already running");  
  36.     }  
  37.     _startFaceDetection(CAMERA_FACE_DETECTION_HW);  
  38.     mFaceDetectionRunning = true;  
  39. }  
    /**
     * Starts the face detection. This should be called after preview is started.
     * The camera will notify {@link FaceDetectionListener} of the detected
     * faces in the preview frame. The detected faces may be the same as the
     * previous ones. Applications should call {@link #stopFaceDetection} to
     * stop the face detection. This method is supported if {@link
     * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0.
     * If the face detection has started, apps should not call this again.
     *
     * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)},
     * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)}
     * have no effect. The camera uses the detected faces to do auto-white balance,
     * auto exposure, and autofocus.
     *
     * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera
     * will stop sending face callbacks. The last face callback indicates the
     * areas used to do autofocus. After focus completes, face detection will
     * resume sending face callbacks. If the apps call {@link
     * #cancelAutoFocus()}, the face callbacks will also resume.</p>
     *
     * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
     * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming
     * preview with {@link #startPreview()}, the apps should call this method
     * again to resume face detection.</p>
     *
     * @throws IllegalArgumentException if the face detection is unsupported.
     * @throws RuntimeException if the method fails or the face detection is
     *         already running.
     * @see FaceDetectionListener
     * @see #stopFaceDetection()
     * @see Parameters#getMaxNumDetectedFaces()
     */
    public final void startFaceDetection() {
        if (mFaceDetectionRunning) {
            throw new RuntimeException("Face detection is already running");
        }
        _startFaceDetection(CAMERA_FACE_DETECTION_HW);
        mFaceDetectionRunning = true;
    }
_startFaceDetection在JNI里,CAMERA_FACE_DETECTION_HW这里初始化值是0在这个文件的开始有定义

在frameworks/base/core/jni/android_hardware_Camera.cpp我们可以找到_startFaceDetection对应的函数:

  1. { "_startFaceDetection",  
  2.   "(I)V",  
  3.   (void *)android_hardware_Camera_startFaceDetection },  
  { "_startFaceDetection",
    "(I)V",
    (void *)android_hardware_Camera_startFaceDetection },
对应:android_hardware_Camera_startFaceDetection,内容如下:

  1. static void android_hardware_Camera_startFaceDetection(JNIEnv *env, jobject thiz,  
  2.         jint type)  
  3. {  
  4.     LOGV("startFaceDetection");  
  5.     JNICameraContext* context;  
  6.     sp<Camera> camera = get_native_camera(env, thiz, &context);  
  7.     if (camera == 0) return;  
  8.   
  9.     status_t rc = camera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, type, 0);  
  10.     if (rc == BAD_VALUE) {  
  11.         char msg[64];  
  12.         snprintf(msg, sizeof(msg), "invalid face detection type=%d", type);  
  13.         jniThrowException(env, "java/lang/IllegalArgumentException", msg);  
  14.     } else if (rc != NO_ERROR) {  
  15.         jniThrowRuntimeException(env, "start face detection failed");  
  16.     }  
  17. }  
static void android_hardware_Camera_startFaceDetection(JNIEnv *env, jobject thiz,
        jint type)
{
    LOGV("startFaceDetection");
    JNICameraContext* context;
    sp<Camera> camera = get_native_camera(env, thiz, &context);
    if (camera == 0) return;

    status_t rc = camera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, type, 0);
    if (rc == BAD_VALUE) {
        char msg[64];
        snprintf(msg, sizeof(msg), "invalid face detection type=%d", type);
        jniThrowException(env, "java/lang/IllegalArgumentException", msg);
    } else if (rc != NO_ERROR) {
        jniThrowRuntimeException(env, "start face detection failed");
    }
}
这里camera->sendCommand对应

device/samsung/common/s5p/libcamera/SecCameraHWInterface.cpp文件里的sendCommand函数,内容如下

  1. status_t CameraHardwareSec::sendCommand(int32_t command, int32_t arg1, int32_t arg2)  
  2. {  
  3.     return BAD_VALUE;  
  4. }  
status_t CameraHardwareSec::sendCommand(int32_t command, int32_t arg1, int32_t arg2)
{
    return BAD_VALUE;
}
到这里调用就结束了。

不同的产家camera的库所存放的目录可能不一样,同时这个函数需要根据具体的要求,进行修改.
资料参考:http://blog.youkuaiyun.com/qq69696698/article/details/7325772

Android人脸追踪拍照Demo:支持10种实时滤镜与自动对焦优化 一个开箱即用的Android拍照示例项目,基于原生Camera API实现人脸检测与持续追踪,在预览画面中实时框选并锁定人脸区域,同步触发自动对焦和曝光补偿,还原主流手机相机的人脸识别体验。兼容横竖屏切换,方向变化时预览画面与UI元素平滑过渡。内置黑白、负片、曝光过度、色调分离、白板、浅绿、浮雕、素描、霓虹灯、高对比共10种图像特效,全部在预览阶段实时渲染,无需拍照后处理。项目已配置完整权限(摄像头、外部存储读写),源码结构清晰,涵盖SurfaceView预览控制、Camera初始化与参数设置、FaceDe 阅读详情

相关推荐

ONNC Open Neural Network Compiler 开源神经网络编译器 一个 开源、模块化、可重用编译器算法和工具链的库,专门针对深度学习加速器(DLA)部署导入ONNX模型

ONNC是一个集合了开源、模块化、可重用编译器算法和工具链的库,专门针对深度学习加速器(DLA)。ONNC从底层开始构建,旨在将ONNX中间表示(IR)翻译成专有DLA代码。其软件架构设计强调可移植性和可重用性,从而简化了开发新后端的工作。上图展示了ONNC软件栈的顶层框图。软件栈从导入ONNX计算图模型到输出相应的硬件二进制文件,展示了各个功能块。

万有文的博客 1997

android相机中的人脸检测注意

andorid相机人脸检测只需要 camera.startFacedetection();就行了,但是一般能想到的是,有start就有stop,如果真这样写,就错了,会报错:stop face detected failed网上找到原因说:camera.stoppreview会自动调用这一系列的方法包括stopFaceDetection等,注释掉就好。对于这中设计,不知道算是好还是不好——————...

pageTan的小基地 1561

Jenkins测试详细使用教程(二):jenkins两种主要构建方法

Jenkins有两种定义构建作业的主要方法:(自由风格项目)和Pipeline(流水线项目)。

m0_62825058的博客 2435

解决安装face_detection失败问题

安装retinaface,提示ERROR: Could not find a version that satisfies the requirement face_detection (from versions: none)

二爷的博客 1540

详解STM32F407双重ADC同步采集与DMA传输的配置技巧及实战应用

本文详细解析了STM32F407双重ADC同步采集与DMA传输的配置技巧及实战应用。通过CubeMX配置、代码实现和常见问题解决方案,帮助开发者高效实现多通道数据同步采集,提升工业自动化和嵌入式系统的数据采集效率与精度。

ii567的博客 364

3D IC中Memory-on-Logic堆叠测试的DFT解决方案与工程实践

在半导体行业,随着摩尔定律逼近物理极限,3D IC技术通过芯片垂直堆叠实现性能提升和异构集成,已成为重要发展方向。其核心原理是利用硅通孔(TSV)或微凸块实现芯片间电气互连,将多个不同功能的芯片(如逻辑芯片与存储芯片)集成在一个封装内。这项技术的核心价值在于能大幅提升系统性能、降低功耗并实现更小的封装尺寸。然而,芯片堆叠后,传统的测试方法面临巨大挑战,尤其是测试访问存在物理屏障,无法直接探测被覆盖的芯片接口。为此,可测试性设计(DFT)成为确保3D IC可靠性与量产可行性的关键技术。它通过在设计阶段植入专用

weixin_42521058的博客 632

【原创】【Android Camera】—— 关于FaceDetection

本文是个人开发Camera APP中总结的问题之一,主要介绍FaceDetection的基本使用方法和注意问题。文中如有错误和不足,欢迎批评指正。 一、关于FaceDetection 1、版本支持 FaceDetection是Android ICE_CREAM_SANDWICH (Android Version 4.0,ADT 14)版开始增加的功能,实际是否支...

weixin_30807779的博客 514

腾讯云TDSQL MySQL版 - 开发指南兼容性

语言结构 分布式实例支持所有 MySQL 使用的文字格式,包括: String Literals Numeric Literals Date and Time Literals Hexadecimal Literals Bit-Value Literals Boolean Literals NULL Values String Literals String Literals 是一个 bytes 或者 characters 的序列,两端被单引号'或者双引号"包围,TDSQL MySQL版

weixin_43872058的博客 911

【亲测免费】 推荐文章:轻量级安卓面部识别新星 —— Face Detection Android

推荐文章:轻量级安卓面部识别新星 —— Face Detection Android 在技术日新月异的今天,高效且易于集成的开源工具成为了开发者们手中的利器。今天,我们将目光聚焦于一款特别的安卓开源项目——Face Detection Android,它不仅仅是一个简单的面部检测工具,更是一把解锁智能应用大门的钥匙。 项目介绍 Face Detection Android是一款专为安卓平台设计的轻...

gitblog_00069的博客 637

富芮坤FR801xH蓝牙协议栈启动流程和notify实现温度数据主动上传

文章目录一、蓝牙协议栈启动流程1.1 初始化代码1.2 初始化流程1.3 回调函数里的初始化二、notify实现2.1 notify介绍2.2 notify实现2.3.1 定义数据2.3.2 获取连接号conidx2.3.3 gatt_notification函数的使用三、notify温度上传测试3.1 蓝牙调试工具3.2 蓝牙调试器设置3.3 测试结果四、参考链接   基于sdk开发的好处是方便项目的快速落地,现在用的是SDK里面的源文件,目前只是学习FR801xH芯片的特性,裁剪这个SDK需要点时间,

weixin_43810563的博客 4319

SQL-拼多多 面试题:连续3次为球队得分的球员名单

1.使用LAG开窗函数 筛选出 下一次和下下一次得分,并用进球时间进行排序。2.使用where筛选出值得嘉奖的球员。

Ftr1998的博客 644

android4.0 FaceDetection笔记

这几天研究了下andoid4.0.3的FaceDetection这里写一下大致的流程,方便日后查阅。 相关说明可以在这里找到: frameworks/base/docs/html/guide/topics/media/camera.jd 起始代码可以在camera.jd里找到也可以在 packages/apps/Camera/src/com/android/camera/Camera.ja

hclydao的专栏 7078

Ubuntu 系统下安装 OpenClaw(原 Clawdbot)的详细指南

Ubuntu 系统下安装 OpenClaw(原 Clawdbot)的详细指南

Science prince的博客 3535

Mediapipe 在Android studio 运行官方的 FaceDetection

参考大佬的文章:https://blog.csdn.net/luozhichengaichenlei/article/details/117289326。

qq_51533157的博客 1786

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

SeetaFace4Android:为Android打造的高性能人脸识别引擎

SeetaFace4Android:为Android打造的高性能人脸识别引擎 去发现同类优质开源项目:https://gitcode.com/ 项目简介 是一个基于深度学习的人脸检测、人脸识别和表情识别的SDK,专为Android平台设计。它由浙江大学计算机视觉实验室开发,提供高效且易于集成的API,使得开发者能够轻松地在Android应用中实现复杂的人脸相关功能。 技术分析 SeetaFace4...

gitblog_00089的博客 768

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

java基于安卓的人脸识别_基于Android平台的人脸识别实现

效果图先上效果,让大家看看如何 现在有很多人脸识别的技术我们可以拿来使用;但是个人认为还是离线端的SDK比较实用;所以个人一直在搜集人脸识别的SDK;原来使用开源的OpenCV;最近有个好友推荐虹软的ArcFace,闲来无事就下来测试了一下。个人感觉还不错,效率比OpenCV要好很多,检测速度很快;20ms左右就可以检测出来;获取特征点(人脸比对)的效率也很高,基本上在200ms左右。 SDK D...

weixin_39769740的博客 422

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

android如何提取人脸特征,Android – 人脸特征检测

目前我正在开发适用于Android手机的应用。 我们想要检测脸部的特征。 程序应该能够检测眼睛,鼻子,嘴巴和脸部边缘的位置。准确性应该没问题,但不一定要完美。 可以放松一些准确性以加快速度。 所有的面都是正面的,我们之前会知道这些特征的大致位置。 我们不需要实时检测。 应从保存的图像中提取要素。 检测时间应该只要不影响用户体验。 所以即使2或3秒也可以。有了这个假设,find一个能让我们实现这个目...

weixin_30500365的博客 818

opencv4android --- android studio上的face_detection过程记录

上个星期至今算是对opencv从零起步吧,而且没有C++的基础,做的挺辛苦,以下是自己的过程中自己的步骤和理解,如果有过opencv安卓端开发经验的高手们看到有什么不对的理解或做法,希望你们一定纠正我的错误,谢谢! --------×--------×--------×--------×--...

chuozhang5407的博客 239

android 人脸识别

android的人脸识别目前为上(4.2)只能进行人脸的识别,而不能进行人脸的对比。 下面是具体代码 package com.example.facedetectdemo; import java.io.IOException; import android.app.Activity; import android.content.pm.ActivityInfo; import andro

3908

OpenCV开发之——人脸识别库生成so文件

在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。

2401_84413631的博客 857

android ndk人脸识别,NDK开发-实现支付宝人脸识别功能

1.下载首先先去官网 https://opencv.org/opencv-3-2.html 下载 Android SDK: sourceforge ,下载下来以后我们的开发方式目前有两种:一种是基于 OpenCV_3.2.0_Manager.apk 的纯 Java 代码;还有一种方式是配置好 opencv 后利用 Android NDK,使用C++开发。解压下载好的文件夹后image.pngapk...

weixin_29471325的博客 1016

openmed 临床上下文分析(analyze_clinical_context)实战指南:零模型的 ConText/体验者合成、结构化任务与事件时间线

`analyze_clinical_context` 是 openmed 中面向服务端调用方提供的"源文本对齐"临床上下文合成入口:它不加载任何 NLP 模型、不调用外部服务,而是把上游抽取器产出的实体 span 与 SDK 既有的章节检测(sections)、实体 span 校验、ConText/体验者(experiencer)分析组合成一个带边界约束的确定性流水线。本文基于 [docs/cli

gitblog_00120的博客 399

基于虹软的Android的人脸识别SDK使用测试

现在有很多人脸识别的技术我们可以拿来使用;但是个人认为还是离线端的SDK比较实用;所以个人一直在搜集人脸识别的SDK;原来使用开源的OpenCV;最近有个好友推荐虹软的ArcFace, 闲来无事就下来测试了一下。个人感觉还不错,效率比OpenCV要好很多,检测速度很快;20ms左右就可以检测出来;获取特征点(人脸比对)的效率也很高,基本上在200ms左右。 SDK Demo使用步骤: 下载 SD...

qq_43451963的博客 234

【Android】零碎笔记

1、关于图片截取 1 // Launch picker to choose photo for selected contact 2 Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); 3 intent.setType("image/...

weixin_30352645的博客 104

年龄性别预测1:年龄性别数据集说明(含下载地址)

主要分享年龄性别人脸数据集,主要介绍MegaAge_Asian,MORPH以及IMDB-WIKI三大数据集,总数约28W+的人脸图片,并且都标注了年龄和性别的信息,可以用于龄性别预测和识别模型的开发。

AI吃大瓜的博客 6923
上一篇: android-sdk-linux/tools/android: java: not found
下一篇: StageFright框架流程解读
vrix
博客等级 码龄24年 674粉丝 167原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值