久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從 Android 中的視頻圖像中獲取幀

Getting frames from Video Image in Android(從 Android 中的視頻圖像中獲取幀)
本文介紹了從 Android 中的視頻圖像中獲取幀的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我已經(jīng)實(shí)現(xiàn)了一個(gè)在屏幕上顯示相機(jī)圖片的簡單應(yīng)用程序.我現(xiàn)在喜歡做的是抓取一個(gè)幀并將其作為位圖處理.據(jù)我所知,這并不是一件容易的事.

I've implemented a simple application which shows the camera picture on the screen. What I like to do now is grab a single frame and process it as bitmap. From what I could find out to this point it is not an easy thing to do.

我嘗試使用 onPreviewFrame 方法將當(dāng)前幀作為字節(jié)數(shù)組獲取,并嘗試使用 BitmapFactory 類對(duì)其進(jìn)行解碼,但它返回 null.幀的格式是無標(biāo)題的 YUV,可以轉(zhuǎn)換為位圖,但在手機(jī)上花費(fèi)的時(shí)間太長.此外,我還了解到 onPreviewFrame 方法對(duì)運(yùn)行時(shí)有限制,如果耗時(shí)過長,應(yīng)用程序可能會(huì)崩潰.

I've tried using the onPreviewFrame method with which you get the current frame as a byte array and tried to decode it with the BitmapFactory class but it returns null. The format of the frame is a headerless YUV which could be translated to bitmap but it takes too long on a phone. Also I've read that the onPreviewFrame method has contraints on the runtime, if it takes too long the application could crash.

那么正確的方法是什么?

So what is the right way to do this?

推薦答案

在 API 17+ 中,您可以使用 'ScriptIntrinsicYuvToRGB' RenderScript 從 NV21 轉(zhuǎn)換為 RGBA888.這使您無需手動(dòng)編碼/解碼幀即可輕松處理預(yù)覽幀:

In API 17+, you can do conversion to RGBA888 from NV21 with the 'ScriptIntrinsicYuvToRGB' RenderScript. This allows you to easily process preview frames without manually encoding/decoding frames:

@Override 
public void onPreviewFrame(byte[] data, Camera camera) { 
   Bitmap bitmap = Bitmap.createBitmap(r.width(), r.height(), Bitmap.Config.ARGB_8888);
    Allocation bmData = renderScriptNV21ToRGBA888(
        mContext,
        r.width(),
        r.height(),
        data);
    bmData.copyTo(bitmap);
}

public Allocation renderScriptNV21ToRGBA888(Context context, int width, int height, byte[] nv21) {
  RenderScript rs = RenderScript.create(context);
  ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));

  Type.Builder yuvType = new Type.Builder(rs, Element.U8(rs)).setX(nv21.length);
  Allocation in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);

  Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height);
  Allocation out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);

  in.copyFrom(nv21);

  yuvToRgbIntrinsic.setInput(in);
  yuvToRgbIntrinsic.forEach(out);
  return out;
}

這篇關(guān)于從 Android 中的視頻圖像中獲取幀的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Why does the android emulator camera stop unexpectedly?(為什么android模擬器相機(jī)會(huì)意外停止?)
Android camera , onPictureTaken(byte[] imgData, Camera camera) method amp; PictureCallback never called(Android camera , onPictureTaken(byte[] imgData, Camera camera) 方法 amp;PictureCallback 從未調(diào)用過) - IT屋-程序員軟件開發(fā)技
Understanding the libGDX Projection Matrix(了解 libGDX 投影矩陣)
QR code reading with camera - Android(使用相機(jī)讀取二維碼 - Android)
IP camera with OpenCv in Java(Java中帶有OpenCv的IP攝像頭)
Android mock Camera(Android 模擬相機(jī))
主站蜘蛛池模板: 一区二区三区免费在线观看 | av男人的天堂在线 | 精品一区二区久久久久久久网站 | 亚洲午夜精品视频 | 中文一区二区 | 91久久久精品国产一区二区蜜臀 | 久久久成人免费视频 | 91影院 | 可以在线观看av的网站 | 国产精品夜间视频香蕉 | 亚洲精品视频播放 | 免费同性女女aaa免费网站 | 亚洲精品二区 | 伊人久麻豆社区 | 日韩欧美福利视频 | 国产一卡二卡三卡 | 国产成人免费视频网站视频社区 | 欧美成人二区 | 欧美成人不卡 | chengrenzaixian| 久久成人一区 | 亚洲精品乱码久久久久v最新版 | 亚洲免费在线播放 | 91久久精品视频 | 久久不卡区 | 亚洲一二三区在线观看 | 亚洲成人av在线播放 | 99视频| 亚洲国产一区二区在线 | av在线免费观看网站 | 午夜视频网站 | 91精品国产777在线观看 | 精品久久精品 | 久久久久久免费免费 | 国产婷婷精品av在线 | 在线中文av| 精国产品一区二区三区四季综 | 中文在线视频观看 | 久久婷婷麻豆国产91天堂 | 我爱操 | 国产精品成人一区二区三区夜夜夜 |