Mobile phone frame CNC machining hole precision detection method based on machine vision
By using image processing and gradient analysis under multi-angle illumination, the micro-flanging and reflective structures of CNC-machined holes in the mobile phone frame are identified and corrected, solving the error problem in hole detection and achieving high-precision hole center coordinate calculation and stability of detection results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANDONG MAITAO TECHNOLOGY CO LTD
- Filing Date
- 2026-03-23
- Publication Date
- 2026-06-19
AI Technical Summary
In the existing technology, the hole position detection method after CNC machining of the mobile phone frame cannot effectively identify the sub-pixel level offset error of the hole position center caused by micro-flanging or reflective structure, resulting in cumulative assembly deviation in the high-density hole array structure.
By acquiring multiple frames of images under a multi-angle ring light source, pixel-level registration is performed to generate composite images of the apertures. Brightness change gradient analysis is performed to identify abnormal gradient regions, the contours are decomposed and boundary continuity and curvature consistency analysis is performed to construct a geometric reconstruction model, correct abnormally offset aperture positions, and establish the topological relationship of the aperture array.
It improves the anti-interference ability and accuracy of borehole detection, significantly enhances the stability of borehole center coordinate calculation and the reliability of overall detection results, and suppresses the influence of local abnormal boundaries on the detection results.
Smart Images

Figure CN122244159A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of mobile phone mid-frame processing and inspection technology, specifically to a machine vision-based method for detecting the accuracy of CNC machining holes in mobile phone mid-frames. Background Technology
[0002] After the CNC machining of the mobile phone frame is completed, it is necessary to perform precision inspection on tiny functional holes such as speaker holes, screw holes, and positioning holes to ensure the accuracy of subsequent assembly positions. Existing production lines typically use 2D machine vision or coordinate measuring machine (CMM) equipment to identify the edges of the holes and calculate the hole center. However, in actual CNC machining, due to factors such as tool wear, local material plastic springback, and coolant residue, irregular micro-flanges or local metallic reflective surfaces with a scale of 10μm may form at the edges of the holes. These structures often form superimposed contours with the real hole boundaries in visual images, making it easy for traditional detection methods based on single edge extraction or circle fitting to misidentify the micro-flanged contours as the real hole boundaries. This results in sub-pixel level offset errors in the hole center. Although this error is small, it can cause cumulative assembly deviations in high-density hole array structures. Existing technologies lack detection methods for reconstructing the real hole boundaries to address this type of micro-structural interference. Summary of the Invention
[0003] The purpose of this invention is to provide a machine vision-based method for detecting the accuracy of holes in CNC machining of mobile phone mid-frames, in order to address the shortcomings of the prior art.
[0004] To achieve the above objectives, the present invention provides the following technical solution: a machine vision-based method for detecting the accuracy of CNC machining holes in a mobile phone frame, comprising:
[0005] Acquire multiple frames of images of the mid-frame of the mobile phone to be inspected under multi-angle ring light source conditions, and perform pixel-level registration on the multiple frames to generate corresponding composite images of the apertures;
[0006] Brightness variation gradient analysis is performed on the composite image of the aperture to identify abnormal gradient regions generated by micro-flanging or reflective structures, and a set of abnormal contour regions is obtained.
[0007] Based on the set of abnormal contour regions, the composite image of the orifice is decomposed into contour layers to obtain a set of candidate real orifice boundaries.
[0008] A boundary continuity and curvature consistency analysis is performed on the candidate set of real orifice boundaries to obtain a set of real orifice boundary curves.
[0009] A geometric reconstruction model of the orifice is established based on the set of true boundary curves of the orifice, and geometric fitting is performed on the true boundary curve of each orifice to obtain the set of coordinates of the orifice center.
[0010] Based on the set of hole center coordinates, a topological relationship of the hole array is constructed, and the abnormally offset hole positions are corrected based on the array topological relationship to obtain the corrected set of hole coordinates.
[0011] The corrected set of hole position coordinates is compared with the preset standard hole position coordinates to calculate the hole position deviation and output the CNC machining hole position accuracy test result of the mobile phone frame.
[0012] Preferably, the brightness change gradient analysis of the composite image of the aperture includes: performing grayscale normalization on the composite image of the aperture, and using a multi-scale gradient operator to calculate the brightness change gradient value of each pixel in different directions to obtain the corresponding gradient distribution map; performing gradient continuity analysis on the aperture region based on the gradient distribution map, extracting candidate contour boundaries that form a continuous closed structure to obtain a candidate boundary set; calculating the local gradient change rate and gradient direction dispersion of each candidate boundary in the candidate boundary set, and identifying abnormal gradient boundaries caused by micro-flanging or reflective structures according to a preset gradient stability judgment rule.
[0013] Preferably, obtaining the abnormal contour region set includes: performing region expansion and connected component marking on the identified abnormal gradient boundaries in the orifice composite image to generate a corresponding abnormal contour region set.
[0014] Preferably, the contour layering decomposition of the orifice composite image based on the abnormal contour region set includes: establishing an abnormal region mask image in the orifice composite image based on the abnormal contour region set, and performing mask separation processing on the orifice composite image to obtain a basic edge image that removes the influence of abnormal contours; performing radial gradient scanning processing on the basic edge image, taking the geometric center of each orifice region as the scanning starting point, and extracting radial gradient change curves along multiple angular directions to obtain the corresponding radial boundary response set.
[0015] Preferably, the candidate true orifice boundary set includes: calculating boundary stability parameters in each direction based on the radial boundary response set, and screening continuous and stable boundary point sequences to form a candidate boundary point set; performing spatial connectivity reorganization and closed contour reconstruction processing on the candidate boundary point set to generate multiple closed boundary contours, and determining the closed contours that meet the preset boundary roundness threshold and continuity threshold as the candidate true orifice boundary set.
[0016] Preferably, the boundary continuity and curvature consistency analysis of the candidate real aperture boundary set includes: performing arc length parameterization on each candidate boundary curve in the candidate real aperture boundary set according to pixel order, constructing a corresponding discrete boundary point sequence, and calculating the arc length distance between adjacent boundary points to obtain an arc length parameter sequence; calculating the discrete curvature value at each boundary point based on the arc length parameter sequence, and constructing a boundary curvature distribution sequence based on the discrete curvature values; constructing an elastic curve energy calculation model based on the boundary curvature distribution sequence, and obtaining the elastic energy value of the corresponding candidate boundary curve by integrating the square of the boundary curvature with the arc length weight.
[0017] Preferably, the selection of the true boundary curve set of the orifice includes: comparing the elastic energy value of each candidate boundary curve with a preset energy stability threshold, and selecting the boundary curve that meets the minimum energy condition in combination with the boundary curvature continuous change constraint, and determining it as the true boundary curve set of the orifice.
[0018] Preferably, geometric fitting is performed on the true boundary curve of each orifice to obtain a set of orifice center coordinates, including:
[0019] For each of the orifice true boundary curves in the set of orifice true boundary curves, uniform arc length resampling is performed to construct the corresponding boundary discrete point sequence, and the radial distance sequence of each boundary point relative to the boundary geometric centroid is calculated.
[0020] A radial consistency evaluation function is constructed based on the radial distance sequence, and a set of stable boundary points is obtained by iteratively removing abnormal boundary points whose radial deviation exceeds a preset deviation threshold.
[0021] A geometric reconstruction model of the orifice is established based on the set of stable boundary points, and the center coordinates and radius parameters are calculated by minimizing the objective function of the distance error from the stable boundary points to the fitted circle.
[0022] The calculated center coordinates of each fitted circle are used as the center coordinates of the corresponding orifice, and then summarized to form a set of orifice center coordinates.
[0023] Preferably, constructing the topological relationship of the hole position array based on the set of hole position center coordinates includes: calculating the spatial adjacency relationship between each hole position based on the set of hole position center coordinates, determining the set of adjacent holes for each hole position by sorting the Euclidean distance between any two hole position centers, and constructing the topological connection diagram of the hole position array accordingly.
[0024] Preferably, the correction of abnormally offset holes based on array topology includes: calculating the relative position vector between the center of each hole and its adjacent hole center according to the hole array topology connection diagram, and constructing an array reference vector set by statistically analyzing the average direction and average distance of all relative position vectors; calculating the offset difference between the actual relative position vector of each hole center and the corresponding array reference vector, and identifying hole centers with offsets exceeding a preset offset threshold as abnormally offset holes; and performing position regression correction on the abnormally offset holes according to the array reference vector relationship between the abnormally offset holes and their adjacent holes to obtain a corrected set of hole coordinates.
[0025] The technical effects and advantages provided by the present invention in the above technical solution are as follows:
[0026] 1. This invention constructs composite images of apertures under multi-angle illumination and combines this with brightness variation gradient analysis to identify abnormal contour regions generated by micro-flanging or reflective structures. This effectively avoids the problem of false boundaries easily generated by traditional visual detection methods when there are micro-reflections or micro-flanging at the aperture edges. By performing mask separation and contour layer decomposition on abnormal contour regions, and combining radial gradient scanning and boundary stability analysis, candidate true aperture boundaries can be accurately extracted from complex images, improving the stability and accuracy of aperture boundary recognition, thereby significantly enhancing the anti-interference capability in the aperture detection process.
[0027] 2. This invention further introduces a boundary continuity and curvature consistency screening method based on the elastic curve energy minimization analysis algorithm, and combines it with the orifice geometric reconstruction model for accurate fitting of the orifice center. Simultaneously, it corrects abnormally offset orifices by constructing a orifice array topology. Through this multi-level analysis and correction process, the impact of local abnormal boundaries or individual orifice detection errors on the overall detection results can be effectively suppressed, making the orifice center coordinate calculation more stable and reliable, thereby improving the overall accuracy and consistency of orifice precision detection in CNC machining of the mobile phone frame. Attached Figure Description
[0028] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0029] Figure 1 This is a flowchart of the machine vision-based CNC machining hole position accuracy detection method for mobile phone mid-frame according to the present invention.
[0030] Figure 2 This is a flowchart of the method for filtering the set of true boundary curves of the orifice according to the present invention. Detailed Implementation
[0031] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0032] For examples, please refer to Figure 1 , Figure 2 As shown in this embodiment, the machine vision-based CNC machining hole position accuracy detection method for mobile phone mid-frame includes:
[0033] The system acquires multiple frames of images of the phone frame under multi-angle ring light source conditions, performs pixel-level registration on the multiple frames, and generates corresponding composite images of the apertures.
[0034] In one embodiment of the present invention, to improve the stability and detection accuracy of hole boundary recognition, it is first necessary to acquire image information of the hole area of the mobile phone frame under different lighting conditions. Specifically, the mobile phone frame to be inspected is fixed on the positioning fixture of the vision inspection station, so that the inspection surface of the mobile phone frame is in a preset inspection position, and the camera optical axis is kept basically perpendicular to the inspection surface of the frame. The vision inspection system includes an industrial camera and a ring light source that can be controlled in sections around the camera lens. The ring light source can change the light emission state of different angle areas in a preset sequence.
[0035] During the detection process, the ring light source is controlled to sequentially illuminate light source areas at different angles according to a preset multi-angle illumination sequence, thereby acquiring multiple images of the hole area in the mobile phone frame under different incident light angles, and obtaining corresponding multiple frames of original images. Since the reflection characteristics of the hole edge, micro-flanged edge, and surface reflective structure differ under different incident angles, the edge information and reflective area distribution presented in different frames of images also differ.
[0036] Subsequently, pixel-level registration processing is performed on the acquired multiple frames of original images. Specifically, one frame is used as a reference image, and the translational offset between each frame and the reference image is calculated through feature point matching. Subpixel-level alignment correction is then performed on each frame based on this offset, ensuring that the multiple frames are superimposed and correspond within the same pixel coordinate system. After pixel-level registration, information fusion processing is performed on the registered multiple frames. The images are weighted and superimposed based on the brightness distribution and gradient features of the aperture region in each frame, generating a composite aperture image that simultaneously preserves stable aperture structural features and suppresses local reflection interference. This composite aperture image provides stable image data for subsequent aperture true boundary recognition and aperture position accuracy calculation.
[0037] Brightness variation gradient analysis is performed on the composite image of the aperture to identify abnormal gradient regions generated by micro-flanging or reflective structures, thus obtaining a set of abnormal contour regions.
[0038] First, the composite image of the aperture is converted into a grayscale image, denoted as I(x,y), where x represents the horizontal coordinate of a pixel, y represents the vertical coordinate, and I(x,y) represents the grayscale value of the corresponding pixel. Then, the grayscale image is standardized. Specifically, the minimum and maximum grayscale values in the image are obtained. Then, the minimum grayscale value is subtracted from the grayscale value of each pixel, and the result is divided by the difference between the maximum and minimum grayscale values, resulting in a standardized grayscale value where all pixel grayscale values are between 0 and 1. After standardization, multi-directional gradient calculations are performed on the standardized grayscale image. Specifically, the gradient change is calculated horizontally using the grayscale difference between adjacent left and right pixels, vertically using the grayscale difference between adjacent up and down pixels, and diagonally between adjacent pixels. Finally, the gradient changes in the four directions are combined using the sum of squares and the square root of the result to obtain the brightness gradient value of each pixel.
[0039] To improve the response capability to edge structures at different scales, the gradient calculations were performed on the image at three convolution window scales, and the images were fused according to preset weights. The weights for the three scales were set to 0.5, 0.3, and 0.2, respectively, and the gradient distribution map G(x,y) representing the intensity distribution of brightness changes in the entire image was finally obtained.
[0040] After obtaining the gradient distribution map G(x,y), gradient thresholding is performed on the gradient distribution map to extract edge pixels. The specific method is as follows: First, the average gradient value of all pixels in the entire gradient distribution map is calculated, and then the dispersion (standard deviation) of the gradient values relative to the average value is calculated. Then, the average gradient value and the standard deviation are superimposed at a fixed ratio to obtain the gradient threshold, which is the average gradient value plus 0.8 times the standard deviation as the judgment threshold.
[0041] When the gradient value of a pixel is greater than or equal to the threshold, the pixel is identified as an edge pixel. A connected component search is performed on all edge pixels according to the eight-neighborhood connectivity rule, grouping interconnected edge pixels into the same connected component.
[0042] For each connected region, its outermost contour curve is extracted using a boundary tracing method, and the number of pixels in the contour curve is counted. When the length of the contour curve is greater than a preset minimum contour length, the contour curve is retained as a candidate contour. The minimum contour length is set to 20 pixels. All retained contours together constitute a candidate boundary set.
[0043] For each candidate boundary curve in the candidate boundary set, all its pixels are extracted in contour order, and the gradient change rate between adjacent pixels is calculated. The gradient change rate reflects the severity of the boundary gradient change, and its calculation method is as follows: ;in, This represents the gradient value of the i-th boundary pixel. This represents the gradient value of the next boundary pixel, with a constant of 0.001 added to the denominator to avoid division by zero. Then, the average gradient rate of change of all gradients along the entire boundary curve is calculated to obtain the average gradient rate of change of that boundary. Simultaneously, the gradient direction angle of each boundary pixel is calculated. The gradient direction angle represents the direction of brightness change, and it is calculated by taking the vertical gradient value... Divide by the horizontal gradient value Then perform arctangent operation: After obtaining all gradient direction angles, the deviation of these angles from the average direction angle is calculated, and the average of the squares of all deviations is used as the direction dispersion to describe whether the gradient direction change is disordered. When a candidate boundary simultaneously satisfies that the average gradient change rate is greater than 0.35 and the gradient direction dispersion is greater than 0.6, the candidate boundary is determined to be an abnormal gradient boundary generated by micro-flanging or reflective structures.
[0044] After identifying the abnormal gradient boundary, the pixels on the boundary are used as the starting seed points for region growing, and the region is expanded in the composite image of the aperture.
[0045] The condition for determining region expansion is that the grayscale difference between the pixel to be expanded and the current region pixel is less than a preset grayscale difference threshold. The grayscale difference threshold is obtained by statistically analyzing the grayscale standard deviation of the entire grayscale image, and then multiplying this standard deviation by 0.5 to obtain the region expansion threshold.
[0046] During the expansion process, pixels satisfying the gray-scale difference condition are gradually added using an eight-neighbor search method until no new pixels meet the expansion condition. After expansion is complete, all expanded regions are marked as connected components, and each connected component is assigned a unique number. All marked connected components together constitute an abnormal contour region set, providing basic data for subsequent screening of the actual aperture boundary.
[0047] Based on the set of abnormal contour regions, the composite image of the orifice is decomposed into contour layers to obtain a set of candidate real orifice boundaries.
[0048] First, an abnormal region mask image is constructed based on the set of abnormal contour regions. Specifically, a mask image M(x,y) with the same size as the composite image of the aperture is created, where the pixel coordinates x and y are consistent with the composite image of the aperture. Initially, all pixel values in the mask image are set to 1. Then, each connected region in the abnormal contour region set is traversed, and the pixel value at the corresponding pixel position in the mask image is set to 0, thus forming the abnormal region mask image. Positions with a pixel value of 0 represent abnormal contour regions, and positions with a pixel value of 1 represent normal regions. After obtaining the abnormal region mask image, a pixel-by-pixel multiplication operation is performed between the composite image of the aperture and the abnormal region mask image. This sets the grayscale value of the pixels at the corresponding abnormal region positions in the composite image of the aperture to 0, retaining only the image information of the normal regions, thus obtaining the base image after removing the influence of abnormal contours. Edge extraction is then performed on the base image. Edge extraction is implemented using a gradient extremum detection method. Specifically, the brightness change gradient of each pixel in the image is calculated, and local maxima are found along the gradient direction. These positions are marked as edge points, and all edge points together constitute the base edge image.
[0049] After obtaining the basic edge image, radial gradient scanning is performed on each aperture region. First, the geometric center of the aperture region is determined. This geometric center is obtained by averaging the coordinates of all pixels within the aperture region; that is, averaging the horizontal coordinates of all pixels to obtain the center's horizontal coordinate, and averaging the vertical coordinates of all pixels to obtain the center's vertical coordinate. Using this geometric center as the scanning starting point, radial scanning is performed at fixed angular intervals within a range of 0 to 360 degrees. In this embodiment, the angular interval is set to 2 degrees, resulting in a total of 180 scanning directions. In each scanning direction, the scan proceeds pixel-by-pixel outward from the geometric center, recording the gradient value changes of each pixel along the scanning path. When the gradient value suddenly rises from a low value region and reaches a local peak, this location is recorded as a boundary response point, along with its corresponding gradient magnitude. For each scanning direction, only the boundary response point with the largest gradient magnitude is retained. The set of boundary response points obtained from all scanning directions constitutes the radial boundary response set.
[0050] After obtaining the radial boundary response set, stability analysis is performed on all boundary response points. First, all boundary response points are arranged in order of scanning angle, and the radial distance from each boundary response point to the geometric center of the orifice is recorded.
[0051] Then, the change in radial distance between adjacent scanning directions is calculated. Let the radial distance in the i-th direction be... The change in distance between adjacent directions is defined as: By statistically analyzing the distance changes across all scanning directions, the average distance change is calculated, and 1.5 times this average is used as the distance stability threshold. When the distance changes between a boundary response point and its adjacent directions are all less than the distance stability threshold, the boundary response point is considered to have stable geometric positional characteristics and is marked as a stable boundary point. All stable boundary points constitute a candidate boundary point set.
[0052] After obtaining the candidate boundary point set, spatial connectivity reorganization is performed on all candidate boundary points. Specifically, adjacent boundary points are connected in order of scanning angle to form a continuous boundary point sequence. For each continuous boundary point sequence, the spatial distance between its first and last points is first determined. If the distance between the first and last points is less than a preset closure distance threshold, the boundary point sequence is considered to constitute a closed profile. The closure distance threshold is set to 5% of the average radius of the aperture. After obtaining the closed profile, roundness analysis is performed on it. The roundness parameter C is measured by calculating the dispersion of the distance from the profile point to its fitted circle center, and its calculation method is as follows: ;in This represents the average distance from all contour points to the center of the circle. This represents the standard deviation of the distance.
[0053] When the roundness parameter C is less than 0.08 and the number of boundary points in the closed profile is greater than 60, the closed profile is determined to meet the characteristics of a true orifice boundary. All closed profiles that meet this condition together constitute a set of candidate true orifice boundaries, which are used in the subsequent calculation of the orifice center coordinates.
[0054] A set of candidate true orifice boundaries is selected by performing boundary continuity and curvature consistency analysis.
[0055] First, discrete points are extracted for each candidate boundary curve in the set of candidate real aperture boundaries. Let a candidate boundary curve consist of N sequentially arranged boundary pixels, and represent the i-th boundary point as... ,in Indicates the horizontal pixel coordinates. This represents the vertical pixel coordinate. Then, the Euclidean distance between adjacent boundary points is calculated, which is used to represent the local arc length of the boundary curve. The expression for calculating the arc length distance between adjacent boundary points is: ;in This represents the arc length distance between the i-th boundary point and the (i+1)-th boundary point.
[0056] The arc length parameters for each boundary point are obtained by summing all the arc length distances. The arc length parameter for the k-th boundary point is defined as follows: The arc length parameter sequence of the boundary curve is obtained through the above calculations. Together with the boundary point sequence, they form an arc-length parameterized sequence of discrete boundary points.
[0057] After obtaining the sequence of discrete boundary points parameterized by arc length, a discrete curvature value is calculated for each boundary point. The discrete curvature is used to describe the degree of curvature of the boundary curve at that location.
[0058] For boundary points Take its previous boundary point With the next boundary point Construct a local three-point structure and calculate adjacent vectors: The curvature change at a point is represented by the angle between the vectors. The curvature calculation expression is: ;in This represents the discrete curvature value at the i-th boundary point. and These represent the arc length distance between adjacent boundary segments. By sequentially calculating the discrete curvature values of all boundary points, a boundary curvature distribution sequence is obtained: This sequence describes the curvature variation of the entire candidate boundary curve. After obtaining the boundary curvature distribution sequence, an elastic curve energy calculation model is constructed to measure the overall bending stability of the boundary curve. This model is based on the integral idea of curvature square and arc length weights, and its discrete calculation expression is: Where E represents the elastic energy value of the candidate boundary curve; This represents the discrete curvature value at the i-th boundary point. This represents the local arc length weight corresponding to the boundary point. To avoid energy deviations between boundary curves of different lengths, the elastic energy value is normalized by length. Let the total arc length of the boundary curve be: The normalized elastic energy calculation expression is as follows: ;in This represents the normalized elastic energy value.
[0059] After obtaining the normalized elastic energy value of each candidate boundary curve, the candidate boundary curves are screened by constructing an energy stability threshold. First, the average normalized elastic energy of all boundary curves in the candidate true orifice boundary set is calculated, and the dispersion of these energy values is also calculated. Then, the average energy value and the dispersion are proportionally superimposed to form the energy stability threshold. ;in This represents the average value of the normalized elastic energy. This represents the standard deviation of the normalized elastic energy. When the normalized elastic energy value of a candidate boundary curve satisfies... Furthermore, if the change in curvature between adjacent curves in the curvature distribution sequence of the boundary curve is less than a preset curvature change threshold, then the boundary curve is considered to simultaneously satisfy the requirements of boundary continuity and curvature consistency. The change in curvature... Defined as: The curvature change threshold is taken as 1.2 times the average value of all curvature changes. Finally, the boundary curves that simultaneously satisfy the elastic energy condition and the curvature continuity condition are determined as the true boundary curves of the orifice, and together they form the set of true boundary curves of the orifice, which are used in the subsequent calculation of the orifice center position.
[0060] A geometric reconstruction model of the orifice is established based on the set of true boundary curves of the orifice. Geometric fitting is performed on the true boundary curve of each orifice to obtain the set of coordinates of the orifice center.
[0061] First, each true boundary curve in the set of true boundary curves for orifices undergoes uniform arc length resampling. Let a true boundary curve for an orifice consist of N boundary points, where the i-th boundary point is denoted as... The arc distance between adjacent boundary points is calculated using the Euclidean distance method, which involves calculating the sum of the squares of the differences in the horizontal and vertical coordinates of the two boundary points, and then taking the square root of the sum to obtain the arc distance between the adjacent boundary points.
[0062] Then, the total arc length of the boundary curve is obtained by summing all the arc lengths. A fixed number of resampling points are set according to the total arc length of the boundary curve. In this embodiment, the number of resampling points is set to 120. The total arc length is evenly divided into 120 equal arc length intervals to obtain uniformly distributed resampling positions. The coordinates of the boundary points corresponding to each resampling position are calculated on the original boundary curve by linear interpolation to form a resampling boundary point sequence.
[0063] After obtaining the resampled boundary point sequence, the average of the horizontal coordinates of all boundary points is calculated as the horizontal coordinate of the geometric centroid, and the average of the vertical coordinates of all boundary points is calculated as the vertical coordinate of the geometric centroid, thus obtaining the position of the geometric centroid of the boundary curve.
[0064] Then, the radial distance from each boundary point to the geometric centroid is calculated. The radial distance is calculated using Euclidean distance, which is obtained by summing the squares of the differences in the lateral and longitudinal coordinates between the boundary point and the geometric centroid, and then taking the square root of the result. The radial distances of all boundary points form a radial distance sequence.
[0065] After obtaining the radial distance sequence, the radial consistency of the boundary points is analyzed. First, the average value of all radial distances is calculated, which is obtained by summing all radial distances and dividing by the number of boundary points.
[0066] The radial deviation at each boundary point is then calculated. The radial deviation is obtained by calculating the absolute difference between the radial distance at that boundary point and the average radial distance.
[0067] To identify anomalous boundary points, the average of all radial deviations is calculated, and 1.5 times this average is taken as the radial deviation threshold. When the radial deviation of a boundary point exceeds this threshold, the boundary point is considered to deviate from the overall circular structure and is removed from the boundary point set.
[0068] After one round of elimination, the average radial distance and radial deviation are recalculated for the remaining boundary points, and the abnormal boundary point elimination is performed again using the same method. In this embodiment, this elimination process is repeated three times to obtain a stable set of boundary points.
[0069] After obtaining the set of stable boundary points, a geometric reconstruction model of the orifice is established, and geometric fitting is achieved by minimizing the distance error between the stable boundary points and the fitted circle.
[0070] Let the center of the fitted circle be (a, b), the radius be R, and the number of stable boundary points be K. Let the j-th stable boundary point be denoted as... The distance error from the boundary point to the fitted circle is defined as: By summing the squared distance errors of all stable boundary points, a sum-of-squares objective function is constructed: The algorithm searches for the center coordinates and radius of a circle that minimize the sum of squared errors using an iterative search method. Specifically, the calculated geometric centroid coordinates are used as the initial center coordinates, and the average radial distance is used as the initial radius. Then, the three parameters—the abscissa, ordinate, and radius—are gradually adjusted, and the sum of squared errors is recalculated after each adjustment.
[0071] When the change in the sum of squared errors after 5 consecutive parameter updates is less than When the fitting process reaches a stable state, the final fitting circle parameters are obtained.
[0072] After completing the geometric fitting, the fitted center coordinates (a, b) of the true boundary curve for each orifice are obtained. These center coordinates represent the center coordinates of the corresponding orifice. The geometric fitting process is repeated for each boundary curve in the set of true boundary curves to obtain the center coordinates of multiple orifices. The center coordinates are recorded according to the spatial position of the orifices in the image, and all center coordinates are combined into a set of orifice center coordinates, providing basic data for subsequent orifice position deviation calculation and orifice position accuracy evaluation.
[0073] Based on the set of hole center coordinates, a hole array topology is constructed, and based on the array topology, abnormally offset holes are corrected to obtain a corrected set of hole coordinates.
[0074] First, establish spatial adjacency relationships for each hole center in the set of hole center coordinates. Let the set of hole center coordinates contain N hole centers, and let the i-th hole center be denoted as... For any two hole centers and Calculate the Euclidean distance between the two. Its calculation expression is: .
[0075] For each hole center, calculate its distance to all other hole centers and sort them in ascending order of distance. Select the four hole centers with the smallest distances as adjacent holes, thus forming a set of adjacent holes. Repeat the above process for all hole centers to obtain the connection relationship between each hole center and its adjacent holes. Record all connection relationships as a topological connection graph of the hole array, where each hole center is a node in the graph, and the connection relationship between adjacent holes is an edge in the graph. After obtaining the topological connection graph of the hole array, calculate the relative position vector between holes for each connection edge. For hole centers... its adjacent hole center Its relative position vector is represented as: Then, the length of the relative position vector is calculated by summing the squares of the horizontal and vertical components and taking the square root.
[0076] After obtaining all relative position vectors, the orientation angles of all vectors are statistically analyzed. The orientation angles are obtained by calculating the ratio of the longitudinal component to the transverse component of the vector and then performing an arctangent operation. Subsequently, the average value of all orientation angles is calculated as the array average orientation angle.
[0077] At the same time, the average length of all vectors is calculated as the average distance of the array.
[0078] The array reference vector is constructed based on the array's average orientation angle and average distance, and its lateral component... and longitudinal components The calculation expression is: The reference vectors calculated from all connection relationships together form the array reference vector set. Among them, This represents the average length of the relative position vector between the centers of the boreholes, which is the average distance between all adjacent borehole centers. This represents the average value of the direction angle of the relative position vector of the hole position. After obtaining the array reference vector set, an offset analysis is performed on the actual relative position vector of each hole position center. First, the difference vector between the actual relative position vector of the hole position center and the array reference vector is calculated. Its calculation expression is: Then the length of the difference vector is calculated, which is obtained by Euclidean distance calculation.
[0079] To determine if there is abnormal displacement of the borehole position, the lengths of all difference vectors are statistically analyzed, and their average value is calculated. Twice the average value is used as the displacement judgment threshold. When the length of the difference vector between the center of a borehole position and its adjacent borehole positions is greater than this displacement judgment threshold, the center of the borehole position is determined to be an abnormally offset borehole position.
[0080] After identifying the abnormally offset hole, its position is corrected based on the array reference vector relationship between its adjacent holes. Let the abnormally offset hole be... The set of adjacent hole centers is The theoretical coordinates of the abnormal hole positions are determined based on the array reference vector. The theoretical position coordinates are calculated by superimposing the coordinates of adjacent holes with the array reference vector. The calculation expression is as follows: When multiple adjacent hole positions exist, the coordinates of all theoretical positions are averaged to obtain the corrected coordinates of the abnormal hole position. Where P represents the number of adjacent holes. Finally, the coordinates will be corrected. The original hole center coordinates are replaced to obtain the corrected set of hole coordinates, providing more stable coordinate data for subsequent hole accuracy assessment.
[0081] The corrected set of hole position coordinates is compared with the preset standard hole position coordinates to calculate the hole position deviation and output the CNC machining hole position accuracy test result of the mobile phone frame.
[0082] In this embodiment, after obtaining the corrected set of hole position coordinates, it is necessary to compare the corrected set of hole position coordinates with the preset standard hole position coordinates to calculate the hole position deviation and output the CNC machining hole position accuracy detection result of the mobile phone frame. The specific implementation process is as follows.
[0083] First, a set of preset standard hole position coordinates is established. These coordinates are derived from the design model data of the mobile phone frame product. They are obtained by reading the theoretical center coordinates of each hole in the design model and transforming them according to the coordinate system of the detection image. Let the set of standard hole position coordinates contain N standard hole positions, and the coordinates of the i-th standard hole position be represented as... ,in The horizontal coordinates of the standard hole position are represented. This represents the longitudinal coordinate of the standard hole position. Meanwhile, let the center coordinate of the corresponding hole position in the corrected hole position coordinate set be... ,in This indicates the corrected lateral coordinates of the hole position. This represents the corrected longitudinal coordinates of the hole position. The corrected hole position coordinates are matched one-to-one with the corresponding standard hole position coordinates using hole position numbers or spatial adjacency relationships.
[0084] After coordinate matching is completed, the coordinate deviations of each hole position in the lateral and longitudinal directions are calculated. The lateral deviation is obtained by subtracting the lateral coordinate of the standard hole position from the lateral coordinate of the corrected hole position, and the longitudinal deviation is obtained by subtracting the longitudinal coordinate of the standard hole position from the longitudinal coordinate of the corrected hole position.
[0085] The overall spatial deviation of the hole position is then calculated. The spatial deviation is obtained by summing the squares of the lateral and longitudinal deviations and taking the square root; its calculation expression is as follows: ;in This represents the spatial deviation value of the i-th hole position.
[0086] To determine whether a hole meets the machining accuracy requirements, a hole accuracy judgment threshold is set. This threshold is determined based on the machining tolerance of the holes in the mobile phone frame, and is set to 0.03 mm in this embodiment. When the spatial deviation of a hole exceeds this accuracy judgment threshold, the hole is judged as an out-of-tolerance hole; when the spatial deviation is less than or equal to the threshold, it is judged as a qualified hole.
[0087] After calculating all hole position deviations, the deviation results for all holes are statistically analyzed, and a hole position accuracy inspection report for the mobile phone mid-frame is generated. The inspection results include the lateral deviation, longitudinal deviation, and spatial deviation for each hole position. The report also outputs the location number and deviation value of any out-of-tolerance holes, thus forming a CNC machining hole position accuracy inspection report for the mobile phone mid-frame, which guides subsequent machining quality analysis and process adjustments.
[0088] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.
Claims
1. A machine vision-based method for detecting the accuracy of holes in CNC-machined mobile phone frames, characterized by: include: Acquire multiple frames of images of the mid-frame of the mobile phone to be inspected under multi-angle ring light source conditions, and perform pixel-level registration on the multiple frames to generate corresponding composite images of the apertures; Brightness variation gradient analysis is performed on the composite image of the aperture to identify abnormal gradient regions generated by micro-flanging or reflective structures, and a set of abnormal contour regions is obtained. Based on the set of abnormal contour regions, the composite image of the orifice is decomposed into contour layers to obtain a set of candidate real orifice boundaries. A boundary continuity and curvature consistency analysis is performed on the candidate set of real orifice boundaries to obtain a set of real orifice boundary curves. A geometric reconstruction model of the orifice is established based on the set of true boundary curves of the orifice, and geometric fitting is performed on the true boundary curve of each orifice to obtain the set of coordinates of the orifice center. Based on the set of hole center coordinates, a topological relationship of the hole array is constructed, and the abnormally offset hole positions are corrected based on the array topological relationship to obtain the corrected set of hole coordinates. The corrected set of hole position coordinates is compared with the preset standard hole position coordinates to calculate the hole position deviation and output the CNC machining hole position accuracy test result of the mobile phone frame.
2. The method for detecting the accuracy of CNC machining holes in a mobile phone frame based on machine vision according to claim 1, characterized in that: The brightness variation gradient analysis of the composite image of the aperture includes: performing grayscale normalization on the composite image of the aperture, and using a multi-scale gradient operator to calculate the brightness variation gradient value of each pixel in different directions to obtain the corresponding gradient distribution map; performing gradient continuity analysis on the aperture region based on the gradient distribution map, extracting candidate contour boundaries that form a continuous closed structure to obtain a candidate boundary set; calculating the local gradient change rate and gradient direction dispersion of each candidate boundary in the candidate boundary set, and identifying abnormal gradient boundaries caused by micro-flanging or reflective structures according to a preset gradient stability judgment rule.
3. The method for detecting the accuracy of CNC machining holes in a mobile phone frame based on machine vision according to claim 2, characterized in that: in, Obtaining a set of abnormal contour regions includes: expanding and marking the connected components of the identified abnormal gradient boundaries in the composite image of the aperture to generate a corresponding set of abnormal contour regions.
4. The method for detecting the accuracy of CNC machining holes in a mobile phone frame based on machine vision according to claim 1, characterized in that: The orifice composite image is decomposed into contour layers based on the set of abnormal contour regions, including: establishing an abnormal region mask image in the orifice composite image based on the set of abnormal contour regions, and performing mask separation processing on the orifice composite image to obtain a basic edge image that removes the influence of abnormal contours; performing radial gradient scanning processing on the basic edge image, taking the geometric center of each orifice region as the scanning starting point, and extracting radial gradient change curves along multiple angular directions to obtain the corresponding radial boundary response set.
5. The method for detecting the accuracy of CNC machining holes in a mobile phone frame based on machine vision according to claim 4, characterized in that: in, The candidate true orifice boundary set includes: calculating boundary stability parameters in each direction based on the radial boundary response set, and screening continuous and stable boundary point sequences to form a candidate boundary point set; performing spatial connectivity reorganization and closed contour reconstruction processing on the candidate boundary point set to generate multiple closed boundary contours, and determining the closed contours that meet the preset boundary roundness threshold and continuity threshold as the candidate true orifice boundary boundary set.
6. The method for detecting the accuracy of CNC machining holes in a mobile phone frame based on machine vision according to claim 1, characterized in that: The boundary continuity and curvature consistency analysis of the candidate real aperture boundary set includes: performing arc length parameterization on each candidate boundary curve in the candidate real aperture boundary set according to pixel order, constructing a corresponding discrete boundary point sequence, and calculating the arc length distance between adjacent boundary points to obtain an arc length parameter sequence; calculating the discrete curvature value at each boundary point based on the arc length parameter sequence, and constructing a boundary curvature distribution sequence based on the discrete curvature values; constructing an elastic curve energy calculation model based on the boundary curvature distribution sequence, and obtaining the elastic energy value of the corresponding candidate boundary curve by integrating the square of the boundary curvature with the arc length weight.
7. The method for detecting the accuracy of CNC machining holes in a mobile phone frame based on machine vision according to claim 6, characterized in that: The selection of the true boundary curve set of the orifice includes: comparing the elastic energy value of each candidate boundary curve with a preset energy stability threshold, and selecting the boundary curve that meets the minimum energy condition by combining the constraint of continuous change of boundary curvature, and determining it as the true boundary curve set of the orifice.
8. The method for detecting the accuracy of CNC machining holes in a mobile phone frame based on machine vision according to claim 1, characterized in that: Geometric fitting is performed on the true boundary curve of each orifice to obtain the set of orifice center coordinates, including: For each of the orifice true boundary curves in the set of orifice true boundary curves, uniform arc length resampling is performed to construct the corresponding boundary discrete point sequence, and the radial distance sequence of each boundary point relative to the boundary geometric centroid is calculated. A radial consistency evaluation function is constructed based on the radial distance sequence, and a set of stable boundary points is obtained by iteratively removing abnormal boundary points whose radial deviation exceeds a preset deviation threshold. A geometric reconstruction model of the orifice is established based on the set of stable boundary points, and the center coordinates and radius parameters are calculated by minimizing the objective function of the distance error from the stable boundary points to the fitted circle. The calculated center coordinates of each fitted circle are used as the center coordinates of the corresponding orifice, and then summarized to form a set of orifice center coordinates.
9. The method for detecting the accuracy of CNC machining holes in a mobile phone frame based on machine vision according to claim 1, characterized in that: Constructing the topological relationship of the hole position array based on the set of hole position center coordinates includes: calculating the spatial adjacency relationship between each hole position based on the set of hole position center coordinates; determining the set of adjacent holes for each hole position by sorting the Euclidean distance between any two hole position centers; and constructing the topological connection diagram of the hole position array accordingly.
10. The method for detecting the accuracy of CNC machining holes in a mobile phone frame based on machine vision according to claim 9, characterized in that: Correcting abnormally offset holes based on array topology relationships includes: calculating the relative position vectors between the center of each hole and its adjacent hole centers according to the hole array topology connection diagram, and constructing an array reference vector set by statistically analyzing the average direction and average distance of all relative position vectors; calculating the offset difference between the actual relative position vector of each hole center and the corresponding array reference vector, and identifying hole centers with offsets exceeding a preset offset threshold as abnormally offset holes; and performing position regression correction on the abnormally offset holes according to the array reference vector relationship between the abnormally offset holes and their adjacent holes to obtain a corrected set of hole coordinates.