这几天研究了下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. }

首先判断硬件是否支持该功能

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. }

而KEY_MAX_NUM_DETECTED_FACES_HW一般是在HAL层initDefaultParameters函数里设置的,设置如下

  1. 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. }

_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 },

对应: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. }

这里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. }

到这里调用就结束了。

不同的产家camera的库所存放的目录可能不一样,同时这个函数需要根据具体的要求,进行修改.

android4.0 FaceDetection笔记的更多相关文章

  1. 【原】webapp开发中兼容Android4.0以下版本的css hack

    话说现在的手机型号越来越多,主要还是android和ios这2个巨头称霸了江湖,而他们自带的浏览器内核是webkit,那对于做移动网页开发的同事来说,一般只要做好webkit内核浏览器的展现效果就行了 ...

  2. 一个Activity掌握Android4.0新控件 (转)

    原文地址:http://blog.csdn.net/lavor_zl/article/details/51261380 谷歌在推出Android4.0的同时推出了一些新控件,Android4.0中最常 ...

  3. QT210 android2.3 和android4.0 烧写编译日记

    QT210下载烧录编译android2.3过程 工作环境:ubuntu12.04.5 | QT210开发板光盘 | QT210开发板 android2.3编译环境:gcc version 4.4.7  ...

  4. 深入浅出-Android系统移植与平台开发(一)- Android4.0系统的下载与编译

    作者:唐老师,华清远见嵌入式学院讲师. 一.Android4.0系统的下载与编译 Android系统的下载与编译,Google的官方网站上已经给出了详细的说明,请参照Android的官方网址: htt ...

  5. 深入浅出 - Android系统移植与平台开发(三)- 编译并运行Android4.0模拟器

    作者:唐老师,华清远见嵌入式学院讲师. 1.   编译Android模拟器 在Ubuntu下,我们可以在源码里编译出自己的模拟器及SDK等编译工具,当然这个和在windows里下载的看起来没有什么区别 ...

  6. QT210 Android4.0源码编译和烧录文档整理

    开发环境说明: Ubuntu 12.04 LTS 32bit 源码文件目录: 勤研光盘2013-5-4\4.0 https://github.com/jackyh (建议在Linux环境下通过git下 ...

  7. [转]使用ant让Android自动打包的build.xml,自动生成签名的apk文件(支持android4.0以上的版本)

    在android4.0以后的sdk里那个脚本就失效了,主要是因为 apkbuilder这个程序不见了: 人家sdk升级,我们的脚本也要跟上趟,修改一下喽. 上网一查,大家的文章还停留在我去年的脚本程度 ...

  8. android4.0浏览器在eclipse中编译的步骤

    工程源码: 注意: 如果下载已经修过的源码,只要进行3.4.8步骤就应该可以了. eclipse版本:adt-bundle-windows (Android Developer Tools Build ...

  9. Android SDK安装Android4.0“冰激淋三明治”(IceCreamSandwich)教程(转载)

    昨天,Google举行了发布会,发布了Nexus Prime手机和Android4.0-IceCreamSandwich手机系统.作为Google旗下Android的最新版本手机系 统,Android ...

随机推荐

  1. 使用win8.1 x64 office2010 php 使用 pdo_odbc 连接excel失败的问题

    public function init($filePath){ $dbq = iconv('UTF-8',"GBK",BASEPATH.'../'.$filePath); $ds ...

  2. javaScript & jquery完美判断图片是否加载完毕

    好久没写东西了,正好最近因为工作需要,写了一个瀑布流异步加载的程序. 今天就不谈瀑布流,来谈一下关于load的问题. ----------------------------------------- ...

  3. Js Carousel

    http://getbootstrap.com/javascript/#carousel http://owlgraphic.com/owlcarousel/#demo https://www.mob ...

  4. Firebird/InterBase内置函数使用说明

    Firebird/InterBase内置函数使用说明(转自:圣域天堂) 2008-10-12 20:56 加*号为FB2.0加入的函数 整理:剑雷(jianlei) 2006-10-13 1. COU ...

  5. 菜鸟Android之路(上)

    自己为什么要学android 本人作为应届毕业生,自己进入社会前做过好多梦,可是呢,现实还是打败了无邪!!面对社会的压力和残酷的竞争力自己如何生成下去??我自己对自己说:第一步 先养活自己,才能走好以 ...

  6. Web应用的组件化(二)

    管控平台 在上一篇中我们提到了组件化的大致思路,这一篇主要讲述在这么做之后,我们需要哪些外围手段去管控整个开发过程.从各种角度看,面对较大规模前端开发团队,都有必要建立这么一个开发阶段的协作平台. 在 ...

  7. Mozilla对HTML5规范支持列表

    翻译自Mozilla Developer Network 在2009年10月28日,HTML 5规范草稿在网络超文本应用技术工作组(WHATWG)中基本出于最后定稿阶段,这意味着HTML 5标准基本定 ...

  8. fzu 2037 Maximum Value Problem

    http://acm.fzu.edu.cn/problem.php?pid=2037 思路:找规律,找出递推公式f[n]=f[n-1]*n+(n-1)!,另一个的结果也是一个递推,s[n]=s[n-1 ...

  9. SpringSecurity的简单应用(一)

    java项目首先要提的就是jar包了,Springsecurity的jar下载地址:http://static.springsource.org/spring-security/site/downlo ...

  10. 使用php-emoji类让网页显示emoji表情

    需要的材料: php-emoji类库的下载地址:https://github.com/iamcal/php-emoji 代码示例:(该代码来自官网) <?php include('emoji.p ...