## 3 Design of RoiSeg
### Online Sample Classifier
#### 3.4.2 Online Sample Updating  
We use the new balanced training samples as training sets for the Naive Bayesian classifier. We use the ROI center points of the latest frame as the test set. After the Naive Bayesian classifies the test set, we get foreground and background represented as follows:  
\[X=\big{\{} \big{[}(r_{1},g_{1},b_{1},x_{1},y_{1}),\cdots\big{(}r_{N_{F}},g_{N _{F}},b_{N_{F}},x_{N_{F}},y_{N_{F}}\big{)}\big{]},\] \[\big{[}(r_{1},g_{1},b_{1},x_{1},y_{1}),\cdots\big{(}r_{N_{B}},g_{ N_{B}},b_{N_{B}},x_{N_{B}},y_{N_{B}}\big{)}\big{]}\big{\}}.\]  
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**Imbalance Degree** & **512** & **522** & **Video1** & **Video2** \\ \hline \(\eta\) & 0.184 & 0.538 & 0.421 & 0.523 \\ \hline \hline \end{tabular}
\end{table}
Table 6: Imbalance degrees of training sets.  
\begin{table}
\begin{tabular}{c c c c c c c c c c} \hline \hline
**Dataset** & **Video Clips** & **2** & **3** & **4** & **5** & **6** & **7** & **8** & **9** & **10** \\ \hline
**512** & 1499 & 0.528 & 0.683 & 0.856 & 0.914 & **0.924** & 0.919 & 0.903 & 0.839 & 0.789 \\ \hline
**522** & 1499 & 0.579 & 0.654 & 0.887 & **0.912** & 0.908 & 0.878 & 0.854 & 0.803 & 0.776 \\ \hline
**My\_video1** & 390 & 0.471 & 0.589 & 0.718 & 0.842 & **0.903** & 0.879 & 0.803 & 0.753 & 0.684 \\ \hline
**My\_video2** & 390 & 0.521 & 0.571 & 0.733 & 0.883 & **0.899** & 0.857 & 0.794 & 0.709 & 0.649 \\ \hline \hline \end{tabular}
\end{table}
Table 5: The precision for classify the foreground and background.  
Figure 9: Result of detecting foreground and background: the red sets represent foreground and the yellow sets represent background.  
Thus, we can get background bounding boxes and copy the pixels in the bounding boxes to the previous frame. Using the frame difference algorithm to process the new previous frame and the current frame, the foreground can then be segmented. To update the trained samples online, the newly classified foreground and background are added to the training samples. Then, we train the Naive Bayesian classifier with the updated training samples so that we can detect the foreground online.  
The experimental results of the training classifier with imbalanced training sets are shown in Figure 10, and the precision results are shown in Figure 11a. The experimental results of training the classifier with the balanced and updated training sets are shown in Figure 12, and the precision is shown in Figure 11b. Red represents the background and yellow represents the foreground, respectively. Figure 11a,b demonstrated that \(P\) increased by 22.7%, \(R\) increased by 2.1%, and \(F\) increased by 23.4%. This means using the proposed K-means oversampling method and online updating training samples to compensate for the weaknesses of the classifier is effective, especially for \(P\) and \(F\).  
Figure 11: (**Left**) Performance evaluation for classifier with imbalanced training sets. (**Right**) Performance evaluation for classifier with the balanced and updated training sets.  
Figure 10: Experimental results from the Naive Bayes with imbalanced training sets. Top to bottom: results for “My_video1”, “My_video2”, “512”, “522”.