
Ask HN: OpenCV – How would you track the spinning of a 'wheel'? - mrburton
So I want to track how many times a wheel spins. I have a few ideas, but I&#x27;m curious about alternative solutions.<p>My solutions all require placing a marker on the wheel and tracking its path. I&#x27;m okay with using a marker.<p>Since I want this solution to work with a night vision camera, I can&#x27;t be dependent on color. So I&#x27;m leaning towards looking for a unique shape that wouldn&#x27;t be found in the environment. e.g., a Star<p>I know this solution seems rather simplistic and limited, but I&#x27;m not trying to build a very flexible or intelligent solution.<p>What I&#x27;ve built already works for a very sterile environment, translation - a white background with a green circle moving in a circular motion.<p>This is just a fun weekend project.
======
RandomOpinion
Perhaps use the pattern used by rotary encoders?
[https://en.wikipedia.org/wiki/Rotary_encoder#Ways_of_encodin...](https://en.wikipedia.org/wiki/Rotary_encoder#Ways_of_encoding_shaft_position)

See
[https://www.youtube.com/watch?v=oc5hIxdCMZ0](https://www.youtube.com/watch?v=oc5hIxdCMZ0)
for a visual example.

~~~
mrburton
I'll certainly read up on this. I noticed the struggles in using gray scale
(night vision images) can be tricky. I have a few ideas but I'll certainly
look into this.

thanks!

------
nikonyrh
Is the wheel constantly rotating, or might it be stationary at times? I had
already typed an answer but I was about measuring the RPM, not its
orientation.

~~~
mrburton
The wheel won't always be spinning. In order to handle that, I'll look to see
if the center of the marker has moved by a factor of say 3-4 pixels from it's
last known position.

I have a list for every point encountered along the way, so this won't be an
issue.

What I think I might try today is identify the wheel by looking for the
largest circle. The wheel is light enough to always present a circle with the
night vision camera. Once I identify the wheel, I'll then do one of two
things.

Using CRSF or KCF tracking on the black marker. The fact that the wheel for
the most part is light (white in the image) and the marker is black, it should
be easy to identify. I do have a few black "circular' like objects on the
wheel, but I feel like I can cancel those out.

Maybe :)

~~~
nikonyrh
Actually once you know the circle's position (this needs to be accurate) and
approximate size you can convert it into log-polar coordinates and then apply
phase correlation [1] to a known "template" to determine the rotation angle
very accurately.

I'm not sure what would be the best pattern for this, but I might actually try
implementing a prototype.

[1]
[https://en.wikipedia.org/wiki/Phase_correlation](https://en.wikipedia.org/wiki/Phase_correlation)

