【翻译】动态图像监测开源代码 motion 学习-----Motion Guide - Special Features(motion的特殊功能)(三)
说在前面:
This topic consists of the following subtopics:TrackingControl, UsingDatabases, LoopbackDevice.
Tracking Control(跟踪控制)
This is still at the experimental stage. Read more about it motion tracking page.目前还处于试验阶段。详情打开motion tracking
Tracking Feature with Logitech Quickcam Sphere/Orbit(用罗技Quickcam实现跟踪控制)
Motion supports controlling the pan and tilt feature of a Logitech Quickcam Sphere/Orbit.Motion支持罗技Quickcam Sphere/Orbit的云台控制功能。
Motion can move the camera to a fixed position given in degrees pan (left-right) and tilt (down-up). Movement can be set with absolute coordinates or relative to current position. There is also an auto tracking feature for the Logitech Quickcam Sphere/Orbit but it is not very mature. It is fun to play with but not very useful yet. See this topic of howKennethLavrsen controls his Sphere:LogitechSphereControl.
当给定一个固定的位置时,Motion可以左右或者上下来移动相机。也可以自动跟踪,但是还不成熟。这种功能很好玩,但是不是那么好用。可以看一下KennethLavrsen 是怎么控制他的LogitechSphereControl.的。
For a detailed description of http remote control see the section Remote Control with http.
关于http远程控制详见Remote Control with http部分。
List of tracking options
下面是跟踪选项
track_auto(自动跟踪)
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
Enable auto tracking
Requires a tracking camera type supported by Motion.
需要相机支持Motion的此功能
track_iomojo_id(仅用在iomojo 相机)
- Type: Integer
- Range / Valid values: 0 - 65535
- Default: 0
- Option Topic
Use this option if you have an iomojo smilecam connected to the serial port instead of a general stepper motor controller.
Only used for iomojo camera.
track_maxx(最大伺服位置x)
- Type: Integer
- Range / Valid values: 0 - 65535
- Default: 0
- Option Topic
The maximum position for servo x.
Only used for stepper motor tracking.
仅用在步进电机跟踪。
track_maxy(最大伺服位置y)
- Type: Integer
- Range / Valid values: 0 - 65535
- Default: 0
- Option Topic
The maximum position for servo y.
Only used for stepper motor tracking.
仅用在步进电机跟踪。
track_motorx(控制x轴的电机序号)
- Type: Integer
- Range / Valid values: 0 - 65535
- Default: 0
- Option Topic
The motor number that is used for controlling the x-axis.
控制x轴的电机序号
Only used for stepper motor tracking.
仅用在步进电机跟踪。
track_motory(控制y轴的电机序号)
- Type: Integer
- Range / Valid values: 0 - 65535
- Default: 0
- Option Topic
The motor number that is used for controlling the y-axis.
控制y轴的电机序号
Only used for stepper motor tracking.
仅用在步进电机跟踪。
track_move_wait
- Type: Integer
- Range / Valid values: 0 - 65535
- Default: 10
- Option Topic
Delay during which tracking is disabled after auto tracking has moved the camera. Delay is defined as number of picture frames.
自动跟踪功能移动相机后跟踪被禁止时开始延时。Delay被定义为图像帧的数量。
The actual delay is depending on the chosen framerate. If you want the camera to move maximum once every 2 seconds and the framerate is 10 then you need to set the track_move_wait value to 2 * 10 = 20.
实际的delay取决于被选择的帧率。告诉你track_move_wait 的计算方法。
track_port
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
This is the device name of the serial port to which the stepper motor interface is connected.
步进电机连接的串口号的设备名称。
Only used for stepper motor tracking.
仅用在步进电机追踪。
track_speed
- Type: Integer
- Range / Valid values: 0 - 255
- Default: 255
- Option Topic
Speed to set the motor to.
设置电机速度。
Only used for stepper motor tracking.
仅用在步进电机追踪。
track_step_angle_x
- Type: Integer
- Range / Valid values: 0-90
- Default: 10
- Option Topic
Angle in degrees the camera moves per step on the X-axis with auto tracking. Currently only used with pwc type cameras.
自动跟踪时相机每一步在x轴上移动的角度。目前只用在pwc类型的相机。
Requires a tracking camera type pwc.
需要pwc类型个跟踪相机。
track_step_angle_y(类似于track_step_angle_x)
- Type: Integer
- Range / Valid values: 0-40
- Default: 10
- Option Topic
Angle in degrees the camera moves per step on the Y-axis with auto tracking. Currently only used with pwc type cameras.
Requires a tracking camera type pwc.
track_stepsize
- Type: Integer
- Range / Valid values: 0 - 255
- Default: 40
- Option Topic
Number of steps to make.
移动步数。
Only used for stepper motor tracking.
仅用在步进电机
track_type(跟踪类型)
- Type: Discrete Strings
- Range / Valid values: 0 (none), 1 (stepper), 2 (iomojo), 3 (pwc), 4 (generic), 5 (uvcvideo)
- Default: 0 (None)
- Option Topic
Type of tracker.
Motion has special tracking options which use either a serial stepper motor controller, an iomojo smile cam or a Philips WebCam driver compatible pan/tilt camera such as the Logitech Quickcam Sphere or Orbit.
To disable tracking, set this to 0 and the other track options are ignored.
把该选项设为0,则禁止跟踪,并且跟踪的其他选项也会被忽略。
下面是介绍每个序号代表的电机的类型。
Value 1 is for the special Motion Tracking project using a stepper motor and a home made controller.
Value 2 is for the iomojo smilecam
Value 3 is for pwc type USB tracking cameras such as the Logitech Quickcam Sphere/Orbit which is driven by the pwc (Philips WebCam) driver. To use this camera your version of pwc must be at least 8.12.
Value 4 is the generic track type. Currently it has no other function than enabling some of the internal Motion features related to tracking. Eventually more functionality will be implemented for this type.
Value 5 is for uvcvideo type USB tracking cameras such as the Logitech Quickcam Sphere/Orbit MP (new Model) which is driven by the uvcvideo driver. This option was added in Motion 3.2.8.
Using Databases(使用数据库)
Motion can be compiled with both MySQL and PostgreSQL database support. When enabled Motion adds a record to a table in the database as specified by the sql_query. The query contains the fields that are used and the value are given by using conversion specifiers for dynamic data like filename, time, number of detected pixels etc. Motion does not place any binary images in the database and it cannot remove old records.Motion支持和MySQL and PostgreSQL一起编译。如果在sql_query指定内容,可以记录相应的信息。
Motion only adds records to the database when files are created. The database contains records of saved files which means to get a record in the database the feature that enables for example motion detection, timelapse, snapshots etc must be enabled. The sql_log options defines which types of files are logged in the database.
The following sql_log options are common to both MySQL and PostgreSQL.
下面个sql_log选项同时适用于MySQL and PostgreSQL.
sql_log_image
- Type: Boolean
- Range / Valid values: on, off
- Default: on
- Option Topic
Log to the database when creating motion triggered image file.
当引发保存图像时记录到数据库。
Configuration option common to MySQL and PostgreSQL. Motion must be built with MySQL or PostgreSQL support to use this feature.
选项同时适用于MySQL and PostgreSQL。要使用这种特性,motion需要和MySQL or PostgreSQL一起编译。
sql_log_mpeg
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
Log to the database when creating motion triggered mpeg file.
当引发保存mpeg视频时记录到数据库。
Configuration option common to MySQL and PostgreSQL. Motion must be built with MySQL or PostgreSQL support to use this feature.选项同时适用于MySQL and PostgreSQL。要使用这种特性,motion需要和MySQL or PostgreSQL一起编译。
sql_log_snapshot
- Type: Boolean
- Range / Valid values: on, off
- Default: on
- Option Topic
Log to the database when creating a snapshot image file.
当引发保存快照时记录到数据库。
Configuration option common to MySQL and PostgreSQL. Motion must be built with MySQL or PostgreSQL support to use this feature.选项同时适用于MySQL and PostgreSQL。要使用这种特性,motion需要和MySQL or PostgreSQL一起编译。
sql_log_timelapse
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
Log to the database when creating timelapse mpeg file
当引发保存时间延迟mpeg文件时记录到数据库。
Configuration option common to MySQL and PostgreSQL. Motion must be built with MySQL or PostgreSQL support to use this feature.选项同时适用于MySQL and PostgreSQL。要使用这种特性,motion需要和MySQL or PostgreSQL一起编译。
sql_query
- Type: String
- Range / Valid values: Max 4095 characters
- Default: insert into security(camera, filename, frame, file_type, time_stamp, text_event) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C')
- Option Topic
SQL query string that is sent to the database. The values for each field are given by using convertion specifiers
Most common conversion specifiers
SQL query字符串会被保存到数据库中。这些值用转换说明符表示。
- %Y = year, %m = month, %d = date
- %H = hour, %M = minute, %S = second
- %v = event
- %q = frame number
- %t = thread (camera) number
- %D = changed pixels
- %N = noise level
- %i and %J = width and height of motion area
- %K and %L = X and Y coordinates of motion center
- %C = value defined by text_event
- %f = filename with full path
- %n = number indicating filetype
See the "MySQL" section for detailed information about the database itself.
详情见MySQL部分。
MySQL(MySQL数据库)
You can use the MySQL database to register each file that is stored by motion.你可以使用MySQL数据库记录在motion中被存储的文件。
You need to generate a new database with a name of your own choice. You must enter this name in the config file (mysql_db option). The default value for the option sql_query requires that you create a new database in MySQL with a new table called "security" with the following fields:
你需要自己选择一个新的数据库。必须在config file 中的mysql_db 选项输入该名字。下面告诉你怎样做。
insert into security(camera, filename, frame, file_type, time_stamp, text_event) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C')
- camera (int) - camera (thread) number
- filename (char60) - filename (full path)
- frame (int) - the number of the picture frame
- file_type (int) - file type as a number - see table below.
- time_stamp (timestamp) - timestamp for the picture in native database format
- text_event (timestamp) - The text from the text_event option which by default is compatible with timestamps in SQL.
Note from version 3.2.4 the introduction of sql_querycompletely redefines the way you setup the SQL feature. It is now 100% flexible and can easily be made compatible with your existing Motion database from earlier versions of Motion.
告诉你从 3.2.4开始对数据库的使用已经很灵活,并且很容易和你之前的motion版本中的motion数据兼容。
These are the file type descriptions and the file type numbers stored in the database.
Normal image | 1 |
Snapshot image | 2 |
Motion image (showing only pixels defined as motion) | 4 |
Normal mpeg image | 8 |
Motion mpeg (showing only pixels defined as motion) | 16 |
Timelapse mpeg | 32 |
You can create the table using the following SQL statement.
你可以用一下声明创建一个数据表项。
CREATE TABLE security (camera int, filename char(80) not null, frame int, file_type int, time_stamp timestamp(14), text_event timestamp(14));
If you choose to use text_event for a non-timestamp value you can instead define something like.
下面这样在text_event 中没有时间戳的声明也行。
CREATE TABLE security (camera int, filename char(80) not null, frame int, file_type int, time_stamp timestamp(14), text_event char(40));
Remember to update grant table to give access to the mysql username you choose for motion.
记得更新授权表,赋予你为motion选择的数据库用户的权限。
It would be too much to go into detail about how to setup and use MySQL. After all this is a guide about Motion. However here are some hints and links.
关于怎样安装和使用数据库的内容非常多。这毕竟是关于Motion的手册。不过,下面给你一些提示和链接。
Setting Up a MySQL Based Website - A beginners guide from Linux Planet.
Webmonkey PHP/!MySQL tutorial - Entertaining and easy to read.
The phpMyAdmin homepage. The best and simplest tool to use MySQL (editors opinion). Requires Apache/PHP.
MySQL相关的选项
mysql_db
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
Name of the MySQL database.
MySQL数据库的名字
MySQL CONFIG FILE OPTION. Motion must be built with MySQL libraries to use this feature.
要使用这个功能,Motion必须与MySQL 的库一起编译。
If you compiled motion with MySQL support you will need to set the mysql options if you want motion to log events to the database.
mysql_host
- Type: String
- Range / Valid values: Max 4095 characters
- Default: localhost
- Option Topic
IP address or domain name for the MySQL server. Use "localhost" if motion and MySQL runs on the same server.
给出MySQL服务器的IP地址或者域名。本机上使用localhost即可。
MySQL CONFIG FILE OPTION. Motion must be built with MySQL libraries to use this feature.
要使用这个功能,Motion必须与MySQL 的库一起编译。
mysql_password
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
The MySQL password.
给出密码
MySQL CONFIG FILE OPTION. Motion must be built with MySQL libraries to use this feature.
要使用这个功能,Motion必须与MySQL 的库一起编译。
mysql_user
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
The MySQL user name.
给出用户名。
MySQL CONFIG FILE OPTION. Motion must be built with MySQL libraries to use this feature.要使用这个功能,Motion必须与MySQL 的库一起编译。
PostgreSQL(PostgreSQL数据库)
Same/similar as for MySQL above.和上面的MySQL 相类似。
The options for PostgreSQL
pgsql_db
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
Name of the PostgreSQL database.
PostgreSQL CONFIG FILE OPTION. Motion must be built with PostgreSQL libraries to use this feature.
If you compiled motion with PostgreSQL support you will need to set all the pgsql_ options if you want motion to log events to the database.
pgsql_host
- Type: String
- Range / Valid values: Max 4095 characters
- Default: localhost
- Option Topic
IP address or domain name for the PostgreSQL server. Use "localhost" if motion and PostgreSQL runs on the same server.
PostgreSQL CONFIG FILE OPTION. Motion must be built with pgsql_db libraries to use this feature.
pgsql_password
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
The PostgreSQL password.
PostgreSQL CONFIG FILE OPTION. Motion must be built with PostgreSQL libraries to use this feature.
pgsql_port
- Type: Integer
- Range / Valid values: 0 - 65535
- Default: 5432
- Option Topic
The PostgreSQL server port number.
PostgreSQL CONFIG FILE OPTION. Motion must be built with PostgreSQL libraries to use this feature.
pgsql_user
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
The PostgreSQL user name.
PostgreSQL CONFIG FILE OPTION. Motion must be built with PostgreSQL libraries to use this feature.
Video4Linux Loopback Device(V4L回送装置)
You can use this driver for looking at motion in realtime. The video4linux driver is written by the same author that first created Motion. You can find the source and a brief description at the video4linux loopback device web page.你可以用这个驱动实时观察motion。这个驱动有motion的创始人开发。你可以在video4linux loopback device web page找到源码和简介。
The video4linux device is a Kernel module which installs itself as a video pipe. It has an input and an output. The module simply takes anything that comes on its input and send it out at the output. The purpose of this is to create a standard video4linux type video device that other programs can then use. You may now ask: "What do I need that for?".
它是一个内核模块,安装为一个视频管道。有输入和输出。目的是为了创建一个标准的V4L类型的视频设备,是其他的程序也可以使用它。你可能会问“我要做什么?”
Only one program can access a video device at a time. When motion is using a camera - no other program can access the same camera. But motion is made to be able to feed a video signal to the video loopback device. This way an additional program such as Camstream, Xawtv, a video stream server etc can watch the signal from a camera that motion uses already. What you see is not the live camera stream but the exact same picture that motion uses for detecting motion and the same pictures that are saved/streamed. You can also choose to see the "motion" type images where you see the pixels that are changing - live. Originally the video4linux pipe was used as an interface between Motion and a Webcam server. Since version 2.9 Motion has had its own webserver so this usage is no longer very relevant.
主要告诉你一下事情:在motion使用相机时,其他程序就不能在使用这个相机。但是这个功能可以在motion使用相机时,让其他的程序也可以使用该相机。最初该功能是作为motion和网络相机的一个接口。从motion的2.9版后motion有了自己的网络相机,所以该功能已经不再那么实用了。
When you install the video loopback device it will create an input - for example /dev/video5 and an output - for example /dev/video6. You can then tell motion to "pipe" the video signal to the /dev/video5 and look at the pictures live using e.g. Camstream on /dev/video6. Camstream is "fooled" to think it is looking at a real camera.
Installing(下面告诉你怎样安装该功能)
Installing the video loopback device is not difficult. At least not when you have this document available.
First you must prepare your system for more video devices. You will need two extra devices for each video pipe that you want.
为多视频设备设置你的系统。
For example if you have 4 cameras they will probably run at /dev/video0, /dev/video1, /dev/video2, and /dev/video3. So you will need additional 8 video devices. This is easy to do.
下面是一个例子。
mknod /dev/video4 c 81 4
mknod /dev/video5 c 81 5
mknod /dev/video6 c 81 6
mknod /dev/video7 c 81 7
mknod /dev/video8 c 81 8
mknod /dev/video9 c 81 9
mknod /dev/video10 c 81 10
mknod /dev/video11 c 81 11
Note that the video device number is the same as the last parameter given on each line.
You may need to set the ownership and permissions (chown and chmod) to be the same as the video devices that were already there.
要设置一下所有权和权限。
Now you need to install the video loopback device.
现在安装loopback device
Download the latest video4linux loopback device . Place the file in a place of your own choice.
下载最新的 video4linux loopback device,放到你选择的位置上。
Untar and uncompress the file to the place you want the program installed. Editor recommends /usr/local/vloopback.
解压安装。作者建议你解压在/usr/local/vloopback目录下
cd /usr/local
tar -xvzf /path/to/vloopback-1.1-rc1.tar.gz
You now have a directory called vloopback-1.1-rc1. You can rename it to vloopback (mv vloopback-1.1-rc1 vloopback). I recommend creating a symbolic link to the current version. This way you can more easily experiment with different versions simply by changing the link.
你可以把名字改一下。建议你创建一个符号链接。
ln -s vloopback-1.1-rc1 vloopback
Now change to the new directory
切换目录
cd vloopback
Build the code
编译
make
There is a good chance that the make will not work and give you a long list of errors. To run make the following must be available on you machine.
给你说编译后很可能出现以下问题。
- The kernel source files must be installed.
- The source files must be available at /usr/src/linux.
E.g. the new Red Hat 7.3 does not have a link to the sources called linux. Instead there is a link called linux-2.4. This is easy to fix. Just create a link to the real source tree. Do not rename! Add a link using this command (replacing the kernel version number with the one you have on your machine)ln -s /usr/src/linux-2.4.18-4 /usr/src/linux
- Alternatively you can change the vloopback makefile so that the "LINUXSRC=/usr/src/linux" line is changed to the actual path. I recommend the link solution since this may solve other similar problems that you can get when installing other software.
When compiling on a newer Linux distribution you may get a warning about a header file malloc.h. To remove this warning simply change the header reference as suggested by the warning.
下面是问题的解决办法。
In vloopback.c you replace the line在vloopback.c中把这行替换成下面这行
#include <linux/malloc.h>
with the line
就是这行
#include <linux/slab.h>
Install the code you built as a Kernel module. There are two options: pipes should be set to the number of video loopbacks that you want. Probably one for each camera. The dev_offset defines which video device number will be the first. If dev_offset is not defined the vloopback module will install itself from the first available video device. If you want the cameras to be assigned to the lower video device numbers you must either load vloopback after loading the video device modules OR use the dev_offset option when loading vloopback. Vloopback then installs itself in the sequence input 0, output 0, input 1, output 1, input 2, output 2 etc. Here is shown the command for our example of 4 cameras and 4 loopback devices and the first loopback device offset to /dev/video4.
下面是一个使用方法
/sbin/insmod /usr/local/vloopback/vloopback.o pipes=4 dev_offset=4
When you run the command you may get a warning about tainting the Kernel. Just ignore this. You can choose to copy the vloopback.o file into a directory in the /lib/modules tree where the insmod/modprobe programs are already looking for modules. Then the command gets simpler (/sbin/insmod vloopback pipes=.....).
If you want the loopback device to load during boot, you can place the call in one of the bootup scripts such as /etc/rc.d/rc.local. Vloopback should be loaded before you start motion.
To activate the vloopback device in motion set the 'video_pipe' option in the motion.conf file. You can also view the special motion pictures where you see the changed pixels by setting the option 'motion_video_pipe' in motion.conf. When setting the video_pipe and/or motion_video_pipe options either specify the input device as e.g. /dev/video4. You can also set the parameter to '-' which means that motion will find the first vacant video loopback device input. If you have more than one camera you may want to control which loopback device each thread uses. Then you need to define the specific device name in motion.conf for the first camera and in each thread config file for the other cameras. If you set the video_pipe parameter to '-' in the motion.conf file and not setting it in the thread config files, motion automatically assign video devices in the same sequence as the threads are loaded. You can combine both video_pipe and motion_video_pipe but then naturally you will need twice as many pipes.
De-activating should be done with this command
使用下面的命令取消激活。
/sbin/modprobe -r vloopback
Description of the motion.conf options related to video loopback device.
与video loopback device相关的选项
motion_video_pipe
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
The video4linux video loopback input device for motion images. If a particular pipe is to be used then use the device filename of this pipe, if a dash '-' is given motion will use /proc/video/vloopback/vloopbacks to locate a free pipe.
如果使用一个特定的管道那么使用该管道的设备文件名,如果使用'-',那么motion将用 /proc/video/vloopback/vloopbacks 找一个未使用的管道。
Default: not set
Using this you can view the results in real time. E.g. by using the program camstream. The difference between this option and the video-pipe option is that this option shows the motion version of the images instead of the normal images.
Disable this option by not having it in the config file (or comment it out with "#" or ";").
video_pipe
- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined
- Option Topic
The video4linux video loopback input device for normal images. If a particular pipe is to be used then use the device filename of this pipe. If a dash '-' is given motion will use /proc/video/vloopback/vloopbacks to locate a free pipe.
如果使用一个特定的管道那么使用该管道的设备文件名,如果使用'-',那么motion将用 /proc/video/vloopback/vloopbacks 找一个未使用的管道。
Using this you can view the results in real time. E.g. by using the program camstream.
Disable this option by not having it in the config file (or comment it out with "#" or ";").
-- KennethLavrsen - 13 Apr 2005