Can I train a CNN to detect the number of objects without localizing them first?
There are different approaches to achieve your goals:

1.) Provide only number of objects in an image in order to train an object detector.
This is called weak supervision or weak labeling. 

Some works that utilize this approach:


https://arxiv.org/pdf/1711.05282.pdf : Their approach is to train an object detector on image proposals, together with object counts.
https://hal.inria.fr/hal-02393688/file/1912.00384.pdf : Object detectors can be trained by providing only one categery label per image


2.) There are several works focusing on counting objects:

For example the following works focus on counting arbitrary objects:


https://arxiv.org/pdf/1903.02494.pdf
https://arxiv.org/pdf/1604.03505.pdf


For density estimations there are several works counting people:


https://arxiv.org/abs/1903.00853


Depending on the setup, it could also be used for your application,