java 使用 OpenCV 检测椭圆
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10982988/
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
Ellipse detection with OpenCV
提问by zeroxgames
I would like to detect ellipses with OpenCV for Android, using the Tutorial 2-Basic included with OpenCV 2.4.1 package as a starting point. Note that my ellipse would be a perfect-photoshop one.
我想使用 OpenCV for Android 检测椭圆,使用 OpenCV 2.4.1 包中包含的教程 2-Basic 作为起点。请注意,我的椭圆将是一个完美的 Photoshop 椭圆。
From what I understand, using the "HoughCircles" will only find perfect (or so) circles, thus leaving ellipses out.
据我了解,使用“HoughCircles”只会找到完美的(左右)圆,从而省略了椭圆。
Any help would be much appreciated as I am a total beginner at OpenCV
任何帮助将不胜感激,因为我是 OpenCV 的初学者
This is what I've tried so far
这是我迄今为止尝试过的
case Sample2NativeCamera.VIEW_MODE_CANNY: (ignore the Canny mode...)
capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
Imgproc.HoughCircles(mGray, mCircles, Imgproc.CV_HOUGH_GRADIENT, 1, 20);
Log.d("Ellipse Points", " X " + mCircles.get(1,1)[0] + mCircles.get(1, 1)[1]);
break;
If you think any more info could be useful, please let me know.
如果您认为更多信息可能有用,请告诉我。
采纳答案by Rui Marques
One possible solution to your problem is similar to this thread Detection of coins (and fit ellipses) on an image.
您的问题的一种可能解决方案类似于此线程检测图像上的硬币(和拟合椭圆)。
You should take a look a opencv's function fitEllipse.
您应该看看 opencv 的函数fitEllipse。
回答by karlphillip
The parameters used in HoughCircles
play a fundamental role. HoughCircles
will detect not just perfect, but also near-perfect circles (ellipses). I suggest you check this examples:
中使用的参数HoughCircles
起着基础性的作用。HoughCircles
不仅可以检测完美的圆,还可以检测接近完美的圆(椭圆)。我建议你检查这个例子:
- How to detect circles (coins) in a photo
- Simple object detection using OpenCV
- OpenCV dot target detection
- Reshaping noisy coin into a circle form
And this answerhas a decent collection of references.
而这个答案有引用的一个体面的集合。
回答by Zaphod
If you already have an idea of the sizes of the ellipses that you're looking for, then try the following steps:
如果您已经知道要查找的椭圆的大小,请尝试以下步骤:
- Find Canny edges in the image
- Use a sliding window, the size of which is the maximum length of the major axis of ellipses you're looking for.
- Within the window, collect all edge pixels, pick 6 pixels randomly and use linear least squaresto fit an ellipse in the general form.
- Repeat the above step in a RANSAC like procedure.
- If there are enough inliers, you have an ellipse.