一个演示用的基于表情识别和敲击识别的App

演示用app,表情识别基于微软人脸识别API,可以在点击表情后自动多次拍照,拍照界面已经做了隐藏处理,当与预定义的表情序列匹配后人之成功。
敲击识别的功能上也差不多,是基于加速传感器和录音机实现的,保证较高的准确率,可以设置识别的敲击次数。

下载地址:

https://download.csdn.net/download/fanyishi/10446661

表情识别

基本框架基于微软表情识别基于微软人脸识别API

注:API免费试用一个月申请地址https://azure.microsoft.com/zh-cn/try/cognitive-services/?unauthorized=1

我之前申请的API已经过期,可以在上面的网址申请一个在Cognitive-Face-Android-master\Sample\app\src\main\res\values\strings.xml 中

<!-- Please refer to https://azure.microsoft.com/en-us/services/cognitive-services/face/ to get your subscription key --><!-- If you have subscription key with its corresponding endpoint, you can add them here to use the service --><string name="subscription_key">26e66675269944f4a27656d35afd8026</string><string name="endpoint">https://westcentralus.api.cognitive.microsoft.com/face/v1.0</string>

这里添加自己的key即可。

思路就是在本地用前置摄像头拍一张图片,上传到微软的API,会返回一个人脸的各种信息,从中提取出表情的信息,在界面上显示表情所对应的字符。

相机是做了一个隐藏式的自动连续拍照的相机,用的谷歌官方的自定义相机API。

核心代码:

// Background task of face detection.private class DetectionTask extends AsyncTask<InputStream, String, Face[]> {private boolean mSucceed = true;@Overrideprotected Face[] doInBackground(InputStream... params) {// Get an instance of face service client to detect faces in image.FaceServiceClient faceServiceClient = SampleApp.getFaceServiceClient();try {publishProgress("Detecting...");// Start detection.return faceServiceClient.detect(params[0],  /* Input stream of image to detect */true,       /* Whether to return face ID */true,       /* Whether to return face landmarks *//* Which face attributes to analyze, currently we support:age,gender,headPose,smile,facialHair */new FaceServiceClient.FaceAttributeType[] {FaceServiceClient.FaceAttributeType.Emotion});} catch (Exception e) {mSucceed = false;publishProgress(e.getMessage());addLog(e.getMessage());return null;}}@Overrideprotected void onPreExecute() {mProgressDialog.show();addLog("Request: Detecting in image " + mImageUri);}@Overrideprotected void onProgressUpdate(String... progress) {mProgressDialog.setMessage(progress[0]);setInfo(progress[0]);}@Overrideprotected void onPostExecute(Face[] result) {if (mSucceed) {addLog("Response: Success. Detected " + (result == null ? 0 : result.length)+ " face(s) in " + mImageUri);}// Show the result on screen when detection is done.setUiAfterDetection(result, mSucceed);}}

将传回的文本提取,根据不同表情返回相应的符号:

public View getView(final int position, View convertView, ViewGroup parent) {if (convertView == null) {LayoutInflater layoutInflater =(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);convertView = layoutInflater.inflate(R.layout.item_face_with_description, parent, false);}convertView.setId(position);// Show the face thumbnail.((ImageView) convertView.findViewById(R.id.face_thumbnail)).setImageBitmap(faceThumbnails.get(position));// Show the face details.emotion = getEmotion(faces.get(position).faceAttributes.emotion).substring(0, 2);input(view);return convertView;}
private String getEmotion(Emotion emotion){String emotionType = "";double emotionValue = 0.0;if (emotion.anger > emotionValue){emotionValue = emotion.anger;emotionType = "An: Anger";}if (emotion.contempt > emotionValue){emotionValue = emotion.contempt;emotionType = "Co: Contempt";}if (emotion.disgust > emotionValue){emotionValue = emotion.disgust;emotionType = "Di: Disgust";}if (emotion.fear > emotionValue){emotionValue = emotion.fear;emotionType = "Fe: Fear";}if (emotion.happiness > emotionValue){emotionValue = emotion.happiness;emotionType = "Ha: Happiness";}if (emotion.neutral > emotionValue){emotionValue = emotion.neutral;emotionType = "Ne: Neutral";}if (emotion.sadness > emotionValue){emotionValue = emotion.sadness;emotionType = "Sa: Sadness";}if (emotion.surprise > emotionValue){emotionValue = emotion.surprise;emotionType = "Su: Surprise";}return String.format("%s: %f", emotionType, emotionValue);}

相机部分:

cameraView = new CameraView(this);// 通过一个surfaceview的view来实现拍照cameraView.setTag(1);cameraView = new CameraView(this, this);setContentView(R.layout.activity_camera);relative = (RelativeLayout) this.findViewById(R.id.ly);RelativeLayout.LayoutParams Layout = new RelativeLayout.LayoutParams(1, 1);// 设置surfaceview使其在隐藏的同时可以进行拍照Layout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);Layout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);ActivityManager.getInstance().addActivity(this);relative.addView(cameraView, Layout);

相机具体代码可以在源码里面看。

敲击识别

检测算法核心就是发起一个Timer每隔20ms去侦测录音的敲击声音的录入,以及侦听了加速度传感器的Z轴数值波动;还有一个识别敲击的Timer每隔25ms去读取录音和加速度识别的结果,若是辨识出一次敲击然后起一个2-3s的超时去识别这个时间内敲击响应的次数。

核心代码

录音部分

private void startEventDetectTimer(){mTimer = new Timer();eventGen = new TimerTask(){int nrTicks = 0;EventGenState_t state = EventGenState_t.NoneSet;@Overridepublic void run() {switch(state){//None of the bools setcase NoneSet:if       ( mSoundKnockDetector.spikeDetected && !mAccelSpikeDetector.spikeDetected) state = EventGenState_t.VolumSet;else if    (!mSoundKnockDetector.spikeDetected &&  mAccelSpikeDetector.spikeDetected) state = EventGenState_t.AccelSet; else if   ( mSoundKnockDetector.spikeDetected &&  mAccelSpikeDetector.spikeDetected){mSoundKnockDetector.spikeDetected = false;mAccelSpikeDetector.spikeDetected = false;state =  EventGenState_t.NoneSet;//generate knock eventmPatt.knockEvent();}nrTicks = 0;break;//volum setcase VolumSet:if(mAccelSpikeDetector.spikeDetected){mSoundKnockDetector.spikeDetected = false;mAccelSpikeDetector.spikeDetected = false;state =  EventGenState_t.NoneSet;//generate knock eventmPatt.knockEvent();break;}else{nrTicks+=1;if(nrTicks > period){nrTicks = 0;mSoundKnockDetector.spikeDetected = false;state = EventGenState_t.NoneSet;}}break;//accsel setcase AccelSet:if(mSoundKnockDetector.spikeDetected){mSoundKnockDetector.spikeDetected = false;mAccelSpikeDetector.spikeDetected = false;state =  EventGenState_t.NoneSet;//generate knock eventmPatt.knockEvent();break;}else{nrTicks+=1;if(nrTicks > period){nrTicks = 0;mAccelSpikeDetector.spikeDetected = false;state = EventGenState_t.NoneSet;}}                     break;}}};mTimer.scheduleAtFixedRate(eventGen, 0, period); //start after 0 ms}

加速传感器部分

public void onSensorChanged(SensorEvent event) {prevXVal = currentXVal;currentXVal = abs(event.values[0]); // X-axisdiffX = currentXVal - prevXVal;prevYVal = currentYVal;currentYVal = abs(event.values[1]); // Y-axisdiffY = currentYVal - prevYVal;     prevZVal = currentZVal;currentZVal = abs(event.values[2]); // Z-axisdiffZ = currentZVal - prevZVal;//Z force must be above some limit, the other forces below some limit to filter out shaking motionsif (currentZVal > prevZVal && diffZ > thresholdZ && diffX < threshholdX && diffY < threshholdY){accTapEvent();}}

具体实现部分太多了,就不一一贴了。

参考的项目:

Emotion API:

https://docs.microsoft.com/zh-cn/azure/cognitive-services/emotion/home

微软Cognitive Service:

https://github.com/Microsoft/Cognitive-Face-Android.git

博文:Android 检测手机的敲击事件 https://blog.csdn.net/dahaohan/article/details/52883743

github:https://github.com/lishushu/KnockDetection.git

android实现基于表情识别和敲击识别的认证系统,表情识别支持自动的连续隐藏式拍照相关推荐

  1. tranmac不能识别_U盘插入苹果mac系统不能识别的解决方法

    好多小伙伴都有在使用Macbook air苹果笔记本,与Windows操作系统相比,Mac电脑在执行上述核心功能上毫不逊色.有些用户反馈说本来想要拷贝文件,但是将U盘插入mac系统后竟然不能识别,这是 ...

  2. usb打印机linux识别不了怎么办,win10不识别usb打印机怎么回事_win10系统不识别usb打印机如何修复-系统城...

    打印机是很多办公人员必不可少的打印机,大家都知道要使用打印机的话,要先连接打印机,然而有不少小伙伴遇到这样一个问题,就是不识别usb打印机,导致无法连接使用打印机,这是怎么回事呢,为此,系统城小编给大 ...

  3. 车载仪表android方案,基于NXP iMX8QM 汽车仪表+车载娱乐双作业系统解决方案

    基于NXP iMX8QM 汽车仪表+车载娱乐双作业系统解决方案 在汽车产业不断的发展下,新型汽车都有一个可使用地图.娱乐和其他功能的资讯面板(所谓的车载娱乐系统).另一方面,数位仪表板也正在取代传统汽 ...

  4. 酒店预订系统web端Android端,基于Web Service的掌上酒店预订系统的设计与实现

    摘要: 随着中国经济的发展与人们生活水平的提高,酒店行业得到了飞速的发展.其中酒店预订是酒店发展的重要环节.酒店预订先后经历了以人工.电话.计算机为平台的预订时期.随着无线通信技术和互联网技术的飞速发 ...

  5. 基于python,虹软sdk3.0实现的实时人脸识别

    前言: 虹软sdk3.0是目前用过的最方便,效果最好的且免费的离线人脸识别SDK. 提供的编程语音没有python,有大佬用c++代码接口转成python调用的, 我在此基础上完善了一些功能,能够实现 ...

  6. 计算机32位操作系统最大识别到内存,win7 32位系统可以支持多大的内存_win7 的32位系统最大支持多少g的内存...

    大家都知道win7系统有32位和64位之分,而两者的安装配置是不一样的,一般4G内存的我们安装64位的系统,但是很多用户不知道win7 32位系统可以支持多大的内存,这就给大家分享一下win7 的32 ...

  7. 计算机32位操作系统最大识别到内存,32位系统支持多大内存

    许多小型合作伙伴不知道他们的计算机中最好安装多少内存.事实上,这与我们系统中的位数有关.通常,我们安装64位4G内存系统.32位系统支持多少内存? 很多朋友都知道自己的电脑是安装了64位还是32位的系 ...

  8. Android:基于OpenCV实现身份证识别(C++)——移植图像算法

    系列文章目录 第一章 Android:基于OpenCV实现身份证识别(C++)--图像处理 第二章 Android:基于OpenCV实现身份证识别(C++)--移植图像算法 文章目录 系列文章目录 前 ...

  9. android 身份认证技术,Android平台上基于人脸识别的身份认证系统的设计与实现

    摘要: 随着移动互联网与人工智能技术的发展,基于个人特征的生物识别技术代替传统的身份验证方式已经是大势所趋.而人脸识别是生物识别技术的一个重要组成部分,拥有其他生物识别技术没有的独特优势.本文主要针对 ...

最新文章

  1. 全球第三的晶圆代工厂 也要被卖了?
  2. 二叉树的建立及递归遍历
  3. 具有SmartFilterBar 的 SAP Fiori Elements 自动触发的搜索操作
  4. 计算机视觉中 RNN 应用于目标检测
  5. 计算机普通用户没有软件怎么回事,请教各位高手:单机多用户账户计算机,当管理员用户安装了程序,其它普通用户账户不能使用怎么处理?比如在管理...
  6. 大二上学期数据结构课程设计
  7. 你还在盲目做抖音吗?
  8. python中安装pip_Python中如何安装pip-百度经验
  9. 关于SNIP NTRIP Caster学习笔记
  10. 【Ps问题】PS旋转功能会让图片乱飞的解决方法
  11. matlab求刚度,求整体刚度矩阵matlab程序
  12. MODBUS RTU协议
  13. js修改div标签中的内容
  14. 《寒江独钓》内核学习笔记(1)-- IRP - .Little Hann
  15. Linux系统下Jsp验证码显示不出来, nginx 返回500 解决方法
  16. 移动端常见芯片名及其对应代号
  17. 堡垒机和防火墙的区别是什么?能防删库跑路吗?
  18. python代码代写_python代写代码
  19. 进入游戏后如何回到计算机界面,网易云我的世界电脑版怎样回到游戏主界面 | 手游网游页游攻略大全...
  20. JVM源码系列:JVM内部运行之Class的Method

热门文章

  1. 【java类型转换】
  2. js两数相乘出现多小数
  3. 用NCL将GRIB/GRIB2文件转成nc文件(批量转),JRA-55再分析为例
  4. CSDN开发云-优雅使用云容器服务
  5. ViewPager的使用及获取子view控件的操作(inflate)
  6. linux入门学习(3权限管理)
  7. YbtOj#20073. 「NOIP2020 模拟赛 B 组 Day6」钻石守卫
  8. 用Java语言开发物联网设备应用(5)
  9. PTA 7-191 百钱百鸡
  10. python主函数调用格式_Python的模块与函数