DJI Mobile SDK를 통해 무인항공기의 영상 흐름 전송을 통해 YUV 이미지를 얻다

이 기사는 DJI Mobile SDK가 드론의 영상 흐름 전송에서 YUV 이미지를 얻는 것을 소개한다.

DJI UX SDK


DJI UX SDK 간단한 설치 절차를 통해 드론의 영상 흐름 전송과 드론 조작의 UI를 응용 프로그램에 가져올 수 있다.

영상 흐름 매체에서 YUV 이미지를 얻다


Android Video Stream Decoding Sample 샘플은 영상 흐름 전송을 디코딩하고 YUV 이미지를 출력한다.

1. SurfaceTexture에 이미지 표시 및 디코더 생성

    /**
     * Init a fake texture view to for the codec manager, so that the video raw data can be received
     * by the camera
     */
    private void initPreviewerTextureView() {
        videostreamPreviewTtView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
            @Override
            public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
                Log.d(TAG, "real onSurfaceTextureAvailable");
                videoViewWidth = width;
                videoViewHeight = height;
                Log.d(TAG, "real onSurfaceTextureAvailable: width " + videoViewWidth + " height " + videoViewHeight);
                if (mCodecManager == null) {
                    mCodecManager = new DJICodecManager(getApplicationContext(), surface, width, height);
                    //For M300RTK, you need to actively request an I frame.
                    mCodecManager.resetKeyFrame();
                }
            }

        });
    }

2. 디코더에 YuvDataCallback 등록

                    mCodecManager.enabledYuvData(true);
                    mCodecManager.setYuvDataCallback(this);

3. 디코딩된 YUV 이미지 수신

    @Override
    public void onYuvDataReceived(MediaFormat format, final ByteBuffer yuvFrame, int dataSize, final int width, final int height) {
        //In this demo, we test the YUV data by saving it into JPG files.
        //DJILog.d(TAG, "onYuvDataReceived " + dataSize);
        if (count++ % 30 == 0 && yuvFrame != null) {
            final byte[] bytes = new byte[dataSize];
            yuvFrame.get(bytes);
            //DJILog.d(TAG, "onYuvDataReceived2 " + dataSize);
            AsyncTask.execute(new Runnable() {
                @Override
                public void run() {
                    // two samples here, it may has other color format.
                    int colorFormat = format.getInteger(MediaFormat.KEY_COLOR_FORMAT);
                    switch (colorFormat) {
                        case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar:
                            //NV12
                            if (Build.VERSION.SDK_INT <= 23) {
                                oldSaveYuvDataToJPEG(bytes, width, height);
                            } else {
                                newSaveYuvDataToJPEG(bytes, width, height);
                            }
                            break;
                        case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar:
                            //YUV420P
                            newSaveYuvDataToJPEG420P(bytes, width, height);
                            break;
                        default:
                            break;
                    }

                }
            });
        }
    }

좋은 웹페이지 즐겨찾기