## 4 Component Recognition
### Identification of Blood Collection Needle Head  
From Figure 3, it is evident that the blood collection needle head exhibits numerous other features with similar grayscale values in each component image. Despite attempts to adjust the upper and lower threshold values of the H, S, and V components in the cv2.inRange function module for HSV component segmentation, significant interference around the blood collection needle head feature persists. Consequently, accurately extracting the characteristics of the blood collection needle head becomes challenging, as depicted in Figure 10.  
To address the above issue, a method based on locating the ROI of the blood collection needle head using key points of the drawbar piston is adopted. The main principle is to use the cv2.findContours function for contour detection of the segmented drawbar piston, and extract the top-left key point (x, y) of the contour. As the blood collection needle head is mounted at one end of the sample container and its shape, size, and vertical movement range are fixed, the key point of the drawbar piston can be cropped in the X-axis-positive direction. In order to ensure that each cropping area includes the features of blood collection needle head, the maximum projection D\({}_{\text{max}}\) of the distance between point (x, y) and the feature of blood collection needle head is selected as the cropping length in the direction of  
Figure 10: Segmentation result of blood collection needle head based on packaging ROI. Figure 9: Image processing result. (**a**) Non-adhesive comprehensive segmentation; (**b**) adhesive comprehensive segmentation; (**c**) non-adhesive morphological processing; (**d**) adhesive morphological processing. X axis, that is, when the needle is parallel to X axis. In addition, to avoid cropping beyond the region of interest (ROI), the sum of the key point's horizontal coordinate x and d\({}_{\text{max}}\), denoted as x\({}_{\alpha}\), should be less than the ROI's horizontal size w, as shown in Equation (7). The ROI image has a non-active area for the blood collection needle in the vertical direction, so a length of d is cropped in both positive and negative directions of the Y axis, resulting in the Y axis coordinate points y\({}_{\alpha 1}\) and y\({}_{\alpha 2}\) used to crop the blood collection needle ROI, as shown in Equation (8). \[\text{x}_{\alpha 2}=\text{x}+\text{D}_{\text{max}}<\text{W} \tag{7}\]  
\[\text{y}_{\alpha 1}=\text{d},\text{y}_{\alpha 2}=\text{H}-\text{d} \tag{8}\]  
where the vertical height of the packaging ROI is h, and the coordinates for cropping the ROI are (x, y\({}_{\alpha 1}\)) and (x\({}_{\alpha 2}\), y\({}_{\alpha 2}\)) for the blood collection needle head ROI, as shown in Figure 11a. After locating the ROI for the blood collection needle, it undergoes filtering with the cv2.Gaussianblur function to achieve a smoother image. Similar to other component segmentation methods, multiple trials were conducted to determine the optimal upper and lower threshold values. It was found that setting the upper threshold as np.array(40,40,78) and the lower threshold as np.array(0,0,30) yielded a more pronounced segmentation effect for the needle plug feature and other background regions in the image. Since the segmented features are relatively discrete, a dilation morphology operation is applied to connect them. The resulting segmentation is depicted in Figure 11b,c. Due to the presence of irrelevant interference in the processed image, further determination of features based on the connectivity domain area and diagonal length is necessary. Firstly, the connected domain contours are detected using the cv2.findContours function. The top-left corner point (x\({}_{i}\), y\({}_{i}\)), horizontal projection w\({}_{i}\), and vertical projection hi of the connected domain contour are obtained to calculate the diagonal length D(i) of the feature using expression (9).