java OpenCV Android - 如何在轮廓周围绘制圆形/矩形?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12556073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:21:26  来源:igfitidea点击:

OpenCV Android - How to draw a circle/rectangle around contours?

javaandroidopencvdrawcontour

提问by manfred reichelt

I am new to openCV and therefor I have a few problems.

我是 openCV 的新手,因此我有一些问题。

One question is how I can get the coordinates of contours to draw for example a circle around it.

一个问题是我如何获得轮廓的坐标以绘制例如围绕它的圆圈。

My code so far looks like this:

到目前为止,我的代码如下所示:

List<MatOfPoint> contours = mDetector.getContours();
Imgproc.drawContours(mRgba, contours, -1, CONTOUR_COLOR, -1);
<<code that I need>>
Core.circle(mRgba, new Point(150.0,150.0), 100, CONTOUR_COLOR, 5);

the contours are "extracted" and drawn on the surface the testcircle also, but how can I get the coordinates(bounds) from the contours to draw a circle around each of the contours.

轮廓被“提取”并绘制在测试圆的表面上,但是我如何从轮廓中获取坐标(边界)以围绕每个轮廓绘制一个圆圈。

thank you

谢谢

回答by Sassa

I believe that boundingRectand minEnclosingCircleare available for android too. These functions do directly what you want to do. You can find a very nice tutorial that does exactly this, here.

我相信boundingRectminEnclosureCircle也可用于 android。这些函数直接做你想做的事。您可以在此处找到一个非常好的教程来完成此操作