weixin_44613287
weixin_44613287
2019-04-26 17:39

求助,opencv车辆识别报错

20
  • java
  • android-studio
  • android

错误信息

java.lang.NullPointerException: Attempt to invoke virtual method 'void org.opencv.objdetect.CascadeClassifier.detectMultiScale(org.opencv.core.Mat, org.opencv.core.MatOfRect, double, int, int, org.opencv.core.Size, org.opencv.core.Size)' on a null object reference
        at com.example.myapplication.MainActivity.procSrc2Gray(MainActivity.java:139)
        at com.example.myapplication.MainActivity$ProcessClickListener.onClick(MainActivity.java:188)
        at android.view.View.performClick(View.java:4780)
        at android.view.View$PerformClick.run(View.java:19866)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

说是空指针但是找不到问题在哪里。。

求好心人帮帮我。。

前面我有给分类器赋值

public void initializeOpenCVDependencies() {
        try {
            // Copy the resource into a temp file so OpenCV can load it
            InputStream is = getResources().openRawResource(R.raw.cars);
            File cascadeDir = getDir("cars", Context.MODE_PRIVATE);
            File mCascadeFile = new File(cascadeDir.getAbsoluteFile(), "cars.xml");
            FileOutputStream os = new FileOutputStream(mCascadeFile);
            byte[] buffer = new byte[4096];
            int bytesRead=0;
            while ((bytesRead = is.read(buffer)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
            is.close();
            os.close();
            // Load the cascade classifier
            detectface = new CascadeClassifier(mCascadeFile.getAbsolutePath());
        } catch (Exception e) {
            Log.e("OpenCVActivity", "Error loading cascade", e);
        }         
    }
```请问是不是赋值语句有问题?
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答