Showing posts from May, 2013

Analog Clock Using OpenCV

Here is a simple code that create an analog clock synchronized with system clock using OpenCV.
      The idea is simple first we create an image of size 640X640 and draw second, minute and hour markings. These marking are drawn using OpenCV line and the co-ordinates are find-out using parametric equation of circle. Before that we need to draw a circle from the centre of the image with a radius r=image->width/2=320;
The parametric equation of a circle can be written as
x = cx + r * cos(a * CV_PI / 180.0)
y = cy + r * sin(a * CV_PI / 180.0)

Where "cx" and "cy" are the center of image, "r" is the radius of circle, "a" is the angle.

       As we know the hour hand of a normal 12-hour analogue clock turns 360° in 12 hours so angle between each marking will be 360/12=30 degree. As I said before our hour markings are just lines and we need to find co-ordinates of each line, so as a first step we will find out the inner co-ordinates of each line from cent…