How Can detect time from analog clock
Show older comments
I try to detect the time shown on the clock in hours and minutes, and seconds.
The style of the clocks can vary. Some have Arabic numbering whilst others are in Roman. Some have dashes for the numbers whilst others have neither.
Like this images:


10 Comments
Jan
on 24 Mar 2021
Okay. What have you tried so far? Which toolboxes are available? Is this a homework or your master thesis? Do you want to solve this with a fuzzy logic approach, image segementation or a neural network?
Please mention any details and ask a specific question.
Kamal Saad
on 24 Mar 2021
Jan
on 24 Mar 2021
This is an interesting project. Which kind of answer to which question do you need from the forum?
Kamal Saad
on 24 Mar 2021
Adam Danz
on 24 Mar 2021
So the clocks are already cropped as in the 2nd clock in your image, right? If the clocks aren't cropped or their surfaces aren't orthogonal to the camera view, the task becomes very difficult.
Assuming the clocks are cropped and orthogonal to the camera angle, can you assume the base of the hands are centered on the clock unlike these clocks? If this cannot be assumed, the task again becomes more difficult.

Lastly, the complexity of the solution also depends on the clock background. Clocks with radial lines on the clock face will pose a difficulty in parsing the clock hands from the background.

Kamal Saad
on 24 Mar 2021
Edited: Kamal Saad
on 24 Mar 2021
Adam Danz
on 24 Mar 2021
The scope of your questions are quite large and span an entire project so I'm not sure what answers you're looking for. If the camera view is not orthogonal to the surface of the clock and if you don't know the shape of the clock (circle / square) the task is quite difficult.
- Crop clock (this alone is a project).
- Apply any needed transformations to adjust for camera angles (this is a large task)
- Apply image rotation so clock is in expected orientation (ie, 12 on top) (also a large task since clocks represent hours differently).
- Isolate clock hands from background (this could be a large task if your clocks have complex backgrounds as I've shared in a previous comment).
- Identify which hand is the Hour and Minutes hand. If a seconds hand is present you'll have to deal with that too. Cross your fingers that all hour hands are shorter than minute hands.
- Calculate the angle of each hand (relatively easy).
- Convert the angles to hour/minute (relatively easy).
Some resources:
- https://www.damirscorner.com/blog/posts/20020101-TimeRecognitionFromAnalogClock.html
- https://community.wolfram.com/groups/-/m/t/884007
- https://www.mathworks.com/matlabcentral/answers/21832-get-time-from-the-clock-image-in-matlab-image-processing
- https://felixduvallet.github.io/blog/deep.time/
- https://towardsdatascience.com/training-neural-net-to-read-clock-time-9473175171e3
- https://stackoverflow.com/questions/1951679/get-time-from-the-clock-image-in-matlab-image-processing
- https://combine.se/reading-an-analog-clock-using-image-processing/
Kamal Saad
on 24 Mar 2021
omar bahaa
on 9 Jun 2021
Hi kamal saad If you found the appropriate code for the project can you send it to me through email (omar000888@hotmail.com) because i cant find any source Thanks in advance
Answers (1)
Image Analyst
on 24 Mar 2021
2 votes
So what are your plans? Since you have such a wide variety of clock appearances, I'd look into first using deep learning to find and crop the clocks out. Then I'd probably use traditional image analysis to find the hands, get their angles, and (assuming that 12 is at the top in all cases), convert the angles into a time. Sorry, no I don't have code that does that. It will be a fun part of your learning to develop that code. Good luck.
3 Comments
Kamal Saad
on 24 Mar 2021
Image Analyst
on 24 Mar 2021
For some of the images it can, but you'll have to put in a lot of special handling for "weird" images. Ideal would be a bright (or dark) clock on a uniform contrasting color/brightness background. Then you could just threshold to find the clock. Take the largest blob with bwareafilt(), fill it with imfill(), mask the image to erase everything except the clock face, then threshold again to find the hands. Determine if there are two or three hands and if there are 3, take the two longest hands and throw out the thinnest hand (second hand). Then find the centroid of the binary image mask (the clock) and find out which blob has a coordinate closest to the centroid. That should be the pair of hands that is the hours and minutes. Then mask out a little circle at the centroid so that you have two separated blobs. Then call regionprops again and get the angle of the two hands, which you can then convert to a time.
Kamal Saad
on 24 Mar 2021
Categories
Find more on Image Processing and Computer Vision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!