Method for detecting position deviation of magnetic material product
Patent Information
- Application Number
- CN202611022320.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-10
- Publication Date
- 2026-10-20
- Estimated Expiration
- 2046-07-10
AI Technical Summary
1、检测易受产品状态影响,毛刺、脏污等对检测数据影响较大,易造成检测误差;
1、本发明通过单圆定位孔和跑道形定位槽的三点建系算法建立稳定的目标坐标系,通过形状模板匹配和仿射变换进行位姿矫正,结合亚像素边缘提取算法,有效排除了毛刺、脏污等因素对边缘定位的干扰,提高了检测的稳定性和鲁棒性。
Smart Images

Figure CN122523963B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of magnet testing technology, and in particular to a method for detecting positional deviations in magnetic material products. Background Technology
[0002] Position deviation measurement of PET magnetic products is a key indicator for controlling the shape and relative position of parts, directly affecting the assembly accuracy and magnetic circuit performance of magnets. Excessive position deviation leads to inaccurate magnetic pole positions, affecting the symmetry and balance of the magnetic circuit, especially crucial in multi-pole magnetization and precision positioning applications. The accuracy range for position deviation measurement is typically extremely stringent. To ensure product quality, the standard dimensional tolerance must be approximately ±0.1mm, and the visual tolerance must be 0.2 times the standard dimensional tolerance, i.e., 0.02mm.
[0003] Currently, the detection of positional deviations in PET magnetic products mainly relies on large-scale, high-precision testing equipment. This type of equipment has the following shortcomings: 1. The test results are easily affected by the condition of the product. Burrs, dirt, etc., have a significant impact on the test data and can easily cause test errors. 2. Current testing is based solely on manual loading and unloading, with only one product allowed at a time. This is inconvenient, labor-intensive, and only allows for random sampling of a portion of the products to check their pass rate. Full inspection would be too costly in terms of both manpower and time, and would also make it impossible to trace production data. Summary of the Invention
[0004] The purpose of this invention is to provide a method for detecting positional deviations in magnetic materials, thereby achieving high-precision and high-efficiency detection of magnetic materials and ensuring product quality.
[0005] To achieve the above objectives, the solution of the present invention is as follows: A method for detecting positional deviation in magnetic materials includes the following steps: S1: Image acquisition, acquiring an image of the object to be tested, including a transparent fixture, a transparent PET substrate placed on the fixture, and a magnet to be tested placed on the PET substrate; The transparent fixture has a pre-set positioning area, which includes a single circular positioning hole on the left, a racetrack-shaped positioning groove on the right, and multiple reference holes corresponding to the shape and theoretical design position of the magnet. The racetrack-shaped positioning groove is composed of two arcs whose centers do not coincide. S2: Feature point extraction: The center point of the single circular positioning hole and the center of the two arcs in the racetrack-shaped positioning groove are extracted by image processing algorithms. S3: Establish a coordinate system. Take the center point of the single circular positioning hole as the origin of the coordinate system, calculate the midpoint of the center of the two arcs in the racetrack-shaped positioning groove, take the line connecting the origin and the midpoint as the X-axis, and take the direction perpendicular to the X-axis as the Y-axis, thereby establishing the target coordinate system. S4: Magnet detection, based on the target coordinate system, to detect the position or size of the magnet to be detected.
[0006] In a preferred embodiment, in step S1, images are acquired using an industrial camera, which is a 20-megapixel monochrome camera equipped with a 0.246x telecentric lens and a parallel backlight, with a single pixel accuracy of 0.01mm.
[0007] In a preferred embodiment, after step S1 and before step S2, step S11 is further included: using a shape template matching algorithm to perform pose correction on the acquired image, calculating the affine transformation matrix, and performing an affine transformation on the image.
[0008] In a preferred embodiment, in step S11, a shape template is created using Halcon's create_generic_shape_model operator, the template is found using the find_generic_shape_model operator to obtain the row coordinates, column coordinates, and angle of the matching position, the affine transformation matrix is calculated using the vector_angle_to_rigid operator, and the image is subjected to affine transformation using the affine_trans_image operator.
[0009] In a preferred embodiment, step S4, the position or size detection of the magnet to be detected includes: extracting sub-pixel edges of the magnet region and calculating the center point of each magnet region.
[0010] The preferred approach for subpixel edge extraction of the magnet region includes: using Halcon's edges_sub_pix operator and a Canny filter, setting the Gaussian smoothing standard deviation to 1, and setting the low threshold of the hysteresis dual threshold to 20 and the high threshold to 40.
[0011] In a preferred embodiment, the method for calculating the center point of the magnet region includes: extracting the sub-pixel edges of the four sides of the magnet region, calculating the midpoint of each side, connecting the midpoints of opposite sides to obtain two center lines, and defining the intersection of the two center lines as the center point of the magnet region.
[0012] The preferred scheme also includes a step of segmenting the extracted sub-pixel edge contours: using Halcon's segment_contours_xld operator, the contours are simultaneously segmented into straight line segments and arcs, where the maximum allowable error for straight line fitting is 4 pixels and the maximum allowable error for arc fitting is 2 pixels.
[0013] In the preferred scheme, when performing circle fitting on the segmented arc contour, an algebraic fitting algorithm is used, with the maximum number of fitting points set to 20, the maximum closure distance to 5 pixels, and the number of clipping endpoints to 1.
[0014] In a preferred embodiment, after step S4, step S5 is further included: saving the test results in CSV file format, the file containing the test timestamp and the dimension field corresponding to the product drawing.
[0015] After adopting the above solution, the beneficial effects of the present invention are as follows: 1. This invention establishes a stable target coordinate system through a three-point system establishment algorithm using a single circular positioning hole and a racetrack-shaped positioning groove. It performs pose correction through shape template matching and affine transformation, and combines a sub-pixel edge extraction algorithm to effectively eliminate interference from factors such as burrs and dirt on edge positioning, thereby improving the stability and robustness of detection.
[0016] 2. This invention utilizes a testing scheme combining a transparent fixture, a transparent PET substrate, and an industrial camera to simultaneously inspect multiple magnets, achieving online automated full inspection of magnetic materials and significantly improving testing efficiency. Furthermore, by saving the test results in CSV file format, including the test timestamp and dimension fields corresponding to the product drawings, it achieves full record-keeping and traceability of product test data, facilitating subsequent statistical analysis and quality feedback adjustments for preceding surface mount processes. Attached Figure Description
[0017] Figure 1 This is a schematic diagram of the detection process in an embodiment of the present invention; Figure 2 This is a schematic diagram of the template search results when using a shape template matching algorithm to perform pose correction on the acquired image in an embodiment of the present invention; Figure 3 This is a schematic diagram illustrating the reflection transformation performed based on the found template image when the shape template matching algorithm is used to correct the pose of the acquired image in an embodiment of the present invention. Figure 4 This is a schematic diagram of semicircle fitting in an embodiment of the present invention; Figure 5 This is a top view of the relative positions of the magnet and the transparent fixture in an embodiment of the present invention; Figure 6 This is a schematic diagram illustrating the establishment of the X-axis in an embodiment of the present invention; Figure 7 This is a schematic diagram illustrating the establishment of the Y-axis in an embodiment of the present invention; Figure 8 This is a schematic diagram of the sub-pixel edges of the four sides of the magnet region extracted in an embodiment of the present invention; Figure 9This is a schematic diagram of two centerlines obtained by connecting the midpoints of opposite sides of the magnet in an embodiment of the present invention; Figure 10 This is a schematic diagram in an embodiment of the present invention where the intersection of the two center lines is defined as the center point of the magnet region; Figure 11 This is a schematic diagram illustrating the detection of defects on a PET substrate as described in an embodiment of the present invention.
[0018] Label Explanation: 1. Transparent fixture; 2. Magnet; 3. Reference hole; 4. Positioning hole; 5. Positioning groove. Detailed Implementation
[0019] The present invention will now be further described in conjunction with the accompanying drawings and specific embodiments.
[0020] This embodiment provides a method for detecting positional deviations in magnetic material products, such as... Figure 1 As shown, this method is developed and implemented based on Halcon and C#, and is applied to the online full inspection of PET magnetic products.
[0021] Halcon is a comprehensive standard machine vision software with full feature coverage. It is an efficient development tool widely used in the field of industrial automation, and its algorithms can provide high-precision and robust processing results.
[0022] C#, built on the .NET framework, can quickly construct feature-rich and interactive WinForm or WPF desktop applications. Its clear object-oriented programming facilitates the management of complex business processes, making it suitable for developing systems requiring complex user interactions. Simultaneously, its automatic garbage collection mechanism effectively avoids memory leaks and other issues. The combination of C# and Halcon precisely balances development efficiency, runtime performance, and system maintainability. C# seamlessly calls Halcon operators through the HalconDotNet interface, greatly simplifying the programming process; leveraging Halcon's multi-core and GPU acceleration capabilities, combined with C#'s multi-threaded parallel processing, decomposes and executes visual tasks, significantly improving system efficiency; C# can communicate with PLCs and call mainstream camera SDKs, realizing a complete process from hardware control to visual processing, and its strongly typed language characteristics can also detect errors during the compilation phase, improving code quality.
[0023] like Figure 5As shown, the transparent fixture 1 used in this embodiment has a pre-set positioning area. Within this area are a single circular positioning hole 4 on the left, a racetrack-shaped positioning groove 5 on the right, and multiple reference holes 3 corresponding to the shape and theoretically designed position of the magnet 2. The racetrack-shaped positioning groove 5 is formed by two non-coincident arcs connected by straight lines, resembling a running track. This asymmetrical positioning structure design provides a foundation for establishing a stable target coordinate system.
[0024] like Figure 6 As shown in the specific testing interface diagram, the gray area represents a transparent fixture with reference holes corresponding to the shape and theoretically designed position of the magnets. A transparent PET substrate is pre-placed on the transparent fixture, and the magnets to be tested are pre-placed on the PET substrate, with their positions corresponding to the reference holes on the fixture. The magnets can be rectangular or triangular in shape. Figure 6 A rectangle with one corner cut off from each of its four corners (also referred to as a rectangle in this embodiment). During inspection, the fixture, PET substrate, and magnet enter the inspection station together, and an industrial camera captures an image of the object to be inspected, including all three. Since both the PET substrate and the fixture are transparent, the camera can simultaneously acquire an image showing the positional relationship between the magnet and the reference hole in the transparent fixture below.
[0025] Specifically, the detection method of the present invention includes the following steps: Step S1: Image Acquisition An industrial camera is used to acquire images of a transparent fixture, a transparent PET substrate placed on the fixture, and a magnet to be tested placed on the PET substrate. Since both the PET substrate and the fixture are transparent, the camera can simultaneously acquire images showing the positional relationship between the magnet and a reference hole in the transparent fixture below. In this embodiment, a camera is selected based on a detection accuracy of 0.015mm. The maximum product size is 31.01mm × 11.20mm, and the product occupies 60% of the field of view, resulting in a calculated field of view of 52mm × 19mm. To improve detection robustness, pixel conversion is performed based on a 0.01mm single-pixel accuracy: 52 / 0.01 = 5200 pixels. Therefore, a 20-megapixel monochrome camera is selected, with a resolution of 5472 × 3648, a target surface size of 1 inch, a pixel size of 2.4μm × 2.4μm, and a magnification of 0.0024 / 0.01 = 0.24x. The camera is equipped with a 0.246x telecentric lens and a parallel backlight. The telecentric lens, with its parallel optical path design, exhibits lens distortion of less than 0.1%, a large depth of field, and good resolution uniformity, making it particularly advantageous for dimensional inspection. The parallel backlight provides clear black and white imaging, stable boundary points, high measurement repeatability, and is less affected by tilt, offering significant advantages for dimensional measurement. With the above hardware configuration, a single pixel accuracy of 0.01mm is achieved, meeting the requirement of a detection accuracy of ±0.015mm. The accompanying drawings of this embodiment do not illustrate the specific structures of the industrial camera and the parallel backlight, which are well known to those skilled in the art. The specific relative positions of the components are as follows: the transparent fixture is horizontally placed between the industrial camera and the parallel backlight, the lens of the industrial camera faces downwards, and the optical path of the parallel backlight faces upwards.
[0026] Step S11: Template Training and Posture Correction like Figures 1 to 3 As shown, after step S1 and before step S2, a shape template matching algorithm is used to correct the pose of the acquired image. The shape template is obtained through template training. Specifically, the operator manually draws a rectangular Region of Interest (ROI) on the transparent fixture image of the magnet to be detected through a human-computer interaction interface. This ROI is used to limit the search range for subsequent shape model generation. Subsequently, the system uses the edge features extracted within the ROI to call Halcon's create_shape_model operator to generate a shape model for subsequent matching. This process is the fundamental step for achieving high-precision magnet positioning and pose correction, ensuring that the model can stably match in complex backgrounds during subsequent detection. The principle of image affine transformation is to maintain the "flatness" and "parallelism" of the image, that is, straight lines in the original image remain straight lines after transformation, and parallel lines remain parallel after transformation. It maps pixels in the image from one coordinate system to another through a linear transformation (rotation, scaling, shearing) plus a translation vector.
[0027] Specifically, a generic shape model is created using Halcon's `create_generic_shape_model` operator, which can be trained to adapt to complex deformations, lighting changes, and high noise. After creating the template, it is trained using the `train_generic_shape_model` operator.
[0028] Then set the search model parameters: The function `set_generic_shape_model_param(ModelID,min_score',0.5)` sets the minimum matching score to 0.5. The function `set_generic_shape_model_param(ModelID,num_matches',1)` sets the maximum number of matches to 1. The function `set_generic_shape_model_param(ModelID,greediness',0.7)` sets the greediness level to 0.7. The `set_generic_shape_model_param(ModelID, angle_start', 0.0)` method sets the starting angle for the search to 0.0. The function `set_generic_shape_model_param(ModelID,'angle_end',3.14)` sets the search end angle to 3.14. The `find_generic_shape_model` operator is used to find the template and obtain the row coordinates, column coordinates, and angle of the matching position. get_generic_shape_model_result(MatchResultID,'best','row',RowMatch); get_generic_shape_model_result(MatchResultID,'best','column',ColMatch); get_generic_shape_model_result(MatchResultID,'best','angle',AngleMatch); The affine transformation matrix is then calculated using the `vector_angle_to_rigid` operator, and the image is then subjected to an affine transformation using the `affine_trans_image` operator. That is: vector_angle_to_rigid(RowMatch,ColMatch,AngleMatch,Row,Column,0,MovementOfModel); affine_trans_image(Image, ImageAffineTrans, MovementOfModel, 'constant', 'false'); The mathematical principle of the reflection transformation matrix is as follows: Let M be the affine transformation matrix calculated by the vector_angle_to_rigid operator, and let it be of the form: ; In this reflection transformation matrix, the parameters of the transformation matrix are specified as (a, b, c, d, e, f). For any pixel point (x, y) in the image, it is represented as (x, y, 1) in homogeneous coordinates. The output coordinates after affine transformation are (x', y') = (a*x + b*y + c, d*x + e*y + f).
[0029] In actual implementation, a reverse mapping plus interpolation method is used for processing: For each pixel location (u, v) in the output image (transformed image), the inverse transform M is performed. -1 Calculate the corresponding coordinates (x, y) of this location in the original target image. s y s Because (x) s y s The coordinates are usually not integers, so bilinear interpolation or nearest neighbor interpolation is used to obtain the pixel value of that point. By traversing all output pixels, the corrected image is finally generated. The entire process of the above inverse mapping and interpolation is automatically implemented by the affine_trans_image operator.
[0030] By performing affine transformations on images using templates, the positions of the detection boxes can be recorded, avoiding repeated drawing operations and improving the ease of operation of the algorithm program.
[0031] Step S2: Feature Point Extraction The center point of the single circular positioning hole and the centers of the two arcs in the racetrack-shaped positioning groove are extracted using image processing algorithms. Specifically, the image is first preprocessed and the region of interest is cropped. Then, the same sub-pixel edge extraction, contour segmentation, and circle fitting algorithms as in step S4 are used to calculate the coordinates of each center.
[0032] Step S3: Establishing the coordinate system like Figure 6 and Figure 7As shown, the center point of the single circular positioning hole is taken as the origin of the coordinate system. The midpoint of the centers of the two arcs in the racetrack-shaped positioning groove is calculated. The line connecting the origin and this midpoint is taken as the X-axis, and the direction perpendicular to the X-axis is taken as the Y-axis, thus establishing the target coordinate system. Specifically, this is implemented through the following Halcon code: Three-point fitted line -- X-axis dev_close_window(); dev_open_window(0,0,912,608,'black',WindowHandle4); dev_display(ImageAffineTrans); Calculate the midpoint of the centers of the two arcs. RowMid:=(Parameter_circle2[0]+Parameter_circle3[0]) / 2; ColMid:=(Parameter_circle2[1]+Parameter_circle3[1]) / 2; PointMid:=[RowMid,ColMid]; Establish X-axis RowSet:=[Parameter_circle1[0],PointMid[0]]; ColSet:=[Parameter_circle1[1],PointMid[1]]; gen_contour_polygon_xld(LineContour,RowSet,ColSet); In this system, Parameter_circle1 represents the center coordinates of the single circular positioning hole, while Parameter_circle2 and Parameter_circle3 represent the center coordinates of the two arcs within the racetrack-shaped positioning groove. The Y-axis is perpendicular to the X-axis, with the center of the single circle as the reference point, following a right-handed coordinate system. There is no need to distinguish the coordinate axis directions; the final determination is the absolute distance from the magnet to the reference. This three-point coordinate system construction method fully utilizes the symmetry of the double circles on the right, resulting in a more stable coordinate system with strong anti-interference capabilities.
[0033] Step S4: Magnet Detection Based on the established target coordinate system, the position or size of the magnet to be detected is measured. Specifically, this includes: extracting sub-pixel edges of the magnet region and calculating the center point of each magnet region.
[0034] Combination Figure 4The complete algorithm flow for sub-pixel edge extraction, contour segmentation, and circle fitting is as follows: First, the `edges_sub_pix` operator is used to extract sub-pixel precision edges from the cropped image. A Canny filter is used, with the Gaussian smoothing standard deviation set to Alpha=1, and a hysteresis double threshold of Low=20 and High=40. The Canny algorithm achieves a good balance between noise resistance and edge localization. Its internal steps include: Gaussian smoothing → gradient magnitude and direction → non-maximum suppression → double-threshold hysteresis connection. Alpha=1 represents the standard deviation of Gaussian smoothing, controlling the smoothing degree; Low=20 and High=40 are lower thresholds, which detect more edges (including weak edges and noise), ensuring the extraction of edge details.
[0035] Secondly, the selected_contours_xld operator is used to perform preliminary filtering of the extracted contours, and the contour length filtering range is set to 0.5 to 200 pixels.
[0036] Then, Halcon's segment_contours_xld operator is used to segment the filtered contours into straight line segments or arcs / circles. Mode='lines_circles' is set, which means that the contours are segmented into straight line segments and arcs / circles at the same time. SmoothCont=5 is a medium-intensity smoothing, which is suitable for contours with more noise and avoids the influence of burrs. MaxLineDist=4 is the maximum allowable error of straight line fitting, which is 4 pixels. If the contour segment deviates from the fitted line by more than 4 pixels, it will be segmented at that point. MaxCircleDist=2 is the maximum allowable error of circle / arc fitting, which is 2 pixels. When trying to fit the contour segment into an arc / circle, if the fitting error exceeds 2 pixels, the arc will be abandoned and the segment will be segmented by a straight line instead.
[0037] Finally, the `fit_circle_contour_xld` operator is used to perform circle fitting on the segmented circular contour. `Algorithm='algebraic'` is set, which is an algebraic fitting algorithm that minimizes the algebraic distance from points to the circle. This algorithm is fast and has moderate sensitivity to noise. `MaxNumPoints=20` sets the maximum number of points used for fitting to 20. If the number of contour points exceeds this value, it is uniformly downsampled to 20 points. `MaxClosureDist=5` sets the maximum closure distance to 5 pixels. If the distance between the first and last points of the contour is less than this value, it is considered a closed circle. `ClippingEndPoints=1` sets the number of clipped endpoints to 1, removing a specified number of points from both ends of the contour before fitting to avoid endpoint noise. `Iterations=2` indicates that points with a distance greater than twice the residual standard deviation are treated as outliers and removed.
[0038] like Figures 8 to 10 As shown, the method for calculating the center point of the magnet region is as follows: extract the sub-pixel edges of the four sides of the magnet region, calculate the midpoint of each side, connect the midpoints of opposite sides to obtain two center lines, and define the intersection of the two center lines as the center point of the magnet region. Compared with the region centroid method, this method is more resistant to the influence of edge burrs.
[0039] Then, the vertical distances from the center point of each magnet region to the X and Y axes of the target coordinate system are calculated to obtain the X-axis distance and Y-axis distance, which are used as the position deviation detection results. Specifically, this is implemented using the following Halcon code: Intersection of the midlines; intersection_lines(LineLeftCenX,LineLeftCenY,LineRightCenX,LineRightCenY,LineUpCenX,LineUpCenY,LineDownCenX,LineDownCenY,CenterX,CenterY,IsOverlapping4); dev_set_color('blue'); gen_cross_contour_xld(CenterPoint, CenterX, CenterY, 15, 0); dev_display(CenterPoint); Distance to X-axis distance_pl(CenterX,CenterY,Parameter_circle1[0],Parameter_circle1[1],PointMid[0],PointMid[1],Distance); projection_pl(CenterX,CenterY,Parameter_circle1[0],Parameter_circle1[1],PointMid[0],PointMid[1],FootX,FootY); disp_line(WindowHandle7,CenterX,CenterY,FootX,FootY); disp_cross(WindowHandle7,FootX,FootY,15,0.78539); Distance to Y-axis distance_pl(CenterX,CenterY,Parameter_circle1[0],Parameter_circle1[1],RowProj,ColProj,Distance1); projection_pl(CenterX,CenterY,Parameter_circle1[0],Parameter_circle1[1],RowProj,ColProj,FootX1,FootY1); disp_line(WindowHandle7,CenterX,CenterY,FootX1,FootY1); disp_cross(WindowHandle7,FootX1,FootY1,15,0.78539); Step S5: Data Saving The test results are saved in CSV file format, containing a test timestamp and corresponding dimension fields from the product drawings. As shown in Table 1, the dimension fields include: SPC_A1, SPC_A2, PC_B, PC_C, SPC_D, SPC_E1, SPC_E2, SPC_E3, SPC_F, and SPC_G, corresponding to the dimensional requirements at various locations in the product drawings. The saved data can be used for subsequent statistical analysis or quality assessment, achieving product data traceability and facilitating feedback and adjustment of the accuracy of preceding surface mount technology (SMT) processes.
[0040] Table 1. CSV file format table of test results
[0041] The method in this embodiment has been verified in practice, and the detection accuracy reaches ±0.015mm, with a tolerance of less than 0.015mm compared with high-precision detection equipment.
[0042] Table 2. Comparison of Test Data with Existing Test Equipment Tolerances
[0043] As shown in Table 2, the differences between the dimensional inspection data (including SPC_A, SPC_B, PC_C, SPC_L, SPC_F, SPC_H, SPC_I1, SPC_I2, SPC_I3, SPC_K, SPC_L, etc.) and the quality inspection data are all within 0.014 mm, and the single inspection time is less than 150 ms, which meets the production efficiency requirements of online full inspection.
[0044] Furthermore, to verify robustness, this embodiment also involves coating a small amount of dirt / creating slight burrs on the PET substrate, such as... Figure 11 As shown, the stain corresponds to the right side of the circular positioning hole. After repeated measurement and testing ten times, the repeatability accuracy of the measurement size is still <0.01mm, indicating that there are no misjudgments in the test results and the interference of burrs can be eliminated.
[0045] The directional terms used in this specification are defined relative to the structures shown in the accompanying drawings. They are relative concepts and may therefore vary depending on their location and usage. Therefore, these or other directional terms should not be interpreted as restrictive.
[0046] The above description is only a preferred embodiment of the present invention and is not intended to limit the design of this case. All equivalent changes made based on the key design features of this case shall fall within the protection scope of this case.
Claims
1. A method for detecting positional deviation in magnetic material products, characterized in that: Includes the following steps: S1: Image acquisition, acquiring an image of the object to be tested, including a transparent fixture, a transparent PET substrate placed on the fixture, and a magnet to be tested placed on the PET substrate; The transparent fixture has a pre-set positioning area, which includes a single circular positioning hole on the left, a racetrack-shaped positioning groove on the right, and multiple reference holes corresponding to the shape and theoretical design position of the magnet. The racetrack-shaped positioning groove is composed of two arcs whose centers do not coincide. S2: Feature point extraction: The center point of the single circular positioning hole and the center of the two arcs in the racetrack-shaped positioning groove are extracted by image processing algorithms. S3: Establish a coordinate system. Take the center point of the single circular positioning hole as the origin of the coordinate system, calculate the midpoint of the center of the two arcs in the racetrack-shaped positioning groove, take the line connecting the origin and the midpoint as the X-axis, and take the direction perpendicular to the X-axis as the Y-axis, thereby establishing the target coordinate system. S4: Magnet detection, based on the target coordinate system, to detect the position or size of the magnet to be detected.
2. The method for detecting positional deviation of magnetic material products as described in claim 1, characterized in that: In step S1, images are acquired using an industrial camera, which is a 20-megapixel monochrome camera equipped with a 0.246x telecentric lens and a parallel backlight, with a single pixel accuracy of 0.01mm.
3. The method for detecting positional deviation of magnetic material products as described in claim 1, characterized in that: After step S1 and before step S2, step S11 is also included: using a shape template matching algorithm to perform pose correction on the acquired image, calculating the affine transformation matrix, and performing an affine transformation on the image.
4. The method for detecting positional deviation of magnetic material products as described in claim 3, characterized in that: In step S11, a shape template is created using Halcon's create_generic_shape_model operator, the template is found using the find_generic_shape_model operator to obtain the row coordinates, column coordinates, and angle of the matching position, the affine transformation matrix is calculated using the vector_angle_to_rigid operator, and the image is affine transformed using the affine_trans_image operator.
5. The method for detecting positional deviation of magnetic material products as described in claim 1, characterized in that: In step S4, the position or size detection of the magnet to be detected includes: extracting sub-pixel edges of the magnet region and calculating the center point of each magnet region.
6. The method for detecting positional deviation of magnetic material products as described in claim 5, characterized in that: Subpixel edge extraction of the magnet region includes: using Halcon's edges_sub_pix operator and a Canny filter, setting the standard deviation of Gaussian smoothing to 1, and setting the low threshold of the hysteresis dual threshold to 20 and the high threshold to 40.
7. The method for detecting positional deviation of magnetic material products as described in claim 5, characterized in that: The method for calculating the center point of the magnet region includes: extracting the sub-pixel edges of the four sides of the magnet region, calculating the midpoint of each side, connecting the midpoints of opposite sides to obtain two center lines, and defining the intersection of the two center lines as the center point of the magnet region.
8. The method for detecting positional deviation of magnetic material products as described in claim 5, characterized in that: It also includes a step of segmenting the extracted subpixel edge contours: using Halcon's segment_contours_xld operator, the contours are simultaneously segmented into straight line segments and arcs, where the maximum allowable error for straight line fitting is 4 pixels and the maximum allowable error for arc fitting is 2 pixels.
9. The method for detecting positional deviation of magnetic material products as described in claim 8, characterized in that: When performing circle fitting on the segmented arc contour, an algebraic fitting algorithm is used, with the maximum number of fitting points set to 20, the maximum closure distance to 5 pixels, and the number of clipping endpoints to 1.
10. The method for detecting positional deviation of magnetic material products as described in claim 1, characterized in that: After step S4, step S5 is also included: saving the test results in CSV file format, which contains the test timestamp and the dimension field corresponding to the product drawing.
Citation Information
Patent Citations
Laser boresight equipment high-precision calibration method and system based on region segmentation mapping
CN121898297A
Method and system for detecting precision of circular positioning hole
CN122175971A