Spatiotemporal anomaly detection method based on convolutional sparse coding and optical flow
Through convolutional sparse coding and optical flow detection methods, the anomalies of video frames are analyzed from the spatial and temporal dimensions, which solves the problem of low efficiency of the existing video surveillance system, realizes the intelligent anomaly detection and alarm functions of the video surveillance system, and improves the efficiency of the video surveillance system. Safety in public places.
Patent Information
- Application Number
- CN202110439560.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-23
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-04-23
AI Technical Summary
Existing video surveillance systems require human eyes to observe real-time video streams for a long time, resulting in low monitoring quality and efficiency, a waste of human resources, and the inability to effectively detect abnormal events in public places with large traffic flows.
A spatiotemporal anomaly detection method based on convolutional sparse coding and optical flow is used to perform feature learning and detection from two dimensions of space and time. The appearance features of video frames are reconstructed through convolutional sparse coding, and motion features are extracted by combining optical flow histogram vectors. The appearance and motion anomaly scores are calculated, and finally the weighted sum is obtained to obtain the total anomaly score to determine abnormal frames.
The video surveillance system has been made intelligent, capable of independent monitoring and decision-making, reducing labor costs, timely detection and alarm of abnormal events, such as fights and crowd panic, and improving the safety of public places.
Smart Images

Figure CN113343757B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of video surveillance technology, and in particular to a spatiotemporal anomaly detection method based on convolutional sparse coding and optical flow. Background Art
[0002] At present, relatively complete monitoring systems have been set up in public places with large traffic such as subways, shopping malls, and stations. These monitoring systems intuitively broadcast and record on-site information in the form of images and videos, which are used by relevant security personnel to monitor different sites in real time, such as Figure 1 Common abnormal events in life are shown, such as cars appearing on the sidewalk, people running at subway entrances and exits, etc.
[0003] However, such a monitoring system requires the human eye to observe one or more real-time video streams for a long time, which ignores the fact that the human body cannot concentrate for a long time. As a result, the monitoring quality and efficiency of the monitoring system cannot be guaranteed, and it also inevitably causes a large waste of human resources. In view of this, we propose a spatiotemporal anomaly detection method based on convolutional sparse coding and optical flow. Summary of the invention
[0004] The purpose of the present invention is to provide a spatiotemporal anomaly detection method based on convolutional sparse coding and optical flow to solve the problems raised in the above background technology.
[0005] To achieve the above-mentioned purpose, the present invention provides the following technical solution: a spatiotemporal anomaly detection method based on convolutional sparse coding and optical flow, which includes two parts: spatiotemporal feature learning of video and anomaly detection of video.
[0006] Preferably, the algorithms of the spatiotemporal feature learning part and the anomaly detection part are both performed from two dimensions: space and time.
[0007] Preferably, the spatial dimension algorithm of the spatiotemporal feature learning part includes the following steps:
[0008] Step 1: Reconstruct the normal frame by learning filters through convolutional sparse coding;
[0009] Step 2: Force the filter to learn the spatial appearance characteristics of normal events.
[0010] Preferably, the time dimension algorithm of the spatiotemporal feature learning part includes the following steps:
[0011] Step 1: Calculate the optical flow image based on the pixel changes between adjacent video frames and extract the optical flow histogram of the frame;
[0012] Step 2: Train the support vector machine using the HOF of the normal frame as the training sample;
[0013] Step 3: Get a single classifier to describe the motion feature distribution of normal events.
[0014] Preferably, the spatial dimension algorithm of the anomaly detection part includes the following steps:
[0015] Step 1: Use the filter obtained in the feature learning stage to reconstruct the test sample;
[0016] Step 2: Get the appearance anomaly score based on the reconstruction error.
[0017] Preferably, the time dimension algorithm of the anomaly detection part includes the following steps:
[0018] Step 1: Input the HOF features of the test sample into a single classifier based on SVM;
[0019] Step 2: Obtain a motion anomaly score based on the output classification probability value.
[0020] Preferably, the anomaly detection part includes a result determination algorithm, which performs weighted summation of the appearance anomaly score and the motion anomaly score to obtain a total anomaly score of the video frame, and compares it with a preset threshold. When the total anomaly score of the frame exceeds the preset threshold, it is classified as an abnormal frame.
[0021] Compared with the prior art, the beneficial effects of the present invention are as follows: the algorithm of the present invention integrates convolutional sparse coding representation and optical flow field to detect abnormal events in the video from the two aspects of spatial appearance and temporal motion, and sums the appearance abnormality score and the motion abnormality score to obtain a total abnormality score with more judgment basis, and finally uses artificial intelligence to realize the intelligence of the video monitoring system, so as to assist security personnel to effectively maintain the safety of the public and reduce unnecessary manpower costs. The so-called "intelligent" means that the monitoring system has the ability to monitor and make decisions independently, so that the monitoring system can screen and judge the information while collecting the on-site image information in real time, and then the monitoring system can send out alarm information in time when abnormal events such as fighting, crowd panic, etc. are detected, so as to reduce the harm caused by abnormal events. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 For common abnormal events in life;
[0023] Figure 2 It is the algorithm block diagram of the present invention;
[0024] Figure 3 This is a block diagram of appearance anomaly detection based on convolutional sparse coding;
[0025] Figure 4 This is a flowchart of the optical flow histogram extraction process. DETAILED DESCRIPTION
[0026] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0027] See also Figures 1 to 4 The present invention provides a technical solution: a spatiotemporal anomaly detection method based on convolutional sparse coding and optical flow, which includes two parts: spatiotemporal feature learning of videos and anomaly detection of videos.
[0028] Spatiotemporal feature learning: The purpose of the spatiotemporal feature learning part is to build a corresponding model for the appearance and motion pattern of normal events in the video sequence, and then to detect anomalies by judging whether the features of the test sample obey the model. This part is carried out in parallel from the two dimensions of space and time: on the one hand, the convolutional sparse coding learning filter is used to reconstruct the normal frame, forcing the filter to learn the spatial appearance features of normal events; on the other hand, the optical flow image is calculated based on the pixel changes between adjacent video frames, the optical flow histogram of the frame is extracted, and the support vector machine is trained with the HOF of the normal frame as the training sample to obtain a single classifier to describe the motion feature distribution of normal events. Finally, each video frame obtains an appearance reconstruction error and an optical flow amplitude change.
[0029] Anomaly detection: Similar to spatiotemporal feature learning, the anomaly detection stage is also performed from the spatial and temporal dimensions. In the spatial dimension, the filter obtained in the feature learning stage is used to reconstruct the test sample, and then the appearance anomaly score based on the reconstruction error is obtained; in the temporal dimension, the HOF feature of the test sample is input into a single classifier based on SVM, and a motion anomaly score is obtained based on the output classification probability value. Finally, the weighted sum of the appearance anomaly score and the motion anomaly score is obtained to obtain the total anomaly score of the video frame, which is compared with the preset threshold. When the total anomaly score of the frame exceeds the preset threshold, it is classified as an abnormal frame.
[0030] Among them, appearance anomaly detection was mainly carried out based on convolutional sparse coding.
[0031] Sparse coding is an unsupervised method, which aims to find a set of basis vectors that can represent the input samples as a linear combination of these basis vectors, specifically the sum of the products of each basis vector and its corresponding sparse coefficient. Convolutional sparse coding is different from the multiplication operation in sparse coding. Convolutional sparse coding first convolves a set of filters with the corresponding feature map, and then sums all the convolution results to represent the input samples. The present invention proposes to use convolutional sparse coding instead of sparse coding to represent video frames. The goal of convolutional sparse coding is to directly represent the entire frame image rather than the underlying features of a single image block. This representation method takes into account the continuity between adjacent pixels in space and realizes end-to-end representation of video frames. The objective function of convolutional sparse coding is defined as follows:
[0032]
[0033] Where s represents the input sample, d m represents m filters, x m is the feature map corresponding to the filter, with the same size as s, and * represents the convolution operation. The first term in the objective function represents the reconstruction error of the input, and the second term ensures the sparsity of the feature map. The alternating multiplier algorithm is used to divide the above equation into two sub-problems to solve the filter and feature map respectively: fix the filter and solve the feature map; fix the feature map and solve the filter, and repeat the alternating iteration until convergence.
[0034] In order to learn the appearance pattern of normal events, given a video dataset containing only normal frames, a set of filters is learned by minimizing formula (1) to represent normal frames with the minimum reconstruction error. This method forces the filters to learn the common characteristics of normal events. To reduce the computational complexity, the k-nearest neighbor classification algorithm
[14] is performed on the obtained filters to select a set of representative filters. When testing, the learned filters are fixed, and a set of corresponding feature maps are learned for a given test sample s to obtain the reconstruction representation of the sample. , specifically expressed as follows:
[0035]
[0036] Intuitively, the filter learned on normal data can represent normal frames with a smaller reconstruction error but cannot represent abnormal frames. Therefore, the appearance anomaly score of the frame can be obtained based on the reconstruction error of the sample, and then it can be determined whether the frame has an appearance anomaly. The appearance anomaly score here is calculated as follows:
[0037]
[0038] After obtaining the anomaly scores of all frames in a video, normalize them to between [0,1]:
[0039]
[0040] Here t represents the tth frame in the video sequence, max s(t) , min s(t) They represent the maximum and minimum values of the abnormal scores of all frames in the video sequence. appe The larger the value, the more likely the frame is to have appearance anomalies. The appearance anomaly detection process based on convolutional sparse coding is as follows: Figure 3 shown.
[0041] Among them, motion anomaly detection was mainly performed based on optical flow histogram vectors.
[0042] The motion field is used to describe the motion trajectory of an object in real three-dimensional space, while the optical flow field attempts to reflect the real motion of an object in three-dimensional space through pixel changes on a two-dimensional image plane. The fundamental principle is to solve the velocity vector of each pixel in the image, which includes not only the amplitude of the pixel's motion, but also the direction of the pixel's motion. If f(x,y,z) represents the intensity of a pixel at (x,y) in a certain frame, where t represents the time dimension of the frame, and in the next frame, the pixel moves a distance of dx and dy in the horizontal and vertical directions, and the time taken is dt, then the intensity of the pixel in the next frame is f(x+dx,y+dy,t+dt). When solving the optical flow field, it is often assumed that the optical flow has small motions and constant brightness, which yields:
[0043] f(x,y,t)=f(x+dx,y+dy,t+dt) (5)
[0044] By expanding equation (5) using the first-order Taylor series, we can further obtain:
[0045]
[0046] That is:
[0047] f x dx+f y dy+f t dgt=0 (7)
[0048] make:
[0049]
[0050] Where u and v represent the optical flow components of the pixel in the horizontal and vertical directions respectively.
[0051]
[0052] So
[0053] fx u+f y v=-f t (10)
[0054] Right now
[0055]
[0056] The core of the optical flow field is to solve the optical flow components u and v in the horizontal and vertical directions respectively. Common traditional optical flow calculation methods include the Lucas-Kanade method and the Horn-Schunck method.
[0057] The Lucas-Kanade optical flow method is a sparse optical flow method that only needs to calculate the optical flow vectors of some pixels in the image, which is equivalent to thinning the image and extracting the more representative pixels to calculate the optical flow vectors. The Horn-Schunck optical flow method is a dense optical flow calculation method that needs to calculate the optical flow values of all pixels in the image. Compared with the former, the calculation cost of the Horn-Schunck optical flow method is higher, but it will not cause information loss. Therefore, the present invention calculates and extracts the optical flow histogram of each frame based on the Horn-Schunck optical flow method. The extraction process is as follows: Figure 4 As shown, the specific steps are as follows:
[0058] 1) After calculating the horizontal and vertical components u and v of the optical flow of all pixels in the frame using the Horn-Schunck optical flow method, the optical flow amplitude and direction of the pixel are calculated according to formulas (12) and (13) to capture the motion pattern of normal events in the video sequence.
[0059]
[0060] Where (i, j, t) represents the spatial position and time dimension of the pixel in the frame, u x 、v y is the optical flow component of the pixel in the horizontal and vertical directions, |h i,j,t |、φ i,j,t They represent the optical flow amplitude and the optical flow direction respectively.
[0061] 2) After obtaining the optical flow images of all frames, the optical flow images of each frame are divided into M×N non-overlapping image blocks, and the 360-degree direction is divided into B angular sub-sectors of the same angle. Then, the optical flow amplitude of all pixels in each divided image block is calculated. i,j,t |Add to its corresponding angle φ i,j,t Location;
[0062] 3) Accumulate the optical flow amplitudes of the image block at each angle sub-sector to obtain B optical flow values, and then cascade them in the order of sectors to form the optical flow vector of the image block;
[0063] 4) Repeat step 3) to obtain the optical flow vectors of all image blocks and then cascade them in sequence to form the optical flow histogram HOF of the corresponding frame, and the vector dimension is X=M×N×B.
[0064] After obtaining the HOF of all frames, the HOF of normal frames is used as a training sample to input into SVM to train a single classifier. When detecting anomalies, first extract the HOF features of a given frame according to the above steps, and then input it into the pre-trained single classifier to output a probability value P belonging to the class. The smaller the value, the smaller the probability that the given test frame belongs to a normal frame, and conversely, the greater the possibility of belonging to an abnormal frame. Therefore, based on this probability value, the motion anomaly score of the frame can be calculated to reflect the possibility of whether the frame contains motion anomalies. After obtaining the classification probability of all frames in a video, the motion anomaly score S is defined. motion as follows:
[0065]
[0066] In summary, the algorithm proposed in this invention combines convolutional sparse coding representation with optical flow field to detect abnormal events in videos from two aspects: spatial appearance and temporal motion. In the sample test phase, given a test frame, the reconstruction error based on convolutional sparse coding and the SVM classification output score based on optical flow features are calculated to obtain the appearance anomaly score S of the frame. appe and motor abnormality score S motion , respectively reflecting the abnormality of the frame in appearance and motion. Then, the two anomaly scores are weighted fused using formula (15) to obtain the final anomaly score:
[0067] Score(t)=S appe (t)+α*S motion (t) (15)
[0068] Where t represents the tth frame in the video sequence, ∝ controls the motion anomaly score S motion The weight of the total anomaly score. Compared with normal frames, abnormal frames often have larger anomaly scores, so we can detect abnormal frames in video sequences by setting a threshold.
[0069] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A spatiotemporal anomaly detection method based on convolutional sparse coding and optical flow, characterized by: The method includes two parts: video spatiotemporal feature learning and video anomaly detection; The algorithms of the spatiotemporal feature learning part and the anomaly detection part are both performed from the two dimensions of space and time; The spatial dimension algorithm of the spatiotemporal feature learning part includes the following steps: Step 1: Reconstruct the normal frame by learning filters through convolutional sparse coding; Step 2: Force the filter to learn the spatial appearance characteristics of normal events; The time dimension algorithm of the spatiotemporal feature learning part includes the following steps: Step 1: Calculate the optical flow image based on the pixel changes between adjacent video frames and extract the optical flow histogram of the frame; Step 2: Train the support vector machine using the HOF of the normal frame as the training sample; Step 3: Get a single classifier to describe the motion feature distribution of normal events; The spatial dimension algorithm of the anomaly detection part includes the following steps: Step 1: Use the filter obtained in the feature learning stage to reconstruct the test sample; Step 2: Get the appearance anomaly score based on the reconstruction error; The time dimension algorithm of the anomaly detection part includes the following steps: Step 1: Input the HOF features of the test sample into a single classifier based on SVM; Step 2: Obtain a motion anomaly score based on the output classification probability value; The anomaly detection part includes a result determination algorithm, which performs weighted summation of the appearance anomaly score and the motion anomaly score to obtain a total anomaly score of the video frame, and compares it with a preset threshold. When the total anomaly score of the frame exceeds the preset threshold, it is classified as an abnormal frame; Appearance anomaly detection was performed based on convolutional sparse coding; The objective function of convolutional sparse coding is defined as follows: Where s represents the input sample, d m represents m filters, x m is the feature map corresponding to the filter, and its size is the same as s. * indicates the convolution operation. The first term in the objective function indicates the reconstruction error of the input, and the second term ensures the sparsity of the feature map. The alternating multiplier algorithm is used to divide the above formula into two sub-problems to solve the filter and feature map respectively: fix the filter and solve the feature map; Fix the feature map, solve the filter, and iterate repeatedly until convergence; In order to learn the appearance pattern of normal events, given a video dataset containing only normal frames, a set of filters is learned by minimizing formula (1) to represent normal frames with the minimum reconstruction error. This method forces the filters to learn the common characteristics of normal events. In order to reduce the computational complexity, the k-nearest neighbor classification algorithm is performed on the obtained filters to select a set of representative filters. When testing, the learned filters are fixed, and a set of corresponding feature maps are learned for a given test sample s to obtain the reconstructed representation of the sample. The specific expressions are as follows: It also includes obtaining an appearance anomaly score of the frame according to a reconstruction error of the sample, and then determining whether the frame has an appearance anomaly; The appearance anomaly score is calculated as follows: After obtaining the anomaly scores of all frames in a video, normalize them to between [0,1]: Here t represents the tth frame in the video sequence, They represent the maximum and minimum values of the abnormal scores of all frames in the video sequence, respectively. The score S appe The larger the value, the greater the probability that the frame has an appearance abnormality; Among them, it also includes motion anomaly detection based on optical flow histogram vectors; The optical flow field is used to solve the optical flow components u and v in the horizontal and vertical directions respectively. The optical flow histogram of each frame is extracted based on the Horn-Schunck optical flow method. The specific steps are as follows: 1) After calculating the horizontal component u and vertical component v of the optical flow of all pixels in the frame using the Horn-Schunck optical flow method, the optical flow amplitude and optical flow direction of the pixel are calculated according to formulas (5) and (6) to capture the motion pattern of normal events in the video sequence; Where (i, j, t) represents the spatial position and time dimension of the pixel in the frame, u x 、v y is the optical flow component of the pixel in the horizontal and vertical directions, |h i,j,t |、φ i,j,t Respectively represent the optical flow amplitude and optical flow direction; 2) After obtaining the optical flow images of all frames, the optical flow images of each frame are divided into M×N non-overlapping image blocks, and the 360-degree direction is divided into B angular sub-sectors of the same angle. Then, the optical flow amplitude of all pixels in each divided image block is calculated. i,j,t |Add to its corresponding angle φ i,j,t Location; 3) Accumulate the optical flow amplitudes of the image block at each angle sub-sector to obtain B optical flow values, and then cascade them in the order of sectors to form the optical flow vector of the image block; 4) Repeat step 3) to obtain the optical flow vectors of all image blocks and then cascade them in sequence to form the optical flow histogram HOF of the corresponding frame, and the vector dimension is X=M×N×B; After obtaining the HOF of all frames, the HOF of normal frames is used as training samples to input into SVM to train a single classifier. When detecting anomalies, the HOF features of a given frame are first extracted according to the above steps, and then input into the pre-trained single classifier to output a probability value P belonging to the class. The probability value P is used to determine whether the test frame belongs to a normal frame; Based on this probability value, the motion anomaly score of the frame can be calculated to reflect the possibility of whether the frame contains motion anomalies. After obtaining the classification probability of all frames in a video, the motion anomaly score S is defined. motion as follows: The two anomaly scores are weighted and fused using formula (8) to obtain the final anomaly score: Score(t)=S appe (t)+α*S motion (t) (8) Where t represents the tth frame in the video sequence, and α is the control motion anomaly score S motion The weight of the total anomaly score.
