DJI Phantom 3相机在Android Studio中遇到openCV问题

时间:2016-10-26 03:00:31

标签: android opencv camera dji-sdk

我正在尝试从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);
                            }
                        }
                    });
                }
            }
        });

    }

}

1 个答案:

答案 0 :(得分:0)

根据这篇文章,您可能正在使用JavaCameraView:What is the difference between `opencv.android.JavaCameraView` and `opencv.android.NativeCameraView`

  

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

您正在使用DJI SDK中的视频供稿,而不是手机的硬件相机,因此可以解释崩溃,因为当您调用OpenCV时,它与传入的Feed相冲突。

由于我没有无人机,我唯一的建议是在视频流解码上查看其他DJI样本

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

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