0

我正在尝试从 DJI 获取相机并使用 OpenCV,问题取决于如何设置 OpenCv 以获取 DJI 在无人机处于活动状态时录制的视频预览器。无人机实际上正在将视频流式传输到我的手机,但是当我尝试使用我的 OpenCV 代码从我在 Android Studio 中的项目布局中获取视频预览 id 时,每次我尝试去应用程序的相机视图部分。这是我用来将 OpenCv 对象初始化为 DJI 相机捕获的视频预览器的代码。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_main);

    openCvCameraView = (JavaCameraView)findViewById(R.id.video_previewer_surface);
    openCvCameraView.setVisibility(SurfaceView.VISIBLE);
    openCvCameraView.setCvCameraViewListener(this);

    initUI();

    // The callback for receiving the raw H264 video data for camera live view
    mReceivedVideoDataCallBack = new CameraReceivedVideoDataCallback() {

        @Override
        public void onResult(byte[] videoBuffer, int size) {
            if(mCodecManager != null){
                // Send the raw H264 video data to codec manager for decoding
                mCodecManager.sendDataToDecoder(videoBuffer, size);
            }else {
                Log.e(TAG, "mCodecManager is null");
            }
        }
    };

    DJICamera camera = FPVDemoApplication.getCameraInstance();

    if (camera != null) {

        camera.setDJICameraUpdatedSystemStateCallback(new DJICamera.CameraUpdatedSystemStateCallback() {
            @Override
            public void onResult(CameraSystemState cameraSystemState) {
                if (null != cameraSystemState) {

                    int recordTime = cameraSystemState.getCurrentVideoRecordingTimeInSeconds();
                    int minutes = (recordTime % 3600) / 60;
                    int seconds = recordTime % 60;

                    final String timeString = String.format("%02d:%02d", minutes, seconds);
                    final boolean isVideoRecording = cameraSystemState.isRecording();

                    MainActivity.this.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {

                            recordingTime.setText(timeString);

                            /*
                             * Update recordingTime TextView visibility and mRecordBtn's check state
                             */
                            if (isVideoRecording){
                                recordingTime.setVisibility(View.VISIBLE);
                            }else
                            {
                                recordingTime.setVisibility(View.INVISIBLE);
                            }
                        }
                    });
                }
            }
        });

    }

}
4

1 回答 1

0

根据这篇文章,您可能正在使用 JavaCameraView:`opencv.android.JavaCameraView` 和 `opencv.android.NativeCameraView` 有什么区别

该类org.opencv.android.JavaCameraView在 OpenCV 库中实现。它继承自 CameraBridgeViewBase,它扩展了 SurfaceView 并使用标准的 Android 相机 API

您使用的是来自 DJI SDK 的视频源,而不是手机的硬件摄像头,因此当您调用 OpenCV 时,它可能与传入的源相冲突。

由于我没有无人机,我唯一的建议是查看有关视频流解码的其他 DJI 示例

https://github.com/DJI-Mobile-SDK-Tutorials/Android-VideoStreamDecodingSample

而不是解码流,而是在 JNI (C/C++) 中将数据发送到 OpenCV。

于 2016-10-26T04:28:00.373 回答