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.java里找到,具体代码我就不说了.
一般起始点是startFaceDetection函数
startFaceDetection函数大致内容如下:
/*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
内容如下:
/**
* 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函数里设置的,设置如下
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函数,内容如下:
/**
* 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对应的函数:
{ "_startFaceDetection",
"(I)V",
(void *)android_hardware_Camera_startFaceDetection },
对应:android_hardware_Camera_startFaceDetection,内容如下:
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函数,内容如下
status_t CameraHardwareSec::sendCommand(int32_t command, int32_t arg1, int32_t arg2)
{
return BAD_VALUE;
}
到这里调用就结束了。
不同的产家camera的库所存放的目录可能不一样,同时这个函数需要根据具体的要求,进行修改.
android4.0 FaceDetection笔记的更多相关文章
- 【原】webapp开发中兼容Android4.0以下版本的css hack
话说现在的手机型号越来越多,主要还是android和ios这2个巨头称霸了江湖,而他们自带的浏览器内核是webkit,那对于做移动网页开发的同事来说,一般只要做好webkit内核浏览器的展现效果就行了 ...
- 一个Activity掌握Android4.0新控件 (转)
原文地址:http://blog.csdn.net/lavor_zl/article/details/51261380 谷歌在推出Android4.0的同时推出了一些新控件,Android4.0中最常 ...
- QT210 android2.3 和android4.0 烧写编译日记
QT210下载烧录编译android2.3过程 工作环境:ubuntu12.04.5 | QT210开发板光盘 | QT210开发板 android2.3编译环境:gcc version 4.4.7 ...
- 深入浅出-Android系统移植与平台开发(一)- Android4.0系统的下载与编译
作者:唐老师,华清远见嵌入式学院讲师. 一.Android4.0系统的下载与编译 Android系统的下载与编译,Google的官方网站上已经给出了详细的说明,请参照Android的官方网址: htt ...
- 深入浅出 - Android系统移植与平台开发(三)- 编译并运行Android4.0模拟器
作者:唐老师,华清远见嵌入式学院讲师. 1. 编译Android模拟器 在Ubuntu下,我们可以在源码里编译出自己的模拟器及SDK等编译工具,当然这个和在windows里下载的看起来没有什么区别 ...
- QT210 Android4.0源码编译和烧录文档整理
开发环境说明: Ubuntu 12.04 LTS 32bit 源码文件目录: 勤研光盘2013-5-4\4.0 https://github.com/jackyh (建议在Linux环境下通过git下 ...
- [转]使用ant让Android自动打包的build.xml,自动生成签名的apk文件(支持android4.0以上的版本)
在android4.0以后的sdk里那个脚本就失效了,主要是因为 apkbuilder这个程序不见了: 人家sdk升级,我们的脚本也要跟上趟,修改一下喽. 上网一查,大家的文章还停留在我去年的脚本程度 ...
- android4.0浏览器在eclipse中编译的步骤
工程源码: 注意: 如果下载已经修过的源码,只要进行3.4.8步骤就应该可以了. eclipse版本:adt-bundle-windows (Android Developer Tools Build ...
- Android SDK安装Android4.0“冰激淋三明治”(IceCreamSandwich)教程(转载)
昨天,Google举行了发布会,发布了Nexus Prime手机和Android4.0-IceCreamSandwich手机系统.作为Google旗下Android的最新版本手机系 统,Android ...
随机推荐
- 列表显示数据 但是数据的字体颜色要js添加
1.需求:数据在前台显示,但是每个条记录的颜色要有点不同 1.java后台数据的处理 String ids=""; for(int x=0;x<sign.size();x++ ...
- c#中struct和class的区别 z
1.struct 是值类型,class是对象类型 2.struct 不能被继承,class可以被继承 3.struct 默认的访问权限是public,而class默认的访问权限是private. 4. ...
- 在ADS上由于volatile惹得祸
C语言关键字volatile是一个危险的东东,笔者再用ADS做S3C2440定时器中断实验就因为这个关键字出了错.出现错误情况的准确描述是:定义一个变量时没有用volatile关键字,而且紧接着whi ...
- angular分页指令
目前的多个项目中都用到分页这个功能,为了提高可复用性,我特地分离出来写了个分页的指令.直接贴代码,详情如下: index.html <body id="sBill" ng-c ...
- 传感器 -UIAccelerometer
// ios 4 之前 UIAccelerometer // ios 5 <CoreMotion/CoreMotion.h> #import "ViewController.h& ...
- docker安装caffe
[最近一直想要学习caffe,但是苦苦纠结于环境安装不上,真的是第一步都迈不出去,还好有docker的存在!下面,对本人如何利用docker安装caffe做以简单叙述,不属于教程,只是记录自己都做了什 ...
- Android中JNI编程的那些事儿(1)
转:Android中JNI编程的那些事儿(1)http://mobile.51cto.com/android-267538.htm Android系统不允许一个纯粹使用C/C++的程序出现,它要求必须 ...
- 启动python解释器的命令(python manage.py shell和python的区别)
如果你曾经使用过Python,你一定好奇,为什么我们运行python manage.py shell而不是python.这两个命令都会启动交互解释器,但是manage.py shell命令有一个重要的 ...
- Uva 10294 Arif in Dhaka (First Love Part 2)
Description 现有一颗含\(N\)个珠子的项链,每个珠子有\(t\)种不同的染色.现求在旋转置换下有多少种本质不同的项链,在旋转和翻转置换下有多少种本质不同的项链.\(N < 51,t ...
- Word中表格内容被遮挡
RT,输入内容后下面的主任签字会被遮挡,解决办法:选中整个表格右键,表格属性,行高值设置为最小值,然后设置允许跨页断行:有人说右键按内容调整表格也行,没试过............