How to Control an External USB Web Camera Using a Raspberry Pi All In One

xgqfrms / 2023-05-27 / 原文

How to Control an External USB Web Camera Using a Raspberry Pi All In One

如何使用树莓派控制外接 USB 网络摄像头

$ lsusb

$ ls -alth /dev/video*

https://www.raspberrypi.com/documentation/accessories/camera.html

fswebcam

# 安装驱动程序, USB 摄像头
$ sudo apt-get install fswebcam
$ 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]

image

https://linuxcommandlibrary.com/man/fswebcam

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
# ...

image

# 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'.

image

locale errors

$ locale
# man: can't set the locale; make sure $LC_* and $LANG are correct ❌

image

USB 网络摄像头

罗技 C270i 高清网络摄像头 (视频120万像素, 照片 300 万像素)

1280 x 720 => 720P

1280 * 720
// 921600 不足 100 万, 90 万 ✅

  • PC
    https://item.jd.com/31856768766.html

  • Mobile
    https://item.m.jd.com/product/31856768766.html

image

image
image





¥93 RMB ✅ (JD)

image

https://wiki.smzdm.com/p/gxz8yqe/

罗技 C270

image

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

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!