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?
3 Answers
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

- 5,887
- 1
- 30
- 22
-
OpenCV supports bezier curves? – Jacob Oct 24 '11 at 16:01
-
1@Jacob: Good catch - I don't believe they are natively supported. I've experimented with 3rd party stuff in the past. Answer edited. – Throwback1986 Oct 24 '11 at 16:18
-
I currently have the x and y values of about 7 points that are on the parabola and I know the equation. I guess Ill just fill in the points of the lines between the ones I know. – a sandwhich Oct 24 '11 at 21:18
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.

- 4,352
- 12
- 41
- 62
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 )

- 19,708
- 4
- 59
- 82