Monday, 11 January 2016

Opencv C++ Code For Drawing a Semi-Circle

This Opencv Tutorial is about drawing a Semi-Circle
You might have wondered that how to draw a Semi-Circle in Opencv when we have no direct syntax available for it.
Even in the Syntax of drawing a circle in Opencv, we dont have any such parameters which can be modified for drawing a semicircle.
C++: void circle(Mat& img, Point center, int radius, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
But, we know that a circle is a special case of an ellipse whose eccentricity is 1. And in the Opencv Ellipse Syntax:
C++: void ellipse(Mat& img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
We can find the parameters like "Start Angle" and "End Angle".
And if we want to draw an Circle From an Ellipse we just need to mention the size of both the axes as same.
Thus,Here is the Opencv Code for drawing a Semi-Circle:

//Opencv C++ Tutorial for drawing a Semi-Circle
#include 
#include 
using namespace cv;
int main( )
{
 // Create black empty images
 Mat image = Mat::zeros( 500, 500, CV_8UC3 );
 // Draw a ellipse
 for(int i=10;i<=250;i=i+10)
 {
 ellipse( image, Point( 250, 250 ), Size( i, i ), 0, 0, 180, Scalar( 255, 255, 0 ), 2, 8 );
 imshow("Image",image);
 waitKey( 250 );
 }
 waitKey( 0 );

 return(0);
}

Output:
Opencv Tutorial For drawing a Semi-Circle

No comments:

Post a Comment