Linux USB摄像头使用
Linux USB摄像头使用
一、使用V4l2工具调试摄像头
1.v4l2-ctl 常用操作
# 安装V4l2工具包
$ sudo apt install v4l-utils# 通过v4l2查看摄像头设备
$ sudo v4l2-ctl --list-devices
EP28WD (usb-fe380000.usb-1.3):/dev/video0/dev/video1# 查看当前摄像头支持的视频压缩格式
$ sudo v4l2-ctl -d /dev/video0 --list-formatsioctl: VIDIOC_ENUM_FMTIndex : 0Type : Video CapturePixel Format: 'YUYV'Name : YUYV 4:2:2Index : 1Type : Video CapturePixel Format: 'H264' (compressed)Name : H.264Index : 2Type : Video CapturePixel Format: 'MJPG' (compressed)Name : Motion-JPEG# 查看摄像头所有参数
$ sudo v4l2-ctl -d /dev/video0 --all
Driver Info (not using libv4l2):Driver name : uvcvideoCard type : EP28WDBus info : usb-fe380000.usb-1.3Driver version: 4.4.167Capabilities : 0x84A00001Video CaptureStreamingExtended Pix FormatDevice CapabilitiesDevice Caps : 0x04200001Video CaptureStreamingExtended Pix Format
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:Width/Height : 640/480Pixel Format : 'YUYV'Field : NoneBytes per Line : 1280Size Image : 614400Colorspace : DefaultTransfer Function : DefaultYCbCr Encoding : DefaultQuantization : DefaultFlags :
Crop Capability Video Capture:Bounds : Left 0, Top 0, Width 640, Height 480Default : Left 0, Top 0, Width 640, Height 480Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 640, Height 480
Selection: crop_bounds, Left 0, Top 0, Width 640, Height 480
Streaming Parameters Video Capture:Capabilities : timeperframeFrames per second: 25.000 (25/1)Read buffers : 0brightness (int) : min=-64 max=64 step=1 default=0 value=0contrast (int) : min=0 max=64 step=1 default=36 value=36saturation (int) : min=0 max=128 step=1 default=64 value=64hue (int) : min=-40 max=40 step=1 default=0 value=0white_balance_temperature_auto (bool) : default=1 value=1gamma (int) : min=72 max=500 step=1 default=100 value=100gain (int) : min=0 max=100 step=1 default=0 value=0power_line_frequency (menu) : min=0 max=2 default=1 value=1white_balance_temperature (int) : min=2800 max=6500 step=1 default=4600 value=4600 flags=inactivesharpness (int) : min=0 max=6 step=1 default=3 value=3backlight_compensation (int) : min=0 max=2 step=1 default=1 value=1exposure_auto (menu) : min=0 max=3 default=3 value=3exposure_absolute (int) : min=1 max=5000 step=1 default=157 value=157 flags=inactiveexposure_auto_priority (bool) : default=0 value=1# 查看摄像头所支持的分辨率sudo v4l2-ctl --list-framesizes=MJPG -d /dev/video0ioctl: VIDIOC_ENUM_FRAMESIZESSize: Discrete 640x480 # Width/HeightSize: Discrete 800x600Size: Discrete 1280x720Size: Discrete 1280x960Size: Discrete 1920x1080Size: Discrete 1600x1200Size: Discrete 2048x1536Size: Discrete 2592x1944Size: Discrete 3264x2448
2.v4l2-ctl 命令
$ v4l2-ctl help
unknown arguments: help General/Common options:--all display all information available-C, --get-ctrl=<ctrl>[,<ctrl>...]get the value of the controls [VIDIOC_G_EXT_CTRLS]-c, --set-ctrl=<ctrl>=<val>[,<ctrl>=<val>...]set the value of the controls [VIDIOC_S_EXT_CTRLS]-D, --info show driver info [VIDIOC_QUERYCAP]-d, --device=<dev> use device <dev> instead of /dev/video0if <dev> starts with a digit, then /dev/video<dev> is used-e, --out-device=<dev> use device <dev> for output streams instead of thedefault device as set with --deviceif <dev> starts with a digit, then /dev/video<dev> is used-h, --help display this help message--help-all all options--help-io input/output options--help-misc miscellaneous options--help-overlay overlay format options--help-sdr SDR format options--help-selection crop/selection options--help-stds standards and other video timings options--help-streaming streaming options--help-tuner tuner/modulator options--help-vbi VBI format options--help-vidcap video capture format options--help-vidout vidout output format options--help-edid edid handling options-k, --concise be more concise if possible.-l, --list-ctrls display all controls and their values [VIDIOC_QUERYCTRL]-L, --list-ctrls-menusdisplay all controls and their menus [VIDIOC_QUERYMENU]-r, --subset=<ctrl>[,<offset>,<size>]+the subset of the N-dimensional array to get/set for control <ctrl>,for every dimension an (<offset>, <size>) tuple is given.-w, --wrapper use the libv4l2 wrapper library.--list-devices list all v4l devices--log-status log the board status in the kernel log [VIDIOC_LOG_STATUS]--get-priority query the current access priority [VIDIOC_G_PRIORITY]--set-priority=<prio>set the new access priority [VIDIOC_S_PRIORITY]<prio> is 1 (background), 2 (interactive) or 3 (record)--silent only set the result code, do not print any messages--sleep=<secs> sleep <secs>, call QUERYCAP and close the file handle--verbose turn on verbose ioctl status reporting
3.usb摄像头与video匹配
linux系统接上usb摄像头会出现/dev/video*设备,如果接多个摄像头,通过/dev/video*无法与真实摄像头一一对应。由于有的时候一个usb摄像头会产生两个或多个video(只有一个能拍照),所以通过udev的rule规则也无法固定。这时可以通过/dev/v4l/by-id/路径的软链接固定。
$ ll /dev/v4l/by-id/
lrwxrwxrwx 1 root root 12 Sep 10 14:32 usb-Generic_HDR_CAMERA_200901010001-video-index0 -> ../../video0
lrwxrwxrwx 1 root root 12 Sep 10 14:32 usb-Generic_HDR_CAMERA_200901010001-video-index1 -> ../../video1
lrwxrwxrwx 1 root root 12 Sep 10 14:24 usb-USB3.0_Camera_8M_USB3.0_Camera_8M_SITN00000000001-video-index0 -> ../../video2
lrwxrwxrwx 1 root root 12 Sep 10 14:24 usb-USB3.0_Camera_8M_USB3.0_Camera_8M_SITN00000000001-video-index1 -> ../../video3
二、安装应用程序显示摄像头捕捉到的视频
1.使用应用程序camorama
sudo apt-get install camorama
camorama#如果使用Xshell进行ssh远程访问,会提醒安装Xmanager软件显示视频流
Xmanager是一个运行于MS Windows平台上的高性能的X window服务器。可以在本地PC上同时运行Unix/Linux和Windows图形应用程序。
Xmanager可以将PC变成X Windows工作站,它可以无缝拼接到UNIX 应用程序中。在UNIX/Linux和Windows网络环境中,Xmanager 是最好的连通解决方案。
2.使用应用程序茄子(cheese)
cheese是Ubuntu自带摄像软件,中文名称茄子。
cheese + 设备号
sudo apt-get install cheese
cheese
# 或
cheese /dev/video0#不支持ssh远程显示
三、ffmpeg获取摄像头图像
sudo apt-get install ffmpegsudo ffmpeg -i /dev/video0 -vframes 1 -s 640x480 -q:v 2 -f image2 /tmp/image6-vdieo0-test1.jpg
FFmpeg常用命令
- 对海康IP摄像头进行拍照、推流和保存视频
sudo ffmpeg -rtsp_transport tcp -i rtsp://192.168.1.19:554/mpeg4 \ # base-vcodec copy -an -f flv rtmp://172.17.0.1/live/camera0 \ # stream-flags +global_header -f stream_segment -segment_time 60 -segment_format_options movflags=+faststart -reset_timestamps 1 -vcodec copy -q:v 4 -an -r 24 -strftime 1 /data/tmpfs/camera/video/%s.flv \ # video-r 2/1 -strftime 1 -y /data/tmpfs/camera/capture.jpg # capture# 从ip摄像头推流
sudo ffmpeg -rtsp_transport tcp -i rtsp://admin:jiangxing123@10.56.0.17:554/h264/ch1/sub/av_stream -vcodec copy -an -f flv rtmp://10.55.2.185:1935/live/camera0# 从视频文件推流
sudo ffmpeg -re -i record.flv -vcodec copy -an -f flv rtmp://10.55.2.185:1935/live/camera0# 从usb摄像头推流
sudo ffmpeg -f video4linux2 -qscale 10 -r 12 -s 640x480 -i /dev/video0 -f flv rtmp://10.55.2.185:1935/live/camera0# ==============test==============
sudo ffmpeg -rtsp_transport tcp -i rtsp://192.168.1.19:554/mpeg4 -f flv -c:v libx264 -an rtmp://10.55.2.185:1935/live/camera0
sudo ffmpeg -rtsp_transport tcp -i rtsp://192.168.1.19:554/mpeg4 -vcodec copy -an -f flv rtmp://10.55.2.185:1935/live/camera0sudo ffmpeg -rtsp_transport tcp -i rtsp://192.168.1.19:554/mpeg4 -vcodec libx264 -crf 5 -acodec aac -f flv rtmp://10.55.2.185:1935/live/camera0 sudo ffmpeg -rtsp_transport tcp -i rtsp://192.168.1.19:554/mpeg4 -vcodec libx264 -acodec aac -f flv rtmp://10.55.2.185:1935/live/camera0
四、gstreamer获取摄像头图像
gstreamer v4l2src 插件
# install gstreamer
apt-get -y install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio# 连续拍照
gst-launch-1.0 --gst-debug-level=3 v4l2src device=/dev/video0 ! \image/jpeg,width=1920,height=1080,framerate=30/1 ! \multifilesink location=/data/tmpfs/capture1.jpg max-files=1 post-messages=true# 单次拍照
gst-launch-1.0 v4l2src device=/dev/video0 num-buffers=1 ! image/jpeg,width=1920,height=1080 ! filesink location=/data/tmpfs/capture2.jpg
- 对海康IP摄像头进行拍照、推流和保存视频
gst-launch-1.0 -e --gst-debug-level=3 rtspsrc location=rtsp://192.168.1.19:554/mpeg4 ! rtph264depay ! h264parse ! tee name=t \t. ! queue ! avdec_h264 ! queue flush-on-eos=true ! videorate ! video/x-raw,framerate=5/1 ! jpegenc ! multifilesink post-messages=true location=/data/tmpfs/camera/capture.jpg max-files=1 \ # capturet. ! queue ! flvmux streamable=true ! rtmpsink sync=false location=rtmp://172.17.0.1/live/camera0 \ # streamt. ! queue ! splitmuxsink max-size-time=600000000000 location=/data/tmpfs/camera/video/%06d.mp4 # video
五、图片加上文字
https://blog.gtwang.org/linux/imagemagick-image-watermarking-tutorial/
html颜色代码
Ubuntu 添加中文字体
sudo apt-get install imagemagick# 左下角
convert /data/tmpfs/capture.jpg -gravity SouthWest -pointsize 40 \-stroke none -fill white -annotate +5+5 "`date "+%Y-%m-%d %H:%M:%S"`" \-stroke none -fill white -annotate +5+70 "$text" /data/tmpfs/output.jpg# 左上角
convert /data/tmpfs/capture.jpg -gravity NorthWest -pointsize 40 \-stroke none -fill white -annotate +5+5 "`date "+%Y-%m-%d %H:%M:%S"`" \-stroke '#40DCD7' -fill white -annotate +5+70 "$text" /data/tmpfs/output.jpg# 有阴影的文字
convert /data/tmpfs/capture.jpg \\( -background 'rgba(0, 0, 0, .5)' -fill white \-font Helvetica -pointsize 60 \label:"`date "+%Y-%m-%d %H:%M:%S"` " -splice 20x20 \\) -gravity NorthWest -geometry +40+40 \-composite /data/tmpfs/output2.jpg# 使用中文字体
text="Hello"
text2="D10.08"
# font对应中文字体路径
convert /data/tmpfs/capture.jpg -font /usr/share/fonts/truetype/wqy/wqy-microhei.ttc -gravity NorthWest -pointsize 60 \-stroke none -fill white -annotate +40+40 "`date "+%Y-%m-%d %H:%M:%S"`" \-gravity NorthEast -pointsize 60 \-stroke none -fill white -annotate +40+40 "$text2" \-gravity SouthEast -pointsize 60 \-stroke none -fill white -annotate +40+40 "$text" /data/tmpfs/output.jpg
图片方位
NorthWest
、North
、NorthEast
、West
、Center
、East
、SouthWest
、South
、SouthEast
。
安装中文字体
sudo apt install -y --force-yes --no-install-recommends fonts-wqy-microhei sudo apt install -y --force-yes --no-install-recommends ttf-wqy-zenhei # 查看中文字体路径 $ fc-list :lang=zh-cn /usr/share/fonts/truetype/wqy/wqy-microhei.ttc: WenQuanYi Micro Hei,文泉驛微米黑,文泉驿微米黑:style=Regular /usr/share/fonts/truetype/wqy/wqy-microhei.ttc: WenQuanYi Micro Hei Mono,文泉驛等寬微米黑,文泉
Linux USB摄像头使用相关推荐
- python linux usb摄像头,树莓派用python中的OpenCV输出USB摄像头画面
本文实例为大家分享了python OpenCV来表示USB摄像头画面的具体代码,供大家参考,具体内容如下 确认Python版本 $ python Python 2.7.13 (default, Jan ...
- linux usb摄像头图像分辨率,linux系统下 USB 摄像头1080分辨率采集帧率低问题的解决方法...
linux系统上一般使用 video4linux2来操作系统摄像. 1.安装一个 v4l2-ctrl工具: sudo apt install v4l-utils 2.查看摄像头支持的视频参数 sudo ...
- linux usb摄像头使用方法,linux 下USB 摄像头的使用说明
此处我只说用uvc通用驱动 查询摄像头是否是UVC设备,参见官网 1 找到CAMERA ID 2 lsusb -d VID:PID -v | grep "14 Video" 如果输 ...
- linux usb 摄像头测试软件
在测试usb camera时,直接插在ubuntu主机行可以看到图像;但是插到开发板时,串口打印枚举错误. 以上说明以下几点: 1.usb camera自身芯片和摄像头正常,因为可以在ubuntu机上 ...
- linux usb摄像头 源码,Linux USB摄像头驱动实现源码分析
Spac5xx的实现是按照标准的USB VIDEO设备的驱动框架编写(其具体的驱动框架可参照/usr/src/linux/drivers/usb/usbvideo.c文件),整个源程序由四个主体部分组 ...
- liunx usb摄像头使用
由于无人机项目需要搭载双光摄像头,故学习一下linux下摄像头的使用. 一.准备 首先要看自己手上的摄像头在linux下是否免驱,也就是看其是不是UVC设备.UVC是USB Video Class的简 ...
- ROS:使用usb_cam软件包调试usb摄像头
0x00 usb_cam软件包简介 为了丰富机器人与外界的交互方式,我们已经增加了与机器人的语音交互方式,不仅使机器人能够说话发声,还能听懂我们说的话,但是如果只有语音交互的话机器人就是一个盲人,无法 ...
- linux下uvc协议访问usb摄像头,Ubuntu调用USB摄像头
FreeBSD Webcam:传送门 1 查看摄像头USB驱动 CMD ls /dev/v* Result /dev/vcs /dev/vcs4 /dev/vcsa1 /dev/vcsa5 /dev/ ...
- 在linux下玩转usb摄像头
硬件平台:PC机一台 .usb摄像头 操作系统:Linux3.0.8 交叉编译环境:arm-none-Linux-gnueabi-gcc 4.5.1 调试步骤: 一.linux 内核解压 1.1使用 ...
最新文章
- bit,Byte、KB、MB、GB、TB、PB、EB之间的关系
- 动态人脸识别系统服务器,动态人脸识别监控管理平台的设计与实现
- SQL Case When Then 条件判断
- Pytorch《DCGAN模型》
- nginx学习文档之一 安装nginx-Windos下安装nginx
- js基础-20-js对象赋值时的key值问题
- svn客户端删除服务器文件,怎么使用Tortoise SVN客户端上传删除文件、创建删除文件夹...
- Python爬虫利器 ——代码转换
- 北京圣思园经典Java培训教学视频分享
- 爬取淘宝买家秀,sign值的生成
- Kotlin基础知识5
- 课外时间学点历史知识~
- springboot项目中favicon.ico的异常处理
- 【CAPL】CAPL的简单介绍及变量
- Elasticsearch:跨集群复制 Cross-cluster replication(CCR)
- 【大学生Python】字典的基础使用
- python多线程爬取ts文件并合成mp4视频
- 使用Bcrypt进行密码加密
- 美团专家:35岁是程序员的终点?
- 《三国群英传2网络版》所有装备掉落查询