简体   繁体   English

使用Python(OpenCV)中的霍夫线变换从模拟时钟读取时间

[英]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. cv2.HoughLines函数返回线条所在的角度(从图像顶部开始测量)以及它们与图像左上角的距离。 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? 那么,您能否建议一个替代解决方案?

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. 当我得到它的那一刻,我将沿着类似函数绘制的线归为一组,按长度对其进行排序,并使用反正弦以及它们的末端位置来找到直立的指针的精确度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM