在 IplImage 上绘制二次圆弧

发布于 2024-12-11 02:25:52 字数 130 浏览 0 评论 0原文

我目前有一个已使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

愿与i 2024-12-18 02:25:52

我不建议转向 OpenGL(基于您在帖子中提供的内容)。

如果您想采取简单的方法,可以逐点求解二次方程(即假设 x 是自变量,然后求解 y)。一旦 x 和 y 已知,您就可以在指定点绘制颜色。我在下面提供了一个片段,说明了在 OpenCV 中为像素着色的方法。按原样使用此代码:它对我有用,但它没有考虑任何抗锯齿、透明度、子像素精度等。

void overlay(IplImage *o, const IplImage *m, const CvScalar &color)
{
  CvSize size = cvGetSize(o);

  unsigned char *p1 = NULL;
  unsigned char *p2 = NULL;

  for (size_t r=0;r<size_t(size.height);r++)
    for (size_t c=0;c<size_t(size.width);c++)
      {
        p1 = cvPtr2D(m, r, c);
        if (p1[0] == 255)
          {
            p2 = cvPtr2D(o, r, c);

            p2[0] = color.val[0];   // R
            p2[1] = color.val[1];   // G
            p2[2] = color.val[2];   // B
          }
      }
}

或者,您可以使用 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.

void overlay(IplImage *o, const IplImage *m, const CvScalar &color)
{
  CvSize size = cvGetSize(o);

  unsigned char *p1 = NULL;
  unsigned char *p2 = NULL;

  for (size_t r=0;r<size_t(size.height);r++)
    for (size_t c=0;c<size_t(size.width);c++)
      {
        p1 = cvPtr2D(m, r, c);
        if (p1[0] == 255)
          {
            p2 = cvPtr2D(o, r, c);

            p2[0] = color.val[0];   // R
            p2[1] = color.val[1];   // G
            p2[2] = color.val[2];   // B
          }
      }
}

Alternatively, you can use OpenCV's Bezier curve support third-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 Curve

恋竹姑娘 2024-12-18 02:25:52

OpenCV 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 )

看透却不说透 2024-12-18 02:25:52

我在 页面。它有效,我确信如果我不知道如何将 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 below above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文