Difference between revisions of "V4L2 mode for Raspberry Pi/zh"

From wiki_veye
Jump to navigation Jump to search
Line 60: Line 60:
  
 
<code>veye327 camera probed</code><br />并且/dev/video0 节点存在,证明摄像头状态正常。
 
<code>veye327 camera probed</code><br />并且/dev/video0 节点存在,证明摄像头状态正常。
 +
 +
如果采用veyecam2m驱动,会提示sensor型号及版型,如:
 +
 +
<code>camera id is veyecam2m</code>
 +
 +
<code>sensor is IMX327</code>
 +
 +
<code>board type is ONE board</code>
 +
 +
<code>veyecam2m camera probed</code>
 +
 
=== Gstreamer应用范例 ===
 
=== Gstreamer应用范例 ===
 
<code>export DISPLAY=:0</code>
 
<code>export DISPLAY=:0</code>

Revision as of 14:30, 16 August 2021

English

如何在树莓派平台使用VEYE和CS系列摄像头模组(V4L2模式)

1 概述

针对VEYE系列和CS系列摄像头模组在树莓派平台的使用方式,我们提供了类似raspicam模式的应用层开源软件——veye_raspicam软件

该系列软件,无需驱动支持,对piOS不同版本的兼容性好。

但是,我们认为V4L2驱动模式,也有比较广泛的应用场合。两种模式不能同时使用,具体体现在驱动是否安装上。后文会有详细描述。

本文描述怎样在树莓派平台,通过V4L2方式调用VEYE系列和CS系列的摄像头模组。

2 硬件准备及安装

VEYE系列的硬件准备及安装

CS系列的硬件准备及安装

3 树莓派系统配置

树莓派系统配置

4 驱动安装

4.1 下载驱动包

git clone https://github.com/veyeimaging/raspberrypi_v4l2.git

4.2 安装驱动

cd raspberrypi_v4l2/release/

chmod +x *

sudo ./install_driver.sh [camera module]

camera module:可以是veye327,csimx307,cssc132,veyecam2m等。

备注:veyecam2m是新版本驱动,可以替代veye327,支持VEYE系列200w分辨率的所有模组。

然后重启树莓派。

Note: For VEYE-MIPI-IMX327S or VEYE-MIPI-IMX462, please make sure hdver must >= 0x5.

http://wiki.veye.cc/index.php/VEYE-MIPI-IMX327S_version_log

4.3 卸载驱动

如需更换为raspicam模式,或者想要更换成其他摄像头模组型号的驱动,必须要先卸载现在的驱动。

sudo ./uninstall_driver.sh [camera module]

camera module:可以是veye327,csimx307,cssc132等。

4.4 列出支持的模式

v4l2-ctl --list-formats-ext

5 摄像头状态验证

以veye327为例:

dmesg | grep veye

可以看到:

veye327 camera probed
并且/dev/video0 节点存在,证明摄像头状态正常。

如果采用veyecam2m驱动,会提示sensor型号及版型,如:

camera id is veyecam2m

sensor is IMX327

board type is ONE board

veyecam2m camera probed

6 Gstreamer应用范例

export DISPLAY=:0

  • 安装gstreamer

sudo apt-get install gstreamer1.0-tools

  • 抓拍一张图片(VEYE-MIPI-327,CS-MIPI-IMX307 @1080p mode)

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

  • 视频预览(VEYE-MIPI-327,CS-MIPI-IMX307 @1080p mode)

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 ! autovideosink sync=false -v

  • 视频预览(CS-MIPI-IMX307,CS-MIPI-SC132 @720p mode)

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1280, height=(int)720,framerate=(fraction)60/1" ! videoconvert ! autovideosink sync=false -v

  • 视频预览(CS-MIPI-IMX307,CS-MIPI-SC132 @vga mode)

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)640, height=(int)480" ! videoconvert ! autovideosink sync=false -v

  • 视频预览(CS-MIPI-SC132 @1280*1080@45 mode)

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1280, height=(int)1080,framerate=(fraction)45/1" ! videoconvert ! autovideosink sync=false -v

  • 帧率测试(VEYE-MIPI-327,CS-MIPI-IMX307 @1080p mode)

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 ! fpsdisplaysink video-sink=fakesink -v

7 参数控制软件包使用

由于我们的摄像头参数自由度比较高,并没有采用V4L2参数进行控制,而是使用脚本进行参数配置。

https://github.com/veyeimaging/raspberrypi/tree/master/i2c_cmd

VEYE系列参数控制软件包使用说明
CS系列参数控制软件包使用说明

8 CM4的补充说明

cm4支持两路摄像头同时使用,采用上面的步骤安装的dtbo将只能使用CAM1。如需使用两路摄像头,请按如下步骤:

8.1 更新dt-blob.bin

wget https://www.raspberrypi.org/documentation/hardware/computemodule/dt-blob-dualcam.bin

sudo cp dt-blob-dualcam.bin /boot/dt-blob.bin

8.2 更新双摄像头的dtbo

以csimx307,5.10.17-v7l+版本kernel为例:

sudo cp raspberrypi_v4l2/release/driver_bin/5.10.17-v7l+/csimx307-dual-cm4.dtbo /boot/overlays/csimx307.dtbo

sudo reboot

8.3 设备文件说明

CM4模块采用两路I2C分别与两个摄像头通信。

description i2c bus num video node
CAM0 0 video0
CAM1 10 video2

注:只连一个摄像头,无论CAM0还是CAM1,都是video0。

8.4 gstreamer应用范例

export DISPLAY=:0

  • CAM0视频预览(VEYE-MIPI-327,CS-MIPI-IMX307 @1080p mode)

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 ! fpsdisplaysink videosink=autovideosink sync=false text-overlay=false -v

  • CAM1视频预览(VEYE-MIPI-327,CS-MIPI-IMX307 @1080p mode)

gst-launch-1.0 v4l2src device=/dev/video2 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! videoconvert ! fpsdisplaysink videosink=autovideosink sync=false text-overlay=false -v

9 源代码编译方法

本节主要参考资料为官方piOS编译方法。我们采用交叉编译的方法,5.4.72版本32bitOS为例进行说明。

以下操作均在ubuntu PC上进行。

9.1 开发环境准备

sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev

sudo apt install crossbuild-essential-armhf

9.2 下载标准版本

9.2.1 首先,请确认自己的树莓派上的piOS版本:
  • Release version$ uname -a

Linux raspberrypi 5.4.72-v7l+ #1356 SMP Thu Oct 22 13:57:51 BST 2020 armv7l GNU/Linux

  • Code tag

$ cp /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz ./

gunzip changelog.Debian.gz

查看最上面一条,确定代码tag。

9.2.2 有两种方法可以得到自己想要的版本的源码:

在PC上:

1. 采用git获取到对应branch上的对应tag版本代码

git clone --branch rpi-5.4.y https://github.com/raspberrypi/linux

git checkout raspberrypi-kernel_1.20201022-1

2. 直接从如下链接手动下载对应tag的版本代码

https://github.com/raspberrypi/linux/tags

9.3 patch我们的驱动代码

  • Driver source code

camera驱动源码路径为: linux/drivers/media/i2c,将camera驱动的源码放到对应目录。

  • Modify the the Makefile and Kconfig files

修改同路径下的Config和Makefile,增加对应camera驱动。

  • dts file

dts文件路径为:linux/arch/arm/boot/dts/overlays,将[camera]-overlay.dts文件放到此路径。

  • Modify dts Makefile

修改同路径下的Makefile,增加对应dts编译选项。

9.4 编译

9.4.1 编译准备

export ARCH=arm

export CROSS_COMPILE=arm-linux-gnueabihf-

不同树莓派的编译选项不同,区别如下:

  • Raspberry Pi 1, Pi Zero, Pi Zero W, and Compute Module default build configuration

KERNEL=kernel

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcmrpi_defconfig

  • Raspberry Pi 2, Pi 3, Pi 3+, and Compute Module 3 default build configuration

KERNEL=kernel7

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig

  • Raspberry Pi 4 default build configuration

KERNEL=kernel7l

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2711_defconfig

9.4.2 增加编译选项

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

增加对应camera模块驱动的编译选项,linux5.4版本路径为driver-->multimedia-->i2c;

5.10版本kernel的路径是Device Drivers --> Multimedia Support --> Media ancillary drivers --> Camera sensor devices。

9.4.3 编译输出

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs -j4

10 参考资料

  • 树莓派的piOS编译方案:

https://www.raspberrypi.org/documentation/linux/kernel/building.md