实验五 基于OpenCV的网络视频监控
实验介绍
本实验通过一个应用软件Motion来实现网络视频监控。
Motion(http://www.lavrsen.dk/foswiki/bin/view/Motion/) 是一款小巧、轻型但又功能强大的应用软件,可以用来在Linux上操控监控摄像头。它能够与任何支持Linux的摄像头协同运行,包括所有的V4L网络摄像头、许多IP摄像头以及安迅士(Axis)摄像头,它还可以控制平移和倾斜功能。由于Motion的内置HTTP服务器,Motion可以录制使用JPEG、PPM和MPEG等格式的短片和快照,并且你可以在Web浏览器中远程查看这些视频。
软硬件清单
1. 硬件清单
- pcDuino8 Uno
- USB摄像头
2. 软件清单
- Ubuntu 14.04
- OpenCV
- Python
- Motion
硬件连接
将摄像头插入USB Host,并启动pcDuino8 Uno
图2.5.1 pcDuino与摄像头硬件连接
实验步骤
安装软件
$ sudo apt-get update $ sudo apt-get install motion
修改配置文件
$ sudo vim /etc/motion/motion.conf $ chmod 777 /media
需要确认下面这些参数:
daemon on #default off (This allows the motion to run in the background) framerate 10 #default 2 (increased framerate) width 640 #default 320 (changed width to match that of the webcam) height 480 #default 240 (same as above but for height) threshold 2000 #default 1500 (*explained in detail below) pre_capture 2 #default 0 (captures 2 frames before motion was detected and adds that to the videos to make them smoother) post_capture 5 #default 0 (same as above but captures frames after) output_normal off #default on (this disables storing images, since we only require video) ffmpeg_video_codec msmpeg4 #default swf (msmpeg4 is accepted by windows media player, hence easier to play on Windows) target_dir /mnt/motionvideos #default /tmp/motion (changed the directory where videos will be stored) webcam_maxrate 5 #default 1 (increase the max framerate on lie stream) webcam_localhost off #default on (allows you to set up a live stream of the webcam)
注意:上面的部分参数需要根据你的摄像头实际参数进行设置
创建目录 我们需要根据上面的target_dir创建一个目录:
$ sudo mkdir /mnt/motionvideos $ sudo chown motion /mnt/motionvideos
修改默认的配置文件,允许后台启动
$ sudo vi /etc/default/motion
将其中的start_motion_daemon= no 修改成 yes
插入USB摄像头,确认系统可以识别
$ ls /dev/video0
启动服务
$ sudo service motion start
如果要关闭服务,可运行:
$ sudo service motion stop
测试
pcDuino8 Uno接入局域网,获得IP地址。在同一局域网中的一台电脑或手机上,浏览器访问: < pcDuino8 Uno IP Address>:8081
实验结果
打开浏览器,浏览器访问: < pcDuino8 Uno IP Address>:8081,便实现了网络视频监控
图2.5.2 网络视频监控结果图