Reputation: 25
i just wanted to draw a parabola in OpenCv. i draw an approximation to parabola by using this code below
cvEllipse( img, cvPoint(500,500), cvSize(100,200), 0,180, 360, cvScalar(255,0,255), 1, 8, 0);
but what i need is to take actual formulas of the parabola and draw the function clearly. y=aX^2
Upvotes: 1
Views: 1844
Reputation: 226
Something like that should do the trick
int width = 500;
float miny = -1, maxy = 1;
Mat image = Mat::zeros(width,width,CV_8UC3);
vector<Point2f> list_point(width);
for(int i = 0; i < width; i++){
list_point[i].x = i;
float real_y = miny + ((maxy-miny)*i)/width;
list_point[i].y = real_y*real_y;
}
//Draw the curve
for(int i = 1; i < width; i++) line(image,list_point[i-1],list_point[i],Scalar(255,255,255));
imshow("image",image);
waitKey();
Here is the result with miny = -20 and maxy = 20 in green and miny = -10, maxy = 30 in blue
Upvotes: 2