日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android开发之虹软人脸识别活体检测SDK包Bitmap转NV21方法

發布時間:2023/12/15 Android 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android开发之虹软人脸识别活体检测SDK包Bitmap转NV21方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/** * Bitmap 轉化為 ARGB 數據,再轉化為 NV21 數據 * * @param src 傳入的 Bitmap,格式為 Bitmap.Config.ARGB_8888 * @param width NV21 圖像的寬度 * @param height NV21 圖像的高度 * @return nv21 數據 */ public static byte[] bitmapToNv21(Bitmap src, int width, int height) { if (src != null && src.getWidth() >= width && src.getHeight() >= height) { int[] argb = new int[width * height]; src.getPixels(argb, 0, width, 0, 0, width, height); return argbToNv21 (argb, width, height); } else { return null; } } /** * ARGB 數據轉化為 NV21 數據 * * @param argb argb 數據 * @param width 寬度 * @param height 高度 * @return nv21 數據 */ private static byte[] argbToNv21(int[] argb, int width, int height) { int frameSize = width * height; int yIndex = 0; int uvIndex = frameSize; int index = 0; byte[] nv21 = new byte[width * height * 3 / 2]; for (int j = 0; j < height; ++j) { for (int i = 0; i < width; ++i) { int R = (argb[index] & 0xFF0000) >> 16; int G = (argb[index] & 0x00FF00) >> 8; int B = argb[index] & 0x0000FF; int Y = (66 * R + 129 * G + 25 * B + 128 >> 8) + 16; int U = (-38 * R - 74 * G + 112 * B + 128 >> 8) + 128; int V = (112 * R - 94 * G - 18 * B + 128 >> 8) + 128; nv21[yIndex++] = (byte) (Y < 0 ? 0 : (Y > 255 ? 255 : Y)); if (j % 2 == 0 && index % 2 == 0 && uvIndex < nv21.length - 2) { nv21[uvIndex++] = (byte) (V < 0 ? 0 : (V > 255 ? 255 : V)); nv21[uvIndex++] = (byte) (U < 0 ? 0 : (U > 255 ? 255 : U)); } ++index; } } return nv21; }

?

總結

以上是生活随笔為你收集整理的Android开发之虹软人脸识别活体检测SDK包Bitmap转NV21方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。