标签:android style blog class c code
Android人脸识别技术用到的底层库:android/external/neven/,framework 层:frameworks/base/media/java/android/media/FaceDetector.java。java层接口的限制:
1、只能接受bitmap的数据。
2、只能识别出双眼睛距离不大于20像素的人脸。
3、只能检测人脸的位置,不能对人脸匹配。
下面代码的运行效果:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.andy ); //设置最大的人脸数目 int maxFaces = 3; //创建人脸识别器 FaceDetector detector = new FaceDetector(bitmap.getWidth(),bitmap.getHeight(), maxFaces); //装在人脸的容器 Face[] faces = new Face[maxFaces]; //寻找脸 detector.findFaces(bitmap, faces ); //创建可以修改的bitmap Bitmap alterBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); Canvas canvas = new Canvas(alterBitmap); Paint paint = new Paint(); canvas.drawBitmap(bitmap, 0,0, paint); for(Face face:faces){ if (face != null) { //人脸眼睛之间的距离 float eyesDistance = face.eyesDistance(); //人脸中心点的坐标 PointF point = new PointF(); //获得人脸的中心点 face.getMidPoint(point); Paint paint_ = new Paint(); paint_.setColor(Color.GREEN); paint_.setAlpha(100); paint_.setAntiAlias(true); paint_.setStyle(Paint.Style.STROKE); paint_.setStrokeWidth(3); // canvas.drawCircle(point.x, point.y,radius , paint_); canvas.drawRect( //矩形框的位置参数 (int)(point.x - eyesDistance), (int)(point.y - eyesDistance), (int)(point.x + eyesDistance), (int)(point.y + eyesDistance), paint_); ImageView iv = new ImageView(this); iv.setImageBitmap(alterBitmap); setContentView(iv); } } }
标签:android style blog class c code
原文地址:http://blog.csdn.net/andywuchuanlong/article/details/26375089