我创建了一个Android应用程序,它使用OpenCV的MSER algorthim实时检测文本区域,并且它的工作正常并且应该做它应该做的事情。然而,当我在不到一分钟后运行它时,应用程序将自行关闭!没有错误或任何错误,它没有崩溃或关闭,它只会关闭应用程序并将我返回到我手机的主页。此外,logcat中没有任何内容。
有人可以帮忙解释一下这个问题吗?
这里是检测文本方法的代码:
private void detectText() {
Scalar CONTOUR_COLOR = new Scalar(255);
MatOfKeyPoint keypoint = new MatOfKeyPoint();
List<KeyPoint> listpoint;
KeyPoint kpoint;
Mat mask = Mat.zeros(mGrey.size(), CvType.CV_8UC1);
int rectanx1;
int rectany1;
int rectanx2;
int rectany2;
int imgsize = mGrey.height() * mGrey.width();
Scalar zeos = new Scalar(0, 0, 0);
List<MatOfPoint> contour2 = new ArrayList<MatOfPoint>();
Mat kernel = new Mat(1, 50, CvType.CV_8UC1, Scalar.all(255));
Mat morbyte = new Mat();
Mat hierarchy = new Mat();
Rect rectan3;
//
FeatureDetector detector = FeatureDetector
.create(FeatureDetector.MSER);
detector.detect(mGrey, keypoint);
listpoint = keypoint.toList();
//
for (int ind = 0; ind < listpoint.size(); ind++) {
kpoint = listpoint.get(ind);
rectanx1 = (int) (kpoint.pt.x - 0.5 * kpoint.size);
rectany1 = (int) (kpoint.pt.y - 0.5 * kpoint.size);
rectanx2 = (int) (kpoint.size);
rectany2 = (int) (kpoint.size);
if (rectanx1 <= 0)
rectanx1 = 1;
if (rectany1 <= 0)
rectany1 = 1;
if ((rectanx1 + rectanx2) > mGrey.width())
rectanx2 = mGrey.width() - rectanx1;
if ((rectany1 + rectany2) > mGrey.height())
rectany2 = mGrey.height() - rectany1;
Rect rectant = new Rect(rectanx1, rectany1, rectanx2, rectany2);
try {
Mat roi = new Mat(mask, rectant);
roi.setTo(CONTOUR_COLOR);
} catch (Exception ex) {
Log.d("mylog", "mat roi error " + ex.getMessage());
}
}
Imgproc.morphologyEx(mask, morbyte, Imgproc.MORPH_DILATE, kernel);
Imgproc.findContours(morbyte, contour2, hierarchy,
Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE);
for (int ind = 0; ind < contour2.size(); ind++) {
rectan3 = Imgproc.boundingRect(contour2.get(ind));
rectan3 = Imgproc.boundingRect(contour2.get(ind));
if (rectan3.area() > 0.5 * imgsize || rectan3.area() < 100
|| rectan3.width / rectan3.height < 2) {
Mat roi = new Mat(morbyte, rectan3);
roi.setTo(zeos);
} else
Imgproc.rectangle(mRgba, rectan3.br(), rectan3.tl(),
CONTOUR_COLOR);
}
}
我描述了设备的内存,它实际上正在增加,如下面的屏幕截图所示:
logcat的一部分:
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Video I/O:
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Parallel framework: TBB (ver 4.4 interface 9003)
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Other third-party libraries:
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Use IPP: NO
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Use Eigen: NO
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Use Cuda: NO
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Use OpenCL: NO
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Use OpenVX: NO
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Use custom HAL: YES (carotene (ver 0.0.1))
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Python 2:
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Interpreter: /usr/bin/python2.7 (ver 2.7.6)
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Python 3:
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Interpreter: /usr/bin/python3.4 (ver 3.4.3)
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Python (for build): /usr/bin/python2.7
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Java:
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: ant: /usr/bin/ant (ver 1.9.3)
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Java wrappers: YES
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Java tests: NO
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Matlab: NO
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Tests and samples:
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Tests: NO
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Performance tests: NO
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: C/C++ Examples: NO
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: Install path: /build/master_pack-android/build/o4a/install
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: cvconfig.h is in: /build/master_pack-android/build/o4a
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication I/OpenCVManager/Helper: -----------------------------------------------------------------
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication D/OpenCVManager/Helper: Init finished with status 0
04-10 15:38:23.183 31168-31168/com.example.lama.myapplication D/OpenCVManager/Helper: Unbind from service
04-10 15:38:23.203 31168-31168/com.example.lama.myapplication D/OpenCVManager/Helper: Calling using callback
04-10 15:38:23.203 31168-31168/com.example.lama.myapplication D/CameraBridge: call checkCurrentState
04-10 15:38:50.803 31168-31178/com.example.lama.myapplication I/art: Background sticky concurrent mark sweep GC freed 97281(3MB) AllocSpace objects, 14(872KB) LOS objects, 16% free, 18MB/22MB, paused 661us total 106.786ms
04-10 15:38:50.813 31168-31178/com.example.lama.myapplication W/art: Suspending all threads took: 5.350ms
04-10 15:39:00.943 31168-31174/com.example.lama.myapplication W/art: Suspending all threads took: 17.194ms
04-10 15:39:04.953 31168-31174/com.example.lama.myapplication W/art: Suspending all threads took: 9.868ms
如何解决这个问题?