TL;DR: You are not aware of the total number of users, but total number of transactions. In order to speculate the number of wallets (mean the number of users), you can adopt some heuristics, but that's all estimation.
First of all, a user can obtain multiple public keys. In order to get the number of public keys, you should firstly parse and extract the bitcoin transaction network that is publicly available. For example, in this dataset, created on Jan 6 2013, there are 8.864.955 public keys.
That's the easy part.
If you wish to calculate the number of users participating in bitcoin networks, you have to adopt some heuristics, as those data are not publicly available, due to the anonymity that is offered by bitcoin.
The first heuristic could be:
When a single transaction has multiple input addresses, we can assume that those addresses belong to the same wallet, thus to the same user. We should bear in mind that users do not share private keys. In fact many users may use web wallets which have pools, so those services will be treated as a single user.
Secondly, you can exploit the change mechanism in transactions. The entire value of unspent output should be sent back to the user as change. Bitcoin, in order to improve anonymity, produces a shadow address which collects back the change that results from any transaction. So when a single transaction has 2 outputs, you have to predict which one of the output addresses is actually belonging to the same user that initiated the transaction. If one of those two outputs has never appeared before in the blockchain, while the other has, then we can assume that the one that never appeared before is the shadow address.
You can read this heuristics in more detail in BitIodine paper. In this work, there are 2.175.621 users found, using the above methodologies.