无法打开Camera Android Studio

时间:2019-07-08 23:55:31

标签: android-studio opencv android-camera

我正在尝试使用带有OpenCV框架的VideoCapture类打开Camera。问题出在videoCaputre.read()方法中。如您在这段代码中所见:

       checkpermission();

        video= new VideoCapture();
        video.open(0);

        scheduleTaskExecutor = Executors.newScheduledThreadPool(5);
        scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {
            public void run() {

                runOnUiThread(new Runnable() {
                    public void run() {
                        if(!mostrar){
                            video.read(frame1);
                            mostrar=true;
                        }
                        else{
                            video.read(frame2);
                            mostrar=false;
                            Core.absdiff(frame1,frame2,resultado);
                            Bitmap bmp;
                            Mat rgb = new Mat();
                            Imgproc.cvtColor(resultado, resultado, Imgproc.COLOR_BGR2RGB);
                            bmp = Bitmap.createBitmap(resultado.cols(), resultado.rows(), Bitmap.Config.ARGB_8888);
                            Utils.matToBitmap(resultado, bmp);
                            imagen.setImageBitmap(bmp);
                        }
                    }
                });
            }
        }, 0, 1000, TimeUnit.MILLISECONDS);

这就是我在控制台中看到的内容。

 java.lang.NullPointerException: Attempt to read from field 'long 
org.opencv.core.Mat.nativeObj' on a null object reference
        at org.opencv.videoio.VideoCapture.read(VideoCapture.java:198)
        at jaodev.energymeter.MainActivity$2$1.run(MainActivity.java:100)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6626)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

0 个答案:

没有答案