This answer references the number of hidden service directories. How can I find out how many HSDir nodes there are?
https://torstatus.blutmagie.de/ lists the number of V2Dir nodes (currently 4174).
Unless I'm reading the wrong statistic, which is possible.
Use the official API called "onionoo".
All you need is to count all of the relays.
Here is the link: https://onionoo.torproject.org/summary?flag=v2dir