在Android上使用OpenCV drawContours的奇怪问题

时间:2012-11-26 09:01:47

标签: android opencv draw

我在Android上偶然发现了OpenCV drawContours的一个奇怪问题。 有时,(没有明显的模式)函数drawContours产生这个:

drawContours http://img17.imageshack.us/img17/9031/screenshotgps.png

虽然它应该显然只产生白色部分。

将其置于上下文中: 我使用canny算法检测边缘,然后用

找到轮廓
Imgproc.findContours(dil, contours, dummy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

然后我选择了几个符合某些要求的轮廓,并将它们添加到列表中:

List<MatOfPoint> goodContours = new ArrayList<MatOfPoint>();

之后我随机选择一个轮廓,然后在垫子上绘制它(用白色填充)并将其转换为android Bitmap:

Mat oneContour = new Mat(orig.rows(), orig.cols(), CvType.CV_8UC1);
int index = (int) (Math.random() * goodContours.size());
Imgproc.drawContours(oneContour, goodContours, index, new Scalar(255, 255, 255), -1);
Bitmap oneContourBitmap = Bitmap.createBitmap(oneContour.cols(), oneContour.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(oneContour, oneContourBitmap);

大多数时候,我得到了我的期望:纯黑色背景上的白色补丁,但有时候我会得到上述内容。我在这里完全不知所措。我怀疑可能会有一些内存泄漏,但我会努力在它们不再使用之后立即释放所有Mat的(我也尝试在函数结束时释放它们,但一切都发生但没有效果)但我无法找出问题的根源。

有没有人有类似的问题?

我首先在OpenCV 2.4.0上发现了这一点,但它在2.4.3上保持不变。

任何建议都表示赞赏。

0 个答案:

没有答案