您好,登錄后才能下訂單哦!
Camera預覽時需要對yuv幀做水平翻轉處理,直接在onPreviewFrame(byte[] data, Camera camera)里調用Mirror函數,處理完后的圖片和預覽效果成水平翻轉關系。
nv21的鏡像算法:
private void Mirror(byte[] src, int w, int h) { //src是原始yuv數組 int i; int index; byte temp; int a, b; //mirror y for (i = 0; i < h; i++) { a = i * w; b = (i + 1) * w - 1; while (a < b) { temp = src[a]; src[a] = src[b]; src[b] = temp; a++; b--; } } // mirror u and v index = w * h; for (i = 0; i < h / 2; i++) { a = i * w; b = (i + 1) * w - 2; while (a < b) { temp = src[a + index]; src[a + index] = src[b + index]; src[b + index] = temp; temp = src[a + index + 1]; src[a + index + 1] = src[b + index + 1]; src[b + index + 1] = temp; a+=2; b-=2; } } }
i420的鏡像算法:
private void Mirror(byte[] src, int w, int h) { //src是原始yuv數組 int i; int index; byte temp; int a, b; //mirror y for (i = 0; i < h; i++) { a = i * w; b = (i + 1) * w - 1; while (a < b) { temp = src[a]; src[a] = src[b]; src[b] = temp; a++; b--; } } //mirror u index = w * h;//U起始位置 for (i = 0; i < h / 2; i++) { a = i * w / 2; b = (i + 1) * w / 2 - 1; while (a < b) { temp = src[a + index]; src[a + index] = src[b + index]; src[b + index] = temp; a++; b--; } } //mirror v index = w * h / 4 * 5;//V起始位置 for (i = 0; i < h / 2; i++) { a = i * w / 2; b = (i + 1) * w / 2 - 1; while (a < b) { temp = src[a + index]; src[a + index] = src[b + index]; src[b + index] = temp; a++; b--; } }
I420,YV12,NV12,NV21均屬于YUV420,以下為四種格式的排列順序:
I420: YYYYYYYY UUVV =>YUV420P
YV12: YYYYYYYY VVUU =>YUV420P
NV12: YYYYYYYY UVUV =>YUV420SP
NV21: YYYYYYYY VUVU =>YUV420SP
以上這篇android camera yuv幀水平翻轉實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。