在 IplImage 上绘制二次圆弧
我目前有一个已使用 opencv 修改的 iplimage。我需要绘制一条像二次方程抛物线那样的圆弧,但我无法使用 opencv 中内置的基本绘图函数来绘制圆弧。我一直在研究 opengl,但我能找到的只是贝塞尔曲线。实现这一目标的最佳库是什么?
I currently have an iplimage that has been modified using opencv. I am needing to draw an arc like that of the parabola of a quadratic equation, and I am unable to make one using the basic drawing functions built into opencv. I have been looking into opengl, but all I can find are bezier curves. What would be the best library to use to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不建议转向 OpenGL(基于您在帖子中提供的内容)。
如果您想采取简单的方法,可以逐点求解二次方程(即假设 x 是自变量,然后求解 y)。一旦 x 和 y 已知,您就可以在指定点绘制颜色。我在下面提供了一个片段,说明了在 OpenCV 中为像素着色的方法。按原样使用此代码:它对我有用,但它没有考虑任何抗锯齿、透明度、子像素精度等。
或者,您可以使用
OpenCV 的贝塞尔曲线支持第三-OpenCV 中贝塞尔曲线支持的第三方库。我过去曾尝试过这个。通过少量计算,您可以使用加权贝塞尔曲线表示任意圆锥曲线。看一下维基百科页面底部附近的有理贝塞尔曲线部分:贝塞尔曲线I wouldn't recommend moving to OpenGL (based upon what you've provided in the post).
If you want to take a simple approach, you can solve the quadratic equation point-by-point (i.e. assume x is the independent variable and then solve for y). Once both x and y are known, you can draw the color at the specified point. I've provided a snippet below that illustrates a method for coloring a pixel in OpenCV. Take this code as it is: it worked for me, but it does not take into account any anti-aliasing, transparency, sub-pixel accuracy, etc.
Alternatively, you can use
OpenCV's Bezier curve supportthird-party libraries for Bezier curve support in OpenCV. I've experimented with this one in the past. With a little computation, you can represent arbitrary conic sections using weighted Bezier curves. Take a look at the Rational Bezier Curves section near the bottom of the wikipedia page: Bezier CurveOpenCV cvEllipse 就是您所需要的。只需注意如何使用参数即可。
cvEllipse(CvArr* img, CvPoint 中心, CvSize 轴, 双角度, 双 startAngle, 双 endAngle, CvScalar 颜色, int 厚度=1, int lineType=8, int 移位=0 )
The OpenCV cvEllipse is all you need for that. Just take care on how to use parameters.
cvEllipse(CvArr* img, CvPoint center, CvSize axes, double angle, double startAngle, double endAngle, CvScalar color, int thickness=1, int lineType=8, int shift=0 )
我在 此页面。它有效,我确信如果我不知道如何将 iplimage 转换为 glut 可以使用的东西,我可以在 opencv 中应用这个算法,因为它与上面提到的
下面非常相似。I found this on this page. It works and I am sure that if I can not figure out how to convert an iplimage to something glut can use I can apply this algorithm in opencv, for it is very similar to what is mentioned
belowabove.