创建新的Mat变量会导致android app

时间:2017-01-25 03:16:45

标签: java android opencv android-studio image-processing

我正在开发一个视觉定位系统,该系统在部分代码中使用openCV。其中一个步骤涉及使用Mats。我使用Mat newMat = Mat()Mat newMat = Mat(2, 2, CvType.CV_8UC3)以及其他一些Cv类型创建了一个新垫子。无论我尝试什么,当我运行代码时,一旦它到达前面提到的行,应用程序就完全崩溃了。堆栈跟踪报告两件事之一。当使用更长形式的mat声明时(第二个代码片段),它看起来像这样:

E/ActivityThread: Activity org.firstinspires.ftc.robotcontroller.internal.FtcRobotControllerActivity has leaked IntentReceiver com.qualcomm.analytics.Analytics@f31dd7d that was originally registered here. Are you missing a call to unregisterReceiver()?
                  android.app.IntentReceiverLeaked: Activity org.firstinspires.ftc.robotcontroller.internal.FtcRobotControllerActivity has leaked IntentReceiver com.qualcomm.analytics.Analytics@f31dd7d that was originally registered here. Are you missing a call to unregisterReceiver()?
                      at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:918)
                      at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:719)
                      at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1172)
                      at android.app.ContextImpl.registerReceiver(ContextImpl.java:1152)
                      at android.app.ContextImpl.registerReceiver(ContextImpl.java:1146)
                      at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:554)
                      at com.qualcomm.analytics.Analytics.register(SourceFile:209)
                      at com.qualcomm.analytics.Analytics.<init>(SourceFile:235)
                      at com.qualcomm.modernrobotics.ModernRoboticsUsbUtil.init(SourceFile:85)
                      at com.qualcomm.ftccommon.FtcEventLoop.init(FtcEventLoop.java:191)
                      at com.qualcomm.robotcore.eventloop.EventLoopManager.startEventLoop(EventLoopManager.java:571)
                      at com.qualcomm.robotcore.eventloop.EventLoopManager.setEventLoop(EventLoopManager.java:545)
                      at com.qualcomm.robotcore.eventloop.EventLoopManager.start(EventLoopManager.java:489)
                      at com.qualcomm.robotcore.robot.Robot.start(Robot.java:59)
                      at com.qualcomm.ftccommon.FtcRobotControllerService$RobotSetupRunnable$1.run(FtcRobotControllerService.java:186)
                      at com.qualcomm.robotcore.util.ThreadPool.logThreadLifeCycle(ThreadPool.java:513)
                      at com.qualcomm.ftccommon.FtcRobotControllerService$RobotSetupRunnable.run(FtcRobotControllerService.java:128)
                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                      at java.lang.Thread.run(Thread.java:818)

但是我应该使用更短的形式(第一个代码片段)我得到的以及第一个堆栈跟踪的内容

E/art: No implementation found for void org.opencv.core.Mat.n_delete(long) (tried Java_org_opencv_core_Mat_n_1delete and Java_org_opencv_core_Mat_n_1delete__J)
E/System: Uncaught exception thrown by finalizer
E/System: java.lang.UnsatisfiedLinkError: No implementation found for void org.opencv.core.Mat.n_delete(long) (tried Java_org_opencv_core_Mat_n_1delete and Java_org_opencv_core_Mat_n_1delete__J)
              at org.opencv.core.Mat.n_delete(Native Method)
              at org.opencv.core.Mat.finalize(Mat.java:911)
              at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:202)
              at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:185)
              at java.lang.Thread.run(Thread.java:818)

是否有一个简单的解释为什么代码导致崩溃?在我现在运行的代码中,唯一的行是类声明,函数声明和mat声明,但似乎只需要它。

1 个答案:

答案 0 :(得分:0)

事实证明,主要活动中缺少几行代码。他们加载openCV库,如果它不存在,他们使用openCV库应用程序。

这是OnCreate

isDisplayed()

这正好在主要活动类的声明之下:

if(!OpenCVLoader.initDebug()) {
          RobotLog.d("OpenCV", "Internal OpenCV library not found. Using OpenCV Manager for Initialization");
          OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_1_0, this, mOpenCVCallBack);
      }else{
          RobotLog.d("OpenCV", "OpenCV library found inside package. Using it!");
          mOpenCVCallBack.onManagerConnected(LoaderCallbackInterface.SUCCESS);
      }
  }