Lis*_*nne 11 camera android image face-detection android-image
我想在非Camera应用程序中使用一些Android 4 API.
API包括一些非常好的人脸检测类,包括Camera.Face自API 14以来可用的类.我想应用相同的人脸检测类,以便对保存在设备上的图像实现人脸检测.我更喜欢使用它来处理存储在设备上的图片(例如:社交标记,面部图像处理等)
我需要有关如何完成此重用任务的指导.
如果你需要的是检测存储在设备上的图像中的面部,你绝对可以做到这一点,而无需破解android的源代码!
有一个FaceDetectorAPI,它是封装下提供android.media自API 1,它接受Bitmap作为输入(在565格式被格式化),并给你面在该图象的位置.
以下是您需要的步骤:
1-加载Bitmap并转换为565 format(假设您facesPicture的可绘制资源下有文件)
Bitmap originalBitmap =
BitmapFactory.decodeResource(getResources(),R.drawable.facesPicture);
Bitmap bitmap = originalBitmap .copy(Bitmap.Config.RGB_565, true);
originalBitmap .recycle(); // allow the GC to collect this object
Run Code Online (Sandbox Code Playgroud)
2-定义Face数组以保存检测到的面信息并初始化FaceDetector
int MAX_FACES = 20; // assuming that the image will have maximum 20 faces
FaceDetector.Face[] faces = new FaceDetector.Face[MAX_FACES];
FaceDetector faceDetector =
new FaceDetector(bitmap.getWidth(), bitmap.getHeight(), MAX_FACES);
Run Code Online (Sandbox Code Playgroud)
3-搜索面和处理结果
int facesCount = faceDetector.findFaces(bitmap, faces);
for(int i=0; i<facesCount; i++) {
FaceDetector.Face face = faces[i];
float detectionConfidence = face.confidence(); // over 0.3 is OK
PointF eyesMidPoint = new PointF();
face.getMidPoint(eyesMidPoint);
float eyesDistance = face.eyesDistance();
float rotationX = face.pose(FaceDetector.Face.EULER_X);
float rotationY = face.pose(FaceDetector.Face.EULER_Y);
float rotationZ = face.pose(FaceDetector.Face.EULER_Z);
// Do something with these values
}
Run Code Online (Sandbox Code Playgroud)
您可以在此处下载完整的项目示例,本文将介绍使用Android API进行人脸检测
如果你想要更高级的东西,你应该考虑使用OpenCV
FaceDetectionListener 是您想要用来检测面部的东西,但它只侦听相机。这是它唯一的本机功能。如果您确实想在用户设备上的图片上使用它,我建议您下载相机 API 的源代码并根据您的需要调整您想要的方法。
您可以在这里找到所有 Android 代码的源代码: https: //android.googlesource.com/
祝你好运!
| 归档时间: |
|
| 查看次数: |
1267 次 |
| 最近记录: |