## 3 Materials and Methods
### Validation
#### 3.6.1 Item Detection and Tracking: GMM and Kalman Filter  
Items detection in the cart is implemented by eliminating the image's background segment, leaving only the foreground segment. The main obstacle of the process is deciding whether the pixels in the image belong to the foreground or background. Segmentation by standard background subtraction using a static background, such as the first frame, would be subject to any insignificant changes. Regarding the problem at hand, the view inside of the cart keeps changing with every new item introduced. Thus, it is crucial to have an updated background with every new variation in the scene of the cart. The best approach for executing the process is to model the background by learning previous information to be adaptive to different forms that the background can have over a specific time. The foreground detection algorithm utilized in this project is based on Gaussian mixture modeling (GMM) [26]. Figure 14 shows the process of item detection and tracking. The method assumes that the background would have the strongest statistical Gaussian distributions compared to the foreground. Relating this to our case, a new item inserted into the scene forms new pixel values that are statistically weak in comparison to the previous values and thus, are detected as the foreground. These new pixel values then increase in strength over time until they become part of the background. There are three distributions, \(k\), initialized in this implementation, each with a mean \(\mu\) of the same value as the pixel of the first frame, variance \(\sigma^{2}\) of 900, and a normalized weight \(\omega\) of 0.33. Every distribution in each pixel location of the first frame is updated through \(t\) number of training frames, which for this project, is chosen to be 40. After processing all of the training frames, the background model is constructed, using minimum number \(b\) of distributions that would be efficient to satisfy the condition shown in (8), where threshold \(T\) is selected to be 0.7. As the process moves forward with foreground detection, the model is updated with the background's changing structure, leading to a robust technique for moving-objects detection.  
Kalman filter is used for tracking moving items once they are inserted inside the cart to the rest point. The Kalman filter consists of two updating operations dependent on each other: one is prediction, and the other is correction. The equations used for prediction are Equations (18) and (19), where \(x_{k}^{\wedge-}\) is the state--in our implementation, it is considered the location and initialized by the centroid of the object detected in the current frame. \(A\) is the state transition set in the form of a block diagonal matrix of identical submatrices of [1 1; 0 1], \(B\) is the control model and given a value of 0, \(P\) is the state estimation error covariance and is initialized by [200, 50], and \(Q\) is the process noise covariance, set at [100, 25]. The equations used for correction are Equations (20)-(22) where \(K\) is the Kalman gain, \(H\) is the measurement model set in the form same as \(A\) but with submatrices of [1 0], and \(z\) is the correct location obtained from the centroid of the object in the next frame.  
\[x_{k}^{\wedge-}=Ax_{k-1}^{\wedge}+Bu_{k} \tag{18}\]  
\[P_{k}^{-}=AP_{k-1}A^{T}+Q \tag{19}\]  
\[K_{k}=P_{k}^{-}H^{T}(HP_{k}^{-}H^{T}+R)^{-1} \tag{20}\]  
\[x_{k}^{\wedge}=x_{k}^{\wedge-}+K_{k}(z_{k}-Hx_{k}^{\wedge-}) \tag{21}\]  
\[P_{k}=(1-K_{k}H)P_{k}^{-} \tag{22}\]As observed, the prediction and correction formulas depend on specific criteria that are impossible to be met most of the time, which would cause multiple tracks for the same item. For this reason, the track is assumed to be reliable only if it has existed for 30 frames or more, which is about 1 s of detection at 30 FPS. The system then waits for another 10 frames after any detection of the item being tracked. This concludes the detection stage, where the item is stationary inside the cart.