使用Python(OpenCV)中的霍夫线变换从模拟时钟读取时间 [英] Reading time from analog clock using Hough Line Transform in Python (OpenCV)

查看:239
本文介绍了使用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.

cv2.HoughLines函数返回线条所在的角度(从图像顶部开始测量)以及它们与图像左上角的距离.经过一些调整后,我设法说服我的代码为每个时钟指针找到一行,但是到目前为止,我仍然无法从中实际读取时间.

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?

推荐答案

我已经设法解决了我的问题.

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.

这篇关于使用Python(OpenCV)中的霍夫线变换从模拟时钟读取时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆