CSDN仅用于增加百度收录权重,排版未优化,日常不维护。请访问:www.hceng.cn 查看、评论。
本博文对应地址: https://hceng.cn/2019/06/23/AM335X——USB摄像头/#more

记录使用AM335X,在LCD和Web上显示USB摄像头图像。

之前在Tiny4412上学习了UVC,并在Tiny4412的LCD上显示了USB摄像头图像。
最近需要在AM335X上,实现USB摄像头图像在LCD和Web上显示,简单记录一下。

1.准备工作

1.1 修改UVC驱动

参考之前博客博客Linux摄像头驱动2——UVC_2.2移植内核摄像头驱动里,修改drivers/media/usb/uvc/uvc_driver.cdrivers/media/usb/uvc/uvc_video.c

1.2 添加UVC驱动

在内核里,添加UVC驱动

Device Drivers  ---> <*> Multimedia support  --->[*]   Media USB Adapters  ---><*>   USB Video Class (UVC)

重新编译内核,烧写。

2.LCD显示

参考之前的博客Linux摄像头驱动3——LCD显示,直接使用代码,交叉编译得到LCD显示程序video2lcd

video2lcd拷贝到AM335X里运行,发现提示报错:

Wrong JPEG library version: library is 92, caller expects 62

video2lcd中的mjpeg2rgb.c会用到libjpeg库,程序里请求的是62版本的,而AM335x里比较新,为92版本,提示不兼容。
看了下LCD显示程序的源码,源码里没看到哪里对版本需求的定义,决定暂时先重新移植62版的libjpeg库。

先下载jpegsrc.v6b.tar.gz,编译该源码会用到libtool-1.5.22.tar.gz,也要下载。

  • 交叉编译libtool-1.5.22
    1、因为是交叉编译,需要先创建安装路径,让生成的文件保存在该目录,避免覆盖主机的相关文件,mkdir /work/out_libtool
    2、解压源码,tar xf libtool-1.5.22.tar.gz
    3、进入解压目录,设置配置文件,./configure --host=arm-linux-gnueabihf --prefix=/work/out_libtool CC=arm-linux-gnueabihf-gcc
    4、交叉编译、安装,make && make install

  • 交叉编译jpegsrc.v6b
    1、先创建安装路径,mkdir /work/out_jpeg
    2、解压源码,tar xf libtool-1.5.22.tar.gz
    3、进入解压目录,设置配置文件,./configure --host=arm-linux-gnueabihf --prefix=/work/out_jpeg CC=arm-linux-gnueabihf-gcc --enable-shared --enable-static
    4、该程序无法自动生成一些目录,手动创建以下四个目录:/work/out_jpeg/man/man1/work/out_jpeg/include/work/out_jpeg/lib/work/out_jpeg/bin
    5、将前面libtool-1.5.22生成的libtoollibtoolize复制到源码根目录,cp /work/libtool/libtool /work/jpeg-6b/cp work/libtool/libtoolize /work/jpeg-6b/
    6、交叉编译、安装,make && make install

/work/out_jpeg/lib会生成如下文件:

libjpeg.so  libjpeg.so.62  libjpeg.so.62.0.0

在AM335x里,执行rm /usr/lib/libjpeg*,删除AM335x的libjpeg*相关文件,复制前面生成的文件到该目录下,因为原来/usr/lib/下还有/usr/lib/libjpeg.so.8libjpeg.so.9,其它程序(后面Web)会用到,还需要执行ln -sf /usr/lib/libjpeg.so.62 libjpeg.so.8ln -sf /usr/lib/libjpeg.so.62 libjpeg.so.9,让libjpeg.so.8libjpeg.so.9软链接到libjpeg.so.62,此时/usr/lib/libjpeg*如下:
{% codeblock lang:shell %}

ls /usr/lib/libjpeg* -lh

-rwxr-xr-x 1 root root 134.3K Jan 1 1970 /usr/lib/libjpeg.so
-rwxr-xr-x 1 root root 134.3K Jan 1 1970 /usr/lib/libjpeg.so.62
-rwxr-xr-x 1 root root 134.3K Jan 1 1970 /usr/lib/libjpeg.so.62.0.0
lrwxrwxrwx 1 root root 22 Jan 1 00:06 /usr/lib/libjpeg.so.8 -> /usr/lib/libjpeg.so.62
lrwxrwxrwx 1 root root 22 Jan 1 00:07 /usr/lib/libjpeg.so.9 -> /usr/lib/libjpeg.so.62
{% endcodeblock %}

此时再执行video2lcd -v /dev/video0 -d /dev/fb0即可在LCD上看到USB摄像头图像。

3.Web显示

MJPG-streamer是一个优秀的开源项目,它可以通过HTTP的方式访问Linux上面的兼容摄像头,从而做到远程视频传输的效果。

Buildroot里添加mjpg-streamer:

Target packages  --->Networking applications  --->[*] mjpg-streamer

重新烧写根文件系统,执行以下命令启动服务:

mjpg_streamer -i "/usr/lib/input_uvc.so -d /dev/video0 -r 640x480 -f 30 -q 90 -n" -o "/usr/lib/output_http.so -w /usr/www"

打开浏览器,输入AM335X的IP:8080即可看到默认显示界面:

/usr/www目录下,有很多html的示例,包括静态图片、视频图像、控制等,参考html修改,实现自定义的Web界面。

如果想要外网访问,参考之前博客黑群辉_3.2.2 反向代理frp尝试外网访问。

最后再记录下命令参数含义。

{% codeblock lang:shell %}

mjpg_streamer --help


Usage: mjpg_streamer
-i | --input “<input-plugin.so> [parameters]”
-o | --output “<output-plugin.so> [parameters]”
[-h | --help ]…: display this help
[-v | --version ]…: display version information
[-b | --background]…: fork to the background, daemon mode

Example #1:
To open an UVC webcam “/dev/video1” and stream it via HTTP:
mjpg_streamer -i “input_uvc.so -d /dev/video1” -o “output_http.so”

Example #2:
To open an UVC webcam and stream via HTTP port 8090:
mjpg_streamer -i “input_uvc.so” -o “output_http.so -p 8090”

Example #3:
To get help for a certain input plugin:
mjpg_streamer -i “input_uvc.so --help”

In case the modules (=plugins) can not be found:

  • Set the default search path for the modules with:
    export LD_LIBRARY_PATH=/path/to/plugins,
  • or put the plugins into the “/lib/” or “/usr/lib” folder,
  • or instead of just providing the plugin file name, use a complete
    path and filename:
    mjpg_streamer -i “/path/to/modules/input_uvc.so”

{% endcodeblock %}

得知mjpg_streamer后需要接-i-o两个参数,再分别看这两个参数提供的不同so插件文件支持哪些选项。
可选的-h查询帮助信息、-v查询版本信息、-b后台执行就不多介绍了。

输入so插件包含:input_uvc.soinput_testpicture.so、(input_file.soinput_ptp2.soinput_http.so)
输出so插件包含:output_http.so、(output_file.sooutput_udp.sooutput_rtsp.sooutput_viewer.so)
其中括号部分,我这个Buildrootmjpg_streamer版本没有提供。

  • 输入插件1:input_uvc.so
    {% codeblock lang:shell %}

mjpg_streamer -i “/usr/lib/input_uvc.so --help”

MJPG Streamer Version: git rev: fd184d0

Help for input plugin…: UVC webcam grabber

The following parameters can be passed to this plugin:

[-d | --device ]…: video device to open (your camera)
[-r | --resolution ]…: the resolution of the video device,
can be one of the following strings:
QQVGA QCIF CGA QVGA CIF PAL
VGA SVGA XGA HD SXGA UXGA
FHD
or a custom value like the following
example: 640x480
[-f | --fps ]…: frames per second
(activates YUYV format, disables MJPEG)
[-q | --quality ] …: set quality of JPEG encoding
[-m | --minimum_size ].: drop frames smaller then this limit, useful
if the webcam produces small-sized garbage frames
may happen under low light conditions
[-e | --every_frame ]…: drop all frames except numbered
[-n | --no_dynctrl ]…: do not initalize dynctrls of Linux-UVC driver
[-l | --led ]…: switch the LED “on”, “off”, let it “blink” or leave
it up to the driver using the value “auto”
[-t | --tvnorm ] …: set TV-Norm pal, ntsc or secam
[-u | --uyvy ] …: Use UYVY format, default: MJPEG (uses more cpu power)
[-y | --yuv ] …: Use YUV format, default: MJPEG (uses more cpu power)
[-fourcc ] …: Use FOURCC codec ‘argopt’,
currently supported codecs are: RGBP

Optional parameters (may not be supported by all cameras):

[-br ]…: Set image brightness (auto or integer)
[-co ]…: Set image contrast (integer)
[-sh ]…: Set image sharpness (integer)
[-sa ]…: Set image saturation (integer)
[-cb ]…: Set color balance (auto or integer)
[-wb ]…: Set white balance (auto or integer)
[-ex ]…: Set exposure (auto, shutter-priority, aperature-priority, or integer)
[-bk ]…: Set backlight compensation (integer)
[-rot ]…: Set image rotation (0-359)
[-hf ]…: Set horizontal flip (true/false)
[-vf ]…: Set vertical flip (true/false)
[-pl ]…: Set power line filter (disabled, 50hz, 60hz, auto)
[-gain ]…: Set gain (auto or integer)
[-cagc ]…: Set chroma gain control (auto or integer)

input_init() return value signals to exit
{% endcodeblock %}

基本参数:
-d:指定video设备节点
-r:指定分辨率,VGA或640x480类似值
-f:指定每秒帧数
-q:指定JPEG编码质量
-m:指定丢弃小于该值的帧
-e:删除除编号以外的所有帧
-n:不要初始化Linux-UVC驱动程序的dynctrls
-l:设置LED on/off/blink,设置auto将取决于驱动程序
-t:设置TV-Norm pal,ntsc或secam
-u:指定输入为UYVY格式,通过CPU将UYVC转为MJPEG,这样会消耗更多CPU
-v:指定输入为YUV格式,通过CPU将YUV转为MJPEG,这样会消耗更多CPU
-fourcc:使用FOURCC编解码器argopt,目前支持的编解码器是:RGBP
新版新增:
-timestamp:使用系统时间填充帧时间戳
-softfps:丢帧以尝试实现此FPS

图像参数:
-br:设置图像亮度
-co:设置图像对比度
-sh:设置图像清晰度
-sa:设置图像饱和度
-cb:设置图像颜色平衡
-wb:设置图像白平衡
-ex:设置图像曝光
-bk:设置图像曝光补偿
-rot:设置图像旋转0-359
-hf:设置图像水平翻转
-vf:设置图像垂直翻转
-pl:设置图像避免闪烁频率
-gain:设置图像增益
-cagc:设置图像色度增益控制

  • 输入插件2:input_testpicture.so
    {% codeblock lang:shell %}

mjpg_streamer -i “/usr/lib/input_testpicture.so --help”

MJPG Streamer Version: git rev: fd184d0

Help for input plugin…: TESTPICTURE input plugin

The following parameters can be passed to this plugin:

[-d | --delay ]…: delay to pause between frames
[-r | --resolution]…: can be 960x720, 640x480, 320x240, 160x120

input_init() return value signals to exit
{% endcodeblock %}

基本参数:
-d:指定在两帧之间的延时
-r:指定在分辨率

  • 输入插件3:input_file.so
    {% codeblock lang:shell %}

mjpg-streamer -i “/snap/mjpg-streamer/42/lib/mjpg-streamer/input_file.so --help”

MJPG Streamer Version: git rev: f387bb44e6c087271b763b27da998bf2e06c4f5d

Help for input plugin…: FILE input plugin

The following parameters can be passed to this plugin:

[-d | --delay ]…: delay (in seconds) to pause between frames
[-f | --folder ]…: folder to watch for new JPEG files
[-r | --remove ]…: remove/delete JPEG file after reading
[-n | --name ]…: ignore changes unless filename matches
[-e | --existing ]…: serve the existing *.jpg files from the specified directory

input_init() return value signals to exit
{% endcodeblock %}

基本参数:
-d:指定在两帧之间的延时(单位:s)
-f:指定查看新JEPG文件的目录
-r:指定读取后要删除的JEPG文件
-n:指定除非文件名匹配忽略更改
-e:指定目录读取现有JPG文件

  • 输入插件4:input_ptp2.so
    {% codeblock lang:shell %}

mjpg-streamer -i “/snap/mjpg-streamer/42/lib/mjpg-streamer/input_ptp2.so --help”

MJPG Streamer Version: git rev: f387bb44e6c087271b763b27da998bf2e06c4f5d
PTP2 input plugin: invalid option – ‘-’

Help for input plugin…: PTP2 input plugin

The following parameters can be passed to this plugin:

[-h ]…: print this help
[-u X ]…: delay between frames in us (default 0)
[-d X ]…: camera address in [usb:xxx,yyy] form; use
gphoto2 --auto-detect to get a list of
available cameras

input_init() return value signals to exit
{% endcodeblock %}

基本参数:
-h:打印帮助
-u:指定在两帧之间的延时(单位:us)
-d:指定可用相机

  • 输入插件5:input_http.so
    {% codeblock lang:shell %}

mjpg-streamer -i “/snap/mjpg-streamer/42/lib/mjpg-streamer/input_http.so --help”"

MJPG Streamer Version: git rev: f387bb44e6c087271b763b27da998bf2e06c4f5d

Help for input plugin…: HTTP Input plugin

The following parameters can be passed to this plugin:

[-v | --version ]…: current SVN Revision
[-h | --help]…: show this message
[-H | --host]…: select host to data from, localhost is default
[-p | --port]…: port, defaults to 8080

input_init() return value signals to exit
{% endcodeblock %}

基本参数:
-v:打印版本信息
-h:打印帮助信息
-H:指定主机地址
-p:指定端口

  • 输出插件1:output_http.so
    {% codeblock lang:shell %}

mjpg_streamer -o “/usr/lib/output_http.so --help”

MJPG Streamer Version: git rev: fd184d0

Help for output plugin…: HTTP output plugin

The following parameters can be passed to this plugin:

[-w | --www ]…: folder that contains webpages in
flat hierarchy (no subfolders)
[-p | --port ]…: TCP port for this HTTP server
[-l ] --listen ]…: Listen on Hostname / IP
[-c | --credentials ]…: ask for “username:password” on connect
[-n | --nocommands ]…: disable execution of commands

output_init() return value signals to exit
{% endcodeblock %}

基本参数:
-w:指定网页根目录(不支持子文件夹)
-p:指定HTTP服务器的TCP端口
-l:指定监听主机IP
-c:指定在连接时询问的账户名、密码
-n:指定禁用命令执行

  • 输出插件2:output_file.so
    {% codeblock lang:shell %}

mjpg-streamer -o “/snap/mjpg-streamer/42/lib/mjpg-streamer/output_file.so --help”

MJPG Streamer Version: git rev: f387bb44e6c087271b763b27da998bf2e06c4f5d

Help for output plugin…: FILE output plugin

The following parameters can be passed to this plugin:

[-f | --folder ]…: folder to save pictures
[-m | --mjpeg ]…: save the frames to an mjpg file
[-l | --link ]…: link the last picture in ringbuffer as this fixed named file
[-d | --delay ]…: delay after saving pictures in ms
[-i | --input ]…: read frames from the specified input plugin
The following arguments are takes effect only if the current mode is not MJPG
[-s | --size ]…: size of ring buffer (max number of pictures to hold)
[-e | --exceed ]…: allow ringbuffer to exceed limit by this amount
[-c | --command ]…: execute command after saving picture

output_init() return value signals to exit
{% endcodeblock %}

基本参数:
-f:指定保存图片文件夹
-m:将帧保存的mjpg文件夹
-l:将ringbuffer中的最后一张图片链接为此固定命名文件
-d:保存图片后延时(单位:ms)
-i:从指定的输入插件中读取帧
仅当当前模式不是MJPG时,以下参数才会生效
-s:环形缓冲区的大小(要保留的最大图片数)
-e:允许ringbuffer超过此数量的限制
-c:保存图片后执行命令

  • 输出插件3:output_udp.so
    {% codeblock lang:shell %}

mjpg-streamer -o “/snap/mjpg-streamer/42/lib/mjpg-streamer/output_udp.so --help”

MJPG Streamer Version: git rev: f387bb44e6c087271b763b27da998bf2e06c4f5d

Help for output plugin…: UDP output plugin

The following parameters can be passed to this plugin:

[-f | --folder ]…: folder to save pictures
[-d | --delay ]…: delay after saving pictures in ms
[-c | --command ]…: execute command after saveing picture
[-p | --port ]…: UDP port to listen for picture requests. UDP message is the filename to save

[-i | --input ]…: read frames from the specified input plugin (first input plugin between the arguments is the 0th)


output_init() return value signals to exit
{% endcodeblock %}

基本参数:
-f:指定保存图片的文件夹
-d:保存图片后延时(单位:ms)
-c:保存图片后执行命令
-p:指定UDP端口监听图片请求
-i:从指定的输入插件读取帧

  • 输出插件4:output_rtsp.so
    {% codeblock lang:shell %}

mjpg-streamer -o “/snap/mjpg-streamer/42/lib/mjpg-streamer/output_rtsp.so --help”

MJPG Streamer Version: git rev: f387bb44e6c087271b763b27da998bf2e06c4f5d

Help for output plugin…: RTSP output plugin

The following parameters can be passed to this plugin:

[-p | --port ]…: UDP port to listen for picture requests. UDP message is the filename to save

[-i | --input ]…: read frames from the specified input plugin (first input plugin between the arguments is the 0th)


output_init() return value signals to exit
{% endcodeblock %}

基本参数:
-p:指定UDP端口监听图片请求
-i:从指定的输入插件读取帧

  • 输出插件5:output_viewer.so
    {% codeblock lang:shell %}

mjpg-streamer -o “/snap/mjpg-streamer/42/lib/mjpg-streamer/output_viewer.so --help”

MJPG Streamer Version: git rev: f387bb44e6c087271b763b27da998bf2e06c4f5d

Help for output plugin…: VIEWER output plugin

output_init() return value signals to exit
{% endcodeblock %}

基本参数:

AM335X——USB摄像头相关推荐

  1. FFmpeg实现获取USB摄像头视频流测试代码

    通过USB摄像头(注:windows7/10下使用内置摄像头,linux下接普通的usb摄像头(Logitech))获取视频流用到的模块包括avformat和avdevice.头文件仅include ...

  2. NVIDIA TX2 使用 USB 摄像头

    用了一个很冷门的 USB 摄像头,在 Windows 下会自动安装驱动,本来以为在 Ubuntu 下得手动安,试了 easycam 和 gspca 都失败(太老了).没想到貌似根本不需要安装,TX2 ...

  3. [转载]树莓派新版系统上使用mjpg-streamer获取USB摄像头和树莓派专用摄像头RaspiCamera图像...

    树莓派新版系统上使用mjpg-streamer获取USB摄像头和树莓派专用摄像头RaspiCamera图像 网上有很多关于mjpg-stream移植到树莓派的文章,大部分还是使用的sourceforg ...

  4. 2.7 usb摄像头之usb摄像头描述符打印

    学习目标:参考lsusb源码,打印USB摄像头的设备描述符.配置描述符.接口联合描述符.端点描述符: 一.lsusb命令和源码 使用命令lsusb可以看看设备的id,并执行 # lsusb -v -d ...

  5. NanoPi NEO Air使用十五:使用V4L2驱动USB摄像头

    USB摄像头初识   Linux UVC driver(uvc) 该驱动适用于符合USB视频类(USB Video Class)规范的摄像头设备,它包括V4L2内核设备驱动和用户空间工具补丁.大多数大 ...

  6. (原创)基于ZedBoard的Webcam设计(二):USB摄像头图片采集+QT显示

    在(原创基于ZedBoard的Webcam设计(一):Zedboard上的USB摄像头(V4L2接口)的图片采集中,我们完成了ZedBoard上USB摄像头的单幅图片采集,采集到的图片是存储在文件系统 ...

  7. 31全志r58平台Android4.4.2下打开USB摄像头

    31全志r58平台Android4.4.2下打开USB摄像头 2018/10/26 16:00 版本:V1.0 开发板:SC5806 1.系统编译:(略) 2.需要修改的文件: W:\r58_andr ...

  8. linux下uvc协议访问usb摄像头,Ubuntu调用USB摄像头

    FreeBSD Webcam:传送门 1 查看摄像头USB驱动 CMD ls /dev/v* Result /dev/vcs /dev/vcs4 /dev/vcsa1 /dev/vcsa5 /dev/ ...

  9. 如何将usb摄像头连接到虚拟机vmware ubuntu系统上?

    先插上usb摄像头,打开虚拟机 右下角有个圈圈小按钮,点击它,点击连接(断开与主机的连接) 摄像头就会与windows断开,而连接到ubuntu系统上 连上后,就显示成这样 再点击它,能实现断开操作

最新文章

  1. dirwatcher java_commonIO
  2. python软件下载安装要钱吗-PyCharm下载和安装详细步骤
  3. 正则匹配所有包括换行符
  4. SAP配置webdynpro完全手册
  5. 利用 Cosole 来学习、调试JavaScrip
  6. 新一代大数据处理引擎 Apache Flink
  7. 联想继续为其硬件产品完善Linux支持
  8. 大数据业务学习笔记_学习业务成为一名出色的数据科学家
  9. list ajax封装,util-pagelist_基于layui封装的ajax分页列表
  10. linux内核编译,内核参数修改
  11. 看了这份《算法中文手册》笔记,就再也不怕字节了~
  12. MySQL创建新连接时,不能成功连接的问题
  13. jacob调用word宏
  14. Linux查看cuda版本
  15. linux 耳机驱动程序,TAS571XSW-LINUX
  16. Spring boot整合Drools、flowable决策引擎解决方案
  17. 驱动学习(九)字符设备的非阻塞操作
  18. js正则验证身份证号码(最后一位x不区分大小写)
  19. 超越阿里达摩院成绩,这个斯坦福团队用“国产求解器”助中国企业实现智能决策|快公司...
  20. Vue中一些需要注意的点(采坑)

热门文章

  1. MUJI 在日本最大的旗舰店翻新,卖起了蔬菜和迷你别墅
  2. 【Python】Avi转Mp4 视频转换
  3. HR 告诉你:用邮箱发简历应注意哪些
  4. 搜索引擎排名实战经验
  5. mysql按专业人数升序查询_sql 语句排序 在查询结果中按人数降序排列,若人数相同,则按课程号升序排列?...
  6. 字符串入门练习题7 男孩或者女孩 题解
  7. fanuc机器人码垛编程实例_FANUC机器人码垛教程
  8. 新世纪大学英语(第二版)综合教程第一册 Unit 1 重点单词
  9. 辐射避难所ol服务器维护,辐射避难所Online出现网络或设备异常怎么解决 解决方案一览...
  10. 解决Coursera的视频不能播放问题