Installing the v4l2 driver

OpenCV libraries can, by default, recognize the USB camera attached to the RPi's USB port, but it cannot directly detect the RPi camera. To recognize our RPi camera, we need to load the v4l2 driver inside the modules file. To open this file, enter the following command inside the Terminal window:

sudo nano /etc/modules

To load the v4l2 driver, add bcm2835-v4l2 inside the following file:

Press Ctrl + O, followed by Enter, to save this file and press Ctrl + X to exit the file, then reboot your RPi. Once rebooted, the RPi camera will be recognized by the OpenCV libraries.

Get Hands-On Robotics Programming with C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.