How to Control an External USB Web Camera Using a Raspberry Pi All In One
How to Control an External USB Web Camera Using a Raspberry Pi All In One
如何使用树莓派控制外接 USB 网络摄像头
$ lsusb
$ ls -alth /dev/video*
#!/usr/bin/env bash
# SH_DATE
DATE=$(date +"%Y-%m-%d_%H%M")
# 720P 照片,定时拍摄 corntab
fswebcam -r 1280x720 --no-banner /home/pi/webcam/$DATE.jpg
$ chmod +x webcam.sh
$ ./webcam.sh
# 定时拍摄 corntab
$ corntab -l
$ cornatb -e
# * * * * * /home/pi/webcam.sh 2>&1
# 开机自动拍摄 rc.local
# Raspberry Pi /etc/rc.local
$ cat /etc/rc.local
https://www.raspberrypi.com/documentation/accessories/camera.html
https://www.raspberrypi.com/documentation/computers/camera_software.html#getting-started
https://github.com/raspberrypi/libcamera-apps
Raspberry Pi camera
python3-picamera2
/boot/config.txt
https://datasheets.raspberrypi.com/camera/picamera2-manual.pdf
https://projects.raspberrypi.org/en/projects/getting-started-with-picamera
https://www.raspberrypi.com/products/camera-module-v2/
https://www.raspberrypi.com/products/camera-module-3/
Raspberry Pi
/etc/rc.local
$ sudo vim /etc/rc.local
# Raspberry PI 设置开机自动拍摄脚本
# 自动发送 Base64 图片到钉钉群消息 🚀
su pi -c "exec /home/pi/web-camera.sh"
# 自动上传图片到云网盘 🚀🚀
su pi -c "exec /home/pi/web-camera-cloud.sh"
# 自动上传图片到本地 NAS 🚀🚀🚀
su pi -c "exec /home/pi/web-camera-nas.sh"
# Raspberry PI 设置开机自启动脚本
# 自动发送 IP 地址到钉钉群消息 🚀
su pi -c "exec /home/pi/dd-ip-notice-robot.sh"
cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
# 禁用电源关闭
iwconfig wlan0 power off
# Raspberry PI 设置开机自启动脚本
# 自动发送 IP 地址到钉钉群消息 🚀
# 绝对路径错误 ❌
# su pi -c "exec /home/pi/dd-ip-notice-robot.sh"
su pi -c "exec /home/pi/Desktop/dd-ip-notice-robot.sh"
exit 0
https://www.cnblogs.com/xgqfrms/p/16485330.html
https://gist.github.com/xgqfrms/bae96dd2e1b8ee766867c430c65c609b
fswebcam
# 安装驱动程序, USB 摄像头
$ sudo apt-get install fswebcam
$ man fswebcam
$ man fswebcam > man-fswebcam.md
$ fswebcam --help
$ fswebcam -h
$ man fswebcam
$ man fswebcam > man-fswebcam.md
$ fswebcam --help
$ fswebcam -h
Usage: fswebcam [<options>] <filename> [[<options>] <filename> ... ]
Options:
-?, --help Display this help page and exit.
-c, --config <filename> Load configuration from file.
-q, --quiet Hides all messages except for errors.
-v, --verbose Displays extra messages while capturing
--version Displays the version and exits.
-l, --loop <seconds> Run in loop mode.
-b, --background Run in the background.
-o, --output <filename> Output the log to a file.
-d, --device <name> Sets the source to use.
-i, --input <number/name> Selects the input to use.
-t, --tuner <number> Selects the tuner to use.
-f, --frequency <number> Selects the frequency use.
-p, --palette <name> Selects the palette format to use.
-D, --delay <number> Sets the pre-capture delay time. (seconds)
-r, --resolution <size> Sets the capture resolution.
--fps <framerate> Sets the capture frame rate.
-F, --frames <number> Sets the number of frames to capture.
-S, --skip <number> Sets the number of frames to skip.
--dumpframe <filename> Dump a raw frame to file.
-s, --set <name>=<value> Sets a control value.
--revert Restores original captured image.
--flip <direction> Flips the image. (h, v)
--crop <size>[,<offset>] Crop a part of the image.
--scale <size> Scales the image.
--rotate <angle> Rotates the image in right angles.
--deinterlace Reduces interlace artifacts.
--invert Inverts the images colours.
--greyscale Removes colour from the image.
--swapchannels <c1c2> Swap channels c1 and c2.
--no-banner Hides the banner.
--top-banner Puts the banner at the top.
--bottom-banner Puts the banner at the bottom. (Default)
--banner-colour <colour> Sets the banner colour. (#AARRGGBB)
--line-colour <colour> Sets the banner line colour.
--text-colour <colour> Sets the text colour.
--font <[name][:size]> Sets the font and/or size.
--no-shadow Disables the text shadow.
--shadow Enables the text shadow.
--title <text> Sets the main title. (top left)
--no-title Clears the main title.
--subtitle <text> Sets the sub-title. (bottom left)
--no-subtitle Clears the sub-title.
--timestamp <format> Sets the timestamp format. (top right)
--no-timestamp Clears the timestamp.
--gmt Use GMT instead of local timezone.
--info <text> Sets the info text. (bottom right)
--no-info Clears the info text.
--underlay <PNG image> Sets the underlay image.
--no-underlay Clears the underlay.
--overlay <PNG image> Sets the overlay image.
--no-overlay Clears the overlay.
--jpeg <factor> Outputs a JPEG image. (-1, 0 - 95)
--png <factor> Outputs a PNG image. (-1, 0 - 10)
--save <filename> Save image to file.
--exec <command> Execute a command and wait for it to complete.
https://github.com/fsphil/fswebcam
http://www.sanslogic.co.uk/fswebcam/
# Take a picture
$ fswebcam [filename]
# Take a picture with custom resolution, -r 指定分辨率/尺寸大小🌠
$ fswebcam -r [width]x[height] [filename]
# Take a picture from selected device(Default is /dev/video0), -d 指定摄像头 📸
$ fswebcam -d [device] [filename]
# Take a picture with timestamp(timestamp string is formatted by strftime),设置时间戳 ⏰
$ fswebcam --timestamp [timestamp] [filename]
https://linuxcommandlibrary.com/man/fswebcam
FTP
/ SFTP
FileZilla
$ ifconfig | grep 192
inet 192.168.18.135 netmask 255.255.255.0 broadcast 192.168.18.255
# sftp 22
sftp://192.168.18.135 ✅
sftp://192.168.1.135 ❌
https://www.cnblogs.com/xgqfrms/p/17267400.html
demos
pi@raspberrypi:~/Desktop $ lsusb
Bus 001 Device 004: ID 046d:0825 Logitech, Inc. Webcam C270
Bus 001 Device 003: ID 0424:ec00 Microchip Technology, Inc. (formerly SMSC) SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Microchip Technology, Inc. (formerly SMSC) SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
pi@raspberrypi:~/Desktop $ ls -alth /dev/video*
crw-rw----+ 1 root video 81, 13 May 27 09:33 /dev/video0
crw-rw----+ 1 root video 81, 14 May 27 09:33 /dev/video1
# ...
# Webcam C270
$ /dev/video0
$ /dev/video1
树莓派支持两种类型的摄像头:
一种是 Raspberry Pi 官方的 Camera Module
;
另一种是第三方的 USB 摄像头
/ USB Web 摄像头
;
# 1. Raspberry Pi 官方的摄像头模块,在终端可以直接使用 raspivid 和 raspistill 操作
$ raspivid
$ raspistill
$ sudo raspi-config
# 2. USB 摄像头, 安装驱动程序
$ sudo apt-get install fswebcam
# test
$ fswebcam --no-banner -r 640*480 camera-test.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 640x-1 to 640x480.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
Disabling banner.
Writing JPEG image to 'camera-test.jpg'.
C270i 的 720P
固定对焦有点模糊
呀 💩
焦距 30cm 左右
# 通配符 `*` 两边有空格,导致所有文件被覆盖 bug ❌
# $ fswebcam --no-banner -r 1280 * 720 camera-test.jpg ❌
GitHub 备份文件找回 ✅ https://github.com/xgqfrms/Raspberry-Pi
Linux 如何恢复被覆盖的文件? (数据还原)
# test 720P ❓
$ fswebcam --no-banner -r 1280*720 camera-test.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 1280x-1 to 1280x960.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
Disabling banner.
Writing JPEG image to 'camera-test.jpg'.
焦距 60cm 左右
最佳对焦距离 1m 左右 ✅
$ fswebcam --no-banner -r 1280*960 camera-test.jpg
$ fswebcam --no-banner -r 1920*1080 camera-test.jpg
locale
errors
$ locale
# man: can't set the locale; make sure $LC_* and $LANG are correct ❌
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
USB 网络摄像头
罗技
C270i
高清网络摄像头 (视频120万像素, 照片 300 万像素)
1280 x 720 => 720P
1280 * 720
// 921600 不足 100 万, 90 万 ✅
¥93
RMB ✅ (JD)
https://wiki.smzdm.com/p/gxz8yqe/
罗技
C270
❌
Max Resolution: 720p/30fps
Camera mega pixel: 0.9
✅ (0.9 百万)
Focus type: fixed focus
Lens type: plastic
Built-in mic: Mono
Mic range: Up to 3 ft (1 m)
Diagonal field of view (dFoV): 55°
Universal mounting clip fits laptops, LCD or monitors
https://www.logitech.com.cn/zh-cn/products/webcams/c270-hd-webcam.960-000625.html
https://www.logitech.com/en-us/products/webcams/c270-hd-webcam.960-001063.html
https://www.logitech.com/en-eu/products/webcams/c270-hd-webcam.960-001063.html
为什么罗技官网没有
C270i
详情介绍 ???
https://www.logitech.com.cn/zh-cn/products/webcams.html
refs
https://www-users.york.ac.uk/~mjf5/shed_cam/src/USB webcam.html
https://shumeipai.nxez.com/2020/08/23/raspberry-pi-fswebcam.html
https://www.yahboom.com/build.html?id=2033
https://www.ncnynl.com/archives/201607/266.html
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17436359.html
未经授权禁止转载,违者必究!