## 2 ROI Extraction  
Accurately and efficiently extracting ROIs from images can reduce computational complexity [6]. In machine vision image processing, there are various methods for ROI extraction, such as machine learning and template matching. Machine learning can provide powerful object detection capabilities [7], but often requires a large amount of annotated data for sample training, making it difficult to meet the conditions in many cases. In contrast, template matching methods can bypass manual annotation and determine the most likely location of a single template image in a target image with minimal computational cost [8].  
Figure 1: Composition of arterial blood collector.  
When identifying the presence or absence of arterial blood sample collector packaging components in an image, it is necessary to locate the ROI of the packaging image since the range of component locations can be controlled within the packaging background area.  
In template matching, pixel-level matching is used to determine the position of a template image within a target image. By sliding the template image over different positions of the target image and calculating the similarity between them, the best-matching pixel position can be found.  
Specifically, the template and target images are first converted to grayscale for pixel-level matching. The template image is then slid over every possible position in the target image, and the similarity between pixels at each sliding position is measured using methods like normalized squared difference. This involves calculating the squared differences and normalizing them to obtain similarity values. These similarity values are organized into a matching result matrix, which has the same size as the target image. Each element of the matrix represents the similarity measure at the corresponding position. The best matching position in the result matrix is typically determined by finding the minimum or maximum value, which corresponds to the vertex or center position of the template image in the target image. Pixel-level matching allows for accurate localization of the template image within the target image, enabling ROI extraction.  
The specific operation steps are as follows:  
First, the template image and the image to be matched need to be passed into the cv2.matchTemplate function to make the template image in the image match the sliding calculation; this is developed through the cv2.TM_SQDIFF_NORMED normalized squared difference matching method, which calculates the squared difference value of each sliding. Each calculation results will be organized into the form of a matrix.  
Secondly, the minimum value in the result matrix is counted using the cv2.minMaxLoc function, and the minimum coordinate point is the coordinate of the upper left corner of the ROI. The shape function is used to calculate the width and height (w, h) of the template image and to add them with the minimum coordinate to obtain the coordinate point of the lower right corner of the ROI.  
Finally, the two points of the horizontal and vertical coordinate values are calculated through two-dimensional array slicing (to extract the data in the matrix with the coordinates as the index number) to obtain the packing image ROI; the cv2.Rectangle function is used to draw the ROI region in the original image.  
In this paper, we use the principle of normalized correlation template matching to determine the degree of image matching and find the matching position based on the grayscale information of the image, using the correlation function between the matching sub-image and the grayscale value of the template image. The results of image processing template matching are shown in Figure 2.  
Figure 2: Template matching result. (**a**) Source image; (**b**) template image; (**c**) ROI image.