Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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 )

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top