重要文章
树莓派4b跑通了:https://www.ncnynl.com/archives/202110/4813.html
sudo wget https://datasheets.raspberrypi.org/cmio/dt-blob-dualcam.bin -O /boot/firmware/dt-blob.bin
https://segmentfault.com/a/1190000040009665
参考地址:https://github.com/raspberrypi/linux/blob/rpi-3.10.y/Documentation/video4linux/bcm2835-v4l2.txt
首先添加驱动支持
打开/boot/config.txt 文件在最下面下添加
start_x=1
gpu_mem=128
打开/etc/modules 最下面添加一行
bcm2835-v412
输入控制台命令将视频组添加到自己的用户中,这里的username是在ubuntu中的用户名
sudo usermod -aG video username
我的用户名是ubuntu,那么就是
sudo usermod -aG video ubuntu
安装fswebcam 测试相机是否能驱动
sudo apt-get install fswebcam
测试相机,输出图片,这样在home目录里面就有图片输出了
fswebcam /dev/video0 -r 640x480 ~/test.jpg
————————————————
版权声明:本文为CSDN博主「ourkix」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ourkix/article/details/114752891
In Ubuntu, installing raspi-config is necessary for configuring a Raspberry Pi because raspi-config is a tool specifically designed for configuring various settings on a Raspberry Pi, such as expanding the file system, setting up the network, and enabling or disabling certain features. Without raspi-config, it may be difficult or impossible to configure a Raspberry Pi properly on an Ubuntu system.
wget https://archive.raspberrypi.org/debian/pool/main/r/raspi-config/raspi-config_20230214_all.deb
sudo apt install -y lua5.1 libatopology2 libfftw3-single3 libsamplerate0 alsa-utils
sudo dpkg -i raspi-config_20230214_all.deb
The reason why we need to mount /dev/mmcblk0p1 to /boot before using raspi-config is because raspi-config needs to access and modify the configuration files that are stored in the /boot directory. By mounting the /dev/mmcblk0p1 partition to /boot, we make the configuration files accessible to raspi-config.
df -h
sudo mount /dev/mmcblk0p1 /boot
将user_name
更换成你的username,例如minipupper
sudo usermod -aG video user_name
After mounting /boot, we need to run the command “sudo usermod -aG video ubuntu” to add the user “ubuntu” to the “video” group. The reason for doing this is that the “video” group is required to access the Raspberry Pi’s GPU (Graphics Processing Unit). By adding the “ubuntu” user to the “video” group, we grant it permission to access the GPU and use its hardware acceleration capabilities. This is particularly important if we plan to use the Raspberry Pi for tasks that require graphics processing, such as video playback or computer vision applications.
sudo raspi-config
choose 3 Interface Options
->I1 Legacy Camera
->Enable camera interface
->Yes
->OK
->Finish
->Yes,reboot now
reboot
sudo apt-get install -y v4l-utils
show devices
v4l2-ctl --list-devices
Install the necessary software to use the camera. You can use the raspistill and raspivid commands to take photos and videos with the camera. These commands are part of the raspberry pi userland package, which you can install using the following command:
arduino
Copy code
sudo apt-get install -y raspberry pi userland
Test the camera by running the raspistill command. You should see a preview of the camera output on your screen, and a photo should be taken when you press the Enter key.
in /boot/config.txt
,add
gpu_men=128
start_x=1 # enable the camera interface and the GPU on the CM4
脚本如下
sudo sed -i '$ a # For camera support' /boot/firmware/config.txt
sudo sed -i '$ a gpu_mem=128' /boot/firmware/config.txt # set GPU memory
sudo sed -i '$ a start_x=1' /boot/firmware/config.txt # enable the camera interface and the GPU on the CM4
sudo sed -i '$ a camera_auto_detect=1' /boot/firmware/config.txt # autoload overlays for any recognized cameras for libcamera support
Configuration
Due to CSI and DSI are disabled by default, we need to load the device tree to enable, and I2C-10, I2C-11, and I2C-0, will be occupied when using the CSI camera and DSI screen.
Enter the following command:
sudo apt-get install p7zip-full
wget https://www.waveshare.com/w/upload/4/41/CM4_dt_blob.7z
7z x CM4_dt_blob.7z -O./CM4_dt_blob
sudo chmod 777 -R CM4_dt_blob
cd CM4_dt_blob
sudo dtc -I dts -O dtb -o /boot/firmware/dt-blob.bin dt-blob-disp0-double_cam.dts
#When using any DSI, HDMI1 has no image output, even if you do not connect the DSI screen, as long as the corresponding file is compiled, then HDMI1 will not output.
#If you need to restore, delete the corresponding dt-blob.bin: sudo rm -rf /boot/dt-blob.bin
Enable CSI Camera
Make sure to connect the CSI camera and DSI screen in a power-off state, otherwise the equipment may be damaged.
In addition to modifying the device tree, the CSI camera also needs to be set to enable the camera function.
To enable the CSI camera in Raspberry Pi CM4 running Ubuntu, you can follow these steps:
Connect the CSI camera to the camera port on the Raspberry Pi CM4.
Boot up the Raspberry Pi CM4 and log in to the Ubuntu terminal.
Install the uv4l
package using the following command:
sudo apt-get install uv4l uv4l-raspicam
Once the installation is complete, start the UV4L server using the following command:
uv4l --driver raspicam --auto-video_nr --width 640 --height 480 --encoding mjpeg
This command starts the UV4L server with the raspicam
driver, sets the video resolution to 640x480 pixels, and uses the MJPEG encoding.
Open a web browser on your computer and navigate to the following URL:
http://:8080/stream
Replace
with the IP address of your Raspberry Pi CM4.
You should now see the live video stream from the CSI camera in your web browser.
Note: If you want to access the camera from other devices on your network, you may need to configure your router to forward port 8080 to the IP address of your Raspberry Pi CM4.
wenti # Enable the KMS (“full” KMS) graphics overlay, leaving GPU memory as the
#dtoverlay=vc4-kms-v3d
start_x=1
新方法
sudo apt install ffmpeg
ffplay /dev/video0
在 Ubuntu 上安装树莓派摄像头 v2 驱动程序需要执行以下步骤:
更新系统软件包列表:
sudo apt-get update
安装 raspberrypi-kernel-headers
包:
sudo apt-get install raspberrypi-kernel-headers
安装 git
工具:
sudo apt-get install git
从 GitHub 上克隆摄像头驱动程序的源代码:
git clone https://github.com/raspberrypi/firmware.git
进入驱动程序的源代码目录:
cd firmware
切换到摄像头驱动程序的目录:
cd extra/modules
编译摄像头驱动程序:
make -C ./media
安装驱动程序:
sudo make -C ./media install
重新启动系统,以使摄像头驱动程序生效。
完成以上步骤后,您应该能够使用树莓派摄像头 v2 在 Ubuntu 上进行图像捕获和处理。
sudo nano /etc/modules
1
进去之后加上这样一条命令就行
在结尾处但由于picamera为树莓派或兼容树莓派平台专用的库,且仅能供树莓派使用,下面将介绍更为通用的使用方法。
1.2 V4L2
目前,CSI摄像头可通过picamera等库进行调用,但在Raspbian系统中,并不属于一个video设备而存在,若想将CSI摄像头作为一个视频设备文件使用,则要开启V4L2(Video for Linux 2)模块以开启:
开启方法如下:
sudo vim /etc/modules
在末尾添加一行:
bcm2835-v4l2
此时,CSI摄像头便成为了一个video设备,此时在终端执行:
ls -ltrh /dev/video*
便可查看到video设备,其中video0便是CSI摄像头:
该video设备可同时供Python与C++调用,具体使用请参考《树莓派OpenCV系列教程1:开发环境搭建》的例程。
bcm2835-v4l2
vcgencmd get_camera
微雪 libcamera脚本https://github.com/waveshare/libcamera-install
To use the Raspberry Pi camera on Ubuntu, you will need to install the raspberrypi
kernel module and the uv4l
package. Here are the steps to follow:
Install the raspberrypi
kernel module by running the following command:
sudo apt-get install raspberrypi-kernel-headers
Install the uv4l
package by running the following command:
curl http://www.linux-projects.org/listing/uv4l_repo/lrkey.asc | sudo apt-key add -
echo "deb http://www.linux-projects.org/listing/uv4l_repo/raspbian/stretch stretch main" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install uv4l uv4l-raspicam
Load the bcm2835-v4l2
kernel module by running the following command:
sudo modprobe bcm2835-v4l2
Start the uv4l
server by running the following command:
uv4l --driver raspicam --auto-video_nr --width 640 --height 480 --encoding jpeg
This will start the uv4l
server with the Raspberry Pi camera as the video source, and it will output JPEG-encoded frames with a resolution of 640x480.
To view the camera stream, open a web browser and navigate to http://localhost:8080/stream
.
That’s it! You should now be able to use the Raspberry Pi camera on Ubuntu.
最终测试:
sudo apt install -y python3-pip git
sudo pip3 install jinja2
sudo apt install -y libboost-dev
sudo apt install -y libgnutls28-dev openssl libtiff5-dev
sudo apt install -y qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5
sudo apt install -y meson
sudo pip3 install pyyaml ply
sudo pip3 install --upgrade meson
sudo apt install -y libglib2.0-dev libgstreamer-plugins-base1.0-dev
cd
git clone https://github.com/raspberrypi/libcamera.git
cd libcamera
meson build --buildtype=release -Dpipelines=raspberrypi -Dipas=raspberrypi -Dv4l2=true -Dgstreamer=enabled -Dtest=false -Dlc-compliance=disabled -Dcam=disabled -Dqcam=enabled -Ddocumentation=disabled
sudo ninja -j2 -C build install
sudo apt install -y libegl1-mesa-dev
cd
git clone https://github.com/anholt/libepoxy.git
cd libepoxy
mkdir _build
cd _build
meson
ninja
sudo ninja install
sudo apt install -y cmake libboost-program-options-dev libdrm-dev libexif-dev
cd
git clone https://github.com/raspberrypi/libcamera-apps.git
cd libcamera-apps
mkdir build
cd build
cmake .. -DENABLE_DRM=1 -DENABLE_X11=1 -DENABLE_QT=1 -DENABLE_OPENCV=0 -DENABLE_TFLITE=0
make -j4 # use -j1 on Raspberry Pi 3 or earlier devices
sudo make install
sudo ldconfig # this is only necessary on the first build
sudo apt install -y libcamera-dev libepoxy-dev libjpeg-dev libtiff5-dev
sudo apt install -y qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5
sudo apt install libavcodec-dev libavdevice-dev libavformat-dev libswresample-dev
但由于picamera为树莓派或兼容树莓派平台专用的库,且仅能供树莓派使用,下面将介绍更为通用的使用方法。
1.2 V4L2
目前,CSI摄像头可通过picamera等库进行调用,但在Raspbian系统中,并不属于一个video设备而存在,若想将CSI摄像头作为一个视频设备文件使用,则要开启V4L2(Video for Linux 2)模块以开启:
开启方法如下:
sudo vim /etc/modules
在末尾添加一行:
bcm2835-v4l2
此时,CSI摄像头便成为了一个video设备,此时在终端执行:
ls -ltrh /dev/video*
便可查看到video设备,其中video0便是CSI摄像头:
该video设备可同时供Python与C++调用,具体使用请参考《树莓派OpenCV系列教程1:开发环境搭建》的例程。
https://raspberrypi.stackexchange.com/questions/37359/how-to-use-raspistill-on-ubuntu