Method and system for positioning control of medical devices based on machine vision

By combining mask filtering and local curvature features, the problem of pixel grayscale saturation in overexposed areas was solved, and the pixel coordinates and grayscale gradients were accurately restored, improving the stability and consistency of positioning control of medical equipment.

CN123181580APending Publication Date: 2026-11-27FUJIAN RUISIKE MEDICAL TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611687933.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-29
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

In machine vision-based positioning control of medical devices, pixel grayscale saturation in overexposed areas leads to the loss of texture and gradient information, affecting the consistency of marker point coordinate extraction, and consequently affecting the stability and response consistency of the medical device's pose.

Method used

Overexposed areas are processed by mask filtering. Combined with local curvature features and grid segmentation, grid deformation adjustment values ​​are generated to compensate for feature distribution. Non-rigid deformation compensation vectors are extracted to improve the recovery of pixel coordinates and grayscale information, thereby enhancing the anti-interference capability of binocular vision positioning.

Benefits of technology

It effectively weakens the interference of overexposed pixels, improves the recovery and matching of pixel coordinates and grayscale gradients, and enhances the stability and response consistency of the pose closed-loop control of medical devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123181580A_ABST
    Figure CN123181580A_ABST
Patent Text Reader

Abstract

The application provides a medical equipment positioning control method and system based on machine vision, and relates to the technical field of data processing.The method comprises the following steps: compensating and adjusting the feature distribution in the sub-grid area by a grid deformation adjustment value to obtain a feature extraction image containing multiple local grid areas; calculating a non-rigid deformation compensation vector according to the feature extraction image, extracting the corner point coordinate offset in each local grid area, and obtaining a compensated binocular feature point set; performing binocular vision pose calculation on the three-dimensional space coordinates extracted from the compensated binocular feature point set to obtain six-degree-of-freedom pose data; and performing closed-loop feedback operation on the position deviation and the attitude deviation between the six-degree-of-freedom pose data and a preset target pose to obtain a motor control instruction.The application can enhance the anti-interference capability of binocular vision positioning and improve the stability and response consistency of the closed-loop control of the medical equipment pose.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and in particular to a machine vision-based method and system for positioning and controlling medical equipment. Background Technology

[0002] In machine vision-based medical device positioning and control, such as surgical robots and implant navigation, binocular stereo vision is often used to acquire the spatial pose of the target instrument. Taking mobile phone positioning in dental implant surgery as an example, for easy tracking, surgical mobile phones are mostly equipped with highly reflective optical markers. Under the illumination of surgical shadowless lamps or auxiliary light sources, when the incident angle of the light source forms a specific reflection direction with the instrument surface, some marker areas in the acquired binocular images may be overexposed. The pixel grayscale in such overexposed areas tends to be saturated, and local texture and gradient information are lost. In existing processing methods, some methods first detect the overexposed range, then fill the overexposed positions through neighborhood interpolation or image inpainting techniques, and then extract the sub-pixel coordinates of the markers. However, such inpainting mostly relies on the information of surrounding unsaturated pixels for inference, and the recovered grayscale distribution sometimes does not completely match the gradient changes of the real reflective surface. In practice, in the left and right views after inpainting, the extracted coordinates of the same marker may produce a small inconsistent displacement. This displacement often no longer satisfies the rigid body transformation relationship, but will manifest as a local, non-rigid coordinate offset.

[0003] For example, during mobile phone positioning, if the surface of a spherical marker is locally overexposed due to lighting, the gradient morphology of the marker's edge may be slightly distorted after repair. This causes the extracted center coordinates to deviate from the true projection center in different directions in the left and right eye images. After stereo matching, this deviation results in residual deformation of the reconstructed spatial point position, leading to a deviation in the calculated mobile phone pose. This pose deviation, when further involved in closed-loop feedback, may cause errors between the angle or depth of the planting hole preparation and the preset plan. Summary of the Invention

[0004] The technical problem to be solved by the present invention is to provide a positioning control method and system for medical devices based on machine vision, which can enhance the anti-interference capability of binocular vision positioning and improve the stability and response consistency of the closed-loop control of medical device pose.

[0005] To solve the above-mentioned technical problems, the technical solution of the present invention is as follows: In a first aspect, a machine vision-based method for positioning and controlling medical devices, the method comprising: Step 1: Obtain the original stereo image. Based on the original stereo image, extract the pixel grayscale gradient of the overexposed area and perform mask filtering to obtain the initial stereo image. Step 2: Select three calibration anchor points in the initial binocular image to construct a reference triangle region and extract local curvature features within the reference triangle region; calculate the initial area of ​​the reference triangle region and segment it based on the local curvature features to obtain multiple sub-grid regions; calculate the actual area of ​​each sub-grid region and allocate the theoretical area of ​​the corresponding sub-grid region from the initial area of ​​the reference triangle region according to the positional proportion of each sub-grid region in the reference triangle region; compare the actual area with the theoretical area determined based on the initial area to obtain area change features and extract the boundary morphology characteristics of each sub-grid region; generate a grid deformation adjustment value based on the area change features and boundary morphology characteristics, and compensate and adjust the feature distribution within the sub-grid region using the grid deformation adjustment value to obtain a feature extraction image containing multiple local grid regions; Step 3: Based on the feature extraction image, extract the corner coordinate offset of each local grid region to calculate the non-rigid deformation compensation vector and obtain the compensated binocular feature point set; Step 4: Based on the compensated binocular feature point set, extract the three-dimensional spatial coordinates to perform binocular visual pose calculation and obtain six-degree-of-freedom pose data. Step 5: Based on the six-degree-of-freedom pose data, calculate the position deviation and attitude deviation between the pose and the preset target pose, perform closed-loop feedback calculation, and obtain motor control commands.

[0006] Secondly, a machine vision-based positioning and control system for medical equipment includes: The processing module is used to acquire the original stereo image, extract the pixel grayscale gradient of the overexposed area based on the original stereo image, perform mask filtering processing, and obtain the initial stereo image. The calculation module is used to select three calibration anchor points in the initial binocular image to construct a reference triangular region, extract local curvature features within the reference triangular region, calculate the initial area of ​​the reference triangular region, and segment the reference triangular region based on the local curvature features to obtain multiple sub-grid regions. It then calculates the actual area of ​​each sub-grid region, allocates the theoretical area of ​​the corresponding sub-grid region from the initial area of ​​the reference triangular region according to the proportion of each sub-grid region within the reference triangular region, compares the actual area with the theoretical area determined based on the initial area to obtain area change features, and extracts the boundary morphology characteristics of each sub-grid region. Finally, it generates a grid deformation adjustment value based on the area change features and boundary morphology characteristics, and uses this grid deformation adjustment value to compensate and adjust the feature distribution within the sub-grid region, resulting in a feature extraction image containing multiple local grid regions. The correction module is used to extract the corner coordinate offset of each local grid area based on the feature extraction image, calculate the non-rigid deformation compensation vector, and obtain the compensated binocular feature point set. The extraction module is used to extract three-dimensional spatial coordinates from the compensated binocular feature point set to perform binocular visual pose calculation and obtain six-degree-of-freedom pose data. The control module is used to calculate the position and attitude deviations between the six-degree-of-freedom pose data and the preset target pose, perform closed-loop feedback calculations, and obtain motor control commands.

[0007] Thirdly, a computing device includes: One or more processors; A storage device for storing one or more programs that, when executed by one or more processors, cause the one or more processors to implement the method.

[0008] Fourthly, a computer-readable storage medium storing a program that, when executed by a processor, implements the method.

[0009] The above-described solution of the present invention has at least the following beneficial effects: This invention optimizes the original binocular image by using mask filtering to effectively reduce image interference caused by overexposed pixel saturation. Simultaneously, it constructs a reference triangle region based on three calibration anchor points at fixed locations on the medical equipment. Combining local curvature features, it accurately characterizes the deformation distribution of the overexposed area. Through grid segmentation, the overall deformation region is decomposed into multiple independent sub-grid regions. This invention uses sub-grids as refined correction units, comprehensively determining the degree of local deformation by combining area change characteristics and boundary morphology characteristics. It generates grid deformation adjustment values ​​suitable for each region, achieving targeted compensation and optimization of pixel coordinates and grayscale information. This effectively restores the grayscale gradient and edge morphology of the overexposed area, improving the insufficient fit of texture and gradient information restoration in traditional repair methods. Attached Figure Description

[0010] Figure 1 This is a schematic flowchart of a machine vision-based medical device positioning and control method provided in an embodiment of the present invention.

[0011] Figure 2 This is a schematic diagram of a machine vision-based medical device positioning control system provided in an embodiment of the present invention. Detailed Implementation

[0012] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.

[0013] like Figure 1 As shown, embodiments of the present invention propose a machine vision-based positioning and control method for medical devices, the method comprising the following steps: Step 1: Obtain the original stereo image. Based on the original stereo image, extract the pixel grayscale gradient of the overexposed area and perform mask filtering to obtain the initial stereo image. Step 2: Select three calibration anchor points in the initial binocular image to construct a reference triangle region and extract local curvature features within the reference triangle region; calculate the initial area of ​​the reference triangle region and segment it based on the local curvature features to obtain multiple sub-grid regions; calculate the actual area of ​​each sub-grid region and allocate the theoretical area of ​​the corresponding sub-grid region from the initial area of ​​the reference triangle region according to the positional proportion of each sub-grid region in the reference triangle region; compare the actual area with the theoretical area determined based on the initial area to obtain area change features and extract the boundary morphology characteristics of each sub-grid region; generate a grid deformation adjustment value based on the area change features and boundary morphology characteristics, and compensate and adjust the feature distribution within the sub-grid region using the grid deformation adjustment value to obtain a feature extraction image containing multiple local grid regions; Step 3: Based on the feature extraction image, extract the corner coordinate offset of each local grid region to calculate the non-rigid deformation compensation vector and obtain the compensated binocular feature point set; Step 4: Based on the compensated binocular feature point set, extract the three-dimensional spatial coordinates to perform binocular visual pose calculation and obtain six-degree-of-freedom pose data. Step 5: Based on the six-degree-of-freedom pose data, calculate the position deviation and attitude deviation between the pose and the preset target pose, perform closed-loop feedback calculation, and obtain motor control commands.

[0014] In this embodiment of the invention, the original binocular image is optimized by mask filtering to effectively weaken the image interference caused by overexposed pixel saturation. At the same time, a reference triangle region is constructed based on three calibration anchor points of the fixed point of the medical equipment. Combined with local curvature features, the deformation distribution characteristics of the overexposed area are accurately characterized. The overall deformation region is decomposed into multiple independent sub-grid regions by grid segmentation. This invention uses sub-grids as fine correction units, and comprehensively judges the degree of local deformation by combining area change features and boundary morphology characteristics. It generates grid deformation adjustment values ​​that are suitable for each region, realizing targeted compensation and optimization of pixel coordinates and grayscale information. It can better restore the grayscale gradient and edge morphology of the overexposed area and improve the problem of insufficient texture and gradient information restoration fit in traditional restoration methods.

[0015] In a preferred embodiment of the present invention, the execution process of step 1 is as follows: The image sensors of the left and right cameras are triggered synchronously; a unified hardware trigger signal is used to control the two cameras to expose at the same time to acquire a pair of original binocular images of the same scene; each original image is a single-channel grayscale image, and the grayscale value of each pixel ranges from 0 to 255; the left and right cameras have completed stereo calibration during the system installation phase, and the calibration parameters include the focal length, principal point coordinates, radial distortion coefficient and tangential distortion coefficient of each camera, as well as the rotation matrix and translation vector between the coordinate systems of the left and right cameras.

[0016] Overexposure region detection is performed on both the left and right original images. Each pixel in the image is scanned row by row and column by column, and its grayscale value is compared with a preset overexposure threshold of 250. Pixels with a grayscale value greater than or equal to 250 are initially marked as overexposure candidate pixels. After marking, for each overexposure candidate pixel, the grayscale distribution of its eight neighboring pixels (top, bottom, left, right, top left, top right, bottom left, and bottom right) is checked. If at least six of the eight neighboring pixels of the candidate pixel also have a grayscale value greater than or equal to 245, the candidate pixel is confirmed as an overexposure core pixel. If the number of pixels satisfying the condition of a grayscale value greater than or equal to 245 among the eight neighboring pixels of the candidate pixel is between three and five, and the candidate pixel itself has a grayscale value greater than or equal to 245, the candidate pixel is confirmed as an overexposure edge pixel. For candidate pixels that are neither overexposure core pixels nor overexposure edge pixels, their overexposure marking is removed, and they are restored to normal pixels.

[0017] Connected overexposed pixels are aggregated into overexposed regions. Specifically, an eight-neighbor connected region growing algorithm is used. First, a global access marker array is established, initially all elements of the array are marked as unvisited. Each pixel in the image is traversed. When an unvisited overexposed core pixel is encountered, a new overexposed region label is created, the pixel is added to the region and pushed into a processing queue, and simultaneously marked as visited. A pixel is taken from the head of the queue, and its eight neighboring pixels are checked: for each neighboring pixel, if it is an overexposed core pixel or an overexposed edge pixel and has not been visited, the neighboring pixel is added to the current overexposed region, pushed to the end of the processing queue, and marked as visited. This process of taking a pixel from the head of the queue, checking neighboring pixels, and pushing qualified neighboring pixels into the queue is repeated until the queue is empty. At this point, the current overexposed region is grown, and all pixels contained within this region constitute a complete overexposed region. The image is then traversed again to find the next unvisited overexposed core pixel, initiating a new overexposed region growing process, until all overexposed core pixels in the entire image are assigned to an overexposed region. After processing, a collection of all overexposed areas in the image is obtained.

[0018] For each overexposed region, its boundary pixel set is extracted. Boundary pixels are determined by two conditions that must be met simultaneously: Condition 1, the pixel belongs to the current overexposed region; Condition 2, at least one of the pixel's eight neighboring pixels does not belong to any overexposed region, meaning that neighboring pixel is a normal pixel. Each pixel within an overexposed region is iterated through, and its eight neighboring pixels are checked. Pixels that simultaneously meet both conditions are collected into the boundary pixel set. This boundary pixel set defines the outer contour shape of the overexposed region.

[0019] For each boundary pixel of an overexposed region, extract its grayscale gradient information. Centered on the current boundary pixel, take a 3x3 local window containing 9 pixels. Calculate the horizontal and vertical grayscale changes. The horizontal change is calculated by subtracting the grayscale value of the pixel immediately to the left of the center pixel from the grayscale value of the pixel immediately to the right of the center pixel. The vertical change is calculated by subtracting the grayscale value of the pixel immediately above the center pixel from the grayscale value of the pixel immediately below the center pixel. Calculate the gradient magnitude: multiply the horizontal and vertical changes by themselves to obtain the horizontal square value, then multiply the vertical changes by themselves to obtain the vertical square value. Add the two squares and take the square root of the result. The resulting value is the gradient magnitude of the boundary pixel, expressed in grayscale levels per pixel. The gradient direction is calculated as follows: calculate the ratio of the change in the vertical direction to the change in the horizontal direction, take the arctangent of this ratio, convert the arctangent result from radians to degrees to obtain the gradient direction angle, which ranges from 0 degrees to 360 degrees; 0 degrees corresponds to the gradient pointing to the right of the image, and the angle gradually increases in the counterclockwise direction.

[0020] Gradient magnitudes of boundary pixels are filtered for validity. A minimum gradient threshold of 5 gray levels per pixel is set. For boundary pixels with gradient magnitudes less than 5, their gradient information is deemed unreliable due to saturation effects, and these pixels are excluded from subsequent gradient direction statistics and mask construction. Only boundary pixels with gradient magnitudes greater than or equal to 5 have their gradient information retained and used for subsequent processing. For all boundary pixels that pass the validity screening in all overexposed areas, binning statistics are performed according to gradient direction. The complete angular range from 0 degrees to 360 degrees is evenly divided into 36 angular intervals, each spanning 10 degrees. The first interval covers 0 degrees (inclusive) to 10 degrees (exclusive), the second interval covers 10 degrees (inclusive) to 20 degrees (exclusive), and so on, with the 36th interval covering 350 degrees (inclusive) to 360 degrees (inclusive). Each valid boundary pixel is extracted one by one, and its gradient direction angle is used to classify it into the corresponding angle interval. Simultaneously, the gradient magnitude of that pixel is accumulated in the magnitude accumulator of that interval, and the pixel counter for that interval is incremented by 1. After all valid boundary pixels have been classified, each angle interval is processed one by one: the sum of the magnitudes in that interval is divided by the pixel count in that interval to obtain the average gradient magnitude of that angle interval. For angle intervals with a pixel count of 0, their average gradient magnitude is directly recorded as 0.

[0021] The validity of the average gradient magnitude in each angular interval is determined. A gradient validity threshold of 8 gray levels per pixel is set. The average gradient magnitude of each angular interval is checked one by one: if the average gradient magnitude of an interval is less than 8, the gradient information in that angular direction is deemed unreliable, and the angular interval is marked as an unreliable direction; if the average gradient magnitude is greater than or equal to 8, the angular interval is marked as a reliable direction. Boundary gradient information in reliable directions retains the original brightness transition characteristics before overexposure relatively completely; however, gradient information in unreliable directions has been severely damaged by saturation effects, and inferring pixel values ​​along these directions will introduce uncontrollable deformation.

[0022] Based on the determination of gradient direction validity, a mask is constructed for each overexposed region. Each boundary pixel in each overexposed region is processed sequentially. For boundary pixels whose gradient direction is unreliable, the gradient direction of that pixel is extended outwards by 3 pixels, and all pixels along this extension path are included in the mask extension area. For boundary pixels with a gradient magnitude lower than 5 gray levels per pixel (i.e., those boundary pixels excluded in step 106), the gradient direction of that pixel is extended outwards by 2 pixels in each of its eight adjacent pixel directions, and all pixels covered by these eight extension paths are included in the mask extension area. The original overexposed region, i.e., all overexposed pixels aggregated in step 103, is then combined with the first and second types of mask extension areas, and the result is used as the mask area for the current overexposed region. Finally, the mask areas of all overexposed regions are combined to obtain the complete mask for the image. This complete mask marks the positions of all pixels in the image that require filtering.

[0023] The original stereo image is subjected to mask-guided filtering using the constructed complete mask to obtain the initial stereo image. The filtering is performed pixel by pixel. For each pixel position in the image, it is first checked whether the position falls within the complete mask. If the pixel is not within the mask, its original gray value remains unchanged and is not modified. If the pixel is within the mask, an alternative gray value needs to be calculated to replace its original gray value.

[0024] The calculation of the alternative grayscale value uses a weighted filtering method. A 7x7 square filtering window is defined centered on the current pixel to be processed, with each side measuring 7 pixels. Within this window, all pixels not within the mask area are selected; these pixels are called effective reference pixels. Their grayscale values ​​are not affected by saturation destruction and can provide a reliable reference for grayscale recovery of the pixel to be processed. For each effective reference pixel, two weights are calculated. The first is the spatial distance weight. The Euclidean distance between the effective reference pixel and the pixel to be processed is calculated as the square root of the sum of the squares of their horizontal and vertical coordinate differences. The reciprocal of this distance plus 1 is taken as the spatial distance weight. The closer the reference pixel, the greater its weight. The second is the gradient direction consistency weight. The dominant gradient direction at the location of the pixel to be processed is determined: the nearest effective boundary pixel on the boundary of the overexposed area to the current pixel to be processed is found, and its gradient direction is taken as the dominant gradient direction. Then, the azimuth angle of the effective reference pixel relative to the pixel to be processed is calculated. If the angle between this azimuth angle and the gradient dominance direction is less than 45 degrees, the gradient direction consistency weight is 1.0; if the angle is between 45 degrees and 90 degrees, the weight decreases linearly from 1.0 to 0.5; if the angle exceeds 90 degrees, the weight is 0.1.

[0025] After calculating the two weights, a weighted contribution calculation is performed for each valid reference pixel: the grayscale value of the valid reference pixel is first multiplied by its spatial distance weight, and then multiplied by its gradient direction consistency weight to obtain the weighted grayscale contribution value of the valid reference pixel; the weighted grayscale contribution values ​​of all valid reference pixels are summed to obtain the total weighted grayscale contribution; at the same time, the products of the spatial distance weight and the gradient direction consistency weight of all valid reference pixels (i.e., the composite weight) are summed to obtain the total weighted product; the total weighted grayscale contribution is divided by the total weighted product, and the result is the alternative grayscale value of the pixel to be processed. The alternative grayscale value is rounded to the nearest integer and limited to the range of 0 to 255.

[0026] Binocular consistency is verified on the filtered left and right eye images. Using camera intrinsic and extrinsic parameters obtained from stereo calibration, the epipolar geometry between the left and right eye images is determined. For each pixel in the left eye image located within the mask region, its corresponding epipolar line position in the right eye image is calculated based on epipolar geometric constraints. Along this epipolar line, a search strip with a width of 5 pixels is taken in the right eye image, extending 2 pixels to each side of the epipolar line as its center. Within this strip, the corresponding position most similar to the local texture of the left eye pixel is found. The similarity is measured as follows: a 5x5 window is taken, and the grayscale values ​​of all pixels within the window are calculated. The grayscale values ​​in the left eye window are subtracted from the corresponding grayscale values ​​in the right eye window one by one, and the absolute values ​​are summed. The position with the smallest total grayscale difference is the most similar corresponding position. At the most similar corresponding position, a 5x5 window is taken, and the average gray value of the 25 pixels within the window is calculated. Simultaneously, the average gray value is also calculated within a 5x5 window at the corresponding pixel position in the left eye image. The average gray value of the left eye window is subtracted from the average gray value of the right eye window, and the absolute value of this difference is taken. If this absolute value exceeds the preset binocular consistency threshold of 15 gray levels, it is determined that the filtering result for that region is inconsistent between the left and right eyes. For regions with inconsistencies, the size of the filtering window is expanded from 7x7 to 11x11, and the weighted filtering calculation described in step 110 is re-executed using effective reference pixels within the larger window range, replacing the original filtering result with a new alternative gray value. After all inconsistent regions have been re-filtered, the binocular consistency processing is complete. The filtered and binocular consistency-verified left and right eye images are output as a pair of initial binocular images.

[0027] In a preferred embodiment of the present invention, step 2 is performed as follows: The label detection operation is performed on the left and right images of the initial binocular images to identify the imaging regions of three label points in the images, and the center pixel coordinates of the imaging region of each label point are extracted to form a set of calibration anchor point coordinates. Three optical label points are installed on the medical device: a first label point located at the upper left vertex of the front face of the medical device, a second label point located at the upper right vertex of the front face of the medical device, and a third label point located at the midpoint of the lower edge of the rear face of the medical device. These three label points are made of highly reflective material, and under the illumination of the surgical light source, their imaging regions in the image will exhibit a gray value significantly higher than the surrounding tissue background. The first step of the label detection operation is gray-scale thresholding; all pixels in the image are traversed row by row and column by column, and the gray value of each pixel is compared with a preset segmentation threshold of 200; if the gray value of a pixel is greater than or equal to 200, the pixel is marked as a candidate label point pixel; if the gray value is less than 200, it is marked as a background pixel. After all the labeling work is completed, a binary image is obtained, in which the value of the candidate label pixel is 1 and the value of the background pixel is 0.

[0028] The second step in marker detection is connected component analysis. Using the eight-neighbor connectivity criterion, connected components are identified and numbered for all candidate marker pixels with a value of 1 in the binary image. Starting from the top left corner of the image, the image is scanned row by row, pixel by pixel. Whenever a pixel with a value of 1 that has not yet been assigned a region number is encountered, a new connected component number is created for that pixel, and a seed queue is established, pushing the pixel's coordinates into the queue. A pixel is taken from the head of the queue, and its eight neighboring pixels are checked one by one: top, bottom, left, right, top left, top right, bottom left, and bottom right. For each neighboring pixel, if it is within the valid range of the image, has a value of a candidate marker pixel, and has not yet been assigned any region number, it is pushed to the end of the queue and assigned the same region number as the current pixel. This process of taking a pixel from the head of the queue and checking its eight neighboring pixels is repeated until the queue is empty. At this point, the connected component corresponding to the current region number has been grown. The region number is incremented by 1, and the image is scanned again to find the next pixel with a value of 1 that has not been assigned a number, initiating the growth of a new connected component. This process is repeated until the entire image has been scanned, and all candidate marker pixels with a value of 1 are assigned to a connected region.

[0029] The third step in marker detection is region filtering, which includes two rounds of filtering: area filtering and shape filtering. The first round is area filtering: the number of pixels contained in each connected region is counted one by one; the minimum allowable area is set to 30 pixels and the maximum allowable area is 3000 pixels; connected regions with fewer than 30 or more than 3000 pixels are removed from the candidate list, because these regions are likely to be small spots caused by image noise or large areas of unmarked reflective surfaces; only connected regions with a pixel count between 30 and 3000 are retained and enter the next round of filtering; the second round is shape filtering: for each connected region that passes the area filtering, its roundness index is calculated. The roundness index is calculated in three steps: First, the perimeter of the region is calculated by examining each boundary pixel, tracing along the boundary contour, and counting the step distance between adjacent boundary pixels. If two adjacent boundary pixels are horizontally or vertically adjacent, the step distance is counted as 1; if two adjacent boundary pixels are diagonally adjacent, the step distance is approximately 1.414. The total step distance along the entire closed boundary contour is then summed to obtain the perimeter of the region. The total number of pixels contained within the region is taken as the area of ​​the region. The perimeter is multiplied by itself, divided by the area, and then divided by 4 times pi (approximately 12.566). The resulting ratio is the roundness index of the region. The closer the roundness index is to 1.0, the closer the shape of the region is to a standard circle. The acceptable range for the roundness index is set to greater than 0.7 and less than 1.3. Only connected regions with a roundness index falling within this acceptable range are retained; connected regions with a roundness index exceeding this range are discarded because their shape deviates too much from a circle and does not meet the morphological characteristics of optical marker imaging.

[0030] The fourth step in marker detection is spatial distribution matching. After area and shape filtering, each of the left and right eye images should have three candidate connected regions, corresponding to the imaging areas of the first, second, and third marker points, respectively. Next, a correct correspondence needs to be established between each candidate connected region and the three marker points. The matching is based on the predicted spatial layout of the three marker points on the medical device: the first and second marker points are both located on the front face of the device, one on the left and one on the right, with similar heights and the largest horizontal distance among the three marker points; the third marker point is located at the midpoint of the lower edge of the rear face of the device, with a relatively large vertical distance between it and the first and second marker points. Matching is performed according to this geometric rule: first, the horizontal and vertical distances between the center coordinates of each pair of the three candidate connected regions are calculated; from the three pairs, the pair with the largest horizontal distance is selected, which must correspond to the imaging areas of the first and second marker points; after determining the two regions corresponding to the first and second marker points, the remaining candidate connected region naturally corresponds to the imaging area of ​​the third marker point. For the pair of regions marked by the first and second markers, compare their center horizontal coordinates: the region with the smaller horizontal coordinate, which is located further to the left, corresponds to the first marker, which is the top left vertex; the region with the larger horizontal coordinate, which is located further to the right, corresponds to the second marker, which is the top right vertex.

[0031] The fifth step in marker detection is center coordinate extraction. For each connected region where the correspondence between marker points has been confirmed, its gray-weighted centroid coordinates are calculated as the center pixel coordinates of the marker point image region. The gray-weighted centroid is calculated as follows: All pixels within the current connected region are extracted one by one. For each pixel, its horizontal pixel coordinate is multiplied by its gray value to obtain the pixel's gray-weighted contribution in the horizontal direction; its vertical pixel coordinate is multiplied by its gray value to obtain the pixel's gray-weighted contribution in the vertical direction; the horizontal gray-weighted contributions of all pixels in the region are summed to obtain the horizontal gray-weighted sum; the vertical gray-weighted contributions of all pixels are summed to obtain the vertical gray-weighted sum; and the gray values ​​of all pixels are summed to obtain the total gray value. The horizontal gray-weighted sum is divided by the total gray value, and the result is rounded to the nearest integer. The resulting integer value is the center horizontal pixel coordinate of the marker point image region. Divide the weighted sum of gray levels in the vertical direction by the sum of gray levels, and round the result to the nearest integer to obtain the center vertical pixel coordinates. After extracting the center coordinates of all three marker point image regions, a set of calibration anchor point coordinates is obtained. This set contains three two-dimensional coordinates, which correspond to the imaging center positions of the first, second, and third marker points in the current image, respectively.

[0032] Using the coordinates of three center pixels from the calibration anchor point coordinate set, a triangular pixel region is enclosed on the current image as a reference triangle region. Specifically, a straight line segment connects the center coordinates of the first and second marker points, forming the first side of the reference triangle region; a straight line segment connects the center coordinates of the second and third marker points, forming the second side; and a straight line segment connects the center coordinates of the third and first marker points, forming the third side. All pixels within this closed triangular region constitute the reference triangle region. The curvature response value of each pixel within the reference triangle region is calculated to extract local curvature features. For each valid pixel within the reference triangle region, a 5x5 square neighborhood window is defined centered on the pixel's location, containing 25 pixels. Within this 5x5 window, the Sobel operator is used to calculate the grayscale gradient values ​​of the pixel's location in both the horizontal and vertical directions. The Sobel operator's horizontal gradient kernel is a 3x3 numerical array. The first row contains three values: -1, 0, +1; the second row contains three values: -2, 0, +2; and the third row contains three values: -1, 0, +1. The vertical gradient kernel is the transpose of the horizontal kernel, with the first column containing three values: -1, 0, +1; the second column containing three values: -2, 0, +2; and the third column containing three values: -1, 0, +1. The horizontal gradient kernel is multiplied one-to-one with the corresponding grayscale values ​​of the central 3x3 sub-region (9 pixels in total, from the second row, second column to the fourth row, fourth column). The sum of these nine products is the horizontal grayscale gradient value for that pixel. Similarly, the vertical gradient kernel is multiplied one-to-one with the grayscale values ​​of the nine pixels in the central 3x3 sub-region and summed to obtain the vertical grayscale gradient value. For each pixel within the reference triangle region, the horizontal and vertical gradient values ​​are calculated. For pixels near the boundary of the reference triangle region, if a portion of their 5x5 neighborhood window extends beyond the reference triangle region, the pixels extending beyond this area are considered missing and do not participate in the convolution operation. In this case, the effective convolution region is reduced to 3x3, and the Sobel gradient kernel described above is still used for calculation.

[0033] For each pixel with obtained horizontal and vertical gradient values, these two gradient values ​​are used to determine its gradient direction angle. The calculation method is as follows: first, calculate the ratio of the vertical gradient value to the horizontal gradient value, take the arctangent of this ratio, and then convert the result of the arctangent from radians to degrees to obtain the gradient direction angle, in degrees, with a value range of 0 to 360 degrees. The 0-degree gradient direction is defined as pointing to the right of the image, that is, the direction where the horizontal gradient is positive and the vertical gradient is 0. The angle value increases counterclockwise, so 90 degrees points to the top of the image, 180 degrees points to the left, and 270 degrees points to the bottom. For the special case where the horizontal gradient value is 0: if the vertical gradient value is positive, the gradient direction angle is directly taken as 90 degrees; if the vertical gradient value is negative, the gradient direction angle is directly taken as 270 degrees. When both the horizontal and vertical gradient values ​​are 0, it means that this pixel is located in a completely flat area with no grayscale variation. In this case, the pixel is marked as having no dominant gradient direction and does not participate in the subsequent direction change rate calculation.

[0034] For each pixel with a valid gradient direction within the reference triangle region, its eight neighboring pixels are examined one by one to quantify the degree of local change in the gradient direction around this pixel location. Specifically, taking the current pixel as the center, each of its eight neighboring pixels is selected. For each neighboring pixel, if it also has a valid gradient direction (i.e., it is not a flat pixel without a dominant gradient direction), the angle difference between the gradient direction angle of the neighboring pixel and the gradient direction angle of the current pixel is calculated. The calculation of the angle difference needs to consider the periodicity of the angle on the circumference: first, the values ​​of the two angles are subtracted and the absolute value is taken; if this absolute difference is greater than 180 degrees, then 360 degrees is subtracted from this value. The absolute difference is used as the corrected angle difference. If the absolute difference does not exceed 180 degrees, it is directly used as the angle difference. After this processing, all angle differences will necessarily fall within the range of 0 to 180 degrees. For all pixels with effective gradient directions among the eight neighboring pixels, the angle differences between each such neighboring pixel and the current pixel are summed, and then divided by the number of neighboring pixels with effective gradient directions. The resulting arithmetic mean is the gradient direction change rate at that pixel location, in degrees. If none of the eight neighboring pixels has an effective gradient direction, then the gradient direction change rate of that pixel is directly recorded as 0. The physical meaning of the gradient direction change rate is: in flat areas or areas with uniform gray-level gradients in an image, the gradient directions of adjacent pixels are roughly the same, and the direction change rate is small; in locations with local structures such as corners, texture intersections, and abrupt curvature changes, the gradient directions of adjacent pixels will show significant deflection, and the direction change rate is large.

[0035] For each pixel within the reference triangular region, the gradient direction change rate calculated in the third operation is directly used as its initial curvature response value. Non-maximum suppression (NMS) is then applied to all initial curvature response values ​​across the entire region. The NMS operation involves taking each pixel one by one and comparing its initial curvature response value with the initial curvature response values ​​of its eight neighboring pixels. If the initial curvature response value of a pixel is less than that of any of its eight neighboring pixels, then the pixel's curvature response value is set to 0, i.e., it is suppressed. Only when the initial curvature response value of the current pixel is greater than or equal to the initial curvature response values ​​of all eight neighboring pixels is the pixel's original initial value retained. The purpose of NMS is to retain only those pixels with the strongest curvature response in their local neighborhood and suppress relatively weak response pixels near the edges, thus making the final selected curvature feature points more concentrated and representative.

[0036] After non-maximum suppression (NMS) is completed, a preset curvature threshold of 15 degrees is set. Each pixel within the reference triangle region after NMS is traversed, and its curvature response value is compared to the preset curvature threshold of 15 degrees. If the curvature response value is greater than 15 degrees, the pixel is identified as a curvature feature point, and its horizontal pixel coordinates (column number) and vertical pixel coordinates (row number) are recorded, along with its curvature response value. If the curvature response value is less than or equal to 15 degrees, the pixel is discarded. The coordinates and curvature response values ​​of all pixels identified as curvature feature points are then combined to form a local curvature feature set within the reference triangle region. Each element in this set contains three numerical pieces of information: the horizontal pixel coordinates, vertical pixel coordinates, and curvature response value of the curvature feature point.

[0037] The total number of pixels contained within the reference triangle region is counted, and this total number is used as the initial area of ​​the reference triangle region. The count is performed using a line-by-line scanning method. First, the range of lines spanned by the reference triangle region in the vertical direction is determined: the minimum value among the vertical pixel coordinates of the three vertices is found and used as the starting line number for the scan; the maximum value is found and used as the ending line number for the scan; for each line between the starting and ending line numbers, the intersection points between this line and the three sides of the reference triangle region are determined one by one. For each edge, the specific method for finding the intersection point is as follows: If the edge is horizontal, that is, the vertical coordinates of its two endpoints are the same, and the current scan line just passes through this edge, then all pixels on the entire edge belong to the boundary of the triangle, and the horizontal coordinates of the two endpoints of this edge are taken as the intersection point; if the edge is not horizontal, the intersection point is found using linear interpolation: Let the two endpoints of this edge be endpoint one and endpoint two, the coordinates of endpoint one be (horizontal coordinate one, vertical coordinate one), the coordinates of endpoint two be (horizontal coordinate two, vertical coordinate two), and the row number of the current scan line be the current vertical coordinate; the horizontal coordinate of the intersection point is equal to horizontal coordinate one, plus the difference between horizontal coordinate two and horizontal coordinate one, multiplied by the difference between the current vertical coordinate and vertical coordinate one, and then divided by the difference between vertical coordinate two and vertical coordinate one.

[0038] After intersecting the current scan line with each of the three sides, two valid intersection points are usually obtained (when the scan line passes through the interior of the triangle), sometimes one intersection point is obtained (when the scan line passes through a vertex or the tip of the triangle), and in rare cases, three intersection points are obtained (when the scan line intersects with both endpoints of a horizontal side). The minimum and maximum horizontal coordinates are found from these intersection points. The horizontal coordinates of each integer value within this closed interval—rounding up to the nearest integer from the minimum and rounding down to the nearest integer from the maximum—correspond to a pixel inside the triangle in the current scan line. The number of pixels inside the triangle in this line is accumulated into the total pixel counter. After scanning all lines, the final accumulated value in the total pixel counter is the total number of pixels contained within the reference triangle region; this value is the initial area of ​​the reference triangle region.

[0039] The pixel coordinates of all curvature feature points are extracted from the local curvature feature set. A triangular mesh is constructed for all curvature feature points using the point-by-point insertion Delaunay triangulation method. The geometric center coordinates of each triangle in the triangular mesh are extracted, and these geometric center coordinates are used as region segmentation nodes. The complete Delaunay triangulation process is as follows: First, construct an initial containing triangle. This initial containing triangle must be large enough to ensure that all curvature feature points in the local curvature feature set fall within it. The method for constructing the containing triangle is as follows: first, traverse the coordinates of all curvature feature points and find the minimum and maximum values ​​of the horizontal and vertical pixel coordinates. Determine three vertices: the first vertex is located at the position where the minimum horizontal coordinate is minus one times the total width of the reference triangle region, and the vertical coordinate is located at the position where the minimum vertical coordinate is minus one times the total height of the reference triangle region. The second vertex is located at the position where the maximum horizontal coordinate is plus one times the total width of the reference triangle region, and the vertical coordinate is located at the position where the minimum vertical coordinate is minus one times the total height of the reference triangle region. The third vertex is located at the position where the minimum and maximum horizontal coordinates are averaged, and the vertical coordinate is located at the position where the maximum vertical coordinate is plus one times the total height of the reference triangle region. These three vertices form a sufficiently large triangle that can enclose all curvature feature points. Add the three vertices of this containing triangle to a vertex list in sequence, giving each vertex a unique index number. The index numbers of the three vertices are 0, 1, and 2, respectively. Simultaneously, this encompassing triangle is added as an initial triangle to a triangle list, recording the indices of its three vertices (0, 1, 2) and the indices of its three adjacent triangles. Since the initial encompassing triangle has no adjacent triangles, all three adjacent triangle indices are recorded as invalid values ​​(e.g., negative 1). The Deloitte triangular mesh is then constructed point by point. First, all curvature feature points in the local curvature feature set are placed into a queue of points to be inserted; the order of the points in the queue can be arbitrary. An edge flip stack is initialized to store edges that need to be checked one by one in subsequent edge flip operations. A curvature feature point is sequentially retrieved from the queue of points to be inserted; this point is called the current insertion point.

[0040] Perform the following operations on the current insertion point: To locate the triangle containing the current insertion point, starting from the first triangle in the triangle list, the centroid coordinate method is used to determine if a point is inside a triangle. The centroid coordinate method is as follows: Let the three vertices of the triangle being examined be labeled as the first vertex, second vertex, and third vertex in counter-clockwise order. For the first edge of the triangle (pointing from the first vertex to the second vertex), calculate the direction vector of this edge (the coordinates of the second vertex minus the coordinates of the first vertex) and the vector pointing from the first vertex to the current insertion point (the coordinates of the current insertion point minus the coordinates of the first vertex). Calculate the cross product of these two vectors: multiply the horizontal component of the direction vector by the vertical component of the pointing vector, and subtract the vertical component of the direction vector multiplied by the horizontal component of the pointing vector. If the cross product is non-negative (greater than or equal to 0), the current insertion point is either to the left of the first edge or on the edge. Similarly, calculate the cross product for the second edge (pointing from the second vertex to the third vertex) and the third edge (pointing from the third vertex to the first vertex). If all three cross product results are non-negative or all are non-positive, then the current insertion point is located inside or on the boundary of this triangle, and a triangle containing the current insertion point has been found. If the triangle being checked does not meet the above conditions, it means that the current insertion point is not inside this triangle. In this case, based on the relative position of the current insertion point and this triangle, an adjacent triangle is selected as the next object to be checked. The specific selection method is as follows: for the side whose cross product result is negative (if the three side results are not all the same sign), cross this side and enter the adjacent triangle opposite the side to continue searching until a triangle containing the current insertion point is found.

[0041] The original triangle is divided into three parts. Let the triangle containing the current insertion point found in Operation 1 be the original triangle, and let the indices of its three vertices in the vertex list be vertex index 1, vertex index 2, and vertex index 3, respectively. The current insertion point is added to the vertex list, resulting in a new vertex index. The original triangle is then deleted from the triangle list, and three new triangles are added instead. These three new triangles divide the original triangle into three parts. The three vertices of the first new triangle are, in order, vertex index 1, vertex index 2, and the index of the current insertion point; the three vertices of the second new triangle are, in order, vertex index 2, vertex index 3, and the index of the current insertion point; and the three vertices of the third new triangle are, in order, vertex index 3. The system sets the indices of vertex index 1 and the current insertion point. It then establishes the adjacency relationships between the three new triangles: the first and second new triangles share an edge (with vertex index 2 and the current insertion point as endpoints), so the corresponding position in the adjacent triangle record of the first new triangle is set to the index of the second new triangle, and vice versa. Similarly, the second and third new triangles share an edge (with vertex index 3 and the current insertion point as endpoints), and the third new triangle shares an edge (with vertex index 1 and the current insertion point as endpoints), setting their adjacency relationships bidirectionally. Furthermore, it updates the relationships between these three new triangles and the original triangle's existing adjacent triangles; it checks each of the original triangle's three edges: the first edge has vertex index 1 and vertex index 2 as endpoints, the second edge has vertex index 2 and vertex index 3 as endpoints, and the third edge has vertex index 3 and vertex index 1 as endpoints. For each edge, if the original triangle originally had an adjacent triangle on this edge (i.e., the adjacent index is not invalid), then the adjacent record in that adjacent triangle that points to the original triangle needs to be updated to point to the new triangle that includes this edge. Taking the first edge as an example, after the original triangle is split on this edge, this edge is inherited by the first new triangle. Therefore, the corresponding adjacent records of the triangles adjacent to the original triangle on this edge need to be updated to point to the first new triangle. This process is repeated for all three edges.

[0042] After completing the addition, deletion, and adjacency update of triangles, push all three newly generated shared edges (three edges with the current insertion point as one endpoint and the three original vertices as the other endpoints) and the edges between the original triangle and its existing adjacent triangles onto the edge flip stack, awaiting subsequent empty circle property checks. Perform edge flipping operations to maintain the empty circle property, popping edges to be checked one by one from the edge flip stack. For each popped edge, perform the following checks and processing: First, check if the edge is part of the initial containing triangle: If either of the two endpoints of the edge is one of the three virtual vertices of the initial containing triangle, skip it directly without flipping, because the virtual vertices of the containing triangle should not participate in the Delaunay criterion. If the edge is not part of the containing triangle, find the two adjacent triangles with this edge as a shared edge. Let the two endpoints corresponding to this edge be shared endpoint one and shared endpoint two; in the two adjacent triangles, in addition to shared endpoint one and shared endpoint two, the first triangle has a third vertex, and the second triangle has a fourth vertex. The core issue in checking the properties of an empty circle is determining whether the fourth vertex falls inside the circumcircle of the triangle formed by shared endpoints one, two, and the third vertex. The center and radius of the circumcircle are determined as follows: Take any two sides of the triangle and draw their perpendicular bisectors. The intersection of these two perpendicular bisectors is the center of the circumcircle. Taking the line connecting shared endpoints one and two as an example, the midpoint coordinates of this side are the average of the coordinates of the two endpoints, and the direction of this side is determined by the difference in coordinates between the two endpoints. The direction perpendicular to this side is obtained by rotating the direction vector by 90 degrees, specifically by swapping the horizontal and vertical components of the direction vector and inverting the horizontal component. Extending perpendicularly from the midpoint of this side, the resulting line is the perpendicular bisector of that side. Using the same method, draw the perpendicular bisector of the other side, and the intersection of the two perpendicular bisectors is the center of the circumcircle. The distance from the center of the circumcircle to shared endpoint one is the radius of the circumcircle. Then calculate the distance from the fourth vertex to the center of the circumcircle; if the distance from the fourth vertex to the center is less than the radius of the circumcircle, it means that the fourth vertex has fallen into the interior of the circumcircle, the empty circle property has been violated, and edge flipping must be performed.

[0043] The specific operation of edge flipping is as follows: Flip the original shared edge from (shared endpoint 1, shared endpoint 2) to (third vertex, fourth vertex); correspondingly, replace the two triangles sharing this edge—the original triangle (shared endpoint 1, shared endpoint 2, third vertex) and triangle (shared endpoint 1, shared endpoint 2, fourth vertex)—with two new triangles (third vertex, fourth vertex, shared endpoint 1) and (third vertex, fourth vertex, shared endpoint 2); delete the original two triangles from the triangle list, add these two new triangles, and reset the adjacency relationships between the new triangles, as well as the adjacency relationships between the new triangles and their surrounding original adjacent triangles. After the flip operation is completed, the edges whose adjacency relationships have been changed due to this flip need to be pushed onto the edge flip stack so that they can also be rechecked for the empty circle property. Specifically, all edges of the two newly formed triangles except for the shared edge between them, as well as the corresponding edges of the original triangles adjacent to these two new triangles, are pushed onto the stack. Repeatedly popping edges from the edge flip stack, checking the empty circle property, performing flips if necessary, and pushing the affected edges back onto the stack, and so on, until the edge flip stack is completely empty. At this point, all triangles in the triangular mesh satisfy the Delaunay empty circle criterion, that is, for any triangle, its circumcircle does not contain any other vertices.

[0044] Take the next curvature feature point from the insertion point queue and repeat the complete process of operations one through three: first, locate the triangle containing the point, then segment the triangle, and then perform edge flipping to restore the empty circle property; repeat this process until the insertion point queue is empty and all curvature feature points have been inserted into the triangular mesh; traverse all triangles in the triangle list. For each triangle, check its three vertex indices: if at least one of the three vertex indices points to one of the three virtual vertices of the initial containing triangle (i.e., the vertex with indices 0, 1, and 2), then the triangle contains virtual vertices and should be deleted. Mark all triangles containing virtual vertices and delete them from the triangle list. After deletion, the remaining triangles in the triangle list constitute the Delaunay triangular mesh covering all curvature feature points; this triangular mesh has the empty circle property and the maximum and minimum angle property, meaning that its triangle shape is the most uniform among all possible connection methods, and there will be no degenerate triangles that are too sharp or too flat; extract the region segmentation nodes. Each valid triangle in the Delaunay triangulation mesh is extracted one by one. For each triangle, its geometric center coordinates are calculated as follows: the horizontal pixel coordinates of the three vertices of the triangle are added together, divided by 3, and the result is rounded to the nearest integer to obtain the horizontal pixel coordinates of the geometric center of the triangle; the vertical pixel coordinates of the three vertices are added together, divided by 3, and the result is rounded to the nearest integer to obtain the vertical pixel coordinates of the geometric center. The geometric center coordinates of all triangles are collected together to form a set of region segmentation nodes. Each node in this set corresponds to the geometric center of a triangle in the Delaunay triangulation mesh formed by curvature feature points. The spatial distribution of the nodes naturally reflects the local density variation of curvature feature points: in areas where curvature feature points are densely distributed, the area of ​​the Delaunay triangle is smaller, and the geometric center nodes are also more densely distributed; in areas where curvature feature points are sparsely distributed, the area of ​​the Delaunay triangle is larger, and the geometric center nodes are correspondingly more sparsely distributed.

[0045] Using a set of region segmentation nodes, a partitioning structure is constructed within the reference triangular region, dividing it into multiple adjacent and non-overlapping sub-mesh regions. All nodes in the region segmentation node set are used as internal partitioning base points. The spatial distance between any two internal partitioning base points is calculated. The spatial distance between two base points is defined as follows: subtracting the horizontal pixel coordinates of the two base points yields the horizontal difference; subtracting the vertical pixel coordinates yields the vertical difference; multiplying the horizontal difference by itself yields the squared horizontal difference; multiplying the vertical difference by itself yields the squared vertical difference; adding the squared horizontal and vertical differences and taking the square root gives the spatial distance between the two base points. All base points are paired, and the spatial distance for each pair is calculated and recorded in a distance list along with the endpoint identification information. This distance list is sorted in ascending order of spatial distance. An initially empty set of internal mesh skeleton segments is created, and each internal partitioning base point is assigned an independent connected component label. Initially, each base point has a different label, belonging to a single connected component containing only itself.

[0046] Extract each pair of base points one by one from the sorted distance list in ascending order of distance. For the currently extracted pair of base points, check if their respective connected component labels are the same. If the labels are different, it means that the two base points belong to different connected components. In this case, connect them with a line segment, add this line segment to the internal mesh skeleton line segment set, and then merge the connected components of the two base points into a single connected component. The merging method is to update the labels of all base points in one connected component to the labels of the other connected component. If the connected component labels of the currently extracted pair of base points are already the same, it means that they have been indirectly connected through the previously added line segment. In this case, skip this pair of base points and do not connect them again to avoid... Form closed loops in the skeleton; continue to take the next pair of base points and repeat the above judgment and connection operations; stop when all internal partition base points belong to the same connected component; at this time, the number of line segments contained in the internal mesh skeleton line segment set is exactly equal to the total number of internal partition base points minus 1. These line segments connect all internal partition base points into a tree-like skeleton structure without loops; use the internal mesh skeleton to generate partition line segments and complete the region segmentation; process each line segment in the internal mesh skeleton one by one; for the current line segment, first determine the coordinates of its two endpoints and calculate the direction of the line segment: the horizontal component is equal to the horizontal coordinate of the second endpoint minus the horizontal coordinate of the first endpoint, and the vertical component is equal to the vertical coordinate of the second endpoint minus the vertical coordinate of the first endpoint.

[0047] Starting from the first endpoint of the line segment, extend forward in increments of one pixel along the direction of the line segment. After each increment, check if the currently reached pixel position is still inside the reference triangle region. The method for determining if a pixel is inside the triangle is the centroid coordinate method: calculate the three centroid coordinate components of the pixel position relative to the three vertices of the reference triangle region. The calculation of the three centroid coordinate components involves the proportional relationship of the triangle area, which can be obtained by solving a system of linear equations. If all three centroid coordinate components are non-negative (greater than or equal to 0), the pixel is located inside the triangle or on its boundary. If one of the three components is negative, the pixel is located outside the triangle. When a pixel on the extension path first falls on or exceeds the boundary of the triangle, the extension stops immediately, and this stopping position is recorded as the boundary intersection point in that direction. Similarly, starting from the other endpoint of the line segment, extend forward in the opposite direction of the line segment direction (i.e., the horizontal component is negative, and the vertical component is negative) in increments of one pixel until the boundary of the reference triangle region is reached, and another boundary intersection point is recorded.

[0048] After the aforementioned bidirectional extension, the original skeleton line segment, plus the two extended line segments extending to the boundaries at both ends, are connected to form a complete dividing line segment that runs through the entire reference triangle region. Both ends of this dividing line segment terminate at the boundaries of the reference triangle region. After performing the aforementioned bidirectional extension operation on each line segment in the internal mesh skeleton, a set of dividing line segments is obtained. These dividing line segments intersect each other within the reference triangle region, dividing the spatial plane within the reference triangle region into multiple adjacent polygonal regions. Each closed polygonal region enclosed by all the dividing line segments is a sub-mesh region. All sub-mesh regions, when combined, perfectly cover all pixels of the reference triangle region, with no unallocated gaps or overlapping parts. The actual area of ​​each sub-mesh region is calculated, and a theoretical area is allocated to each sub-mesh region according to its positional proportions.

[0049] The actual area is calculated using a line-by-line scanning method. First, the vertical range of pixels spanned by the current sub-grid region is determined (taking the minimum and maximum vertical coordinates of all pixels within the region). For each row within this range, each column is checked to determine which pixels belong to the sub-grid region, and the number of pixels belonging to the sub-grid region is accumulated into the pixel counter of that sub-grid region. After scanning, the total number of accumulated pixels is the actual area of ​​the sub-grid region. This line-by-line scanning and statistical process is performed for each sub-grid region. The theoretical area allocation process is as follows: Each region segmentation node is extracted one by one, and each region segmentation node corresponds to a triangle in the Delaunay triangulation mesh. Each region segmentation node is also associated with a sub-grid region. Specifically, a sub-grid region contains one or more region segmentation nodes, and the node closest to the geometric center of the sub-grid region is taken as the representative node of the sub-grid region. The geometric center coordinates of the sub-grid region are defined as the average value of all pixel coordinates within the region.

[0050] Extract the area of ​​the Delaunay triangle corresponding to each region segmentation node. The area of ​​the Delaunay triangle is the number of pixels contained within the area enclosed by the three vertices of the triangle, and its statistical method is also line-by-line scanning. Assuming there are a total number of region segmentation nodes, sum the areas of the Delaunay triangles corresponding to each node to obtain a total area value. Assign a theoretical area to each sub-mesh region. For the current sub-mesh region, find its representative node and obtain the area of ​​the Delaunay triangle corresponding to that representative node. Divide this Delaunay triangle area by the total area value of all Delaunay triangles obtained earlier to get the area ratio of that node in the entire Delaunay triangular mesh. Then multiply this area ratio by the initial area of ​​the reference triangular region, and the resulting product is the theoretical area of ​​the current sub-mesh region. Calculate this for each sub-mesh region in the above manner to complete the allocation of all theoretical areas. After this allocation, the sum of the theoretical areas of all sub-mesh regions must be equal to the initial area of ​​the reference triangular region, because this allocation process is essentially distributing the initial area of ​​the reference triangular region proportionally according to the area ratio of each triangle in the Delaunay triangular mesh.

[0051] The calculation of area change characteristics and boundary morphology features describes the degree and manner in which each sub-mesh region is affected by non-rigid deformation from two dimensions: area change and boundary shape, respectively. Each sub-mesh region is processed one by one. For the current sub-mesh region, its actual area is subtracted from its theoretical area; the difference is the area deviation of this sub-mesh region. The area deviation can be positive, negative, or zero: a positive value indicates that the sub-mesh region has expanded relative to the theoretically uniform distribution, occupying more pixels than theoretically expected, which usually corresponds to a scene with dense curvature features and complex local geometry in this region; a negative value indicates that the sub-mesh region has shrunk, occupying fewer pixels than theoretically expected, which usually corresponds to a scene with sparse curvature features and flat local geometry in this region; a zero value indicates that the actual area is consistent with the theoretical area, and no area deformation has occurred. The area deviations of all sub-mesh regions are arranged sequentially according to their sub-mesh region numbers to form an area change feature sequence.

[0052] Process each sub-mesh region one by one. For the current sub-mesh region, extract its boundary tortuosity as follows: To extract the boundary contour pixel sequence, first find a boundary pixel within the sub-grid region as the starting point for tracing. The method for finding the starting point is as follows: scan all pixels within the current sub-grid region line by line, finding the first pixel that satisfies the following conditions: this pixel belongs to the current sub-grid region, and at least one of its eight neighboring pixels does not belong to the current sub-grid region; this pixel is the boundary starting point. Starting from the starting point, perform chain code tracing counter-clockwise along the boundary of the sub-grid region. The tracing process is as follows: upon reaching each boundary pixel, check its eight neighboring pixels to find the next boundary pixel, i.e., a pixel that simultaneously satisfies two conditions: first, the neighboring pixel belongs to the current sub-grid region; second, at least one of the neighboring pixel's eight neighboring pixels does not belong to the current sub-grid region. If multiple candidate pixels satisfying the conditions are found among the eight neighboring pixels of the current boundary pixel, the pixel located to the left of the current tracking direction is selected first to ensure that the tracking proceeds counterclockwise around the region. Following the chain code tracking sequence, the coordinates of each boundary pixel are sequentially recorded into the boundary contour pixel sequence. When the tracking returns to the starting point, it indicates that the region has been circled once, and the boundary contour extraction is complete. At this point, the boundary contour pixel sequence contains the coordinates of all pixels on the boundary of the sub-grid region in a continuous adjacent order along the boundary.

[0053] Calculate the direction angle of the line connecting adjacent pixels, processing each pixel in the boundary contour pixel sequence one by one: extract the current pixel and its direct successor pixel in the sequence; if the current pixel is already the last element of the sequence, then its successor pixel is the first element of the sequence, forming a closed loop; for the line connecting the current pixel to its successor pixel, calculate the direction angle. The calculation method is as follows: subtract the horizontal coordinate of the current pixel from the horizontal coordinate of the successor pixel to obtain the horizontal offset; subtract the vertical coordinate of the current pixel from the vertical coordinate of the successor pixel to obtain the vertical offset. Calculate the ratio of the vertical offset to the horizontal offset, take the arctangent, and then convert it to an angle value to obtain the direction angle of the line, in degrees, with a value range of 0 to 360 degrees; if the horizontal offset is 0 (i.e., the line is completely vertical), then the direction angle is determined according to the sign of the vertical offset: the direction angle is 90 degrees when the vertical offset is positive, and 270 degrees when the vertical offset is negative. To calculate the direction change angle, pair all the lines in the boundary contour pixel sequence together. For each pair of adjacent lines (the first line pointing to the second pixel and the second line pointing to the third pixel), calculate the difference between their direction angles. Subtract the two direction angles and take the absolute value. If this absolute value is greater than 180 degrees, subtract it from 360 degrees to obtain the corrected direction change angle. If the absolute value is less than or equal to 180 degrees, use it directly as the direction change angle. This process ensures that the direction change angle always falls within the range of 0 to 180 degrees. Calculate the direction change angle between each pair of adjacent lines in the sequence in the same way. To calculate boundary sortability, the directional change angles of all adjacent line pairs are summed, and then divided by the total number of pixels in the boundary contour pixel sequence (i.e., the boundary length in pixels). The resulting arithmetic mean is the boundary sortability of the sub-grid region, measured in degrees. Boundary sortability reflects the unevenness of the boundary contour of a sub-grid region: a larger sortability value indicates that the boundary of the sub-grid region is tortuous and irregular in shape, usually meaning that in addition to changes in area, the boundary has also undergone significant twisting or jagged deformation; a smaller sortability value indicates that the boundary of the sub-grid region is relatively smooth and its shape is close to a simple polygon. After calculating the boundary sortability of each sub-grid region, all values ​​are aggregated to form a boundary morphology characteristic set.

[0054] The area deformation coefficient is calculated based on the area deviation, and the boundary deformation constraint coefficient is calculated based on the boundary tortuosity. Each sub-mesh region is processed one by one. For the current sub-mesh region, the calculated area deviation is extracted. This area deviation is divided by the theoretical area of ​​the sub-mesh region to obtain the relative proportion of area change. The area deformation coefficient is this relative proportion plus 1.0. Thus, when the area deviation is positive, the relative proportion is greater than 0, and the area deformation coefficient is greater than 1.0. Subsequent adjustments will stretch the pixels of the sub-mesh region outward. When the area deviation is negative, the relative proportion is negative, and the area deformation coefficient is less than 1.0. Subsequent adjustments will compress the pixels of the sub-mesh region inward. When the area deviation is 0, the area deformation coefficient is exactly equal to 1.0, indicating that the area of ​​the sub-mesh region is completely consistent with the theoretical expectation, and no stretching or compression adjustment is required.

[0055] The boundary deformation constraint coefficient is calculated by processing each sub-mesh region one by one. For the current sub-mesh region, the calculated boundary tortuosity is extracted. The role of the boundary deformation constraint coefficient is to impose constraints on the magnitude of deformation adjustment: the larger the boundary tortuosity of the sub-mesh region, the more severe the irregular deformation of its internal pixel distribution has been. If a large coordinate adjustment is applied at this time, it will not only be difficult to effectively restore the original shape, but may also introduce more texture distortion and distortion. Therefore, stronger constraints should be applied to such regions to reduce the magnitude of adjustment.

[0056] The specific calculation method for the boundary deformation constraint coefficient is as follows: set a reference tortuosity of 45 degrees, which represents a reference level of moderate boundary tortuosity; divide the boundary tortuosity of the current subgrid region by this reference tortuosity of 45 degrees to obtain a ratio; take this ratio as a negative value, that is, multiply it by negative 1, and then use the natural constant (approximately equal to 2.718) as the base and this negative ratio as the exponent to calculate the power value. The result is the boundary deformation constraint coefficient. Based on the properties of exponential operations, the characteristics of this constraint coefficient are as follows: When the boundary tortuosity is very small, the ratio is close to 0, and the negative ratio is also close to 0. The zero power of the natural constant equals 1.0, therefore the constraint coefficient is close to 1.0, meaning that almost no restriction is imposed on the adjustment range, allowing for sufficient deformation compensation. When the boundary tortuosity is large, the ratio becomes larger, and the negative ratio is a negative number with a large absolute value. The large negative power of the natural constant is a positive decimal close to 0, therefore the constraint coefficient will approach 0, meaning that a strong restriction is imposed on the adjustment range, suppressing large coordinate changes. The boundary deformation constraint coefficient always ranges from 0 to 1.0.

[0057] A mesh deformation adjustment value is generated by combining the area deformation coefficient and the boundary deformation constraint coefficient, and this adjustment value is used to compensate for the feature distribution within each sub-mesh region. Each sub-mesh region is processed one by one. For the current sub-mesh region, the calculated area deformation coefficient and the boundary deformation constraint coefficient are multiplied together to obtain the comprehensive deformation coefficient. This comprehensive deformation coefficient carries two aspects of information: one is from the area deformation coefficient, indicating the direction (stretching or compression) and magnitude of the deformation adjustment; the other is from the boundary deformation constraint coefficient, indicating the degree to which the boundary morphology of the sub-mesh region accepts deformation adjustment. For each pixel within the current sub-mesh region, the original position offset of the pixel relative to the geometric center of the sub-mesh region is first determined: the horizontal offset equals the original horizontal coordinate of the pixel minus the horizontal coordinate of the geometric center of the sub-mesh region, and the vertical offset equals the original vertical coordinate of the pixel minus the vertical coordinate of the geometric center of the sub-mesh region. The horizontal offset is multiplied by the comprehensive deformation coefficient of the sub-mesh region to obtain the adjusted horizontal offset; the vertical offset is also multiplied by the comprehensive deformation coefficient to obtain the adjusted vertical offset. The adjusted horizontal offset is added back to the horizontal coordinates of the geometric center to obtain the initial adjusted horizontal coordinates of the pixel; the adjusted vertical offset is added back to the vertical coordinates of the geometric center to obtain the initial adjusted vertical coordinates of the pixel; when the overall deformation coefficient is greater than 1.0, the adjusted offset is greater than the original offset, and the pixel is spatially further away from the geometric center, i.e., an outward stretching effect occurs; when the overall deformation coefficient is less than 1.0, the adjusted offset is less than the original offset, and the pixel is spatially closer to the geometric center, i.e., an inward compression effect occurs; when the overall deformation coefficient is exactly equal to 1.0, the adjusted offset is equal to the original offset, and the pixel position remains unchanged.

[0058] Extract the area deviation of the current sub-grid region from the area change characteristics; determine the direction of translation correction based on the sign of the area deviation: if the area deviation is positive, it indicates that the sub-grid region is expanding outward, and the translation direction is the opposite direction from the geometric center of the sub-grid region to the overall geometric center of the reference triangular region, that is, pushing outward from the overall center; if the area deviation is negative, it indicates that the sub-grid region is contracting inward, and the translation direction is the opposite direction from the geometric center of the sub-grid region to the overall geometric center of the reference triangular region, that is, pulling inward towards the overall center; the coordinates of the overall geometric center of the reference triangular region are the average of the coordinates of the three calibration anchor points; determine the magnitude of translation correction based on the absolute value of the area deviation: the translation magnitude is the absolute value of the area deviation divided by 100, that is, a translation of 1 pixel is generated for every 100 pixels of deviation.

[0059] The translation direction is converted into a unit direction vector, pointing from the geometric center of the sub-mesh region to the overall geometric center of the reference triangular region, or vice versa. After obtaining a direction vector, its two components (horizontal and vertical) are divided by its length (i.e., the square root of the sum of the squares of the horizontal and vertical components). The resulting horizontal and vertical unit components are the unit direction vectors. The horizontal component of the translation correction equals the translation amplitude multiplied by the horizontal unit component, and the vertical component of the translation correction equals the translation amplitude multiplied by the vertical unit component. The calculated preliminary adjusted horizontal coordinates are added to the translation correction horizontal component to obtain the final adjusted horizontal coordinates of the pixel. The preliminary adjusted vertical coordinates are added to the translation correction vertical component to obtain the final adjusted vertical coordinates. Two constraints are applied to the final adjusted coordinates: the first is a boundary constraint: if the final adjusted coordinates fall outside the boundary of the reference triangular region, the coordinates are reversed along their original movement path, shrinking back by 0.5 pixels each time, until they fall back into the reference triangular region. The second aspect is amplitude truncation: if the displacement amplitude of a pixel from its original position to its final adjusted coordinate exceeds twice the maximum original displacement amplitude of all pixels in the sub-grid region (i.e., the distance from the geometric center to the farthest pixel in the region), the final adjusted coordinate will be truncated so that its displacement amplitude does not exceed this upper limit. These two protective measures ensure that deformation adjustment will not cause individual pixels to be significantly thrown out of the reasonable area, thus avoiding local distortion. The above process is performed on all pixels in the current sub-grid region until deformation compensation adjustment has been completed in all sub-grid regions.

[0060] Based on the final adjusted coordinates of each pixel, resampling interpolation is performed on the pixel grayscale values ​​within the sub-grid region to generate a compensated and adjusted reference triangular region image. This adjusted triangular region image is then stitched together with the part outside the reference triangular region to obtain a complete feature extraction image. The resampling interpolation process is as follows: First, determine the integer coordinate position of each pixel within the reference triangular region in the output image (i.e., the pixel grid position where both row and column numbers are integers). For each output pixel position, find its four nearest neighbors among all the deformed and adjusted pixels (i.e., the pixels with the final adjusted coordinates). The method for finding the nearest neighbors is as follows: calculate the spatial distance between the final adjusted coordinates of each adjusted pixel and the current output pixel position (i.e., the square root of the sum of the squares of the horizontal and vertical coordinate differences), sort them in ascending order of distance, and take out the four closest adjusted pixels. Use the grayscale values ​​of these four nearest neighbors to perform bilinear interpolation to determine the grayscale value of the current output pixel position. The specific steps of the interpolation are: first, perform two one-dimensional linear interpolations in the horizontal direction. Among these four nearest neighbor points, the two points at the top vertically are grouped together, and the two points at the bottom are grouped together. For the two points in the top group, the interpolated grayscale value is calculated based on the ratio of the current output pixel position to the horizontal coordinates of these two points. Similarly, for the two points in the bottom group, the interpolated grayscale value is calculated based on the ratio of the horizontal coordinates. Then, in the vertical direction, based on the ratio of the current output pixel position to the vertical coordinates of the top and bottom points, a one-dimensional linear interpolation is performed on both the top and bottom interpolated grayscale values ​​to obtain the final interpolated grayscale value.

[0061] The interpolated grayscale value is rounded to the nearest integer and limited to a grayscale value range of 0 to 255. If no four nearest neighbors are found around the current output pixel location (e.g., in a gap area caused by deformation expansion, where the surrounding pixels are very sparse after adjustment), the distance between the nearest adjusted pixel and the output location is checked: if this nearest distance is no more than 5 pixels, the grayscale value of this nearest adjusted pixel is directly used as the grayscale value of the output location; if the nearest distance is more than 5 pixels, the search radius is expanded to 10 pixels to find the nearest neighbor, and the grayscale value of the nearest point is still directly used. After performing the above interpolation calculation for all output pixel locations within the reference triangle region, a compensated and adjusted image of the reference triangle region is obtained. In this image, the problem of non-rigid deformation and drift of some marker point coordinates caused by overexposure has been corrected by the combined compensation driven by area change features and boundary morphology characteristics. The spatial distribution of pixels has been restored, making it closer to the real imaging geometry. Finally, an image stitching operation is performed, embedding the compensated and adjusted reference triangle region image into the original position of the reference triangle region in the initial stereo image. Using the coordinates of three calibration anchor points as positioning references, the gray values ​​of each pixel in the adjusted image are used to cover the original gray values ​​at the corresponding coordinate positions in the initial stereo image one by one. All pixels outside the reference triangle region area retain their original gray values ​​in the initial stereo image without any modification. After the stitching is completed, a complete feature extraction image is obtained.

[0062] In a preferred embodiment of the present invention, step 3 is performed as follows: Corner detection is performed independently for each local grid region in the feature extraction image. Within each local grid region, the corner response intensity is calculated pixel by pixel. For the currently examined pixel, a 5x5 square analysis window is defined centered on it, containing a total of 25 pixels. For each of these 25 pixels, its horizontal and vertical gray-level gradients are calculated using a 3x3 Sobel operator. Based on the horizontal and vertical gradients of each of these 25 pixels, a gradient distribution matrix is ​​constructed. This matrix has a size of 2x2 and contains 4 values. The four values ​​are calculated as follows: Squaring the horizontal gradient of each of the 25 pixels and summing them up, the resulting sum of squared horizontal gradients is the element in the first row and first column of the matrix; Squaring the vertical gradient of each of the 25 pixels and summing them up, the resulting sum of squared vertical gradients is the element in the second row and second column of the matrix; Multiplying the horizontal and vertical gradients of each of the 25 pixels and summing them up, the resulting sum of horizontal and vertical gradient products is the element in the first row and second column of the matrix, and also the element in the second row and first column (both have the same value).

[0063] Two key features are extracted from the gradient distribution matrix described above. The first feature is the trace of the matrix, which is the sum of the elements in the first row and first column of the matrix and the elements in the second row and second column, which is the sum of the squares of the horizontal and vertical gradients. The second feature is the determinant of the matrix, which is the product of the elements in the first row and first column of the matrix and the elements in the second row and second column, minus the product of the elements in the first row and second column of the matrix and the elements in the second row and first column (since the elements in the first row and second column are equal to those in the second row and first column, this is equivalent to subtracting the square of the sum of the horizontal and vertical gradient products). The corner response intensity is obtained by subtracting an empirical constant (with a value of 0.04) from the second feature and multiplying it by the square of the first feature. The larger this response intensity value, the higher the probability that the current pixel is located at a corner.

[0064] After calculating the corner response intensity for all pixels within the current local grid region, all pixels are sorted from largest to smallest response intensity. From the sorted results, several pixels with the highest response intensity are selected as corner points of the local grid region. The number of selected corner points is adaptively determined based on the area of ​​the local grid region: more corner points are selected for larger areas (more pixels), and fewer corner points are selected for smaller areas, with the number of selected corner points controlled between 5 and 15. For each selected corner point, its actual pixel coordinates are recorded, that is, the horizontal and vertical pixel coordinates of the corner point in the feature extraction image.

[0065] For each extracted corner point, its local grid region is identified; the theoretical coordinate reference value of the corner point is determined using information pre-acquired during the system calibration phase; during the system calibration phase, the medical device is placed in a standard reference pose, and high-precision measurement methods (such as a coordinate measuring machine) are used to comprehensively pre-acquire the texture features of the optical markers installed on the device and their surrounding areas; the pre-acquired content includes: the standard imaging position of each corner point in the binocular image under the standard reference pose, i.e., the expected horizontal pixel coordinates and expected vertical pixel coordinates corresponding to each corner point; during the actual operation phase, the theoretical coordinate reference value of the corner point is determined based on the actual coordinates of the three calibration anchor points in the current image (i.e., the center pixel coordinates of the extracted first, second, and third marker points). The system establishes a mapping relationship from the device's local coordinate system to the image pixel coordinate system from the current viewpoint, based on the three markers and their known spatial positions on the device. This mapping relationship is a perspective projection transformation, uniquely determined by three non-collinear calibration anchor points. The corresponding spatial position of each corner point recorded during the system calibration phase in the device's local coordinate system is reprojected into the current image through the above mapping relationship. The resulting pixel coordinates are the theoretical coordinate reference values ​​of the corner point under ideal conditions without any overexposure distortion. In other words, the theoretical coordinate reference values ​​reflect the pixel position that the corner point should appear in under conditions of no overexposure and where the marker point imaging completely conforms to the rigid perspective projection law.

[0066] Each corner point is processed one by one. For the current corner point, its actual pixel coordinates are compared with its theoretical coordinate reference values. The horizontal coordinate offset is equal to the actual horizontal pixel coordinates minus the theoretical horizontal reference coordinates, and the vertical coordinate offset is equal to the actual vertical pixel coordinates minus the theoretical vertical reference coordinates. The offset can be positive or negative: a positive value indicates that the actual position of the corner point has shifted to the right (horizontally) or down (vertically) relative to the ideal position; a negative value indicates that it has shifted to the left or up. The absolute value of the offset reflects the severity of the non-rigid deformation affecting the position of the corner point. The coordinate offsets of all corner points are collected to form a discrete control point set. Each discrete control point in this set contains three pieces of information: the actual pixel coordinates of the corner point in the feature extraction image (i.e., the spatial position of the control point), and the values ​​of the horizontal and vertical offsets. Using all the obtained discrete control points as the basis for interpolation, a continuous offset vector field covering the entire feature extraction image region is generated by the thin plate spline interpolation method. The core idea of ​​this interpolation method is to find a smooth surface that passes through all discrete control points and minimizes the overall bending energy, and use this surface to describe the distribution law of the offset vector at each position in the image.

[0067] The calculation process for thin plate spline interpolation consists of two stages: In the first stage, the weighting coefficients are calculated. Let the total number of discrete control points be the number of points. First, a distance transformation matrix of size is constructed, consisting of rows and columns of the number of points. Then, each row and column of the distance transformation matrix is ​​taken one by one, with each row corresponding to a control point and each column corresponding to a control point. The element in the first row and column of the matrix (i.e., the element jointly determined by the control point corresponding to the row and the control point corresponding to the column) is calculated according to the following rules: First, calculate the spatial distance between the coordinates of the control point corresponding to the row and the control point corresponding to the column, which is the square of the difference between the horizontal coordinates of the two points plus the square of the difference between the vertical coordinates, and then take the square root. If the spatial distance is greater than 0, the value of the element is the square of the distance multiplied by the natural logarithm of the distance; if the spatial distance is 0 (i.e., the row and column correspond to the same control point), the value of the element is 0; to the right of the above distance transformation matrix, an augmented matrix of size 3 rows and 3 columns is concatenated; the first column of the augmented matrix is ​​filled with 1s, the second column is filled with the horizontal coordinates of each control point in the order of their numbers, and the third column is filled with the vertical coordinates of each control point in the order of their numbers.

[0068] Below the combined matrix (distance transformation matrix plus augmented matrix), concatenate the transpose of the augmented matrix (3 rows, 3 columns) and a 3x3 matrix of all zeros, ultimately forming a large square matrix with a size equal to the number of points plus 3 rows and 3 columns. This large square matrix is ​​the coefficient matrix of a system of linear equations. For the horizontal offset, construct a right-hand vector of length 3 points. The first 3 elements of this vector are filled with the horizontal coordinate offsets of each control point, and the last 3 elements are filled with 0. Solve this system of linear equations (i.e., calculate the inverse of the coefficient matrix and then multiply the inverse by the right-hand vector) to obtain the number of points plus 3 weight coefficients. The first 3 coefficients correspond to the radial basis weights of each control point, and the last 3 coefficients correspond to the linear part of the overall affine transformation (corresponding to the constant term, horizontal coordinate coefficient, and vertical coordinate coefficient, respectively).

[0069] For the vertical offset, construct the right-end vector in the same way (filling the vertical coordinate offsets of each control point with the number of elements from the previous point), and solve for the number of points in the vertical direction plus 3 weight coefficients. In the second stage, use the weight coefficients to perform pixel-by-pixel interpolation. For each integer coordinate pixel position in the feature extraction image, perform the following interpolation calculation: First, calculate the spatial distance between the current pixel position and each discrete control point. Transform each distance: if the distance is greater than 0, the transformation value is the square of the distance multiplied by the natural logarithm of the distance; if the distance is 0 (i.e., the current pixel position is exactly the position of a control point), the transformation value is 0. Multiply the transformation value corresponding to each control point by the radial basis weight coefficient (horizontal radial basis weight coefficient) obtained in the first stage for that control point, sum all the multiplications of the number of points, add the contribution of the overall affine part, i.e., the constant term weight multiplied by 1, add the horizontal coordinate coefficient weight multiplied by the horizontal coordinate of the current pixel, add the vertical coordinate coefficient weight multiplied by the vertical coordinate of the current pixel, and the sum is the horizontal offset interpolation amount at the current pixel position. Using the exact same calculation process, but with weighting coefficients in the vertical direction (vertical radial basis weighting coefficients and vertical global affine coefficients), the vertical offset interpolation amount at the current pixel position is calculated. The horizontal and vertical offset interpolation amounts are combined to form the compensation vector at the current pixel position. The corresponding compensation vector is calculated for each pixel position in the feature extraction image. The compensation vectors for all pixel positions are aggregated to form a non-rigid deformation compensation vector field covering the entire feature extraction image region.

[0070] For each corner point, the compensation vector at that location is extracted from the non-rigid deformation compensation vector field. The horizontal component of the compensation vector is superimposed onto the actual horizontal pixel coordinates of the corner point: if the horizontal component is positive, the horizontal coordinates of the corner point are shifted to the right by the corresponding amount; if the horizontal component is negative, they are shifted to the left by the corresponding amount. Similarly, the vertical component of the compensation vector is superimposed onto the actual vertical pixel coordinates of the corner point. The resulting coordinates are the compensated coordinates of the corner point. It should be noted that the corner point participates in the construction of the weight coefficients as a discrete control point in the interpolation calculation, and also acts as the object of compensation in the compensation superposition stage. The two steps use different information: the original offsets of all corner points are used when constructing the weight coefficients, while the value at that location in the continuous compensation vector field generated by interpolation is used when superimposing the compensation. This value is usually not completely consistent with the original offset due to the smoothing effect of thin plate spline interpolation, which is reasonable because interpolation ensures the continuity and smoothness of the offset field globally. The above operations are performed independently on the left and right eye feature extraction images, respectively, to obtain the compensated corner point coordinate sets for the left and right eyes. These two sets are then merged to form the compensated binocular feature point set. Each feature point in this set consists of the following information: a source view identifier (whether the feature point comes from the left or right eye image); compensated pixel coordinates (the horizontal and vertical pixel coordinates after non-rigid deformation compensation); and a local image description vector. The local image description vector is constructed as follows: a 9x9 square window containing 81 pixels is taken, centered on the compensated coordinates of the feature point. The grayscale values ​​of these 81 pixels are arranged sequentially from top left to bottom right, forming a numerical sequence of length 81. This numerical sequence is then normalized by calculating the arithmetic mean of the 81 values ​​and subtracting this mean from each value in the sequence, thus making the description vector insensitive to changes in the overall brightness of the image.

[0071] In a preferred embodiment of the present invention, step 4 involves extracting three-dimensional spatial coordinates based on the compensated binocular feature point set to perform binocular visual pose calculation, thereby obtaining six-degree-of-freedom pose data, including: The feature points in the compensated binocular feature point set are separated according to the source view to obtain a left-eye feature point subset and a right-eye feature point subset. The left-eye feature point subset contains all corner points extracted from the left view and compensated, and the right-eye feature point subset contains all corner points extracted from the right view and compensated. Each feature point in each feature point subset carries two pieces of data: one is the compensated subpixel coordinates, and the other is the constructed local image description vector.

[0072] Using the epipolar geometric constraints obtained from stereo calibration, feature points are paired between the left-eye and right-eye feature point subsets. For each feature point in the left-eye feature point subset, the epipolar line equation corresponding to that feature point in the right-eye image is calculated based on the essential matrix and fundamental matrix determined during the stereo calibration stage. This epipolar line is a straight line in the right-eye image, and its geometric meaning is that the right-eye image projection point corresponding to the same three-dimensional space point as the left-eye feature point must fall on this epipolar line. A search strip is drawn along this epipolar line, and this strip extends 2 pixels to each side with the epipolar line as the center line, forming a total strip width of 5 pixels. Collect all right-eye feature points within this strip region to form a candidate matching set. For each candidate right-eye feature point in the candidate matching set, calculate the similarity of its descriptive vector with the current left-eye feature point. Specifically, subtract the 81-dimensional descriptive vector of the left-eye feature point from the 81-dimensional descriptive vector of the candidate right-eye feature point element by element, taking the absolute value to obtain 81 absolute differences. Then, sum these 81 absolute differences to obtain the total descriptive vector difference. The smaller this total difference, the more similar the local image textures around the two feature points. In the candidate matching set, select the right-eye feature point with the smallest total descriptive vector difference as the best candidate match.

[0073] A bidirectional consistency check is applied to the best candidate matches. The check method is as follows: using the selected best candidate right eye feature point as a new starting point, the best matching left eye feature point is searched along its corresponding epipolar line in the left eye image. If the best match found by this reverse search is exactly the original left eye feature point, then this pair passes the bidirectional consistency check and is confirmed as a valid feature point pair. If the best match found by the reverse search is not the original left eye feature point, it means that this pair is unreliable and is rejected. This left eye feature point will not participate in the subsequent 3D spatial coordinate reconstruction for the time being. For each valid feature point pair that passes the bidirectional consistency check, sub-pixel precision coordinate fine-tuning is performed. Taking the current coordinates of the left eye feature point as the initial position, the coordinates around this initial position are adjusted. A 3x3 local window is defined, and the grayscale values ​​of the nine pixels within this window form a local grayscale surface. A two-dimensional quadratic surface is fitted to this local grayscale surface. The grayscale changes of this quadratic surface in both the horizontal (pixel column direction) and vertical (pixel row direction) directions follow the law of a quadratic curve, thus the surface contains a total of six undetermined coefficients. Using the grayscale values ​​of the nine pixels and their relative coordinates within the window, a system of nine equations is constructed. The best estimates of these six undetermined coefficients are obtained using the least squares method. On the fitted quadratic surface, the precise coordinates of the grayscale extrema (which can be either maxima or minima, depending on whether the feature point is a bright or dark spot type) are found. Since the quadratic surface is continuous and smooth, the coordinates of the extrema are usually not integers but values ​​with decimal parts. These decimal coordinates are the sub-pixel fine-tuning coordinates of the left eye feature point. The same two-dimensional quadratic surface fitting and extreme value localization operations were performed on the right eye feature points to obtain the sub-pixel fine-tuning coordinates of the right eye feature points. After sub-pixel fine-tuning, the coordinate accuracy of the feature point pairs was improved from the original integer pixel level to the fractional pixel level. Using the radial distortion coefficient and tangential distortion coefficient in the camera intrinsic parameters obtained from stereo calibration, distortion correction was performed on the sub-pixel fine-tuning coordinates of the left eye feature points and the right eye feature points, respectively. The purpose of distortion correction is to eliminate the influence of optical distortion of the camera lens on the imaging position of the feature points.

[0074] The distortion correction calculation process is as follows: For a given pixel coordinate containing distortion, firstly, calculate the radial distance from the pixel position to the camera principal point (i.e., the intersection of the optical axis and the imaging plane). The radial distance is calculated as follows: subtract the horizontal coordinate of the principal point from the horizontal coordinate of the pixel to obtain the horizontal offset; subtract the vertical coordinate of the principal point from the vertical coordinate of the pixel to obtain the vertical offset; multiply the horizontal offset by itself and the vertical offset by itself, add the two squares, and take the square root to obtain the radial distance; calculate the radial distortion offset based on the radial distortion coefficients, which typically have two orders; multiply the first-order radial distortion coefficient by the square of the radial distance, and then multiply by the horizontal and vertical offsets respectively to obtain the first-order distortion offset components in the horizontal and vertical directions. Multiply the second-order radial distortion coefficient by the fourth power of the radial distance, and then multiply by the horizontal and vertical offsets respectively to obtain the second-order distortion offset components.

[0075] Next, the tangential distortion offset is calculated based on the tangential distortion coefficient, which also has two terms. The first tangential distortion coefficient is multiplied by a combination of two factors (one of which is twice the square of the horizontal offset plus the square of the radial distance, and the other is twice the product of the horizontal and vertical offsets) to obtain the tangential distortion offset component in the horizontal direction. The second tangential distortion coefficient is multiplied by another set of combination factors to obtain the tangential distortion offset component in the vertical direction. The original distorted pixel coordinates are then subtracted from the sum of all the above distortion offset components (radial first order, radial second order, and tangential terms) to obtain the corrected distortion-free pixel coordinates. The above distortion correction calculations are performed on the left and right eye feature points respectively. Stereo correction is then performed on the distortion-free left and right eye coordinates after distortion correction. The purpose of stereo correction is to make the epipolar lines of the left and right eye images completely parallel to the horizontal scan lines of the images, thus simplifying the two-dimensional feature matching problem into a one-dimensional horizontal disparity search problem. Stereo correction is achieved using rotation matrices and translation vectors between the left and right cameras obtained from stereo calibration. A pair of rotation matrices is calculated, one applied to the left camera coordinate system and the other to the right camera coordinate system. The effect is that after the left and right cameras rotate by a certain angle (each bearing half of the total rotation angle), the optical axes of the two cameras become parallel to each other, and the imaging planes of the two cameras become coplanar, while keeping the baseline direction between the two cameras (i.e., the direction of the straight line connecting the two optical centers) unchanged. This pair of external rotation matrices is then applied to the distortion-free coordinates of the left and right eye feature points, respectively, to obtain the stereo-corrected coordinates. After correction, the vertical coordinates of the feature point corresponding to the same three-dimensional space point should be completely consistent in the left and right eye corrected images, and the difference between their horizontal coordinates is the disparity value of that point. Using the principles of triangulation, the spatial coordinates of the corresponding 3D points for each effective feature point pair are reconstructed based on disparity values ​​and stereo calibration parameters. First, the baseline length of the binocular camera system is obtained from the stereo calibration results. The baseline length refers to the physical distance between the optical centers of the left and right cameras, measured in millimeters. Simultaneously, the physical focal length of the camera is obtained. The physical focal length is calculated by multiplying the focal length value (in pixels) obtained from stereo calibration by the pixel size of the camera's image sensor. The pixel size refers to the physical side length of a single photosensitive unit on the image sensor, typically measured in millimeters per pixel, and is provided by the camera manufacturer or determined through calibration.

[0076] For each pair of valid feature points, the calculation process for reconstructing the 3D coordinates using triangulation is as follows: First, multiply the physical focal length by the baseline length to obtain the product. Then, divide this product by the disparity value of the feature point pair (i.e., the difference between the corrected horizontal coordinates of the left and right eye feature points). The quotient is the depth value of the 3D spatial point in the camera coordinate system, which is the distance from the point to the midpoint of the camera baseline along the optical axis, in millimeters. After obtaining the depth value, using the horizontal and vertical pixel differences between the corrected left eye feature point coordinates and the principal point coordinates, combined with the physical focal length and depth value, calculate the other two coordinate components of the 3D spatial point in the camera coordinate system. The calculation method is as follows: the horizontal coordinate component is equal to the horizontal pixel difference divided by the physical focal length, then multiplied by the depth value; the vertical coordinate component is equal to the vertical pixel difference divided by the physical focal length, then multiplied by the depth value. After completing the above triangulation calculation for all valid feature point pairs, a 3D spatial point cloud expressed in the camera coordinate system is obtained. Each point in this point cloud is described by three values: the first axis coordinate, the second axis coordinate, and the third axis coordinate in the camera coordinate system (corresponding to the horizontal, vertical, and depth directions, respectively), all in millimeters. The resulting 3D point cloud in the camera coordinate system is then transformed to the base coordinate system of the medical device using a pre-defined hand-eye transformation relationship. This hand-eye transformation relationship is a set of rigid transformation parameters determined during the system installation and debugging phase using a hand-eye calibration program. It consists of a 3x3 rotation matrix and a 3x1 translation vector. The nine values ​​of the rotation matrix describe the direction cosine relationship between the three coordinate axes of the camera coordinate system and the three coordinate axes of the device base coordinate system. The three values ​​of the translation vector describe the spatial translation of the origin of the camera coordinate system relative to the origin of the device base coordinate system.

[0077] The steps for coordinate transformation are as follows: For each point in the 3D point cloud, first perform a rotation operation; multiply the three values ​​in the first row of the rotation matrix by the three coordinate values ​​in the camera coordinate system of that point and sum them to obtain the first coordinate component after rotation; similarly multiply the three values ​​in the second row by the three coordinate values ​​and sum them to obtain the second coordinate component; multiply the three values ​​in the third row by the three coordinate values ​​and sum them to obtain the third coordinate component. After the rotation operation is completed, a translation operation is performed: the first coordinate component after rotation is added to the first value of the translation vector to obtain the first axis coordinate in the device's base coordinate system; the second coordinate component after rotation is added to the second value of the translation vector to obtain the second axis coordinate; the third coordinate component after rotation is added to the third value of the translation vector to obtain the third axis coordinate; after all points are transformed, a three-dimensional point cloud in the device's base coordinate system is obtained; using the three-dimensional point cloud transformed to the device's base coordinate system, it is registered with a known set of optical markers on the medical device, and the six-degree-of-freedom pose of the medical device is calculated from the registration result; the known point set is obtained during the system calibration phase by using high-precision measuring equipment (such as a coordinate measuring machine or laser tracker) to accurately measure each optical marker installed on the medical device, and the three-dimensional spatial coordinates of these markers in the medical device's own local coordinate system are obtained. The origin of the device's local coordinate system is usually set at a certain structural feature of the medical device, for example, using the center of the front face of the surgical handpiece as the origin, and the long axis direction of the handpiece as a coordinate axis direction to establish the coordinate system. The goal of registration is to find an optimal rigid transformation (consisting of a rotation matrix and a translation vector) that, after the known point set undergoes this rigid transformation, achieves the best spatial alignment with the measured 3D point cloud. Rigid registration is implemented using a variant of the iterative nearest-point algorithm. This algorithm iteratively performs nearest-point search, outlier removal, transformation estimation, and convergence checks to gradually approach the optimal registration transformation. The rotation matrix estimated in the current iteration is set to a 3x3 identity matrix, meaning the three elements on the main diagonal (row 1, column 1; row 2, column 2; row 3, column 3) are set to 1, and the remaining six elements are all set to 0. The estimated translation vector is set to a zero vector, meaning all three translation components are set to 0. The maximum allowed number of iterations is set to 50. The convergence threshold is set to 0.1 mm. The counter for the current iteration is initialized to 1.

[0078] For each point in the measured 3D point cloud, find the nearest known point in the known point set. The spatial distance between two points is defined as their Euclidean distance in 3D space, calculated by subtracting the coordinates of the two points along the three coordinate axes, squaring each difference, summing the squares, and taking the square root. By traversing all points in the known point set, the minimum spatial distance and its corresponding known point index are recorded, thus finding a one-to-one matching known point for each point in the measured point cloud. This constructs a set of point pairs, where each pair consists of a measured point and its nearest known point, and the total number of point pairs equals the number of points in the measured point cloud. The constructed set of point pairs undergoes quality screening, eliminating abnormal point pairs with poor matching quality, which may be noise or mismatches. First, the statistical distribution characteristics of the spatial distances of all point pairs are calculated. Then, all point pairs are sorted in ascending order of their spatial distances, and the median distance is taken as the middle value. Then, calculate the median absolute deviation: for each point pair's spatial distance, calculate the absolute value of its difference from the median. Compile all these absolute values ​​into a new sequence, sort this new sequence in ascending order, and take the median; the resulting value is the median absolute deviation. Next, determine the threshold for inlier retention: add three times the median absolute deviation to the median. Point pairs whose spatial distance exceeds this threshold are marked as outliers and removed from the point pair set. Point pairs whose spatial distance does not exceed this threshold are retained, forming the inlier set. Calculate the centroid coordinates of the measured point cloud and the predicted point set in the inlier set respectively. The centroid of the measured point cloud is calculated as follows: sum the first-axis coordinates of all measured points in the inlier set and divide by the number of inliers to obtain the first-axis coordinate of the centroid; sum the second-axis coordinates of all measured points and divide by the number of inliers to obtain the second-axis coordinate of the centroid; the third-axis coordinates are calculated similarly. The centroid of the predicted point set is calculated in the same way, using the average of the coordinates of the corresponding predicted points in the inlier set. The centroid removal process involves subtracting the corresponding coordinate components of the centroid of the measured point cloud from the three coordinate components of each measured point in the interior point set, resulting in the centroid-removed measured coordinates. Simultaneously, the corresponding coordinate components of the centroid of the predicted point set are subtracted from the three coordinate components of each predicted point, resulting in the centroid-removed predicted coordinates. The purpose of centroid removal is to translate the geometric centers of both point sets to the origin, ensuring that subsequent rotation matrix estimation is not affected by the translation.

[0079] Using the centroid-free coordinates of point pairs, construct a 3x3 cross-covariance matrix. The nine elements of this matrix are calculated one by one according to the following rules: For the element corresponding to a certain row (value 1, 2, or 3) and a certain column (also value 1, 2, or 3), its value is equal to: multiplying the component of the centroid-free measured coordinates of all point pairs in the interior point set in the certain row by the component of the centroid-free predicted coordinates in the certain column, and then summing all these multiplications; after the cross-covariance matrix is ​​constructed, perform singular value decomposition on it. Singular Value Decomposition (SVD) decomposes this matrix into the product of three matrices: the first matrix is ​​a 3x3 left singular vector matrix, with its three columns being mutually orthogonal unit vectors; the second matrix is ​​a 3x3 diagonal singular value matrix, with only three non-negative values ​​(i.e., singular values) on the main diagonal, arranged in descending order; the third matrix is ​​the transpose of a 3x3 right singular vector matrix, with its three rows being mutually orthogonal unit vectors. After SVD, the left singular vector matrix is ​​multiplied by the transpose of the right singular vector matrix, resulting in a new 3x3 matrix. The determinant of this new matrix is ​​then checked. The determinant is a scalar value calculated from the nine elements of the matrix using a specific alternating multiplication and summation rule. If the determinant is positive 1, then this new matrix is ​​the optimal rotation matrix sought. If the determinant is negative 1, the right singular vector matrix needs to be corrected: multiply all three elements of the third column (i.e., the last column) of the right singular vector matrix by negative 1 (i.e., take their opposites), and then multiply the left singular vector matrix by the transpose of the corrected right singular vector matrix again. The resulting product is the optimal rotation matrix.

[0080] Using the optimal rotation matrix and the two obtained centroid coordinates, the corresponding optimal translation vector is calculated. The calculation method is as follows: First, the optimal rotation matrix is ​​multiplied by the centroid coordinate vector of the predicted point set according to the matrix multiplication rule to obtain a 3D intermediate result vector. This matrix multiplication rule is: the three elements of the first row of the rotation matrix are multiplied by the three components of the centroid vector and summed to obtain the first component of the intermediate result vector; the second and third rows are calculated similarly. Then, the corresponding components of the intermediate result vector are subtracted from the three components of the centroid coordinate vector of the measured point cloud, and the resulting three-dimensional vector is the optimal translation vector. The rotation matrix estimated in the current iteration is updated to the obtained optimal rotation matrix, and the currently estimated translation vector is updated to the optimal translation vector. Using the updated rotation matrix and translation vector, a rigid transformation is performed on all points in the measured point cloud (not limited to points in the inlier set): first, each point is rotated using the rotation matrix, and then the rotated coordinates are added to the translation vector. After the transformation, these measured points are mapped to the coordinate system of the known point set. For each transformed measured point, its nearest point is searched again in the known point set, and the spatial distance between the nearest points is calculated. The square of all the spatial distances between the nearest points is taken, the arithmetic mean of these squares is calculated, and then the square root is taken. The resulting value is the root mean square residual, in millimeters. The root mean square residual quantitatively reflects the overall deviation between the measured point cloud and the known point set under the current registration transformation. The smaller the value, the more accurate the registration. The calculated root mean square residual is compared with the preset convergence threshold of 0.1 millimeters. If either of the following two conditions is met, the algorithm is considered to have converged: Condition 1: The root mean square residual is less than or equal to 0.1 millimeters. Condition 2: The change in the root mean square residual in the most recent three consecutive iterations is all less than 0.01 millimeters (i.e., the decrease or increase in residual in each iteration compared to the previous iteration does not exceed 0.01 millimeters). If convergence is determined, the iteration terminates.

[0081] If the root mean square residual is greater than 0.1 mm and does not meet the stability condition of three consecutive changes, and the current iteration count is less than the maximum iteration count of 50, then the iteration count counter is incremented by 1, and the updated rotation matrix and translation vector are used as the new current estimate to continue the next iteration. If the iteration count has reached 50 but the convergence condition is still not met, then the iteration with the smallest root mean square residual is selected from all 50 iterations, and the rotation matrix and translation vector corresponding to that iteration are taken as the final registration result. From the optimal rotation matrix and translation vector obtained after registration convergence, six pose parameters are extracted. These six parameters completely describe the spatial position and spatial orientation of the medical device in the base coordinate system. The position parameters are directly taken from the three components of the translation vector: the first component represents the position offset of the origin of the medical device's local coordinate system along the first coordinate axis in the device's base coordinate system; the second component represents the position offset along the second coordinate axis; and the third component represents the position offset along the third coordinate axis. The units of the three position parameters are all millimeters. The orientation parameters are extracted from the rotation matrix according to the following rules. The pitch angle represents the rotation angle of the device around the first coordinate axis of the device's base coordinate system. Its value is the arcsine of the negative value of the element in the 3rd row, 1st column of the rotation matrix, in degrees. The yaw angle represents the rotation angle of the device around the second coordinate axis of the device's base coordinate system. Its value is the arctangent of the ratio of the element in the 2nd row, 1st column of the rotation matrix to the element in the 1st row, 1st column, in degrees. The roll angle represents the rotation angle of the device around the third coordinate axis of the device's base coordinate system. Its value is the arctangent of the ratio of the element in the 3rd row, 2nd column of the rotation matrix to the element in the 3rd row, 3rd column, in degrees. The values ​​of these three attitude angles range from -180 degrees to +180 degrees. The arctangent can be corrected using the quadrant information of the angle value to ensure that the value falls within this range. The three position parameters and three attitude parameters together constitute six values, forming the complete six-degree-of-freedom pose data of the medical device.

[0082] In a preferred embodiment of the present invention, step 5 is performed as follows: The current target pose is loaded from the surgical planning system. This target pose is generated preoperatively based on patient imaging data and surgical path planning, and includes three target positions (mm) and three target attitude angles (degrees). A position tolerance of 0.05 mm and an attitude tolerance of 0.1 degrees are included. The position deviations of the three positions in the current six-DOF pose are obtained by subtracting the target positions from the three position parameters. The total position deviation is the square root of the sum of the squares of the three deviations, representing the spatial straight-line distance between the current position and the target position. The initial deviation is obtained by subtracting the current attitude angle from the target attitude angle, and then angle normalization is performed: if it is greater than +180 degrees, 360 degrees are subtracted; if it is less than -180 degrees, 360 degrees are added, ensuring the deviation falls within the range of -180 to +180 degrees, guaranteeing the shortest rotation path. The total attitude deviation is the square root of the sum of the squares of the three normalized deviations.

[0083] If the total position deviation does not exceed 0.05 mm and the total attitude deviation does not exceed 0.1 degrees, the target pose is determined to have been reached, and the system enters pose holding mode, sending an arrival signal to the surgical planning system to trigger the loading of the next path point; otherwise, closed-loop control continues. Proportional gain coefficients are configured for the six degrees of freedom: 2.0 for the first and second translation axes, 1.5 for the third translation axis, 0.8 for the pitch and yaw axes, and 0.6 for the roll axis. The current deviation of each degree of freedom is multiplied by its proportional gain coefficient to obtain the proportional control component; the larger the deviation, the higher the output speed, and the speed automatically decreases as the deviation decreases. A deviation accumulation memory is maintained for each degree of freedom, and the current deviation is accumulated into the memory every control cycle (10 milliseconds); the translation axis memory is limited to ±100.0, and the rotation axis memory is limited to ±50.0 to prevent integral saturation. The accumulated value after limitation is multiplied by the integral gain coefficient (0.1 for translation axis, 0.05 for rotation axis) to obtain the integral control component, which eliminates steady-state error; small deviations accumulate over time to generate sufficient driving force to return to zero. The deviation change is obtained by subtracting the previous cycle deviation from the current cycle deviation for each degree of freedom. This deviation change rate is then divided by the cycle duration of 0.01 seconds. The rate of change is multiplied by the differential gain coefficient (0.05 for translation axis and 0.02 for rotation axis) to obtain the differential control component, which applies damping to prevent overshoot and oscillation.

[0084] The proportional, integral, and differential components are abbreviated to obtain the original composite control signal for each degree of freedom. Maximum velocity limits are applied: translation axis not exceeding 20 mm / s, rotation axis not exceeding 10 degrees / s. Dead zone processing is then applied: the absolute value of the translation axis control signal is zeroed if it does not exceed 0.01 mm / s, and the rotation axis control signal is zeroed if it does not exceed 0.01 degrees / s, eliminating micro-jitter caused by measurement noise. After processing, the final velocity commands for the 6 degrees of freedom are obtained. The Jacobian matrix (6 rows, joint number column) is calculated using the current angle of each joint and the kinematic parameters of the robotic arm. For rotational joints, the first 3 rows of the corresponding column are obtained by the cross product of the joint rotation axis direction vector and the joint-to-end position vector, and the last 3 rows are the rotation axis direction vectors. After constructing the Jacobian matrix, its pseudo-inverse matrix is ​​calculated (the standard inverse matrix is ​​obtained when the number of joints is equal to 6; for more than 6, the solution that minimizes the sum of squares of the joint velocities is obtained through algebraic operations). The pseudo-inverse matrix is ​​multiplied by the 6-degree-of-freedom velocity command vector to obtain the velocity commands for each joint.

[0085] Stepper motor driven joints: The motor step angle is 1.8 degrees per step, with 1 / 16 microstep subdivision, requiring 3200 pulses per revolution; the joint speed command is multiplied by 3200 and divided by 360 to obtain the pulse frequency, generating a square wave signal with a 50% duty cycle, the direction of which is determined by the speed sign, and packaged into a command frame. Servo motor driven joints: The joint speed is converted into motor speed through a reduction ratio, and the correspondence between the calibrated speed and the command is mapped to a control quantity, while current limiting is set, and packaged into a command frame. Each motor command frame is sent to the driver via a real-time control bus (communication cycle 10 milliseconds synchronized with the closed-loop cycle), while the position, speed, and current feedback of each motor are read from the driver.

[0086] The first safety monitoring item is joint position limit: an emergency stop and alarm will be triggered if the actual angle exceeds the preset limit. The second item is speed over-limit: an emergency stop will be triggered if the actual speed exceeds the maximum limit by 120% for more than 3 cycles (30 milliseconds). The third item is current overload: an emergency stop will be triggered if the actual current exceeds the rated current by 150% for more than 5 cycles (50 milliseconds). The fourth item is pose change: closed-loop control will be paused and the current position maintained if the total position change exceeds 5 mm or the total attitude change exceeds 5 degrees in adjacent cycles. It will automatically resume after the pose stabilizes. After the safety monitoring passes, return to step 1 to begin a new round of visual acquisition and control calculation.

[0087] Once the target pose is reached, the system enters a stable dwell state; the control cycle remains at 10 milliseconds, but the proportional and derivative gains are reduced to 1 / 10 of their normal values, and the integral accumulator is frozen; small-amplitude homing control is only generated when external disturbances cause deviations to exceed the tolerance, to avoid control oscillations near the target pose. After receiving the target pose of the next path point, all control parameters are restored to normal values, and the system enters the next closed-loop tracking stage.

[0088] like Figure 2As shown, embodiments of the present invention also provide a machine vision-based medical device positioning and control system, including: The processing module is used to acquire the original stereo image, extract the pixel grayscale gradient of the overexposed area based on the original stereo image, perform mask filtering processing, and obtain the initial stereo image. The calculation module is used to select three calibration anchor points in the initial binocular image to construct a reference triangular region, extract local curvature features within the reference triangular region, calculate the initial area of ​​the reference triangular region, and segment the reference triangular region based on the local curvature features to obtain multiple sub-grid regions. It then calculates the actual area of ​​each sub-grid region, allocates the theoretical area of ​​the corresponding sub-grid region from the initial area of ​​the reference triangular region according to the proportion of each sub-grid region within the reference triangular region, compares the actual area with the theoretical area determined based on the initial area to obtain area change features, and extracts the boundary morphology characteristics of each sub-grid region. Finally, it generates a grid deformation adjustment value based on the area change features and boundary morphology characteristics, and uses this grid deformation adjustment value to compensate and adjust the feature distribution within the sub-grid region, resulting in a feature extraction image containing multiple local grid regions. The correction module is used to extract the corner coordinate offset of each local grid area based on the feature extraction image, calculate the non-rigid deformation compensation vector, and obtain the compensated binocular feature point set. The extraction module is used to extract three-dimensional spatial coordinates from the compensated binocular feature point set to perform binocular visual pose calculation and obtain six-degree-of-freedom pose data. The control module is used to calculate the position and attitude deviations between the six-degree-of-freedom pose data and the preset target pose, perform closed-loop feedback calculations, and obtain motor control commands.

[0089] It should be noted that this system is a system corresponding to the above method. All implementation methods in the above method embodiments are applicable to this embodiment and can achieve the same technical effect.

[0090] Embodiments of the present invention also provide a computing device, including: a processor and a memory storing a computer program, wherein the computer program, when executed by the processor, performs the method described above. All implementations in the above method embodiments are applicable to this embodiment and can achieve the same technical effects.

[0091] Embodiments of the present invention also provide a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the method described above. All implementations in the above method embodiments are applicable to this embodiment and can achieve the same technical effects.

[0092] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A machine vision-based positioning and control method for medical equipment, characterized in that, The method includes: Step 1: Obtain the original stereo image. Based on the original stereo image, extract the pixel grayscale gradient of the overexposed area and perform mask filtering to obtain the initial stereo image. Step 2: Select three calibration anchor points in the initial binocular image to construct a reference triangle region and extract local curvature features within the reference triangle region; calculate the initial area of ​​the reference triangle region and segment it based on the local curvature features to obtain multiple sub-grid regions; calculate the actual area of ​​each sub-grid region and allocate the theoretical area of ​​the corresponding sub-grid region from the initial area of ​​the reference triangle region according to the positional proportion of each sub-grid region in the reference triangle region; compare the actual area with the theoretical area determined based on the initial area to obtain area change features and extract the boundary morphology characteristics of each sub-grid region; generate a grid deformation adjustment value based on the area change features and boundary morphology characteristics, and compensate and adjust the feature distribution within the sub-grid region using the grid deformation adjustment value to obtain a feature extraction image containing multiple local grid regions; Step 3: Based on the feature extraction image, extract the corner coordinate offset of each local grid region to calculate the non-rigid deformation compensation vector and obtain the compensated binocular feature point set; Step 4: Based on the compensated binocular feature point set, extract the three-dimensional spatial coordinates to perform binocular visual pose calculation and obtain six-degree-of-freedom pose data. Step 5: Based on the six-degree-of-freedom pose data, calculate the position deviation and attitude deviation between the pose and the preset target pose, perform closed-loop feedback calculation, and obtain motor control commands.

2. The machine vision-based medical device positioning and control method according to claim 1, characterized in that, Three calibration anchor points are selected in the initial binocular image to construct a reference triangular region. Local curvature features within the reference triangular region are extracted, including: The initial binocular image is marked and detected to identify the first marker image region corresponding to the upper left vertex of the front face of the medical device, the second marker image region corresponding to the upper right vertex of the front face of the medical device, and the third marker image region corresponding to the lower midpoint of the rear face of the medical device. The center pixel coordinates of the first marker image region, the second marker image region, and the third marker image region are extracted to obtain the calibration anchor point coordinate set. Using the three center pixel coordinates in the set of calibration anchor points as vertices, a triangular pixel region is formed within the initial binocular image as a reference triangular region. For each pixel in the reference triangle region, the rate of change of the neighborhood gray-level gradient direction is calculated. The curvature response value of the pixel is generated from the rate of change of the gray-level gradient direction. Pixels with curvature response values ​​greater than a preset curvature threshold are selected as curvature feature points. The pixel coordinates and curvature response values ​​of all curvature feature points are collected to form local curvature features within the reference triangle region.

3. The machine vision-based medical device positioning and control method according to claim 2, characterized in that, The initial area of ​​the reference triangular region is calculated, and the reference triangular region is segmented based on local curvature features to obtain multiple sub-mesh regions, including: The number of pixels contained in the triangular region formed by the three center pixel coordinates in the set of calibration anchor points is counted, and the counted number of pixels is used as the initial area of ​​the reference triangular region. Extract the pixel coordinates of all curvature feature points from the local curvature features, perform density clustering on the pixel coordinates of all curvature feature points to obtain multiple clusters, extract the cluster center pixel coordinates of each cluster, and determine the cluster center pixel coordinates as the region segmentation node. Using all region segmentation nodes as internal dividing base points, connect adjacent region segmentation nodes within the reference triangle region and extend the connecting line segments to the boundary of the reference triangle region to form multiple dividing line segments. These dividing line segments divide the reference triangle region into multiple adjacent and non-overlapping sub-grid regions.

4. The machine vision-based medical device positioning and control method according to claim 3, characterized in that, Using all region segmentation nodes as internal partitioning base points, adjacent region segmentation nodes are connected within the reference triangular region, and the connecting lines are extended to the boundary of the reference triangular region to form multiple partitioning lines. These partitioning lines divide the reference triangular region into multiple adjacent and non-overlapping sub-mesh regions, including: Use all region segmentation nodes as internal partitioning base points; select the two internal partitioning base points with the closest spatial distance from the internal partitioning base points, connect the two selected internal partitioning base points with a line segment to form an internal connection line segment, repeat the selection and connection until all internal partitioning base points are interconnected through the internal connection line segment to obtain the internal mesh skeleton. For each internal connecting line segment in the internal mesh skeleton, extend the internal connecting line segment along the directions at both ends of the line segment so that the extension line intersects the boundary of the reference triangular region. The internal connecting line segment and the extension line segment from the internal dividing base point to the boundary intersection point are used together as a dividing line segment. The reference triangular region is divided into multiple adjacent and non-overlapping sub-mesh regions by all dividing line segments.

5. The machine vision-based medical device positioning and control method according to claim 4, characterized in that, Calculate the actual area of ​​each sub-grid region, compare the actual area with the theoretical area determined based on the initial area to obtain area change characteristics, and extract the boundary morphology characteristics of each sub-grid region, including: For each sub-grid region, count the total number of pixels contained within the region, and use the counted number of pixels as the actual area of ​​the corresponding sub-grid region; For each sub-grid region, the difference between the actual area and the theoretical area is calculated to obtain the area deviation. The area deviation of all sub-grid regions constitutes the area change feature. For each sub-grid region, a continuous sequence of boundary pixels is extracted along the boundary contour. The mean angle of the direction change of the line connecting adjacent pixels in the boundary pixel sequence is calculated. The mean angle of the direction change is used as the boundary tortuosity of the corresponding sub-grid region. The boundary tortuosity of all sub-grid regions is collected to obtain the boundary morphology characteristics.

6. The machine vision-based medical device positioning and control method according to claim 5, characterized in that, Based on the area change characteristics and boundary morphology features, a grid deformation adjustment value is generated. This value is then used to compensate for and adjust the feature distribution within the sub-grid region, resulting in a feature extraction image containing multiple local grid regions, including: The area deviation of each sub-grid region is obtained from the area change characteristics, and the area deformation coefficient is calculated based on the area deviation; the boundary tortuosity of each sub-grid region is obtained from the boundary morphology characteristics, and the boundary deformation constraint coefficient is calculated based on the boundary tortuosity. Multiply the area deformation coefficient of each sub-grid region by the boundary deformation constraint coefficient to obtain the comprehensive deformation coefficient; multiply the comprehensive deformation coefficient by the original coordinates of the pixels in the sub-grid region to obtain the preliminary adjustment coordinates; determine the translation direction based on the sign of the area deviation, determine the translation magnitude based on the absolute value of the area deviation, and use the translation direction and magnitude to perform translation correction on the preliminary adjustment coordinates to obtain the final adjustment coordinates; The original grayscale values ​​of the pixels are resampled and interpolated according to the final adjusted coordinates to obtain new grayscale values. The new grayscale values ​​are mapped to the output position of the reference triangle region to form a compensated and adjusted reference triangle region image. The compensated and adjusted reference triangle region image is stitched together with the image region outside the reference triangle region in the initial binocular image to obtain the feature extraction image. The step of determining the translation direction based on the sign of the area deviation and determining the translation magnitude based on the absolute value of the area deviation includes: if the area deviation is positive, the translation direction is the opposite direction from the geometric center of the sub-grid region to the overall geometric center of the reference triangle region; if the area deviation is negative, the translation direction is the direction from the geometric center of the sub-grid region to the overall geometric center of the reference triangle region, where the coordinates of the overall geometric center of the reference triangle region are the average of the coordinates of the three calibration anchor points; the translation magnitude is the absolute value of the area deviation divided by 100.

7. The machine vision-based medical device positioning and control method according to claim 6, characterized in that, Based on the feature extraction image, the corner coordinate offsets of each local grid region are extracted to calculate the non-rigid deformation compensation vector, resulting in the compensated binocular feature point set, including: Corner points are extracted from each local grid region of the feature extraction image, and the actual pixel coordinates of each corner point are obtained. The theoretical coordinate reference value is determined based on the area deviation and boundary curvature of the local grid region where the corner point is located, and the coordinate offset between the actual pixel coordinates and the theoretical coordinate reference value is calculated. The coordinate offsets of all corner points are used as discrete control points, and a non-rigid deformation compensation vector field covering the entire feature extraction image is generated through interpolation. The compensation vector corresponding to the position of each corner point in the non-rigid deformation compensation vector field is superimposed on the actual pixel coordinates of the corner point to obtain the compensated coordinates of each corner point. The coordinates of all corner points extracted and compensated in the left and right views of the stereo image are summarized to form the compensated stereo feature point set.

8. A machine vision-based positioning control system for medical devices, wherein the system implements the method as described in any one of claims 1 to 7, characterized in that, include: The processing module is used to acquire the original stereo image, extract the pixel grayscale gradient of the overexposed area based on the original stereo image, perform mask filtering processing, and obtain the initial stereo image. The calculation module is used to select three calibration anchor points in the initial binocular image to construct a reference triangular region and extract local curvature features within the reference triangular region. Calculate the initial area of ​​the reference triangular region, and divide the reference triangular region based on the local curvature features to obtain multiple sub-grid regions; calculate the actual area of ​​each sub-grid region, and allocate the theoretical area of ​​the corresponding sub-grid region from the initial area of ​​the reference triangular region according to the position ratio of each sub-grid region in the reference triangular region; The actual area is compared with the theoretical area determined based on the initial area to obtain the area change characteristics, and the boundary morphology characteristics of each sub-grid region are extracted. The grid deformation adjustment value is generated by combining the area change characteristics and boundary morphology characteristics. The feature distribution in the sub-grid region is compensated and adjusted by the grid deformation adjustment value to obtain a feature extraction image containing multiple local grid regions. The correction module is used to extract the corner coordinate offset of each local grid area based on the feature extraction image, calculate the non-rigid deformation compensation vector, and obtain the compensated binocular feature point set. The extraction module is used to extract three-dimensional spatial coordinates from the compensated binocular feature point set to perform binocular visual pose calculation and obtain six-degree-of-freedom pose data. The control module is used to calculate the position and attitude deviations between the six-degree-of-freedom pose data and the preset target pose, perform closed-loop feedback calculations, and obtain motor control commands.

9. A computing device, characterized in that, include: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a program that, when executed by a processor, implements the method as described in any one of claims 1 to 7.