我需要在Android 4.0的應用程序中實現人臉識別登錄。由於Android冰淇淋三明治中提供了人臉識別解鎖功能,是否有任何開放的SDK或構建的庫來實現此功能。到目前爲止,我遇到了外部API,例如http://www.kooaba.com/,http://developers.face.com/docs/。我知道如何檢測一張臉,但有沒有內置支持面部識別登錄或我必須使用外部API? 任何幫助,將不勝感激。在Android的人臉識別
3
A
回答
1
據我所知,在Android 4.0中沒有人臉識別的實際支持(只有人臉識別,如你所知)。 Face Unlock是一個獨立的解決方案,不會暴露任何東西。
3
RES /值/ strings.xml中:
<resources>
<string name="app_name">FaceDetectionExample</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_face_detection_example">FaceDetectionExample</string>
<string name="app_info">Click on the \'Take Picture\' to take a picture using Camera and detect the face(s) in the picture taken.</string>
<string name="take_picture">Take Picture</string>
<string name="detect_face">Detect Face</string>
</resources>
RES /佈局/ detectlayout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/image_view"
android:layout_weight="1.0"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/detect_face"
android:text="@string/detect_face"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/app_info"
android:gravity="center_horizontal"
android:layout_weight="1.0"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/take_picture"
android:layout_margin="5dip"
android:text="@string/take_picture"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
的AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.facedetectionexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".FaceDetectionExample"
android:label="@string/title_activity_face_detection_example" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
FaceDetectionExample.java
package com.example.facedetectionexample;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.media.FaceDetector;
import android.media.FaceDetector.Face;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class FaceDetectionExample extends Activity {
private static final int TAKE_PICTURE_CODE = 100;
private static final int MAX_FACES = 5;
private Bitmap cameraBitmap = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((Button)findViewById(R.id.take_picture)).setOnClickListener(btnClick);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(TAKE_PICTURE_CODE == requestCode){
processCameraImage(data);
}
}
private void openCamera(){
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE_CODE);
}
private void processCameraImage(Intent intent){
setContentView(R.layout.detectlayout);
((Button)findViewById(R.id.detect_face)).setOnClickListener(btnClick);
ImageView imageView = (ImageView)findViewById(R.id.image_view);
cameraBitmap = (Bitmap)intent.getExtras().get("data");
imageView.setImageBitmap(cameraBitmap);
}
private void detectFaces(){
if(null != cameraBitmap){
int width = cameraBitmap.getWidth();
int height = cameraBitmap.getHeight();
FaceDetector detector = new FaceDetector(width, height,FaceDetectionExample.MAX_FACES);
Face[] faces = new Face[FaceDetectionExample.MAX_FACES];
Bitmap bitmap565 = Bitmap.createBitmap(width, height, Config.RGB_565);
Paint ditherPaint = new Paint();
Paint drawPaint = new Paint();
ditherPaint.setDither(true);
drawPaint.setColor(Color.RED);
drawPaint.setStyle(Paint.Style.STROKE);
drawPaint.setStrokeWidth(2);
Canvas canvas = new Canvas();
canvas.setBitmap(bitmap565);
canvas.drawBitmap(cameraBitmap, 0, 0, ditherPaint);
int facesFound = detector.findFaces(bitmap565, faces);
PointF midPoint = new PointF();
float eyeDistance = 0.0f;
float confidence = 0.0f;
Log.i("FaceDetector", "Number of faces found: " + facesFound);
if(facesFound > 0)
{
for(int index=0; index<facesFound; ++index){
faces[index].getMidPoint(midPoint);
eyeDistance = faces[index].eyesDistance();
confidence = faces[index].confidence();
Log.i("FaceDetector",
"Confidence: " + confidence +
", Eye distance: " + eyeDistance +
", Mid Point: (" + midPoint.x + ", " + midPoint.y + ")");
canvas.drawRect((int)midPoint.x - eyeDistance ,
(int)midPoint.y - eyeDistance ,
(int)midPoint.x + eyeDistance,
(int)midPoint.y + eyeDistance, drawPaint);
}
}
String filepath = Environment.getExternalStorageDirectory() + "/facedetect" + System.currentTimeMillis() + ".jpg";
try {
FileOutputStream fos = new FileOutputStream(filepath);
bitmap565.compress(CompressFormat.JPEG, 90, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ImageView imageView = (ImageView)findViewById(R.id.image_view);
imageView.setImageBitmap(bitmap565);
}
}
private View.OnClickListener btnClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.take_picture: openCamera(); break;
case R.id.detect_face: detectFaces(); break;
}
}
};
}
和岩石!!!!!!!
相關問題
- 1. Android人臉識別
- 2. 人臉識別Android應用
- 3. 人臉識別 - Python
- 4. Javacv:eigenface人臉識別
- 5. 人臉識別Node.Js
- 6. 人臉識別opencv
- 7. C#人臉識別
- 8. 人臉識別在MATLAB
- 9. Android中的人臉識別庫
- 10. 面向Java的人臉識別API Android
- 11. Android中沒有opencv的人臉識別
- 12. Android中的OpenCV人臉識別
- 13. AS3中的人臉識別
- 14. R中的人臉識別
- 15. 人臉識別OpenCV的3
- 16. Java中的人臉識別
- 17. OpenCV + Android - 人臉識別不起作用
- 18. Android 4.0人臉識別意圖?
- 19. 使用javacv進行人臉識別android
- 20. Dlib android實時人臉識別問題
- 21. iPhoto人臉識別算法
- 22. 人臉識別IOS/iPhone
- 23. 人臉檢測與識別
- 24. 人臉識別:d 11951
- 25. 人臉識別分類
- 26. OpenCV/EmguCV人臉識別
- 27. 人臉識別邏輯
- 28. 人臉識別系統在Python Tensorflow
- 29. phone中的人臉檢測和人臉識別技術差距
- 30. 視頻中的openCV人臉識別