问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/27091836/reading-time-from-analog-clock-using-hough-line-transform-in-python-opencv