模板: IMX462 2MP Starlight Camera Use Guide For Pi

来自Waveshare Wiki
跳转至: 导航搜索

使用说明

由于IMX462不是树莓派默认支持的摄像头型号,因此无法使用树莓派自带的libcamera或者raspicam库。需要另外安装驱动和控制脚本使用。
提供的驱动仅支持树莓派Raspberry PI OS系统,暂时未对其他系统做支持。

配置i2c

打开树莓派终端,输入指令

sudo raspi-config

选择Interface Options -> I2c -> Yes

下载安装驱动

下载驱动前,请确保已经正常烧写最新的树莓派系统,连接好摄像头,并完成开机配置。
打开树莓派终端,并输入以下指令进行安装

wget https://github.com/veyeimaging/raspberrypi_v4l2/releases/latest/download/raspberrypi_v4l2.tgz
tar -xzvf raspberrypi_v4l2.tgz
cd raspberrypi_v4l2/release/
chmod +x *

安装驱动

树莓派5

cd ~/raspberrypi_v4l2/release/
sudo ./install_driver_rpi5.sh veyecam2m

由于在树莓派5上,驱动程序现在使用media control API,必须先正确设置media graph才可以正常使用。这包括正确设置media pad的格式并正确链接它们。 在rpi5_scripts目录提供了一系列脚本实现这个功能。 因此每次重新上电后,需要运行以下指令配置一下,然后才能正常使用。

cd ~/raspberrypi_v4l2/rpi5_scripts/
sudo ./find_entity.sh
sudo ./media_setting_rpi5.sh veyecam2m

其他树莓派

cd ~/raspberrypi_v4l2/release/
sudo ./install_driver.sh veyecam2m

卸载驱动(可选)

如果需要更换其他摄像头型号的额驱动,可以卸载现在的驱动

sudo ./uninstall_driver.sh veyecam2m

测试摄像头

注:如果你是通过远程终端操作摄像头,在使用预览指令前请先输入export DISPLAY=:0指令指定一下屏幕输出。

使用qv4l2预览图像

  • 安装工具
sudo apt-get install qv4l2
  • 运行工具

在终端命令行界面输入以下工具打开软件

qv4l2

运行后,点击左上角的播放图标进行预览即可

使用Gstreamer预览

安装Gstreamer

打开树莓派终端,并输入以下指令进行安装:

sudo apt-get install gstreamer1.0-tools
sudo apt-get install libx264-dev libjpeg-dev
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-ugly gstreamer1.0-tools gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-plugins-good gstreamer1.0-plugins-bad

抓拍图片

gst-launch-1.0 v4l2src num-buffers=1 device=/dev/video0 ! 'video/x-raw, format=(string)UYVY, width=1920,height=1080' ! jpegenc ! filesink location=test_image.jpg

视频预览

gst-launch-1.0 v4l2src io-mode=dmabuf device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! v4l2convert capture-io-mode=dmabuf output-io-mode=dmabuf ! autovideosink sync=false -v

视频预览(加时间戳显示)

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1"  ! videoconvert ! videoscale ! clockoverlay time-format="%D %H:%M:%S" ! video/x-raw, width=640, height=360 ! autovideosink sync=false -v

录制视频 (mkv文件)

gst-launch-1.0 -e v4l2src io-mode=dmabuf device=/dev/video0 num-buffers=300 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! v4l2h264enc capture-io-mode=dmabuf output-io-mode=dmabuf extra-controls="controls, h264_profile=4, video_bitrate=6200000" ! 'video/x-h264, profile=high, level=(string)4' ! h264parse ! matroskamux ! filesink location=output.mkv

录制视频(mp4文件

gst-launch-1.0 -e v4l2src io-mode=dmabuf device=/dev/video0  num-buffers=300 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! v4l2h264enc capture-io-mode=dmabuf output-io-mode=dmabuf extra-controls="controls, h264_profile=4, video_bitrate=6200000" ! 'video/x-h264, profile=high, level=(string)4' ! h264parse ! mp4mux ! filesink location=video.mp4

TCP视频流传输

树莓派端, 监听端口为5000
gst-launch-1.0 -v v4l2src device=/dev/video0 num-buffers=-1 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! v4l2h264enc extra-controls="controls, h264_profile=4, video_bitrate=4000000" ! 'video/x-h264, profile=high, level=(string)4' ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink  host=x.x.x.x port=5000
从机端获取
gst-launch-1.0 -v tcpclientsrc host=x.x.x.x port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! autovideosink sync=false

注意:x.x.x.x需要根据实际的树莓派IP地址更换,比如gst-launch-1.0 -v tcpclientsrc host=192.168.1.10 port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! autovideosink sync=false

使用Opencv获取视频

gst-launch-1.0 v4l2src device=/dev/video0  ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! videoscale ! "video/x-raw,width=640,height=480" ! videoconvert ! "video/x-raw, format=(string)BGR" ! appsink

注意:这里不是直接在树莓派中单运行的,而是最为video.Capture(str)str的参数做调用。

使用Compute Module 计算模块

如果用户使用的是树莓派的CM3或者CM4计算模块,需要安装dtb和设备树文件。

加载设备树

sudo wget https://datasheets.raspberrypi.com/cmio/dt-blob-dualcam.bin -O /boot/dt-blob.bin
sudo cp ~/raspberrypi_v4l2/release/driver_bin/$(uname -r)/veyecam2m.dtbo /boot/overlays/veyecam2m.dtbo
sudo reboot

设备说明

CM4采用两路i2c分别与两个摄像头通信,分别是i2c-0和i2c-10。
如果同时接入两路摄像头,会在系统成识别成video0和video2两个节点。

CAM0预览

gst-launch-1.0 v4l2src io-mode=dmabuf device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! v4l2convert capture-io-mode=dmabuf output-io-mode=dmabuf ! autovideosink sync=false -v

CAM1预览

gst-launch-1.0 v4l2src io-mode=dmabuf device=/dev/video2 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! v4l2convert capture-io-mode=dmabuf output-io-mode=dmabuf ! autovideosink sync=false -v