## 3 Proposed Algorithm
### Hand Patch Extraction Based on HPE
To achieve this, the subject's relative distance from the camera must be estimated in each frame and used to determine an optimal patch size for deep feature extraction via the VAE--ensuring it is neither too small nor too large. Given that the relative distance may fluctuate over time, the skeleton size will also vary accordingly. However, this variation does not follow a linear relationship, which can be described by a second order quadratic function. To address this, our approach utilizes an easy to implement polynomial function (see Figure 5b) of the following form:  
\[f(d)=Ad^{2}+Bd+C \tag{1}\]  
where \(d\) represents the observed distance. We rely on this quadratic function (cf. Equation (1)), i.e., \(\exists A,B,C\in\mathbb{R}\) such that a patch size \(r\) is represented by the \(d\). Fitting the observations using the function \(f(d)\) in Equation (1) results in a fully adaptive model for determining the \(r\) based on the subject's distance \(d\):  
\[r=f(d)+\epsilon \tag{2}\]  
where \(\epsilon\) is a user-defined regularization factor used to fine-tune the \(r\). This parameter helps adjust the _torso_ size-based patch size estimation to account for unseen cases, such as video frames extracted from different datasets. For VISILAB dataset, the default value of \(\epsilon\) is set to 10. This adaptive approach ensures that the extracted \(r\) dynamically adjusts according to the \(d\) (c.f Figure 5a), optimizing the accuracy of feature extraction without unnecessary cropping or oversizing of ROI for deep feature extraction. Figure 5c displays the regression model fitted to the VISILAB firearm dataset. Following the model fitting, the residuals are plotted in Figure 5d. The residuals are randomly scattered around the zero line, suggesting that the model is effectively determining patch size across varying distances based on _torso_ size estimation. To estimate the values of \(d\), we compute the Euclidean distance between _shoulder_ and _hip_ points, which serves as an approximation of the subject's _torso_ size. As the subject moves away from the camera, this Euclidean distance decreases, indicating a smaller _torso_ size. Conversely, as the subject approaches the camera, the Euclidean distance increases, reflecting a larger torso size. To ensure this measurement is invariant to rotation, we compute the diagonal Euclidean distance using the differences in \(x\) and \(y\) coordinates between the shoulder and hip points. Based on the estimated torso size, we determine the appropriate patch size to extract from both hands. For the body landmarks associated with the _torso_, as illustrated in Figure 4, we use the following notations: Let \((J^{x}_{11},J^{y}_{11})\)\((J_{12}^{x},J_{12}^{y})\), \((J_{23}^{x},J_{23}^{y})\), and \((J_{24}^{x},J_{24}^{y})\) denotes the unnormalized coordinates values \((x,y)\) of the _right_shoulder_, _left_shoulder_, _right_hip_ and _left_hip_, respectively. To ensure robustness, the subject's distance from the camera is estimated using both left and right torso landmark pairs. The Euclidean distance is then computed as follows:  
\[ \begin{split} d_{r}(J_{11},J_{23})&=\sqrt{\left(J_ {11}^{x}-J_{23}^{x}\right)^{2}+\left(J_{11}^{y}-J_{23}^{y}\right)^{2}}\\ d_{l}(J_{12},J_{24})&=\sqrt{\left(J_{12}^{x}-J_{24}^{ x}\right)^{2}+\left(J_{12}^{y}-J_{24}^{y}\right)^{2}}\\ d&=\frac{d_{r}(J_{11},J_{23})+d_{l}(J_{12},J_{24})}{ 2}\end{split}  \tag{3}\]  
For our experiments, we utilize a video dataset recorded using three types of cameras: a PTZ camera with a 640 \(\times\) 480 resolution and two mobile phones (OnePlus 6T and OnePlus 5T), both with a 1920 \(\times\) 1080 resolution [11]. From this dataset, 20,461 normal frames and 7352 firearm frames are extracted. Additionally, we assume that the focal length of the imaging device remains fixed during video capture and that the camera position does not change. These constraints are commonly met in most surveillance systems for a given location.