极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 49144|回复: 25

基于USB摄像头的运动视频捕捉和远程web视频监控

[复制链接]
发表于 2013-3-4 23:29:34 | 显示全部楼层 |阅读模式
本帖最后由 Damn_intuition 于 2013-3-5 11:22 编辑

一、首先确定USB摄像头可以用,
[pre lang="bash" line="1"]cd /dev
ls | grep video
如果有个设备名字是video0(多个摄像头数字递增)就可以了[/code]

二、本方案使用的是motion,相当简单的一个工具,让我们来安装他
[pre lang="bash" line="1"]sudo apt-get update
sudo apt-get install motion
[/code]

三、配置motion.conf
[pre lang="bash" line="1"]sudo nano /etc/motion/motion.conf
[/code]
ctrl+w搜索 ”target_dir“ 后面跟着个就是图片/视频文件存储的位置
ctrl+w搜索 ”control_localhost“ 将on改成off,允许非本机访问http控制台

ctrl+x Y保存退出

四、启动 motion
pi@raspberrypi /dev $ sudo motion
[0] Processing thread 0 - config file /etc/motion/motion.conf
[0] Motion 3.2.12 Started
[0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478784
[0] Thread 1 is from /etc/motion/motion.conf
[0] motion-httpd/3.2.12 running, accepting connections
[0] motion-httpd: waiting for data on port TCP 8080
[1] Thread 1 started
[1] cap.driver: "uvcvideo"
[1] cap.card: "HD Pro Webcam C920"
[1] cap.bus_info: "usb-bcm2708_usb-1.2"
[1] cap.capabilities=0x04000001
[1] - VIDEO_CAPTURE
[1] - STREAMING
[1] Test palette YUYV (640x480)
[1] Using palette YUYV (640x480) bytesperlines 1280 sizeimage 614400 colorspace 00000008
[1] found control 0x00980900, "Brightness", range 0,255
[1]     "Brightness", default -8193, current 128
[1] found control 0x00980901, "Contrast", range 0,255
[1]     "Contrast", default 57343, current 128
[1] found control 0x00980902, "Saturation", range 0,255
[1]     "Saturation", default 57343, current 128
[1] found control 0x00980913, "Gain", range 0,255
[1]     "Gain", default 57343, current 0
[1] mmap information:
[1] frames=4
[1] 0 length=614400
[1] 1 length=614400
[1] 2 length=614400
[1] 3 length=614400
[1] Using V4L2
[1] Resizing pre_capture buffer to 1 items

五、远程控制motion

在远程通过浏览器访问 ”http://IP:8080“进行控制

  关于这些配置的具体意义,参见motion官方wiki http://www.lavrsen.dk/twiki/bin/view/Motion/WebHome中的Config options。这里,我只对其中几个解释一下。
  daemon off,关掉deamon模式。最好这项还是选off,否则运行motion后,就会直接在后台运行,需要用top命令查看出motion的进程号(pid),然后再手动kill掉这个进程。
  locate on设置探测到图像中有运动时,把运动区域用矩形框起来。
  videodevice /dev/video0 设置加载USB摄像头的设备,一般都是这个video0,当使用network webcam时,需要设置netcam_url,此时,videodevice选项自动失效。
  threshold_tune off设置是否使用motion detection阈值自动调节。当设置为on时,下一个设置threshold 4500自动失效。设置off时,可以由threshold指定当探测到多少像素变化时,判断为图像中有运动。
  ffmpeg_cap_new on这个选项是指,在detect到运动时,用视频纪录下来。
  ffmpeg_video_codec msmpeg4 设定视频的编码器
  target_dir /root/motion/snapshots当探测到运动时,图片和视频的保存路径,默认时为/var/lib/motion/snapshots。
  snapshot_interval 1设定自动采集图片的周期,当有运动被检测到时,采集频率会自动变高。




使用远程8081端口的在线视频需要将 webcam_localhost 设置为off


乱七八糟的写完了,我的描述能力十分有限,希望新人可以看懂,本着能分享点算一点的原则,只要能对一些人有所帮助那样就太好了。如有不明之处欢迎回复,互相学习探讨。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-3-5 07:56:17 | 显示全部楼层
使用arduino做的么? 果断收藏了先
回复 支持 反对

使用道具 举报

发表于 2013-3-5 08:48:37 | 显示全部楼层
wangku001wei 发表于 2013-3-5 07:56
使用arduino做的么? 果断收藏了先

很明显这个是树莓
回复 支持 反对

使用道具 举报

发表于 2013-3-5 10:58:47 | 显示全部楼层
那种windows下免驱动的设想头能在这上面用吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-3-5 11:21:32 | 显示全部楼层
ailangzhou 发表于 2013-3-5 10:58
那种windows下免驱动的设想头能在这上面用吗?

大多数的摄像头都可以的,话说目前很难买到不支持的摄像头。{:3_59:}
回复 支持 反对

使用道具 举报

发表于 2013-3-5 22:38:47 | 显示全部楼层
运动视频捕捉怎么办?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-3-5 22:43:00 | 显示全部楼层
heiketiguo 发表于 2013-3-5 22:38
运动视频捕捉怎么办?

默认会生成运动视频。swf格式。
############################################################
# FFMPEG related options
# Film (mpeg) file output, and deinterlacing of the video input
# The options movie_filename and timelapse_filename are also used
# by the ffmpeg feature
############################################################

# Use ffmpeg to encode mpeg movies in realtime (default: off)
ffmpeg_cap_new on

# Use ffmpeg to make movies with only the pixels moving
# object (ghost images) (default: off)
ffmpeg_cap_motion off

# Use ffmpeg to encode a timelapse movie
# Default value 0 = off - else save frame every Nth second
ffmpeg_timelapse 0

# The file rollover mode of the timelapse video
# Valid values: hourly, daily (default), weekly-sunday, weekly-monday, monthly, manual
ffmpeg_timelapse_mode daily

# Bitrate to be used by the ffmpeg encoder (default: 400000)
# This option is ignored if ffmpeg_variable_bitrate is not 0 (disabled)
ffmpeg_bps 500000

# Enables and defines variable bitrate for the ffmpeg encoder.
# ffmpeg_bps is ignored if variable bitrate is enabled.
# Valid values: 0 (default) = fixed bitrate defined by ffmpeg_bps,
# or the range 2 - 31 where 2 means best quality and 31 is worst.
ffmpeg_variable_bitrate 0

# Codec to used by ffmpeg for the video compression.
# Timelapse mpegs are always made in mpeg1 format independent from this option.
# Supported formats are: mpeg1 (ffmpeg-0.4.8 only), mpeg4 (default), and msmpeg4.
# mpeg1 - gives you files with extension .mpg
# mpeg4 or msmpeg4 - gives you files with extension .avi
# msmpeg4 is recommended for use with Windows Media Player because
# it requires no installation of codec on the Windows client.
# swf - gives you a flash film with extension .swf
# flv - gives you a flash video with extension .flv
# ffv1 - FF video codec 1 for Lossless Encoding ( experimental )
# mov - QuickTime ( testing )
ffmpeg_video_codec swf

# Use ffmpeg to deinterlace video. Necessary if you use an analog camera
# and see horizontal combing on moving objects in video or pictures.
# (default: off)
ffmpeg_deinterlace off
回复 支持 反对

使用道具 举报

发表于 2013-3-11 12:49:29 | 显示全部楼层
可以用了。。不错 不过显示方面好像只有chroma可以看到图片搜狗之类的好像看不了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-3-11 18:39:21 | 显示全部楼层
ailangzhou 发表于 2013-3-11 12:49
可以用了。。不错 不过显示方面好像只有chroma可以看到图片搜狗之类的好像看不了。

对。的确有这个现象。
我一直用chroma
回复 支持 反对

使用道具 举报

发表于 2013-5-3 22:57:46 | 显示全部楼层
为什么 webcam_localhost 设置为off  8081 还是打不开?
回复 支持 反对

使用道具 举报

发表于 2013-5-17 20:54:46 | 显示全部楼层
直接看不懂啊
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-6-24 15:45:58 | 显示全部楼层
久候 发表于 2013-5-17 20:54
直接看不懂啊

我其实已经尽量写的简单了。
努力吧,慢慢来就看懂了。
如果遇到实在不理解的可以查一下资料或者留言问我。
回复 支持 反对

使用道具 举报

发表于 2013-10-13 18:03:34 | 显示全部楼层
本帖最后由 renye616 于 2013-10-13 18:09 编辑

为什么看不到  监控视频呢?

还有error reading first header re-try 什么意思 怎么解决?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-10-13 18:50:26 | 显示全部楼层
renye616 发表于 2013-10-13 18:03
为什么看不到  监控视频呢?

还有error reading first header re-try 什么意思 怎么解决?

能不能发出全部错误信息。。
回复 支持 反对

使用道具 举报

发表于 2014-3-27 14:08:26 | 显示全部楼层
果断收藏!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-25 23:02 , Processed in 0.053107 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表