Home page : http://www.delphicity.com
Contact : contact@delphicity.com
Support : support@delphicity.com
How does it work?
Cell sensitivity
Color sensitivity
Matrix structure
Matrix representations
Advanced motion detection
CellMotionRatio
ChangeGlobalSensitivity
Compare
ShowMatrixDialog
GlobalMotionRatio
IsMatrixValid
SquareMatrix
SquareSpacedMatrix
SquareSpacedMatrixMotion
Matrix
RejectDifferentBitmapSize
CompareBlue
CompareGreen
CompareMonochrome
CompareRed
ReduceVideoNoise
1. If a previous TMotionSensor package is already installed, remove it
first:
- Components | Install Packages,
- click on "DelphiCity TMotionSensor",
- click "Remove",
- click "Yes",
- click "Ok",
- search for all the "TMSensor.*" and "MoSensorr.*" files in
your Borland directories and delete them, to be certain that old units will not
remain in the search paths (causing later raw errors).
2. Install the current package:
- unzip the archive in a folder of your choice,
- according to your Delphi or C++Builder version, copy all the Delphi\*.* or
CBuilder\*.* archive files to the Borland\Delphi\Imports or \Borland\CBuilder\Imports
directory,
- run Delphi or C++Builder,
- select Component | Install packages,
- press the "Add" button,
- locate the T.bpl file in the Imports directory and select it,
- select Open,
- select Ok,
- check the ActiveX tab in the right of the component palette. The TMotionSensor
object should have been added.
Note: For C++Builder, if you get a "BPL
library not found" error at runtime, uncheck the "Build with runtime
packages" check box in Project | Options | Packages.
How does it work?
The basic principle of the component is to compare 2 bitmaps and to determine if a motion occurred somewhere in the image, according to a predefined sensitivity.
The Compare function returns a value indicating if the comparison has globally detected a motion between the current image and the previous image.
Cell sensitivity:
The image is internally divided in a matrix of rows and columns, defining rectangular cells.
The sensitivity of each cell can be individually or globally defined from 0 (no motion detection) to 9 (maximal sensitivity to motion).
A matrix dialog is available to interactively set the sensitivity of each cell, superposing the matrix on the real image.
Color sensitivity:
The comparison is done by default on the normally colored image.
It is possible to globally disable the sensitivity to any of the 3 colors (R, G , B). If all the 3 colors are disabled, the comparison is performed on a monochrome basis.
Matrix structure:
The matrix corresponds to a division of the image into 10 rows and 10 columns, equally spaced.
A value is associated to each cell represents the sensitivity of this cell, from 0 (no motion sensitivity) to 9 (maximal motion sensitivity).
The matrix can be set and retrieved as a linear string representation of each cell sensitivity. This form allows to easily store it in the registry and retrieve it as a simple string.
It begins by the 1st row, a blank separator, then the 2nd row, a blank separator, the 3rd, row, and so on.
E.g. : 0000044441 5555555551 4444444441 5555555551 6666666661 66666666661 6666666661 3333333331 3333333331 0000000001
After having set the Matrix property, it is possible to check if it has been accepted by testing the IsMatrixValid property.
Matrix representations:
The SquareMatrix property returns a string that is a 2D text representation of the sensitivity of each matrix's cell. It can be assigned to any stringlist property (e.g. Memo1.Text := MoSensor1.SquareMatrix).
For the example above, it will return:
0000044441
5555555551
4444444441
5555555551
6666666661
6666666661
6666666661
3333333331
3333333331
0000000001
The SquareSpacedMatrix property returns a string that is a 2D representation of the sensitivity of each matrix's cell, separated with blanks. It can be assigned to any stringlist property as well (e.g. Memo1.Text := MoSensor1.SpacedSquareMatrix). Use 'Courier New' or any fixed font to display it.
For the example above, it will return:
0 0 0 0 0 4 4 4 4 1
5 5 5 5 5 5 5 5 5 1
4 4 4 4 4 4 4 4 4 1
5 5 5 5 5 5 5 5 5 1
6 6 6 6 6 6 6 6 6 1
6 6 6 6 6 6 6 6 6 1
6 6 6 6 6 6 6 6 6 1
3 3 3 3 3 3 3 3 3 1
3 3 3 3 3 3 3 3 3 1
0 0 0 0 0 0 0 0 0 1
The SquareSpacedMatrixMotion property returns a string that is a 2D representation of the cells where motion has been detected by the last Compare call. The cells where no motion has been detected are represented by a dot, the others by a value from 0 to 9. E.g.:
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . 4 . . . . .
. . . . 7 8 . . . .
. . . . . . . . . .
. . . . . . . . . .
In this sample a motion has been detected on row 7, column 5 and on row 8, columns 5 and 6.
Advanced motion detection :
After a Compare function call, the GlobalMotionRatio function returns the global motion ratio of the cells having a sensitivity between 1 and 9. The CellMotionRatio (x, y) function returns the motion ratio of any individual cell.
For both functions, the ratio is the count of the pixels that moved, divided by the total pixels count of the cells whose sensitivity is greater than 0.
function CellMotionRatio (x, y: integer):
Double;
retrieves the motion ratio (cell's moved pixels
count / cell's total pixels count) of the cell specified by its x and y
coordinates. The return value will be in the range 0...1.
The x and y coordinates are a zero-based index, from 0 to MATRIXSIZE.
procedure ChangeGlobalSensitivity (Increment: integer);
increments or decrements the sensitivity (from 1 to 9) of the cells whose
current sensitivity is greater than 0 (in other words, increases or decreases
the sensibility of the active cells). The value passed as parameter is usually
-1 (do decrease) or 1 (to increase).
function Compare (NewBitmap: TBitmap): integer;
compares the NewBitmap passed as parameter with
the bitmap passed to the previous Compare call. The function returns one of the
following values:
S_NO_MOTION_DETECTED: no motion has been
detected.
S_MOTION_DETECTED: motion has been detected.
E_SIZES_DIFFER: the size of the current bitmap
differs from the previous one. If RejectDifferentBitmapSize is enabled,
NewBitmap is stored to be compared with the next one.
E_SETTINGS_CHANGED: the current settings have
changed since the last compare call, so the compare cannot be done. NewBitmap is
now stored and ready to be compared with the next one.
property IsMatrixValid: Boolean;
returns true if the matrix string is correct, false otherwise. See the Matrix
Structure chapter.
property GlobalMotionRatio: Double;
retrieves the motion ratio ( moved pixels
count / total pixels count) of the cells whose sensitivity is enabled (between 1
and 9). The return value will be in the range 0...1.
procedure ShowMatrixDialog;
displays the matrix dialog that allows to interactively set the sensitivity
of each cell. If compare has been called at least 1 time with the concerned
image as parameter, the dialog superposes the matrix grid and the image,
allowing to precisely position the sensitivity on the image.
property SquareMatrix: string;
retrieves a 2D text
representation of the matrix structure. See the Matrix
Structure chapter.
property SquareSpacedMatrix: string;
retrieves a 2D text
representation of the matrix structure. The sensitivity digit are separated by
blanks to get a "near square" shape. See the Matrix
Structure chapter.
property SquareSpacedMatrixMotion: string;
retrieves a 2D text
representation of the matrix cells where motion has been detected. The
sensitivity digit are separated by blanks to get a "near square"
shape. See the Matrix
Structure chapter.
property Matrix: string;
sets or retrieves the matrix structure, as a simple string. After setting
the matrix property, use IsMatrixValid to know if the matrix has been accepted
or rejected. See the Matrix
Structure chapter.
property RejectDifferentBitmapSize: Boolean;
The bitmap passed as parameter to the Compare
function is compared with bitmap passed in the previous call to Compare. These
bitmaps can be compared only if they have the same size.
If the size of these bitmaps differs, 2 possibilities:
1. if RejectDifferentBitmapSize is disabled, the new bitmap is kept to be compared to the next bitmap (we consider the new bitmap size is the size to use for future bitmaps). The result of the current Compare call is E_SIZES_DIFFER.
2. if RejectDifferentBitmapSize is enabled, the new bitmap is ignored and the previous one is kept for future comparisons. The result of the current Compare call is E_SIZES_DIFFER as well.
property CompareBlue: Boolean;
if disabled, the blue color is ignored when
performing the bitmaps comparison.
property CompareGreen: Boolean;
if disabled, the green color is ignored when
performing the bitmaps comparison.
property CompareMonochrome: Boolean;
if enabled, the bitmap is converted to a monochrome bitmap. In this case,
the CompareBlue, CompareRed and CompareGreen properties are ignored.
property CompareRed: Boolean;
if disabled, the red color is ignored when
performing the bitmaps comparison.
property ReduceVideoNoise: Boolean;
if enabled, an algorithm is applied to the image to reduce the sensitivity to the video noise (snow,
blurred lines caused by an high compression level,
colored points...). This feature helps to increase the matrix sensitivity without
triggering inopportune motion detection.
The author of this program accepts no responsibility for damages resulting from the use of this product and make no warranty or representation, either expressed or implied, including but not limited to, any implied warranty of merchantability or fitness for a practical purpose.
This software package is provided here "AS IS", and you the user, assume all risks when using them.
TMotionSensor is a Delphi / C++ Builder VCL component that detects motion between two consecutives bitmaps. A compare function receives the new image as parameter, compares it with the previous one and returns a value indicating if a motion occurred. The image is splitted internally as a 10 x 10 matrix, defining cells, and within each cell the sensibility can be set from 0 (no sensitivity) to 9 (maximum sensitivity), allowing to precisely set where and how is detected the motion within the image. The matrix is defined by a simple string and can be edited through a specific dialog. After each compare, the global motion ratio of the image is available, as well as the individual motion ratio of each cell. An optional processing applied to the image reduces the sensitivity to video noise. Any of the three RGB colors can be disabled, and the comparison can be performed on a monochrome basis. Most common parameters can be simply set from the Object Inspector.
Delphi 4/5/6, C++ Builder 4/5
Click here to register.
|