设为首页 加入收藏

TOP

大疆无人机 Android 开发总结——视频解码(二)
2019-09-04 00:58:50 】 浏览:89
Tags:无人机 Android 开发 总结 视频 解码
dth] = uSample2; nu[2 * (i * uvWidth + j) + 1 + uvWidth] = uSample2; nv[2 * (i * uvWidth + j)] = vSample1; nv[2 * (i * uvWidth + j) + 1] = vSample1; nv[2 * (i * uvWidth + j) + uvWidth] = vSample2; nv[2 * (i * uvWidth + j) + 1 + uvWidth] = vSample2; } } //nv21test byte[] bytes = new byte[yuvFrame.length]; System.arraycopy(y, 0, bytes, 0, y.length); for (int i = 0; i < u.length; i++) { bytes[y.length + (i * 2)] = nv[i]; bytes[y.length + (i * 2) + 1] = nu[i];

   将Buffer中的raw数据整理成jpeg图像

    /* Save the buffered data into a JPG image file*/
    private void screenShot(byte[] buf, String shotDir) {
        File dir = new File(shotDir);
        if (!dir.exists() || !dir.isDirectory()) {
            dir.mkdirs();
        }
        YuvImage yuvImage = new YuvImage(buf,
                ImageFormat.NV21,
                DJIVideoStreamDecoder.getInstance().width,
                DJIVideoStreamDecoder.getInstance().height,
                null);
        OutputStream outputFile;
        final String path = dir + "/ScreenShot_" + System.currentTimeMillis() + ".jpg";
        try {
            outputFile = new FileOutputStream(new File(path));
        } catch (FileNotFoundException e) {
            Log.e(TAG, "test screenShot: new bitmap output file error: " + e);
            return;
        }
        if (outputFile != null) {
            yuvImage.compressToJpeg(new Rect(0,
                    0,
                    DJIVideoStreamDecoder.getInstance().width,
                    DJIVideoStreamDecoder.getInstance().height), 100, outputFile);
        }
        try {
            outputFile.close();
        } catch (IOException e) {
            Log.e(TAG, "test screenShot: compress yuv image error: " + e);
            e.printStackTrace();
        }
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                displayPath(path);
            }
        });
    }

    public void onClick(View v) {
        if (screenShot.isSelected()) {
            screenShot.setText("Screen Shot");
            screenShot.setSelected(false);
            if (useSurface) {
                DJIVideoStreamDecoder.getInstance().changeSurface(videostreamPreviewSh.getSurface());
            }
            savePath.setText("");
            savePath.setVisibility(View.INVISIBLE);
        } else {
            screenShot.setText("Live Stream");
            screenShot.setSelected(true);
            if (useSurface) {
                DJIVideoStreamDecoder.getInstance().changeSurface(null);
            }
            savePath.setText("");
            savePath.setVisibility(View.VISIBLE);
            pathList.clear();
        }
    }

    private void displayPath(String path){
        path = path + "\n\n";
        if(pathList.size() < 6){
            pathList.add(path);
        }else{
            pathList.remove(0);
            pathList.add(path);
        }
        StringBuilder stringBuilder = new StringBuilder();
        for(int i = 0 ;i < pathList.size();i++){
            stringBuilder.append(pathList.get(i));
        }
        savePath.setText(stringBuilder.toString());
    }

  在大疆的Demo程序中,选择采用存储磁盘的方式来获取是各帧。处理函数为Mainactivity类中screenShot(byte[] buf, String shotDir)方法在此方法中使用Android内置类YUVImage的compressToJpeg()方法以流的方式进行存储,存储路径通过shotDir传入。

  以上就是关于DJI 无人机截取取图像帧的介绍,获取图像帧之后就可进行各式各样的图像任务了。

  小菜鸟一个,大家一起学习交流咯。 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇重温Android和Fragment生命周期 下一篇Android进阶之路(1)-详解MVC

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目