如何使用c ++将点拟合曲线? [英] How can i fit points to curve using c++?

查看:1335
本文介绍了如何使用c ++将点拟合曲线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图片上有一个椭圆形,如下所示。

There a is an ellipse on the picture,just as following.

我通过使用opencv得到了轮廓的点。但是你可以看到pictrue,因为分辨率低,轮廓上有一条直线。我可以把它适合曲线如蓝线吗?

I have got the points of the contour by using opencv. But you can see the pictrue,because the resolution is low, there is a straight line on the contour.How can i fit it into curve like the blue line?

< an href =http://i.stack.imgur.com/VXMtf.jpg =nofollow>

推荐答案

一个解决问题的方法是将你的形状从简单的强度空间到向量空间)。

One Of the method to solve your problem is to vectorize your shape (moving from simple intensity space to vectors space).

我不知道这个领域的最先进的技术。然而,从学校的信息,我可以建议这个解决方案。

I am not aware of the state-of-art in this field. However, from school information, I can suggest this solution.

Bezier曲线 ,你可以尝试使用简单的贝塞尔曲线来建模你的形状。这不是一个艰难的操作,你可以google的十几个。然后,你可以调整它的大小,只要你想,你可以把它呈现为简单的图像。
请注意,您也可以 Splines 而不是Bezier。

Bezier curves, you can try to model your shape using simple bezier curve.This is not a hard operation you can google for dozen of them. Then, you can resizing it as much as you want after that you may render it to simple image. Be aware that you may also Splines instead of Bezier.

另一种方法会更简单但效率较低。由于您提到了OpenCV,因此您可以应用 cv :: fitEllipse 点。注意,这将返回一个包含椭圆的 RotatedRect 。你可以像这样推断你的椭圆:

Another method would be more simple but less efficient. Since you mentioned OpenCV, you can apply the cv::fitEllipse on the points. Be aware that this will return a RotatedRect which contains the ellipse. You can infer your ellipse simply like this:

Center = Center of RotatedRect.
Longest Radius = The Line which pass from the center and intersect with the two small sides of the RotatedRect.
Smallest Radius = The Line which pass from the center and intersect with the two long sides of the RotatedRect.

获得椭圆参数后,您可以根据需要调整大小,您希望使用 cv :: ellipse

After you got your Ellipse Parameters, You can resize it as you want then just repaint it in the size you want using cv::ellipse.

我知道这是一个伪回答。但是,我认为每件事都很容易适用。如果您在实施它时遇到任何问题,请给我一个评论。

I know that this is a pseudo answer. However, I think every thing is easy to apply. If you faced any problem implementing it, just give me a comment.

这篇关于如何使用c ++将点拟合曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆