Accurately counting objects instances in a given image or video frame is a hard problem to solve in machine learning. A number of solutions have been developed to count people, cars and other objects and none of them is perfect. Of course, we are talking about image processing here, so a neural network seems to be a good tool for the job.
The TensorFlow Object Counting API is an API for the TensorFlow. It is an open-source framework built on top of TensorFlow and Keras that makes it easy to develop object counting systems. Here is a cool implementation for the training of a model to count the number of objects in an image using Tensorflow.