Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading time from analog clock using Hough Line Transform in Python (OpenCV)

I've been trying to write a program that locates clock's face on picture and then proceeds to read time from it. Locating works fairly well, reading time - not so much.

The cv2.HoughLines function returns angles at which lines lay (measuring from the top of the image) and their distance from upper-left corner of the image. After a bit of tweaking I've managed to convince my code to find a single line for each of clock's hands, but as for now I remain unable to actually read time from it.

Using appropriate formulas I could find intersection of those lines (middle of the clock) and then iterate along the hands in both directions at once. This could tell me the length of each hand (allowing me to tell them apart) as well as at which direction are they pointing. I'm fairly hesitant about implementing this solution though - not only does it seem somehow ugly but also creates certain risks. For example: problems with rounding could cause the program to check the wrong pixel and find the end of line prematurely.

So, would you kindly suggest an alternative solution?

like image 316
Vindaloo Avatar asked Nov 01 '25 15:11

Vindaloo


1 Answers

I've managed to solve my problem.

I've been trying to use Hough Line Transform where I was supposed to use Hough Probabilistic Transform. The moment I got it, I grouped lines drawn along similar functions, sorted them by length, and used arcsine as well as locations of their ends to find precise degrees at wchich hands stood.

like image 145
Vindaloo Avatar answered Nov 04 '25 06:11

Vindaloo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!