OpenCV provided several tools to train cascade classifiers, but they were removed from version 4.0.0. That removal was mainly because of the rise of the deep learning approach, as we mentioned. The deep learning approach became the modern one, while the others, including cascade classifiers, became legacy. But many cascade classifiers are still in use in the world, and in many situations, they are still a good choice. These tools may be added back in some day. You can find and participate in the discussion about this topic at https://github.com/opencv/opencv/issues/13231.
Fortunately, we can use OpenCV v3.4.x, which provides these tools to train the cascade classifiers. The resulting cascade classifier files trained by v3.4 are compatible with v4.0.x. In other words, we can train cascade classifiers with OpenCV v3.4.x and use them with OpenCV v4.0...