Line Area Monitoring using Structural Similarity Index

Real-time motion detection in specific area is considered the most important task in every video surveillance system. In this paper, a novel real time motion detection algorithm introduced to process Line zones called Line Monitoring Algorithm (LMA). This algorithm integrates Bresenham’s Algorithm and Structural Similarity Index (SSI) in order to achieve the best performance. Bresenham’s Algorithm is used to collect line pixels from two given points. Then, the SSI is used for real-time calculation of similarity for line motion detection. The most attractive side of using the LMA is that the algorithm does not need to compare all pixels of the whole images or regions for line areas monitoring. This algorithm has high capability, treatment speed and efficiency for motion detection and also demands less compilation time for the hardware performance. The main objective of this paper is to use a video surveillance system implementing LMA to supervise the Car Reverse Test (CRT) for driving license exam in Morocco. The evaluation of the experiment results in implementing the proposed algorithm is reported in this paper. Keywords—Bresenham’s Algorithm; Structural Similarity Index; SSI; motion detection; Line Monitoring Algorithm; LMA; OpenCV; surveillance; camera; video surveillance system


I. INTRODUCTION
According to the World Health Organization's (WHO) 2015 [1] Road Safety Situation Report, nearly 1.25 million people die every year on the roads. In Morocco although the total number of registered vehicles (per capita) is low, the rate of road traffic deaths is high with approximately 10 people killed every day. 36% of the fatalities are car occupants and a further 21% are motorcycle riders.
Road Safety has become a matter of national security in Morocco. Many arrangements have been made by the government to decrease the number of car accidents such as installing Speed Radars, Road Signs and Speed Measuring Panels without neglecting the idea of improving driving license exam.
The driving license exam in Morocco is composed of two sections:  Theoretical test: a sort of quiz which, according to the category desired, the candidate must answer correctly to a group questions (Ex: 32/40 for Cars category "B").
 Practical test: shows the ability of the candidate to drive, park and control the vehicle.
Before 2008, the theoretical test was in form of Asking/answering test between the supervisor and the candidate by using a pre-defined list of questions related to road situations, prerequisites and notions in order to evaluate the candidate"s knowledge by calculating the number of correct answers, which must exceed the pass-average related to the chosen category. The pass average is specified by the law for each category (Ex 32/40 for Category "B": Automobile) when a candidate fails in the exam, he/she will be re-called for the second session after fifteen days for his/her last chance.
In 2008, according to the law, the Moroccan government has decided to employ technology in the theoretical test due to various problems. These problems are caused by kipping completely the judgment on supervisors hand besides the time and resources wasting with not much reliable results. Therefore, the proposed solution was to regroup candidates into sessions, each one passes the exam in front of a monitor related to remotes for each candidate. In so doing, it allowed them to answer separately to questions shown in the monitor and get the results by the end of the session. This arrangement made by the government gives more reliable results and solves a lot of problems. However, there were other problems caused by the system such as remotes crashes problems and unsaved results. Therefore, in 2010, computers having a screen-touch and cameras are used for the first time instead of the old system. Thus, each candidate can take anytime his exam separately with random questions. This would give credibility, transparency and efficiency to the test and evaluate objectively the candidate"s abilities and prerequisites and moreover, to facilitate the job for the supervisor to become just an observer instead of being a judge with no pressure.
On the other hand, practice test did not change. That is, according to Moroccan law [2] the practice test divided on four stages for category "B" correspond to car driving : Parking Car Test: The candidate must successfully park the vehicle in and out of a specific zone ( Figure 1) without touching any bars surrounding that zone.
Entering Car to the garage Test: The candidate must successfully enter the vehicle in and out of a dedicated vertical zone ( Figure 2) without touching any bars surrounding the zone which simulates the garage.
123 | P a g e www.ijacsa.thesai.org 1) Title: category "B": make a stop between two barriers on the right and do a half cycle.
2) Width of the parking space "L". 1) Title: category "B": entering to the garage.
3) Garage area width "l" Car Reverse Test: The candidate should drive throw a dedicated zone in reverse without touching the surroundings of that zone or stopping the vehicle (Figure 3). 1) Title: category "B": driving backward in a straight line 2) Passage width "L" = 20m.
3) Passage height "l" = 2.5m Car Ride Test: It tests the candidate"s ability to drive the car and control it in order to evaluate his reactions and knowledge on the field.
As it is mentioned before, unlike the theoretical test, the practice one did not changed and still depends completely on supervisor eyes judgment with total absence of tools that would facilitate their job. Today, the practice test should follow the same path using technology based on motion detection. In this sense, this new vision integrates motion sensors and video surveillance. Each one of them comes with advantages and requirements. Therefore, this research will focus on the concept of video surveillance system and propose methods and algorithms to be implemented in order to supervise and evaluate objectively in real-time the Car Reverse Test (CRT) in driving license exam.
Technically, this paper is going to proceed as the following: In Section 3, an overview of the method and system architecture is presented to show the whole procedure which will be divided in three subsections: subsection 3.1 is about Surveillance System Architecture that would represent the architecture of the system that is used for the proposed solution. The subsection 3.2 is dedicated to the method adapted on the solution and also a literature review to all the steps. The subsection 3.3 describes the application of the proposed method in Car Reverse Test (CRT). Section 4 represents the experimental results. Finally, Section 5 concludes the achievement of the paper.

II. RELATED WORK
The implementation of video surveillance system to manage CRT requires using motion detection techniques to process footages that are captured and tries to analyze them so as to come with a judgment, the common idea in most video motion detection algorithms is to begin with a defined frame f 0 called reference frame and a successive frame f i . This algorithm compares the two frames to detect any possible changes then moves to the next frame f i+1 so the reference frame f 0 becomes f i . This process is successively repeated for all frames.
Many methods for motion detection exist in the literature. For instance, the authors of [3] discuss three methods to detect motion in given images: background subtraction, optical flow and temporal difference which are commonly used alone or side by side with other techniques in many researches on subjects related to motion detection.
The background subtraction was used by authors of [4] and [5] and it consists on comparing an image with a static reference image to distinguish the dynamic foreground of the static background of those images. The optical flow method as cited by the authors of [6] is focused on how much each pixel of the current frame moves between adjacent frames. The temporal difference method used by authors of [7] compares successive frames by analyzing all frame pixels in order to detect any moving regions.
To summarize, there are many methods for motion detection which could be used alone or side by side to achieve significant results.

A. Surveillance System Architecture
Within the same realm, the idea here is to encompass the use of the video surveillance system in CRT. This system consists of video cameras, video processing unit (VPU), network, visualization centre and video database and retrieval tools. The first part of the system is the camera which has the role of capturing videos. Then, in the second part, the video will be transmitted to the VPU through the network which contains the software to process received footages using appropriate algorithms. The system is equipped with video storage and retrieval tools in order to help the VPU to Store and retrieve the related content of a video for processing or archiving. Then, the useful information will be transmitted to the next part, which is Visualization Centre whereby the supervisor (in our case) will get the score and validate the final result. In Figure 4 the architecture of the video-surveillance system is illustrated according to the author of [8].

B. Method Overview
The Method represented in the flow chart of Figure 5 is composed of three steps to be executed in the VPU which will be called Line Monitoring Algorithm (LMA).
The first step is using a noise removing algorithm in order to remove any noise caused by the image capture or the environment which gives clearer image as a result. The second step is to get line pixels using Bresenham"s Algorithm which serves to get minimal calculated pixels between two preselected points in a straight line relaying those points. That algorithm is applied in the reference frame. In this stage, the coordinates of generated pixels will be stored in order to extract the same line location in next frames. The last step is to apply the Structural Similarity Index Method (SSI) in which changes in the generated Line between the reference frame and the current frame is calculated, and the result will be compared to the empirical threshold T h .  The experimental result in Section 4 presents a set of images to help in understanding the processes achieved in the present method.

1) Structural Similarity Index:
In 2002, authors of [9] proposed a new universal image quality measurement method named Structural Similarity Index (SSI) was invented. This method is based on calculating three factors: the luminance, the contrast and the structure. SSI is easy to calculate and apply on various image processing applications.
Mathematically the SSI is represented also by authors of [10] as: Suppose S1 = {v i |i=1,2,…,N} and S2 = {v i |i=1,2,…,N} are two non-negative image signals, which will represent, in this work, the signals corresponding to the lines extracted from reference frame and the current frame successively where i is the index of pixel in the line, and v i is the intensity of that pixel.
According to [10] by the diagram shown in Figure 6, the comparison of luminance, contrast and structure measures is given as follows: Where C 1 , C 2 and C 3 are very small constants, which are linked to the range of pixels values.
2) Bresenham's line algorithm: Bresenham's Line Algorithm (BLA) [11] is named after Jack Elton Bresenham who developed it in 1962 at IBM. This algorithm uses integrated/embedded arithmetic only, and is faster and more accurate than other obvious algorithms that use floating-point arithmetic.
The main idea of BLA is done for the purpose of connecting two given points in a square grid. The result of the BLA for two points P1(x1,y1) and P2(x2,y2) is represented in Figure 7.

C. Proposed LMA applied on CRT
The main objective is to automatically supervise CRT using the Artificial Intelligence AI. The decisions made by the system, without human intervention, are based on computer vision techniques using only installed cameras. This proposed technique will offer objectivity to the test.
According to the Moroccan law, there are four parameters that should be specified concerning CRT shown in Figure 3 and also explained in Figure 8.
Start Line (SL): crossing the start line indicates that the candidate is about to start the exam, the system monitors the tracking area and limits lines to track the vehicle.
End Line (EL): crossing the End Line means that the test is finished. The system stops monitoring the Tracking area and the score with recorded video are saved.
Limit Lines (LL): Two straight Lines indicating Limits that should not be crossed by the vehicle.
Tracking Area (TA): is created between Limits Lines, and it allows system to monitor the car through to the End Line. 126 | P a g e www.ijacsa.thesai.org The proposed algorithm to detect motion on specific line is labeled Line of Interest (LOI). The latter is represented as it is shown in Figure 10. The algorithm can be summarized in the following: 1-The algorithm starts by loading the video from video capturing device through the camera. 2-Display the video feed in Visualization Center to let the user initialize the system. 3-Initializing the system by choosing two points to draw the first line which indicates the Start Line. Afterwards, the second two points bespeak End Line. And finally, the last four points refer to the Tracking Area. 4-Draw the selected areas to be pictured in visualization center 5-Capture the first frame f 0 6-Extract pixels using Bresenham"s Algorithm for reference lines: Start Line SL 0 , End Line EL 0 , Tracking Area TA 0 , and Limit Lines L1 0 and L2 0 7-Start Monitoring changes at Start Line a-Capture the first frame f t at the time instant t b-Extract the line pixels of SL t using Bresenham"s Algorithm c-Convert SL t to gray level format d-Compute the SSI(SL t , SL 0 ) e-Go to "step a" until the similarity between the SL 0 and SL t is below the predetermined threshold T h and this means a motion activity is detected.

8-Start monitoring changes in Tracking Area and Limit
Lines and End Line. 9-Re-execute "step 5" for EL 0 while no activity is detected. 10-Save recorded video and result.
To define the threshold value T h , values of coefficients in combination of SSI score (luminance, contrast and structure), scene environment and tolerated intensity of changes (ex: changes accrued on 50% of line) should be considered.  For each line from parameter lines specified in subsection 3.3 above, the first step in CRT system shown in Figure 9, and also in Figure 10 is extracting the Line Of Interest (L t ) pixels from the frame F t , then, the next step is comparing the line resulted from previous step with the Line of reference (L 0 ).

A. Comparaison between LMA and SSI based ROI
SSI based Region Of Interest (ROI) was used in a various fields of research with similar approaches to this work as [14] and [15]. In this respect, the comparison with SSI based ROI is jugged suitable to appreciate the proposed technique LMA. The main idea in LMA is to monitor limit lines of the whole region instead of what SSI based ROI does.
For the experimental test, flow charts shown in Figure 11 and Figure 12 represent a qualitative and quantitative comparison of the LMA and SSI based ROI method. The Flow www.ijacsa.thesai.org chart in Figure 11 represents the SSI based ROI test program. After the initialization, the program starts with extracting ROI from the current frame. Then the denoising technique is applied using Non-local Means Denoising Algorithm [13], the SSI score is calculated to detect change accrued in the ROI. In this case, the score and elapsed execution time are reported. The flow chart shown in Figure 12 describes the same processing, in which, LMA uses the BLA to extract LOI instead of ROI in the previous program. Same outputs (score and execution time) are reported for the comparison.
All tests are run under Virtual Machine CPU Core Duo 1GHz and 1 GB of memory with Linux Ubuntu 16.4 Debian Distribution 64 bits. As for the programming language, Python is used with OpenCV library for graphic manipulation.
The test program uses as input a recorded video [12] of 1 min captured by a CCTV camera of a parking space. In order to manage the extracting and comparing images, the Multithreading technique is implemented to provide simultaneous execution in order to enhance the performance of test programs and to save more processing time.    Figure 13 shows that LMA and SSI based ROI successfully detects the movement inside the chosen area. However, in this comparison, LMA takes less time to detect changes, and this is justified by the small amount of data processed. Additionally, the SSI score is near 1 before changes accrued, which means that proposed algorithm is more insensitive to noise than SSI based ROI.
The advantage of using LMA is shown also in multiline monitoring specially in real-time implementation. The result shown in Table I denotes the FPS variation by the number of drawn lines. As a result, for each 10 processed lines, the video speed is dilated by only ~ 3 FPS which is less than SSI based ROI.
In this section, the comparison between LMA and SSI based ROI shows that the combination of the two algorithms would give a remarkable solution especially where LMA is been used as a trigger of SSI based ROI which can not affect the video speed.

B. Performance of CRT Supervisor System
To determine objectively the accurate threshold value T h and also to evaluate the performance of the proposed CRT Supervisor System, a primary test has been made using recorded videos. Therefore, in this work, the performance www.ijacsa.thesai.org measures discussed by the authors of [16] will be adopted. These measures are introduced in this work as the following: -True Line Crossed (TLC): It is the number of every couple of successive frames where the vehicle crosses the line meanwhile the CRT system declares the change.
-False Line Crossed (FLC): It is the number of every couple of successive frames where the vehicle crosses the line but no change is declared by CRT system.
-True Line Not Crossed (TLN): It is the number of every couple of successive frames where the line is not crossed while the CRT system declares the change.
-False Line Not Crossed (FLN): It is the number of every couple of successive frames where the line is not been crossed but no change is declared by CRT system.
The extracted values are classified by the confusion matrix shown in Table II.
Using these measures, the following Performance indicators are deduced for the CRT system: To check the quality of the proposed CRT system, different Threshold values are chosen to measure their effect in program results and correctness of the algorithm.
For the experimental purpose, a recorded video of the real scene was used with pre-determined motions. This choice is made in order to simplify the visual motion detection so that the detected motions would be easily compared with those of the proposed algorithm. The main objective is to run this test using a different threshold values to choose finally the most accurate value. The analyzed video specifications are:  Table III and also represented in the graph in Figure 14. The idea is to choose the T h value which gives a minimal false detection (FLC) and nearer value of true detection TLC to the predetermined one. In Table III, the T h value which fills those conditions is T h =0.3.The results of calculating the performance indicators displayed in Table IV and in Figure 15 show that T h =0.3 gives the best accuracy percentage, and this means that the program detects perfectly most the frames where the car is crossing the line.  129 | P a g e www.ijacsa.thesai.org As regards to the experimental results from above, it is clear that choosing the right value of threshold can be affected by the quality of the video. In our case, the change in selected line should be relatively high with the highest value of accuracy and low count of false detected frames FLC. Therefore, we conclude that the most accurate threshold value should not exceed 0.3 in order to achieve best results.

C. The Result of the Proposed Solution
In this section, we will use the same video as the subsection 4.2 above with a threshold value Th=0.3. The results displayed in Table V show that when using the chosen Th value, CRT System detects successfully the changes in start line and end line with an accuracy of 97%. The histogram represented in Figure 16 shows the variation of SSI score by the video frames where TLN, TLC and FLC values are highlighted. As regards the car crossing event, the graph above can be divided into three parts: In the first part (1), the SSI score is greater than 0.3 so the system did not declare the change and the car is not arrived yet to the line (TLN). The highlighted part (2) represents the entering/leaving events of the car where the system declares the change (TLC). In the next part (3), the SSI score is under 0.3 in several frames which leads the system to declare false changes (FLC) and that affects the accuracy (the other missing 3%). It is due to the position of the camera, which shows the line been drown upon the vehicle. Thus, to manage this problem, the CRT system should not monitor the line when a change has already detected for the first time.
In the Figure 17, Figure 18 and Figure 19, the proposed form represents the real scene view of CRT system through the use of captured images from the real scene where all parameters are drawn. In this stage, we tried to manage the monitoring of Start Line and End Line. In further researches, the focus will be on other techniques to process the Tracking Area and Limit Lines; these techniques would provide useful data such as calculating the distance between the vehicle and the limit lines, measuring the vehicle speed, which can be used to make decisions and helping the learning process of the program.

V. CONCLUSION AND PERSPECTIVES
In this paper, in order to design and develop a CRT Supervisor System, which is one of several sub-systems composing a Driving License Supervising System that would give more objectivity to practical tests in driving license in Morocco. Therefore, the proposed Line Monitoring Algorithm based on Structural Similarity Index is investigated. The results exhibit that the proposed algorithm presents a high capacity in motion detection which would be a prominent resource of research.
The proposed LMA is based on extracting lines from successive frames and measures the similarity between them using Structural Similarity Index (SSI) and Bresenham's Algorithm. The proposed algorithm comes with the highest motion detection accuracy in most experiments, especially with the right threshold value and adapted camera view. The experimental results show that the proposed SSI based method has better performance comparing to monitoring the whole region or frame. This method also has shown to provide a high efficiency with a high speed and relatively a low storage, which makes it a great choice when it comes to dealing with limited resources. The main advantages of proposed method are higher detection accuracy and improved processing speed.
The implementation of the proposed method gives an exciting result for a start. Therefore, further researches will focus on providing more techniques to be integrated on the proposed system for the driving license test in order to serve the main cause which is improving the road safety in Morocco.