## 5 Implementation
#### 5.3.4. Tracking
To avoid any loss of information between iterations, each blob is assigned to a new group and the Hungarian algorithm is executed (up to two times, using different weights) between the tracklets of the current group and the blobs associated to it (line 30). After applying the Hungarian algorithm, if there are still many tracklets assigned to a single blob in a group, it is a situation where occlusions and/or ghost blobs happen. In this case, the method in line 26 is applied again. ```
1:calculate assignations between tracklets and blobs using Hungarian algorithm
2:for each blob in the system do
3:if assigned to a tracklet then
4: add blob to the group of the tracklet
5:else
6: create tracklet containing blob
7: create group containing the just created tracklet
8:endif
9:endfor
10:for each group without assigned blobs do
11: move tracklets to the group of the closest blob, or the group of the blob that contains it
12:endfor
```
13:for each group in the system do
14:if has no blobs assigned then
15:for each tracklet in the group do
16:if object disappears for a moment then
17: update position with prediction
18:else
19: remove the tracklet
20:endif
21:endfor
22:else if has one blob then
23:if has one tracklet then
24: update it with the blob information
25:else if has many tracklets then
26: resolves with one-blob-to-many algorithm
27:endif
28:else
29:if has more tracklets than blobs then
30: resolves with many-to-many algorithm
31:endif
32:endif
33:if the group has no tracklets then
34: remove the group from the system
35:endif
36:endfor
```

**Algorithm 2**_Cont._

### Pattern Detection Module

The Pattern Detection module is capable of processing multiple data sources concurrently. The module consists of two stages:

1. The first stage receives messages from multiple instances of the Recognition and Tracking module and routes them depending on the source identifier. Two types of messages exist. The first type of message is the least common (but always necessary) and correspond to the ones used when processing requests by new instances of recognition and tracking. When a request arrives, the Pattern Detection module creates the structures to handle data from the new data source identified in the message, and configuration values in the message are applied to process data from the respective data source. The second type of message is used for communicating data of detected objects. When these data messages arrive, they are routed to the structures previously created to handle the data source. 2. The second stage receives data of the detected objects and has the patterns definition, the recent history of primitives fulfilled by each detected object, and all the logic needed to check patterns compliance. Patterns are defined as a sequence of primitives, defined by a 'primitive type', an 'event type' for each type of primitive, and a 'quantifier' that defines how the values of the met primitives are compared with that required by the pattern. For example, the primitives defined in the implemented system are SPEED, DIRECTION, and AGGLOMERATION. Each primitive type has events, for example, for the SPEED primitive, three events are possible: WALKING, RUNNING and STOPPED. The quantifiers defined in the proposed system are LE-lesser or equal, GE-greater or equal, AX-approximate, EQ-equal and NM-irrelevant value. ## 6 Validation and Results

This section presents validation results of the proposed system for detecting pedestrian movement patterns. Validation is performed for a case study in Montevideo, Uruguay, relying on security patterns, which are the most relevant for Ministerio del Interior, the ministry in charge of the public security. ### Recognition and Tracking Module

The validation of the Recognition and Tracking module was performed using a video from scenario S2.L1 of the PETS09 dataset. PETS09 videos were recorded using a fixed camera installed at a higher height than the head of the people, at a rate of 7 FPS with a resolution of 768 \(\times\) 576 pixels and natural light [5].