如何在Android中使用OpenCV从UDP套接字显示视频? (DjiTello)

时间:2019-05-12 04:43:55

标签: java android opencv

我正在尝试从无人机Dji Tello获得流式传输的视频。它流经IP地址0.0.0.0和端口11111上的UDP套接字。

我试图将视频显示在Surfaceview上,按下按钮后运行以下代码。

String udp_address = "udp://@" + "0.0.0.0" + ':' + 11111;
cap = new VideoCapture(udp_address);

cap.open(udp_address);

Mat frame = new Mat();
cap.read(frame);

Log.d("Matrix", frame.toString());

Mat frameOut = new Mat(frame.cols(), frame.rows(), CvType.CV_8UC1);
Imgproc.cvtColor(frame, frameOut, Imgproc.COLOR_BGR2RGB);

Bitmap bm = Bitmap.createBitmap(frameOut.cols(), frameOut.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(frame, bm);

Canvas canvas = new Canvas(bm);

surfaceView.draw(canvas);

然后出现以下错误:

2019-05-11 23:32:11.500 11883-11883/com.example.telloandroid E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.telloandroid, PID: 11883
    java.lang.IllegalStateException: Could not execute method for android:onClick
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
        at android.view.View.performClick(View.java:6329)
        at android.view.View$PerformClick.run(View.java:25002)
        at android.os.Handler.handleCallback(Handler.java:809)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:7555)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
        at android.view.View.performClick(View.java:6329) 
        at android.view.View$PerformClick.run(View.java:25002) 
        at android.os.Handler.handleCallback(Handler.java:809) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:166) 
        at android.app.ActivityThread.main(ActivityThread.java:7555) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963) 
     Caused by: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.1.0) /build/master_pack-android/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
    ]
        at org.opencv.imgproc.Imgproc.cvtColor_1(Native Method)
        at org.opencv.imgproc.Imgproc.cvtColor(Imgproc.java:2309)
        at com.example.telloandroid.MainActivity.startVideo(MainActivity.java:153)
            ... 11 more

我知道我没有从无人机上得到任何东西,因为框架显示为

垫子[0 * 0 * CV_8UC1,isCont = false,isSubmat = false,nativeObj = 0x72c3555d00,dataAddr = 0x0]

我可能做错了什么?

谢谢您

0 个答案:

没有答案