The OpenCV installation can be customized. If you want to customize your OpenCV installation, you can try to install it from the source code. You can find out how to do this installation at https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html.
To work with the examples in this chapter, it's best that you work with OpenCV installed, along with ROS.