## 3 Design of RoiSeg
### Automatic Training-Sample Generation
#### 3.3.3 Trajectory Based Class Classifier  
Figure 5 shows that in the 1 st, 2 nd, and 4 th clips, the red set represents the foreground, and the blue and yellow sets represent the background. In the 3 rd clip, pedestrians were incorrectly detected as another cluster, unlike in the 1 st, 2 nd, 4 th clip. The reason for this is that it is difficult to classify the foreground and background using a GMM because it is a clustering method. Therefore, we propose a trajectory-based-classifier method to foreground and background. Suppose \(G^{t-s+1}\cdots G^{t}\)are the clustering results for the first s frames:  
\[G^{t}=\left\{g_{1}^{t},g_{2}^{t},\cdots,g_{m}^{t}\right\},m=1,2,\cdots,k, \tag{7}\]  
where \(G^{t}\) means the \(t\)th frame clustering result and \(m=k\) means there are \(k\) cluster in \(G^{t}\). \(g_{m}^{t}=\left\{x_{m1}^{t},x_{m2}^{t},\cdots,x_{mn}^{t}\right\}\), \(n=1,2,\cdots,\) num, where \(g_{m}^{t}\) represents the \(m\)th cluster, \(x_{nm}^{t}=\left(t_{i}^{t},g_{i}^{t},b_{i}^{t},x_{i}^{t},y_{i}^{t}\right)\) represents the pooled ROI central point, and num is the total number of ROI central points in \(g_{m}^{t}\). Clusters in \(G^{t}\) the current frame are matched one-by-one with clusters in of \(G^{t-1}\) the previous frame and if the matching is successful, they are considered the same type of target. Our proposed trajectory-based-classifier method is as follows:  
Figure 6: F, P, R of varying the number of GMM components. Figure 7: FPS of varying the number of GMM components. (1) Calculate the mean-feature \(\bar{g}_{m}^{t}\) of each cluster  
\[\bar{g}_{m}^{t}=\frac{1}{num}\sum_{n=1}^{mon}x_{nm}^{t}=\frac{1}{num}\left(\sum_{n =1}^{num}r_{n}^{t},\sum_{n=1}^{mm}g_{n}^{t},\sum_{n=1}^{num}b_{n}^{t},\sum_{n=1}^ {mon}x_{n}^{t}\sum_{n=1}^{mon}y_{n}^{t}\right). \tag{8}\]  
The mean-feature of all clusters in each frame is:  
\[\bar{G}^{t}=\left\{\bar{g}_{1}^{t},\bar{g}_{2}^{t},\cdots,\bar{g}_{m}^{t} \right\},m=1,2,\cdots,k. \tag{9}\]  
(2) Find the same class in adjacent frames  
In adjacent frames, if a cluster \(g^{t-1}\) in the previous frame is the same type of target as a cluster \(g^{t}\) in the current frame, they have similar \(\bar{g}^{t}\). If they are not the same target type, they often have significant differences. The \(\bar{g}^{t}\) of each cluster in the previous and current frames is ordered accordingly, from small to large. The \(\bar{g}^{t}\) of the same sequence location is the same type of target because \(\bar{g}^{t}\) of the same type of target is very similar in adjacent frames. In this way, we can compare two ascending-order clusters in adjacent frames to get the same classes of foreground objects, thus reducing the cost of computation. Then we use this method to match the same type of target in the first \(s\) frames. For example, the first 4 frames matched the result shown in Figure 8. As a result, we changed the classification in Figure 5 and classified the pedestrians as red, the chairs in the middle as blue, and the chairs on the right as yellow, as shown in Figure 8.  
(3) Label Positive and Negative Samples with Trajectories  
We need to identify each class as foreground or background. When we obtain a class of targets in the first s frames, its displacement can be calculated. The proposed principle is as follows: The position coordinates of the mean-feature of the same cluster in the first s frames are denoted as \([(\bar{x}^{t-s+1},\bar{y}^{t-s+1}),(\bar{x}^{t-s+2},\bar{y}^{t-s+2}),\cdots,( \bar{x}^{t},\bar{y}^{t})]\). Then, we compute the moving distance of the clusters in \(t-1,\dots,t-s+2,t-s+1\) and \(t\). We assume that the foreground displacements are increasing in a certain direction in adjacent frames, while the background often remains still or exhibits jitter with uncertain directions. If the moving distance of one cluster is increasing in the first s frames, it is classified as foreground; otherwise it is classified as background. \[X=\left\{