Software Design and Implementation

Published on December 2016 | Categories: Documents | Downloads: 48 | Comments: 0 | Views: 288
of 14
Download PDF   Embed   Report

Implementare Software

Comments

Content


Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
5.1 Chapter Overview
This chapter presents the main software design and implementation issues. It starts !
descriing the general flow chart of the main program that was implemented in
MAT"AB. It then e#plains each component of the flow chart with some details.
$inall! it shows how the graphical user interface %&I was designed.
5.2 Main Program Flow Chart
The main tas' of the software was to read the still images recorded from the camera
and then process these images to detect motions and ta'e necessar! actions
accordingl!. $igure 5.( elow shows the general flow chart of the main program.
)*
Start
Setup +
Initiali,ations
-hat is
$lag
value.
$lag/0 $lag/(
Image
Ac1uisition
Motion Detection
Algorithm Brea' + clear
Is image 2
threshold
3es 4o
Actions on
Motion
Detection
Data
Record
Stop
$igure 5.( Main 5rogram $low Diagram
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
It starts with general initiali,ation of software parameters and o6ects setup. Then7
once the program started the flag value which indicates whether the stop utton was
pressed or not is chec'ed. If the stop utton was not pressed it start reading the images
then process them using one of the two algorithms as the operator was selected. If a
motion is detected it starts a series of actions and then it go ac' to read the ne#t
images7 otherwise it goes directl! to read the ne#t images. -henever the stop utton
is pressed the flag value will e set to ,ero and the program is stopped7 memor! is
cleared and necessar! results are recorded. This terminates the program and returns
the control for the operator to collect the results.
The ne#t sections e#plain each process of the flow chart in figure 5.( with some
details.
5.2.1 Setup and Initializations

$igure 5.) show the flow chart for the setup and initiali,ation process. This process
includes the launch of the graphical user interface 8%&I9 where the t!pe of motion
detection algorithm is selected and threshold value 8the amount of sensitivit! of the
detection9 is eing initiali,ed.
):
Start
"aunch %&I
Start
utton
pressed
3es 4o
Read Threshold
;alue
Stop
Read Algorithm
T!pe
Setup Serial
5ort
Setup ;ideo
<6ect
$igure 5.) Setup and Initiali,ations 5rocess
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
Also7 during this stage a setup process for oth the serial port and the video o6ect is
done. This process ta'es appro#imatel! (5 seconds to e completed78depending on the
specifications of the 5C used9 for the serial port it starts ! selecting a communication
port and reserving the memor! addresses for that port7 then the 5C connect to the
device using the communication setting that was mentioned in the previous chapter.
The video o6ect is part of the image ac1uisition process ut it should e setup at the
start of the program.
5.2.2 Image acuisition
After setup stage the image ac1uisition starts as shown in figure 5.= aove. This
process reads images from the 5C camera and save them in a format suitale for the
motion detection algorithm.
There were three possile options from which one is implemented. The first option
was ! using auto snapshots software that ta'es images automaticall! and save them
on a hard dis' as >5?% format7 and then another program reads these images in the
same se1uence as the! were saved. It was found that the ma#imum speed that can e
attained ! this software is one frame per second and this limits the speed of
detection. Also7 s!nchroni,ation was re1uired etween oth image processing and the
=0
$igure 5.= Image ac1uisitions 5rocess
Start
Stop
Read $irst
$rame
Convert to
%ra!scale
Read Second
$rame
Convert to
%ra!scale
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
auto snapshot software@s where ne#t images need to e availale on the hard dis'
efore processing them.
The second option was to displa! live video on the screen and then start capturing the
images from the screen. This is a faster option from the previous approach ut again it
faced the prolem of s!nchroni,ation7 when the computer monitor goes into a power
saving mode where lac' images are produced all the time during the period of the
lac' screen.
The third option was ! using the image ac1uisition toolo# provided in MAT"AB
A.5.( or higher versions.
The image ac1uisition toolo# is a collection of functions that e#tend the capailit! of
MAT"AB. The toolo# supports a wide range of image ac1uisition operations7
including ac1uiring images through man! t!pes of image ac1uisition devices7 such as
frame graers and &SB 5C cameras7 also viewing a preview of the live video
displa!ed on monitor and reading the image data into the MAT"AB wor'space
directl!.
$or this pro6ect videoinput function was used to initiali,e a video o6ect that connects
to the 5C camera directl!. Then preview function was used to displa! live video on
the monitor. getsnapshot function was used to read images from the camera and place
them in MAT"AB wor'space.
The later approach was implemented ecause it has man! advantages over the others.
It achieved the fastest capturing speed at a rate of five frames per seconds depending
on algorithm comple#it! and 5C processor speed. $urthermore7 the prolem of
s!nchroni,ation was solved ecause oth capturing and processing of images were
done using the same software.
All read images were converted it into a two dimensional monochrome images. This
is ecause e1uations in other algorithms in the s!stem were designed with such image
format.
5.2.! Motion "etection #lgorithm
A motion detection algorithm was applied on the previousl! read images. There were
two approaches to implement motion detection algorithm. The first one was ! using
the two dimensional cross correlation while the second one was ! using the sum of
asolute difference algorithm. These are e#plained in details in the ne#t two su
sections.
=(
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
5.2.!.1 Motion "etection $sing %wo "imensional Cross Correlation
$irst the two images were su divided into four e1ual parts each. This was done to
increase the sensitivit! of calculation where it is easier to notice the difference
etween part of image rather than a whole one. A two dimensional cross correlation
was calculated etween each su image with its corresponding part in the other image.
This process produces four values ranging from B( to ( depending on the difference of
the two correlated images. Because the goal of this division was to achieve more
sensitivit! the minimum value of correlation will e used as reference to the
threshold.
In normal cases7 motion can easil! e detected when the measured minimum cross
correlation value is used to set the threshold. Cowever7 detection fails when images
contain gloal variations such as illuminations changes or when camera moves.
$igure 5.D aove shows a test case that contains consecutive illumination level
changes ! switching the light on and off. During the time where the lights are on
8frames (B50 and frames (00B(D59 the correlation value is around 0.::* and when the
lights are switched off 8frames 5(B:: and frames (DAB(:09 the correlation value is
around 0.DE. If the threshold for detection was fi#ed around the value of 0.:5 it will
continuousl! detect motion during the light off period.
To overcome this prolem continuous reBestimation of threshold value was re1uired.
This can e done ! using an adaptive filter ut it is not eas! to design. Another
=)
$igure 5.D Direct Thresholds for Correlation ;alues
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
solution is to loo' at the variance of the set of data produced from the cross
correlation process7 and detect motion from it. This method solved the prolem of
changing illumination and camera movements.
$igure 5.5 shows the variance signal calculated from the same set of images of figure
5.D. It can e seen that the need for continuousl! reBestimate the threshold value is
eliminated. Choosing a threshold of (F(0
B)
will detect the times when onl! the lights
are switched on and off. This results into a roust motion detection algorithm with
high sensitivit! of detection.
5.2.!.2 Motion "etection $sing Sum o& #'solute "i&&erence (S#")
This algorithm is ased on image differencing techni1ues. It is mathematicall!
represented using the following e1uationG

− = 9 8 9 8
(
9 8
j i
t I t I
N
t D
5.(
-here N is the numer of pi#els in the image used as scaling factor7
9 8
i
t I
is the
image I at time i 7
9 8
j
t I
is the image I at time
j
and
9 8t D
is the normali,ed
sum of asolute difference for that time.
In an ideal case when there is no motion
9 8 9 8
j i
t I t I =
5.)
==
$igure 5.5 ;ariance ;alues as Reference for Threshold
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
and
0 9 8 = t D
. Cowever noise is alwa!s presented in images and a etter model of the
images in the asence of motion will e
9 8 9 8 9 8 p n t I t I
j i
+ =
5.=
-here
9 8 p n
is a noise signal.
The value
9 8t D
that represents the normali,ed sum of asolute difference can e
used as a reference to e compared with a threshold value as shown in figure 5.A
elow.
The aove figure shows a test case that contains a large change in the scene eing
monitored ! the camera this was done ! moving the camera. During the time efore
the camera was moved the SAD value was around (.*E and when the camera was
moved the SAD value was around ).). If the threshold for detection was fi#ed around
the value less than ).) it will continuousl! detect motion after the camera stop
moving.
=D
$igure 5.A Direct Threshold for SAD ;alues
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
To overcome this prolem the same solution that was applied to the correlation
algorithm will e used. The variance value was computed after collecting two SAD
values and the result is shown for the same test case in figure 5.E elow.
This approach solve the need for continuousl! reBestimate the threshold value.
Choosing a threshold of (F(0
B=
will detect the times when onl! the camera is moved.
This results into a roust motion detection algorithm that can not e affected !
illumination change and camera movements.
=5
$igure 5.E ;ariance ;alues as Reference for Threshold
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
5.2.* #ctions on Motion "etection
Before e#plaining series of actions happen when motion is detected it is worth to
mention that the values of variance that was calculated whether it was aove or elow
the threshold will e stored in an arra!7 where it will e used later to produce a plot of
frame numer ;s. the variance value. This plot helps in comparing the variance
values against the threshold to e ale to choose the optimum threshold value.
-henever the variance value is less than threshold the image will e dropped and
onl! the variance value will e recorded. Cowever when the variance value is greater
than threshold se1uence of actions is eing started as shown in figure 5.* elow.
As the aove flow chart show a numer of activities happen when motion is detected.
$irst the serial port is eing triggered ! a pulse from the 5CH this pulse is used to
activate e#ternal circuits connected to the 5C. Also a log file is eing created and then
appended with information aout the time and date of motion also the frame numer
in which motion occur is eing recorded in the log file. Another process is to displa!
the image that was detected on the monitor. $inall! the image that was detected in
motion will e converted to a movie frame and will e added to the film structure.
=A
$igure 5.* Actions on Motion Detection
Time
Date
$rameI
&pdate
"og $ile
Trigger
Serial
5ort
Displa!
Image
Convert
Image to
$rame
Stop
Start
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
5.2.5 +rea, and clear Process
After motion detection algorithm applied on the images the program chec's if the stop
utton on %&I was pressed. If it was pressed the flag value will e changed from one
to ,ero and the program will rea' and terminate the loop then it will return the
control to the %&I. 4e#t oth serial port o6ect and video o6ect will e cleared. This
process is considered as a cleaning stage where the devises connected to the 5C
through those o6ects will e released and the memor! space will e freed.
5.2.- "ata .ecord
$inall! when the program is terminated a data collection process starts where variale
and arra!s that contain result of data on the memor! will e stored on the hard dis'.
This approach was used to separate the real time image processing from results
processing. This has the advantage of calling ac' these data whenever it is re1uired.
The variales that are eing stored from memor! to the hard dis' are variance values
and the movie structure that contain the entire frames with motion.
At this point the control will e returned to the %&I where the operator can callac'
the results that where archived while the s!stem was turned on.
4e#t section will e#plain the design of the %&I highlighting each utton results and
callac's.
5.! /raphical $ser Inter&ace "esign
The %&I was designed to facilitate interactive s!stem operation. %&I can e used to
setup the program7 launch it7 stop it and displa! results. During setup stage the
operator is promoted to choose a motion detection algorithm and select degree of the
detection sensitivit!. -henever the startJstop toggle utton is pressed the s!stem will
e launched and the selected program will e called to perform the calculations until
the startJstop utton is pressed again which will terminate the calculation and return
control to %&I. Results can e viewed as a log file7 movie and plot of frame numer
vs. variance value. $igure 5.: illustrate a flow chart of the steps performed using the
%&I.
=E
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion

The complete %&I code is included in the appendi#.
=*
?nd
Start
Clear all 5revious -or'
;ariale Initiali,ation + Setup
"aunch program
Call Selected main 5rogram
Terminate 5rogram
;iew Results
Start Again
4< 3es
?#it
$igure 5.: %&I flow Chart
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
The %&I as shown in figure 5.(0 was designed using MAT"AB %&I Builder. It
consists of two radio uttons7 two sliders7 two static te#t o#7 four push uttons and a
toggle utton. Sliders and radio uttons were used to prevent entering a wrong value
or selection.
The radio uttons are eing used to choose either SAD algorithm or )D cross
correlation algorithm. Both algorithms can not e selected at the same time.
Sliders are used to select how sensitive the detection is7 ma#imum sensitivit! is
achieved ! moving the slider to the left. The static te#t show the instantaneous value
of the threshold as read from the sliders. -hen %&I first launch it will select the
optimum value for oth algorithms as default vale.
=:
$igure 5.(0 %&I "a!out Design
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
Moving to the control panel Start J Stop utton is used to launch the program when it
is first pushed and to terminate the program when it is pushed again. $igure 5.(( show
flow chart of commands e#ecuted when this utton is pressed.

-henever the StartJStop utton is first pushed it will set the value of the flag to ( then
it will chec' the value of the radio uttons to determine which main program to
launch.
A log file that contains information aout time and date of motions with frame
numer is eing opened when the log file icon is pushed.
The program is eing closed and MAT"AB is shutdown when the e#it utton is
pushed.
-henever the show movie icon is pushed7 MAT"AB will load the film structure that
was created efore from the hard dis' then it will convert the structure into a movie
and displa! it on the screen at a rate of 5 frames per seconds. $inall! the movie
created will e compressed using the Indeo= compression techni1ue and will e saved
on the hard dis' under the name Kfilm.aviL. $igure 5.() elow show the commands
e#ecuted when this icon is pushed.
D0
$igure 5.(( StartJStop utton flow chart
Start
I& start0stop
Flag12 Flag11
.un 2"
Corr.m
.un S#".m
Stop
Pressed Impressed
.adio 'utton
value
1 2
Chapter 5. Software Design and Implementation Activation of Recording Based on Motion
The last utton which is the show plot icon loads the values of the variance to plot it
against the frame numer as shown elow in figure 5.(=.
5ress
ed
3es 4o
Star
t
Stop
"oad $ilm Structure
Convert to Movie +
Displa!
Compress Movie + save
Storage
Storage
D(
$igure 5.() Movie Button Callac's
5ress
3es 4o
Star
t
Stop
"oad ;ariance ;alues
Show 5lot
Storage
$igure 5.(= 5lot Button Callac's

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close