Android如何实现人脸识别竖屏YUV方向调整和图片保存
发表于:2025-11-15 作者:千家信息网编辑
千家信息网最后更新 2025年11月15日,这篇文章将为大家详细讲解有关Android如何实现人脸识别竖屏YUV方向调整和图片保存,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。1.首先可以尝试顺时针旋转90°
千家信息网最后更新 2025年11月15日Android如何实现人脸识别竖屏YUV方向调整和图片保存
这篇文章将为大家详细讲解有关Android如何实现人脸识别竖屏YUV方向调整和图片保存,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
1.首先可以尝试顺时针旋转90°或270°,然后送入识别SDK。
2.旋转方向后依然无法识别时,可以尝试saveImg( ),保存本地检查图片是否符合要求。
/** * 视频顺时针旋转90 * 该方法仅仅在竖屏时候使用 * */ public static byte[] rotateYUV420Degree90(byte[] data, int imageWidth, int imageHeight) { byte[] yuv = new byte[imageWidth * imageHeight * 3 / 2]; int i = 0; for (int x = 0; x < imageWidth; x++) { for (int y = imageHeight - 1; y >= 0; y--) { yuv[i] = data[y * imageWidth + x]; i++; } } i = imageWidth * imageHeight * 3 / 2 - 1; for (int x = imageWidth - 1; x > 0; x = x - 2) { for (int y = 0; y < imageHeight / 2; y++) { yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + x]; i--; yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + (x - 1)]; i--; } } return yuv; } public static byte[] YUV420spRotate270(byte[] src, int width, int height) { int count = 0; int uvHeight = height >> 1; int imgSize = width * height; byte[] des = new byte[imgSize * 3 >> 1]; //copy y for (int j = width - 1; j >= 0; j--) { for (int i = 0; i < height; i++) { des[count++] = src[width * i + j]; } } //u,v for (int j = width - 1; j > 0; j -= 2) { for (int i = 0; i < uvHeight; i++) { des[count++] = src[imgSize + width * i + j - 1]; des[count++] = src[imgSize + width * i + j]; } } return des; } private int i = 1; private String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/0Face/"; private Calendar now = new GregorianCalendar(); private SimpleDateFormat simpleDate = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()); private String fileName = simpleDate.format(now.getTime()); /** * @param data yuv图像数据 * @param width * @param height */ public void saveImg(byte[] data, int width, int height) { File dir = new File(path); if (!dir.exists()) dir.mkdirs(); File f = new File(path + (fileName + "-" + i++) + ".jpg"); FileOutputStream fOut = null; try { //yuv转成bitmap YuvImage image = new YuvImage(data, ImageFormat.NV21, width, height, null); ByteArrayOutputStream stream = new ByteArrayOutputStream(); image.compressToJpeg(new Rect(0, 0, width, height), 80, stream); Bitmap bmp = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size()); //bitmap保存至本地 fOut = new FileOutputStream(f); bmp.compress(Bitmap.CompressFormat.JPEG, 100, fOut); fOut.flush(); fOut.close(); bmp.recycle(); stream.close(); } catch (Exception ex) { Log.e("Sys", "Error:" + ex.getMessage()); } }关于"Android如何实现人脸识别竖屏YUV方向调整和图片保存"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
图片
方向
篇文章
人脸
调整
时针
更多
尝试
不错
实用
内容
图像
数据
文章
方法
时候
知识
视频
参考
帮助
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全相关的课题项目实现
数据库与java对象的数据传递
东莞erp软件开发编程
安徽卫视网络安全攻防
计算机网络安全 论文 安全
下列哪种语句可以修改数据库
图片视频文件服务器
having数据库用法
软件开发项目管理占比
博雅数据库青海二段投档线
ui软件开发多少钱
房得宝网络技术有限公司
弟兄姐妹互联网科技有限公司
政府部门服务器托管
关系代数中的 运算符数据库
广州天祝网络技术
谈我对网络安全的认识
阿里云服务器欠费
怎么做好网络技术
网络安全协议 图标
4G软件开发招聘
东莞erp软件开发编程
计算机网络安全 论文 安全
服务器登录节点和计算节点
怎么在游戏软件开发
数据库操作命令edit
涛思数据库能补值
qq 服务器拒绝
信息系统建设网络安全审查
梵明网络技术