即插即用 Raspberry Pi USB 网络摄像头
即插即用 Raspberry Pi USB 网络摄像头 - Raspberry Pi首先安装 Raspberry Pi OS Bullseye 无桌面系统
安装完成后设置联网
sudo nano /boot/wpa_supplicant.conf
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid=“wxdz”
psk=“123456789”
key_mgmt=WPA-PSK
}
联网后更新系统
sudoapt update
sudo apt full-upgrade
更新完成后重启
sudo nano /boot/config.txt 在最后添加以下内容:
#dtoverlay=OV5647
#dtoverlay=IMX219
#dtoverlay=IMX477
#dtoverlay=IMX290,Clock-Frequency=37125000
#dtoverlay=IMX378
#dtoverlay=OV9281
#dtoverlay=IMX296
#dtoverlay=IMX519
#dtoverlay=IMX708,VCM=0
dtoverlay=dwc2,dr_mode=otg
sudo apt install git meson libcamera-dev libjpeg-dev 按Y确认
完成后执行下一步,下载 UVC 小工具软件。这有助于您的 Raspberry Pi 通过 USB 流式传输视频:
git clone https://gitlab.freedesktop.org/camera/uvc-gadget.git
cd uvc-gadget
我们现在需要使用以下命令制作、构建和安装软件:
make uvc-gadget
cd build
sudo meson install
sudo ldconfig
sudo nano ~/.rpi-uvc-gadget.sh ,添加以下内容:
#!/bin/bash
# Variables we need to make things easier later on.
CONFIGFS="/sys/kernel/config"
GADGET="$CONFIGFS/usb_gadget"
VID="0x0525"
PID="0xa4a2"
SERIAL="0123456789"
MANUF=$(hostname)
PRODUCT="UVC Gadget"
BOARD=$(strings /proc/device-tree/model)
UDC=`ls /sys/class/udc` # will identify the 'first' UDC
create_frame() {
# Example usage:
# create_frame <function name> <width> <height> <format> <name> <intervals>
FUNCTION=$1
WIDTH=$2
HEIGHT=$3
FORMAT=$4
NAME=$5
wdir=functions/$FUNCTION/streaming/$FORMAT/$NAME/${HEIGHT}p
mkdir -p $wdir
echo $WIDTH > $wdir/wWidth
echo $HEIGHT > $wdir/wHeight
echo $(( $WIDTH * $HEIGHT * 2 )) > $wdir/dwMaxVideoFrameBufferSize
cat <<EOF > $wdir/dwFrameInterval
$6
EOF
}
create_uvc() {
CONFIG=$1
FUNCTION=$2
echo " Creating UVC gadget functionality : $FUNCTION"
mkdir functions/$FUNCTION
create_frame $FUNCTION 640 480 uncompressed u "333333
416667
500000
666666
1000000
1333333
2000000
"
create_frame $FUNCTION 1280 720 uncompressed u "1000000
1333333
2000000
"
create_frame $FUNCTION 1920 1080 uncompressed u "2000000"
create_frame $FUNCTION 640 480 mjpeg m "333333
416667
500000
666666
1000000
1333333
2000000
"
create_frame $FUNCTION 1280 720 mjpeg m "333333
416667
500000
666666
1000000
1333333
2000000
"
create_frame $FUNCTION 1920 1080 mjpeg m "333333
416667
500000
666666
1000000
1333333
2000000
"
mkdir functions/$FUNCTION/streaming/header/h
cd functions/$FUNCTION/streaming/header/h
ln -s ../../uncompressed/u
ln -s ../../mjpeg/m
cd ../../class/fs
ln -s ../../header/h
cd ../../class/hs
ln -s ../../header/h
cd ../../class/ss
ln -s ../../header/h
cd ../../../control
mkdir header/h
ln -s header/h class/fs
ln -s header/h class/ss
cd ../../../
# This configures the USB endpoint to allow 3x 1024 byte packets per
# microframe, which gives us the maximum speed for USB 2.0. Other
# valid values are 1024 and 2048, but these will result in a lower
# supportable framerate.
echo 2048 > functions/$FUNCTION/streaming_maxpacket
ln -s functions/$FUNCTION configs/c.1
}
echo "Loading composite module"
modprobe libcomposite
if
[ ! -d $GADGET/g1 ]; then
echo "Detecting platform:"
echo "board : $BOARD"
echo "udc : $UDC"
echo "Creating the USB gadget"
echo "Creating gadget directory g1"
mkdir -p $GADGET/g1
cd $GADGET/g1
if
[ $? -ne 0 ]; then
echo "Error creating usb gadget in configfs"
exit 1;
else
echo "OK"
fi
echo "Setting Vendor and Product ID's"
echo $VID > idVendor
echo $PID > idProduct
echo "OK"
echo "Setting English strings"
mkdir -p strings/0x409
echo $SERIAL > strings/0x409/serialnumber
echo $MANUF > strings/0x409/manufacturer
echo $PRODUCT > strings/0x409/product
echo "OK"
echo "Creating Config"
mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo "Creating functions..."
create_uvc configs/c.1 uvc.0
echo "OK"
echo "Binding USB Device Controller"
echo $UDC > UDC
echo "OK"
fi
uvc-gadget -c 0 uvc.0
按 Ctrl+X,然后按 Y,最后按 Enter 以保存编辑后的文件
sudo chmod +x ~/.rpi-uvc-gadget.sh
sudo nano /etc/rc.local 在最后exit 0前添加以下内容
/home/<username>/.rpi-uvc-gadget.sh &
按 Ctrl+X,然后按 Y,最后按 Enter 以保存
页:
[1]