{'fraction_non_alphanumeric': 0.023453991087483386, 'fraction_numerical': 0.003752638573997342, 'mean_word_length': 4.566579634464752, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Motion Detection for PC based on Security System by using Optical Flow

This system is designed aims to detect and analyze the motion of people that have been recorded on PC, which response rapidly to the abnormal motion based on optical flow method. Horn-Schunck technique is one of optical flow method which has ability to detect the motion in image sequences by examining the velocities of the motion objects. It will response to abnormal motion and triggered the alarm in order to alert the people beware to their surroundings. Keywords— Motion detection; image processing; optical flow; Horn-Schunck method


I. INTRODUCTION
This research focused with the development of a security system for PC based by using optical flow method, which is implemented in Matlab software. This system is created to detect both normal and abnormal motions in the crowd in video streams, which recording by closed-circuit television systems (CCTVs). It is able to distinguish the abnormal motions in video sequences then response to that detection by triggering alarm to alert people to their surroundings. In this case, the normal motion is consider when people are walking. Otherwise, it will consider as abnormal motion.
Optical flow is one of the most popular methods used recently in detecting and calculating the motion of each pixel between two frames, and thus provides a possible way to get the velocities of the motion objects [1]. It is the apparent motion of the brightness pattern in an image sequence. In this research, Horn-Schunck technique is used since it is more sensitive to noise, whereby it is one of the optical flow methods.

II. LITERATURE REVIEW
Motion detection is crucial in many applications, for example in defence and security applications. It is usually performed in pre-processing of a system, whereby the subsequent processes of the system such as tracking and behavior recognition are significantly dependent on it [2]. In computer vision, motion detection is important queue in tracking. According to [3], motion detection aims at segmenting regions corresponding to moving objects from the rest of an image. Environment modelling, motion segmentation and object classification are the processes which are usually involve in motion detection. This paper will be focused on the chosen technique, optical flow.
Optical flow is one of the conventional approaches in motion segmentation. From the review [3], they claimed that optical flow-based motion segmentation uses characteristics of flow vectors of moving objects over time to detect moving regions in an image sequence. It will compute the velocity of the motion object between two consecutive frames of an image sequence [4].
From the study, the implementation of optical flow seems to be succeeded and some results are acceptable. However, this technique still has its own drawbacks. There are number of optical flow methods has been reinvestigated in order to enhance this technique, for example Horn-Schunck optical flow. Horn and Schunck introduced both the brightness constancy and the spatial smoothness constraints for optical flow estimation [5] [6]. The brightness constancy is derived from the observation that surfaces usually persist over time. Hence, the intensity value of a small region remains the same despite its position change. While the spatial smoothness constraint rises out from the observation that neighbouring pixel generally belongs to the same surface and so have nearly the same image motion [5].

A. Optical Flow Constraint Equation
The optical flow cannot be computed at a point in the image independently of neighbourhood points without introducing additional constraints due to the velocity field at each image point has two components while the change in image brightness at a point in an image plane due to motion yields only one component. From the reviews, researchers assumed that the intensity, I of moving points is constant over a period of time. This assumption is known as brightness constancy assumption.

B. Horn-Schunck Technique
In order to generate the output from optical flow, Horn-Schunck method function will be called. From the experimental results, two images will be analyzed and the values of the variable u and v are produced. The Horn-Schunck constraint defines a straight line in the uv velocity space, as shown in Fig. 1. Obviously, the optical flow in the image plane and the velocities is necessary. To detect the moving object, the brightness will be considered and the variations in brightness due to shading effect can be evaded by make an assumption that the objects have flat surface. Horn and Schunck derived an equation that relates the change in image brightness at a point to the motion of brightness pattern. Let the image brightness at point (x, y) in the image plane, t is denoted by E(x, y, t). Now consider what happens when the pattern moves, the brightness of a particular point in the pattern is constant, so that; (1) Using the Chain Rule for differentiation, (2) Let u= dx dt v= dy dt (3) Then, one signal linear equation is obtained, which has two unknown parameters, u and v. (4) In this case neighboring points on the object have similar velocities and the velocity field of the brightness patterns in the image varies smoothly almost everywhere. Discontinuities in flow can be expected where one object occludes another. The additional constraint is to limit the difference between the flow velocity at a point and the average velocity over a small neighborhood containing the point. Equivalently the sum of the squares of the Laplacians of x and y can be minimized and define as; (5) In simple situation, both Laplacians are zero [4].
The derivatives of brightness are estimated from the discrete set of image brightness measurements. The estimates of Ex, Ey and Et needed to be consistent, which need to refer to the same point in the image on the same time. Horn and Schunck used a set which gives estimates of (Ex, Ey, Et) at a point in the center of a cube formed by eight measurements. Each of the estimates is the average of four first differences taken over adjacent measurements in the cube. All of these calculations are done by MATLAB. The output value from Horn-Schunck, u and v are used to analyze the motion velocity.

III. METHODOLOGY
The flowchart in Fig. 2 shows the overall processes involve in this project. This system is developed by using motion ball image, which are created using Paint software with 640x420 pixels. The ball sizes are same for each image in image sequences. The velocities for the object motion are analyzed based on assumptions that are made for further analysis. By using Horn-Schunck method, two variables are produce, u and v. Where u is the flow in x-axis and v is the flow in y-axis and both of these variables will be represented as arrows. So, the velocity can be calculated using the value of u and v by implemented it into equation; (6) In order to analyze the image, there are some assumptions are made. For walking motion, the value of mean of velocity must be lower than running motion. For random motion, the value of mean of velocity must be not constant which its value must be drastically low or high. The last assumption is for the static motion; the value of mean of velocity will be zero (0).
In order to analyze the velocity for different movements, statistical method is used. The maximum, minimum, mean, variance and standard deviation of velocity values for two different images are calculated to get the suitable parameters used in this experiment. Two different movements of ball moving images are created, whereby the long distance is assumed as run and close distance is assumed as walk for the ball motions in a sequence of image. The output from Horn-Schunck method is the value of velocity for each movement, which happen for each pixel.
The value of standard deviation is very useful in classification process. For example, in evaluating people height, standard deviation will let us know who is the tallest and shortest based on the mean value. Hence, in order to analyze the velocity for whole images, mean value is used since the maximum and minimum values do not give useful information to differentiate the movement. Then, the mean of velocity values are decided as fix parameter to be observed.
When the ball is moving randomly, it is consider as people moving randomly. This action can be considered as abnormal motion. The results shown that the velocity mean also do not consistence because it is rapidly changing to high and to low. For static motion, the mean value for the velocity is zero. In this experiment, walking and running will be main analysis. In order to make this system more efficient, looping technique is used to differentiate multiple images in sequences, and differentiate two images which the reference image. So, the first image will be compare with the next image and so on.

A. Real Analysis
Real-time analysis is done by using the video that is captured people walking and running. In order to convert video for processing, converter software is used, named Video to JPG converter. In this experiment, the video recorded is extracted into 5 frames per second to make the datasets constant or acts as controlled variable. Then, the data will be analyzed and compared with the initial output. The output from this step will be used in the next process, which is classification. Each image sequence contains from 10 to 25 images.

B. Feature Extraction
The extracted images will be analyzed based on their velocity values. The velocity value is linear with the mean value of velocity. Greater number of velocity will provide greater number of mean value of velocity. However, the motion cannot be categorized or differentiate without making some additional consideration.

C. Classification
To make this research run efficiently, the moving object should be eliminated from the background image to prevent the value of background affected the velocity value of real moving object. The velocity was divided into sixteen subblocks, as illustrated in Fig. 3. Each sub-block will be evaluated in order to get the mean value of velocity. A division for velocity in programming is done and the velocity for each sub-block is evaluated by calling the row and column value. The mean of velocity value from each sub-block are observed and value 1 is set as the threshold. This threshold will determine which row and column belongs to main motion or background motion. The classification is done by considering the mean value for each row and column, which is below than value 1. This part will be eliminated from evaluation since it is consider as noise. The mean value which is greater than 1 will remain for the next process. The classification is done by summing new mean value for all rows and columns. The mean value and the graph pattern are observed to define the threshold value.  Fig. 4 shows the output image, containing the magnitude of motion, which is represented as arrow. The result of mean value for each velocity are calculated and shown in Fig. 5 and Fig. 6 using the assumptions in Table 1.   Mean of velocity value for small distance and long distance are plotted in the graph as shown in Fig. 7 and Fig.  8. Based on the value plotted in both graphs, it shows that there are slight differences between them. The long distance ball produces mean value lower compared to mean value for small distance ball.  In order to eliminate noise background, sub-block was done. The whole image is divided into 16 sub-blocks. It represented as image because Horn-Schunck method represents velocity based on number of pixel. Fig. 9 shows 16 sub-blocks for the whole image. Each sub-block has its own mean velocity value, as illustrated in Fig. 9. The mean values illustrated in Fig. 9 are obtained before noise elimination. A threshold with value 2 is set so that the background velocity can be removed from the object velocity. Fig. 9 illustrates the mean value for each sub-block after the noise is eliminated.

V. CONCLUSION AND FUTURE WORK
In this work, we presented a system based on optical flow method, Horn-Schunck in order to detect motion. It is developed using Matlab software, through the m-file. According to the experimental results, this system able to detect the abnormal motion and distinguish both normal and abnormal motion. As future work, we plan to explore motion detection and create a system using other methods. The system is recommended to be user-friendly and flexible to be used with various size of image. In order to enhance the motion detection system, we have to learn and analyzed various human patterns and make the system real-time by interfacing it to the closed-circuit television system.