The Raspberry Pi Lite system cannot call the CSI camera using opencv

foreword

When using the Raspberry Pi recently, when using the opencv library to call the camera through python , I always read an empty image, but video0 can be checked in the device list, and the call did not report an error, so I read the official document carefully and online. After consulting relevant information, the problem was finally solved.

The system used in this article is the latest official Raspberry Pi OS Lite (32-bit) Bullseye released on 2022-04-04 . The Raspberry Pi model is zero 2w , and the camera is the OV5640 module.

Here is a link to the camera module documentation on the Raspberry Pi official website . Those who want to know more about the use of the camera can go to read it.

1. The cause of the problem

From the official Raspberry Pi documentation, we can see that the Raspberry Pi OS after Bullseye will only include the libcamera library, and no longer include the traditional Raspicam library.
insert image description here
Using the official libcamera-app test, the photos taken by the camera can be obtained through the following commands:

libcamera-jpeg -o test.jpg

This means that the camera can be read by the device, but when using opencv to call the camera to read and store the image, the program will report an error that the image is empty.

use instructions

vcgencmd get_camera

return

supported=0 detected=0

Unable to recognize hardware camera.

I guess it is because the new system libcamera library is used, so opencv cannot call the camera to obtain images.

Two, the solution

1. Install the Raspicam camera library

Run the following commands in the terminal:

cd ~
sudo apt install cmake
git clone https://github.com/raspberrypi/userland
cd userland
./buildme
sudo cp build/bin/* /bin/

2. Modify the config.txt file

The config file is located in the root directory of the TF card, namely /boot.

Comment the following statement in the config.txt file (originally without #):

#camera_auto_detect=1
#dtoverlay=vc4-kms-v3d

Add the following statement below [all]:

dtoverlay=vc4-fkms-v3d
start_x=1

Save and restart the Raspberry Pi:

sudo reboot

3. Test camera

use command again

vcgencmd get_camera

return

supported=1 detected=1

The camera can be detected

Using the opencv test, the photo can be taken normally.

Summarize

Although Raspberry Pi officially claims that libcamera has many advantages, there are still many bugs, so the official also opened the installation channel of the old version of the library. If there are unsolvable bugs in the use of the camera, it may be a time-saving choice to choose the more stable Raspicam good idea.

If there are problems in this article, students are welcome to point them out in the comment area, or you can private message me.

Guess you like

Origin blog.csdn.net/opklnmiojkbn/article/details/124654469