公司要做安卓开发板的双目识别项目,采用的是Camera+SurfaceView ,其实TextureView这个也是一样的原理。采用的是腾讯本地人脸识别方案,其实所有家的人脸识别道理都是相通的,主要相机采集数据-分析人脸数据-识别,,,,

但是同样遇到了一些问题,首先是摄像头拉伸问题,解决这个问题需要了解相机原理,以分辨率640*480为例    那相机呈现的是这样的

那这样是不拉伸的 我的机器是1280*800的 那如果铺满全屏 那就是相机分辨率和屏幕分辨率是成比例放大的 那就需要拉伸SurfaceView达到和布局一样的分辨率,如图所示

那就是把SurfaceView相机的比例同比扩大相应的倍数才可以下面是我处理方式 然后我在调整布局到中间 就可以了,相机拉伸问题就解决了

   private void initLayout() {int surfaceViewWidth = getWidth();int surfaceViewHeight = getHeight();int cameraWidth = 0;int cameraHeight = 0;RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) faceRelativeLayout.getLayoutParams();//判断相机方向需要改变更改宽和高if (StaticVariables.isRotation) {cameraWidth = StaticVariables.cameraWidth;cameraHeight = StaticVariables.cameraHeight;} else {cameraWidth = StaticVariables.cameraHeight;cameraHeight = StaticVariables.cameraWidth;}//如果相机比例相等 不做拉伸if (Chufa(surfaceViewWidth, cameraWidth) == Chufa(surfaceViewHeight, cameraHeight)) {layoutParams.width = surfaceViewWidth;layoutParams.height = surfaceViewHeight;StaticVariables.faceCameraViewWidth = layoutParams.width;StaticVariables.faceCameraViewHeight = layoutParams.height;StaticVariables.faceCameraViewLeft = 0;StaticVariables.faceCameraViewRight = surfaceViewWidth;StaticVariables.faceCameraViewTop = 0;StaticVariables.faceCameraViewDown = surfaceViewHeight;} else//如果相机与画布比例不等 ,计算画布大小 以及识别范围if (Chufa(surfaceViewWidth, cameraWidth) > Chufa(surfaceViewHeight, cameraHeight)) {layoutParams.width = surfaceViewWidth;layoutParams.height = (int) (cameraHeight * Chufa(surfaceViewWidth, cameraWidth));layoutParams.topMargin = (surfaceViewHeight - layoutParams.height) / 2;layoutParams.bottomMargin = (surfaceViewHeight - layoutParams.height) / 2;StaticVariables.faceCameraViewWidth = layoutParams.width;StaticVariables.faceCameraViewHeight = layoutParams.height;StaticVariables.faceCameraViewLeft = 0;StaticVariables.faceCameraViewRight = surfaceViewWidth;StaticVariables.faceCameraViewTop = -layoutParams.topMargin;StaticVariables.faceCameraViewDown = -layoutParams.topMargin + surfaceViewHeight;} //如果相机与画布比例不等 ,计算画布大小 以及识别范围else {layoutParams.width = (int) (cameraWidth * Chufa(surfaceViewHeight, cameraHeight));layoutParams.height = surfaceViewHeight;layoutParams.leftMargin = (surfaceViewWidth - layoutParams.width) / 2;layoutParams.rightMargin = (surfaceViewWidth - layoutParams.width) / 2;StaticVariables.faceCameraViewWidth = layoutParams.width;StaticVariables.faceCameraViewHeight = layoutParams.height;StaticVariables.faceCameraViewLeft = -layoutParams.leftMargin;StaticVariables.faceCameraViewRight = -layoutParams.leftMargin + surfaceViewWidth;StaticVariables.faceCameraViewTop = 0;StaticVariables.faceCameraViewDown = surfaceViewHeight;}faceRelativeLayout.setLayoutParams(layoutParams);faceRelativeLayout.requestLayout();}

android相机拉伸解决办法相关推荐

  1. Android Bitmap OutOfMemory 解决办法

    Android Bitmap OutOfMemory 解决办法 置顶 2014年07月01日 14:41:22 阅读数:3072 标签: OutOfMemoryBitmapandroid图片优化更多 ...

  2. html背景图片拉伸解决办法

    html背景图片拉伸解决办法 body {background-size: 100% 100%; //关键代码,直接拉伸背景图background-image: url("img/99.jp ...

  3. Android之android.os.NewWorkOnMainThreadException解决办法

    1.问题 用别人提供的的sdk的Demo出现android.os.NewWorkOnMainThreadException 2.解决办法 网络请求开启一个线程请求或者开启异步任务都行 3.总结 1. ...

  4. Android之INSTALL_FAILED_INSUFFICIENT_STORAG解决办法

    INSTALL_FAILED_INSUFFICIENT_STORAG       有时候我们项目再次运行的时候,会出现INSTALL_FAILED_INSUFFICIENT_STORAG错误,先翻译下 ...

  5. Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncExceptio解决办法

    很是奇怪,之前配置好的环境,代码可以运行,但是今天打开就报这个错了: Error while obtaining UI hierarchy XML file: com.android.ddmlib.S ...

  6. Error:(100, 0) Could not find method android() for arguments 解决办法

    大家可能有过这种遭遇,从githu上下载了一个Android studio的工程,却无法在运行,总是出现各种各样的错误,这里笔者遇到了一种错误:Error:(100, 0) Could not fin ...

  7. android 屏幕关闭 eofexception,android EOFException异常解决办法 (SharedPreferences保存对象)...

    SharePreferences可以保存String 但是不能保存对象 这不符合面向对象. 为此可以通过序列化和反序列化将Serializable对象和字符串相互转化 所以可以将Serizlizabl ...

  8. android.os.networkonmainthredexception,android.os.NetworkOnMainThreadException 解决办法:

    产生的原因: 在4.0之后在主线程里面执行Http请求都会报这个错,也许是怕Http请求时间太长造成程序假死的情况 解决办法: 1.在发起Http请求的Activity里面的onCreate函数里面添 ...

  9. [Android] Bitmap OOM解决办法二

    2019独角兽企业重金招聘Python工程师标准>>> 突然出现的Out Of Memory这个BUG导致我们项目中断了好几天,在经过不断地摸索之后,今天终于得到了解决.鉴于其强大的 ...

最新文章

  1. 运维企业专题(4)LVS高可用与负载均衡前篇——先学原理,再学配置
  2. 苹果谷歌脸书大佬前往游说!欧盟将首次对AI进行监管
  3. insightface 切换GPU训练报错解决
  4. python程序实例教程基础-python基础教程第三版源代码
  5. linux系统主机信任,Linux信任主机(SSH)
  6. 福师计算机应用基础离线作业一答案,18秋福师《计算机应用基础》在线作业一答案...
  7. thinkphp环境变量.env配置
  8. qq第三方登录注册php,QQ第三方登录PHP
  9. uniapp 封装网络请求
  10. 函数的基本知识,定义,调用,参数,返回值,说明文档,函数的嵌套及应用
  11. Apache Hawq--优化笔记
  12. html怎么设置动画保持,html – 如何使用CSS3为td列可见性设置动画
  13. python numpy模块玩转矩阵与科学计算
  14. linux指令大全(摘自:http://www.3wbmw.cn/archiver/?tid-4706.html)
  15. 三极管饱和及深度饱和状态的理解和判断!
  16. 查看U盘是USB2.0还是USB3.0
  17. QTableView实现冻结行冻结列
  18. 赵小楼《天道》《遥远的救世主》深度解析(130)有道无术,术尚可求也;有术无道,止于术
  19. 如何更改Dropbox的同步文件夹?
  20. VirtualBox 打开虚拟机后,上面的那栏菜单栏不见了的解决办法

热门文章

  1. 移动互联网实战--移动端音频和图形优化处理
  2. Autosar MCAL-ICU输入捕获
  3. python配置cgi_Python+Apache+CGI完全配置
  4. 架构设计-架构愿景分析
  5. JavaSE 8 离线API下载
  6. UE4中动画优化与压缩
  7. Excel-VBA:文本转换数字
  8. json转换成excel在线js小工具分享【不限制大小】
  9. 职场人必看:提高工作效率的6大法则
  10. FPS游戏UE4逆向视频教程