【GT-Android应用开发之人脸签到】

    最近接到一个项目需求,大致就是参加会议时候进行一个人脸签到。初步确认,程序运行在安卓系统大屏一体机上,接一个摄像头用于人脸采集,大致流程为签到人员手按屏幕开始调整角度,调整好了后松开手开始拍照并发送给后台,后台调用百度人脸查找api实现人脸的识别,返回结果(成功返回人名,安卓端语音提示签到成功)

    首先是界面的设计,其实很简单就是分为左右两部分,左边是一张图片(后期会改成一张手的图片并调整大小),右边则是一个Surface控件用于展示摄像头采集的画面,界面布局如下:


    代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context="com.example.facesigndemo.MainActivity" >


    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="7"
        >
        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher"
            android:layout_centerInParent="true"
            android:id="@+id/btn"/>
    </RelativeLayout>


    <SurfaceView   
        android:id="@+id/surfaceView"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        android:layout_weight="3"
        />

</LinearLayout>

    界面设计跟业务流程上面已经介绍了,现在开始老惯例分享几个知识点:

    知识点一:人脸检测

    为了保证发送给后台的图片是可用的,即照片中是有人脸并且只有一个人,安卓端拍照后需要先进行人脸检测,识别图片中人脸的数目,代码如下:

myFace = new FaceDetector.Face[numberOfFace];
myFaceDetect = new FaceDetector(myBitmap.getWidth(), myBitmap.getHeight(), numberOfFace);

int numberOfFaceDetected = myFaceDetect.findFaces(myBitmap, myFace);

    知识点二:Bitmap转RGB_565

    前面说的人脸检测对图片有要求,必须是RGB_565格式的,因此需要进行转换,代码很简单就一句Bitmap myBitmap = b.copy(Bitmap.Config.RGB_565, false);

    好了,今天先分享这些~

猜你喜欢

转载自blog.csdn.net/qq_17433217/article/details/80895809