Element positioning method and device and storage medium

By using adaptive grayscale range segmentation and multi-directional edge fitting, the problems of poor adaptability of fixed threshold and noise interference in component positioning are solved, and high-precision component positioning in dynamic environments is achieved.

CN121685448APending Publication Date: 2026-03-17SHENZHEN FAROAD INTELLIGENT EQUIP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-08
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

Existing technologies using fixed thresholds for component positioning cannot adapt to dynamic environments, resulting in poor positioning accuracy and making geometric feature extraction susceptible to noise interference.

Method used

An adaptive grayscale range segmentation and multi-directional edge fitting method is adopted. By acquiring component images from an industrial camera under a ring light source, converting them into grayscale images, performing adaptive grayscale range segmentation, extracting the outer contours of candidate regions and calculating geometric features, and combining morphological operations and multi-directional edge fitting, the parameter information of the components is determined.

Benefits of technology

It improves the accuracy and robustness of component positioning, avoids misjudgment in complex backgrounds, and ensures the accuracy of candidate regions and the reliability of subsequent operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121685448A_ABST
    Figure CN121685448A_ABST
Patent Text Reader

Abstract

The invention discloses an element positioning method and device and a storage medium, and relates to the technical field of element positioning, and the method comprises the steps: obtaining an original BGR image of an element collected by an industrial camera under an annular light source; preprocessing the original BGR image to obtain a grey-scale map; carrying out adaptive gray scale range segmentation on the gray scale map to obtain a candidate region comprising elements; extracting the external contour of the candidate region, and calculating the geometric features of the external contour; determining a target candidate region according to the geometric features; performing multi-direction edge collaborative fitting on the contour points of the target candidate area to obtain parameter information of the element; and obtaining a positioning result of the element according to the parameter information of the element. High-precision positioning of the element is achieved, the positioning accuracy is improved, and the stability and reliability of the positioning process are enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of component positioning technology, and in particular to component positioning methods, devices and storage media. Background Technology

[0002] For industrial scenarios such as electronics manufacturing, semiconductor packaging, and precision instruments, the core requirement is to quickly and accurately locate regular geometric components, including the position and orientation of rectangles, circles, and polygons, in complex backgrounds. The orientation includes the center coordinates and rotation angle, thereby providing coordinate guidance for subsequent robotic arm grasping, welding, or inspection.

[0003] Current component localization methods mainly include feature point localization, template matching localization, and grayscale + geometric method localization. The grayscale + geometric method mainly obtains candidate regions by segmenting grayscale images with a fixed threshold, then extracts geometric features of the contour to filter targets, and finally calculates the position by fitting a line / circle. However, the fixed threshold cannot adapt to dynamic environments and is easily affected by noise when extracting geometric features, resulting in poor localization accuracy. Summary of the Invention

[0004] The main objective of this application is to provide a component positioning method, apparatus, and storage medium, which aims to solve the technical problems that current component positioning methods using fixed thresholds cannot adapt to dynamic environments and are easily affected by noise interference during geometric feature extraction, resulting in poor positioning accuracy.

[0005] To achieve the above objectives, this application proposes a component positioning method, the component positioning method comprising: Acquire raw BGR images of components captured by an industrial camera under a ring light source; The original BGR image is preprocessed to obtain a grayscale image; Adaptive grayscale range segmentation is performed on the grayscale image to obtain candidate regions including elements; Extract the outer contour of the candidate region and calculate the geometric features of the outer contour; The target candidate region is determined based on the geometric features; Multi-directional edge co-fitting is performed on the contour points of the target candidate region to obtain the parameter information of the element; The positioning result of the component is obtained based on the parameter information of the component.

[0006] In one embodiment, the step of adaptively segmenting the grayscale image to obtain candidate regions including elements includes: Calculate the grayscale histogram of the grayscale image normalized to a preset range; The main peak is determined based on the grayscale histogram, and the target valley value is determined based on the main peak. The dynamic segmentation grayscale threshold is determined based on the preset scaling factor and the target valley value; The grayscale image is binarized according to the dynamic segmentation grayscale threshold to obtain an initial candidate region mask; The initial candidate region mask is subjected to morphological operations of opening and closing operations in sequence to obtain candidate regions including elements.

[0007] In one embodiment, the steps of determining the main peak based on the grayscale histogram and determining the target valley value based on the main peak include: Traverse the grayscale histogram to obtain local maxima. The peak heights corresponding to the local maxima are sorted, and the first peak and the second peak are obtained based on the sorted peak heights. Obtain the minimum histogram value corresponding to the left and the minimum histogram value corresponding to the right of the first peak and the second peak, and obtain the left valley value and right valley value of the first peak and the left valley value and right valley value of the second peak; A first ratio is calculated based on the left valley value of the first peak and the first peak value, and a second ratio is calculated based on the left valley value of the second peak and the second peak value; Determine the target ratio from the first ratio and the second ratio; The peak value corresponding to the target ratio is taken as the main peak, and the left and right valley values ​​corresponding to the peak value are taken as the target valley values.

[0008] In one embodiment, the step of extracting the outer contour of the candidate region and calculating the geometric features of the outer contour includes: The outer contour is obtained by extracting the outermost boundary point set of each connected foreground region in the binary mask image of the candidate region using an outer contour extraction algorithm. For each of the outer contours, calculate the area, center, width, height, and rotation angle of the outer contour; The minimum bounding rectangle of the outer contour is obtained based on the center, the width and height, and the rotation angle; Based on the area and the minimum bounding rectangle, the closeness between the outer contour and the rectangle is calculated to obtain the rectangularity. Calculate the aspect ratio based on the width and height of the minimum bounding rectangle; The geometric features of the outer contour are obtained based on the minimum bounding rectangle, the area, the rectangularity, and the aspect ratio.

[0009] In one embodiment, the step of determining the target candidate region based on the geometric features includes: Based on the geometric features, the aspect ratio, area, rectangularity, and minimum bounding rectangle are obtained. Get the component type of the component; The filtering conditions are determined based on the component type, including area filtering threshold, rectangularity filtering threshold, and aspect ratio filtering threshold. The area, rectangularity, and aspect ratio are filtered according to the filtering conditions to obtain the filtered area, rectangularity, and aspect ratio. Based on the minimum bounding rectangle, the filtered area, the rectangularity, and the aspect ratio, a region that conforms to the geometry of the component is obtained, and this region is used as the target candidate region.

[0010] In one embodiment, the step of performing multi-directional edge co-fitting on the contour points of the target candidate region to obtain the parameter information of the element includes: Merge the contour points of the target candidate region to obtain the edge point set; Calculate the mean center of the edge point set; Based on the deviation of each contour point from the mean center on the ordinate, a set of horizontal edge points is obtained; Based on the deviation of each contour point from the mean center on the horizontal coordinate, a set of vertical edge points is obtained; The random sampling consensus algorithm is used to fit straight lines to the horizontal edge point set and the vertical edge point set respectively, resulting in the horizontal fitted line and the vertical fitted line. The parameter information of the element is determined based on the horizontal and vertical fitted lines.

[0011] In one embodiment, the step of determining the parameter information of the element based on the horizontal fitted line and the vertical fitted line includes: Find the intersection point of the horizontal fitted line and the vertical fitted line, and take the intersection point as the geometric center of the element; Calculate the horizontal and vertical line angles based on the horizontal and vertical fitted lines; The angle of the element is calculated based on the horizontal line angle and the vertical line angle. The parameter information of the component is obtained based on the geometric center of the component and the angle of the component.

[0012] In one embodiment, after the step of obtaining the positioning result of the element based on the parameter information of the element, the method further includes: The width and height of the minimum bounding rectangle are obtained based on the geometric features of the outer contour. Construct a fitted rotation rectangle based on the geometric center, the width and height, and the angle; Calculate the distance from the contour points of the target candidate region to the fitted rotation rectangle, and calculate the average distance based on the distance; When the average distance is less than a preset distance threshold and the number of valid points in the contour points of the target candidate region is greater than a preset number threshold, the positioning result is determined to be successful.

[0013] Furthermore, to achieve the above objectives, this application also proposes a component positioning device, the component positioning device comprising: The acquisition module is used to acquire raw BGR images of components captured by an industrial camera under a ring light source; The preprocessing module is used to preprocess the original BGR image to obtain a grayscale image; The segmentation module is used to perform adaptive grayscale range segmentation on the grayscale image to obtain candidate regions including elements; An extraction module is used to extract the outer contour of the candidate region and calculate the geometric features of the outer contour; The determination module is used to determine the target candidate region based on the geometric features; The fitting module is used to perform multi-directional edge co-fitting on the contour points of the target candidate region to obtain the parameter information of the element; The acquisition module is also used to obtain the positioning result of the component based on the parameter information of the component.

[0014] In addition, to achieve the above objectives, this application also proposes a component positioning device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the component positioning method as described above.

[0015] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the component positioning method described above.

[0016] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the component positioning method described above.

[0017] One or more technical solutions proposed in this application have at least the following technical effects: 1) Converting the original BGR image to grayscale helps reduce the impact of illumination changes on image processing, reduces noise, and improves the efficiency of subsequent processing. Adaptive grayscale segmentation of the grayscale image can automatically adjust the threshold according to different regions of the image, thus better adapting to uneven illumination or complex backgrounds. This effectively improves the segmentation accuracy of component regions, avoids erroneous segmentation due to inappropriate thresholds, and ensures the accuracy of candidate regions. By extracting the contours of candidate regions and calculating their geometric features, the boundaries and shapes of components can be better identified. By comprehensively considering geometric features to further filter and confirm target regions and eliminate regions that do not meet the conditions, the accuracy of localization is improved. Especially in the case of complex backgrounds or multiple targets, misjudgments can be avoided. Multi-directional edge information is fitted to the contour points of the target candidate region, effectively improving the accuracy of edge recognition and making the edge fitting of components more precise. Finally, through precise contour fitting and parameter calculation, the accurate position and orientation of the component can be obtained, improving the localization effect.

[0018] 2) Normalizing the grayscale values ​​of the grayscale image can unify the illumination variations in the image, reduce the influence of ambient light, and make subsequent histogram analysis more reliable. The normalized grayscale histogram can effectively reflect the brightness distribution characteristics in the image, providing data support for determining an appropriate threshold. By analyzing the peaks and valleys of the grayscale histogram, an appropriate threshold can be automatically determined. This automated method avoids the limitations of manually setting fixed thresholds and can better adapt to different image variations, especially under conditions of significant changes in illumination or object shape, ensuring the accuracy of segmentation. By combining the analysis results of the grayscale histogram and considering a preset scaling factor, the segmentation threshold is dynamically adjusted. This method not only improves the adaptability of image segmentation but also accurately identifies object regions under various environmental conditions, avoiding errors that may be caused by static threshold settings. After binarizing the grayscale image using a dynamic segmentation threshold, the foreground and background can be effectively distinguished, thereby generating an initial candidate region mask. Based on the initial candidate region mask, opening and closing operations are performed to further clean up noise, fill holes, and smooth edges, improving the connectivity and accuracy of the segmented region. Through a series of adaptive segmentation and morphological operations, precise candidate regions including components can be obtained. This provides accurate regions for subsequent target detection and localization, feature extraction, and other operations, avoiding missed or false detections and improving the robustness and stability of the entire process.

[0019] 3) The outer contour extraction algorithm extracts the outermost boundary point set of each connected foreground region from the binarized image. This step ensures accurate extraction of the object's shape and contour, providing a reliable foundation for subsequent analysis. Calculating the area, center, width, height, and rotation angle of the outer contour comprehensively describes the object's shape and position. Based on the center, width, height, and rotation angle of the outer contour, the minimum bounding rectangle is obtained. The minimum bounding rectangle effectively defines the object's spatial extent and provides a standardized reference frame. By calculating the proximity between the outer contour and the minimum bounding rectangle, the regularity of the object's shape can be assessed. Based on the width and height of the minimum bounding rectangle, the aspect ratio is calculated, allowing for rapid differentiation of the object's geometric features. By combining multiple geometric features such as the minimum bounding rectangle, area, rectangularity, and aspect ratio, a multi-dimensional and comprehensive evaluation of the object's contour can be achieved. Attached Figure Description

[0020] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0021] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 This is a flowchart illustrating an embodiment of the component positioning method of this application. Figure 2 This is a flowchart illustrating Embodiment 2 of the component positioning method of this application; Figure 3 This is a flowchart illustrating Embodiment 3 of the component positioning method of this application; Figure 4 A simplified flowchart is provided for one embodiment of the component positioning method of this application; Figure 5 This is a schematic diagram of the module structure of the component positioning device in an embodiment of this application; Figure 6 This is a schematic diagram of the device structure of the hardware operating environment involved in the component positioning method in the embodiments of this application.

[0023] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0024] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.

[0025] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.

[0026] The main solution of this application embodiment is as follows: acquiring the original BGR image of the component captured by an industrial camera under a ring light source; preprocessing the original BGR image to obtain a grayscale image; performing adaptive grayscale range segmentation on the grayscale image to obtain candidate regions including the component; extracting the outer contour of the candidate regions and calculating the geometric features of the outer contour; determining the target candidate region based on the geometric features; performing multi-directional edge co-fitting on the contour points of the target candidate region to obtain the parameter information of the component; and obtaining the positioning result of the component based on the parameter information of the component.

[0027] Existing technologies first segment grayscale images using a fixed threshold, such as the Otsu threshold, to obtain candidate regions. Then, they extract geometric features of the contours, such as area and perimeter, to filter targets. Finally, they use straight lines or circles to fit and calculate the position of the components. However, fixed thresholds cannot adapt to dynamic environments. The grayscale of different batches of components may fluctuate, such as due to differences in coating thickness, or changes in workshop lighting, such as changes in window light transmission. This can lead to candidate regions containing noise or missing targets. Furthermore, there is a lack of coordination between geometric feature extraction and grayscale filtering. Contour extraction is easily affected by noise, such as dust in the image. Noise that is not filtered by grayscale information can lead to deviations in the fitting results, such as fitting a straight line to a noisy point. After obtaining the positioning result, there is a lack of result verification, meaning that the accuracy of the fitted position is not quantified, which may result in the output of incorrect coordinates.

[0028] This application provides a solution that converts the original BGR image into a grayscale image and employs adaptive grayscale range segmentation. This effectively solves the problem of fixed thresholds being difficult to adapt to dynamic environments. It automatically adjusts the segmentation threshold based on the actual grayscale distribution of the image, avoiding excessive noise in candidate regions or target omissions caused by grayscale fluctuations in different batches of components or changes in workshop lighting. When extracting the outer contour of the candidate region and calculating geometric features, it works closely with the grayscale segmentation stage, utilizing accurate candidate regions obtained through adaptive segmentation for contour extraction. This reduces interference from noise such as dust in the image, avoiding fitting result deviations caused by noise points and improving the accuracy of linear or circular fitting calculations of component positions. Furthermore, after obtaining the component positioning result, this application constructs a fitting rotation rectangle, calculates the distance from the contour points of the target candidate region to the fitting rotation rectangle, and obtains the average distance. This average distance is then compared with the number of effective points to a preset threshold to determine whether the positioning was successful. This quantitative accuracy verification of the positioning result effectively avoids outputting incorrect coordinates and improves the accuracy and reliability of the entire component positioning process.

[0029] It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device or component positioning device capable of performing the above functions. The following description uses a component positioning device as an example to illustrate this embodiment and the subsequent embodiments.

[0030] Based on this, embodiments of this application provide a component positioning method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the component positioning method of this application.

[0031] In this embodiment, the component positioning method includes steps S10 to S40: Step S10: Acquire the raw BGR image of the component captured by the industrial camera under a ring light source.

[0032] It should be noted that the core logic of this application is: "Adaptive grayscale screening → Geometric feature pre-screening → Multi-directional edge co-fitting → Result verification," implemented entirely based on OpenCV (Open Source Computer Vision Library), ensuring industrial-grade robustness and real-time performance. The industrial camera has a resolution of 2592×1944, and the ring light source, i.e., a ring LED, is used to supplement the light when the industrial camera captures images of the components, thereby uniformly illuminating the components and reducing reflections.

[0033] The main application scenario of this embodiment is industrial automation visual inspection, such as the mounting and positioning of resistors, capacitors or chips on PCB boards, and can also be used for scenarios such as wafer-level chip picking and connector and interface alignment.

[0034] After capturing images of the components under a ring light source using an industrial camera, the raw BGR image is obtained. The raw BGR image is the unprocessed BGR image. A BGR image is a color digital image stored in the order of the three color channels: Blue, Green, and Red. This is the default color space format used by the OpenCV library when reading images.

[0035] Step S20: Preprocess the original BGR image to obtain a grayscale image.

[0036] Understandably, after obtaining the original BGR image, it can be converted into a grayscale image suitable for subsequent processing to remove noise and lay the foundation for grayscale segmentation. Therefore, preprocessing can include converting the original BGR image into a grayscale image. This conversion can be achieved using the `cvtColor` function in the OpenCV library. This grayscale image stores pixel brightness information in a single-channel format, with pixel values ​​ranging from 0 to 255, where 0 represents black and 255 represents white. Converting to grayscale not only reduces the amount of image data and lowers the computational complexity of subsequent processing, but also avoids interference from color information on image segmentation and feature extraction, allowing the algorithm to focus more on the image's shape and texture features. Furthermore, to further improve image quality, the grayscale image can be denoised using methods such as Gaussian filtering and median filtering to suppress high-frequency noise, such as thermal noise from the image sensor, making the image smoother and providing a more reliable input for subsequent adaptive grayscale range segmentation.

[0037] Step S30: Perform adaptive grayscale range segmentation on the grayscale image to obtain candidate regions including elements.

[0038] Adaptive grayscale range segmentation uses a dynamic segmentation threshold. Since traditional fixed thresholds cannot adapt to dynamic environments, the segmentation method in this embodiment can automatically adjust the segmentation threshold based on the grayscale distribution of different regions in the image to adapt to environments with uneven lighting or complex backgrounds. Specifically, a suitable segmentation threshold can be dynamically determined by analyzing the peaks and valleys of the grayscale histogram and combining them with a preset scaling factor. This method avoids the limitations of fixed threshold segmentation methods in dynamic environments, such as grayscale fluctuations caused by changes in lighting or differences in component batches, thereby effectively improving the segmentation accuracy of candidate regions. After obtaining the initially segmented candidate regions, further morphological operations, such as opening and closing operations, can be used to clean up noise, fill holes, and smooth edges, improving the connectivity and accuracy of the segmented regions. Through these adaptive segmentation and morphological processing steps, accurate candidate regions including components can be obtained, providing a reliable regional basis for subsequent target detection and localization, feature extraction, and other operations.

[0039] Step S40: Extract the outer contour of the candidate region and calculate the geometric features of the outer contour.

[0040] In practice, the candidate regions can be subjected to set feature extraction and filtering to obtain the geometric features of the outer contour of the candidate regions. Since the candidate regions may contain noise, such as dust and silkscreen, it is necessary to use geometric features to filter out non-target regions. By extracting the outer contour of the candidate regions, only the outermost contour is retained, thereby avoiding interference from internal holes of the components and improving the accuracy of contour extraction.

[0041] After extracting the outer contour, relevant functions in the OpenCV library can be used to calculate the contour's geometric features, such as area, center, width, height, and rotation angle. These geometric features can comprehensively describe the object's shape and position information, providing important basis for subsequent target selection and localization.

[0042] Step S50: Determine the target candidate region based on the geometric features.

[0043] In practice, candidate regions can be screened and eliminated based on information such as area, center, width and height in geometric features. This can filter out noisy regions that are too small or too large, or non-target regions that are too flat or too long, thereby obtaining the target candidate region.

[0044] The target candidate region and the region that matches the element geometry after screening the candidate regions are reduced in terms of subsequent fitting computation and noise interference.

[0045] In one feasible implementation, step S50 may include steps A11-A15: Step A11: Obtain the aspect ratio, area, rectangularity, and minimum bounding rectangle based on the geometric features; It should be noted that the set features include aspect ratio, area, rectangularity, and minimum bounding rectangle. Aspect ratio and minimum bounding rectangle are the ratio of the length to the width. Area is the area of ​​the outer contour of the candidate region. Rectangularity is the degree of closeness between the outer contour of the candidate region and the minimum bounding rectangle. Minimum bounding rectangle is the smallest enclosing rectangle of the outer contour.

[0046] Step A12: Obtain the component type of the component; In practice, different component types require different filtering conditions. Therefore, it's essential to first identify the component type to determine appropriate filtering parameters. For instance, resistors and capacitors differ in shape and size, leading to different filtering conditions such as area range and aspect ratio range. Obtaining the component type allows for more targeted filtering of candidate regions, improving the accuracy of target region identification.

[0047] Step A13: Determine the filtering conditions based on the component type. The filtering conditions include area filtering threshold, rectangularity filtering threshold, and aspect ratio filtering threshold. Based on the acquired component type, corresponding filtering conditions can be determined. These filtering conditions are set according to the characteristics of different component types, aiming to accurately filter out regions from the candidate region that match the geometric characteristics of the target component. The area filtering threshold is used to filter out regions that are too large or too small, as these regions are likely noise or non-target components; the rectangularity filtering threshold measures the proximity of the candidate region's outer contour to the minimum bounding rectangle to exclude irregularly shaped regions that do not conform to the target component's shape characteristics; the aspect ratio filtering threshold further filters out regions whose aspect ratio does not meet the requirements based on the target component's aspect ratio range. For example, the area filtering threshold can be set to 100 pixels. 2 The rectangle size filter threshold is set to 0.9, and the aspect ratio filter threshold range is set to 0.8-1.2. Rectangle size > 0.9 is considered a rectangular element.

[0048] Step A14: Filter the area, the rectangularity, and the aspect ratio according to the filtering conditions to obtain the filtered area, rectangularity, and aspect ratio; After determining the filtering criteria, the next step is to compare the geometric features of the candidate regions with these criteria. This involves filtering based on area, rectangularity, and aspect ratio, for example, selecting regions with areas smaller than a few pixels. 2 The area is eliminated, and components with a rectangle size less than or equal to 0.9 are eliminated. Areas with an aspect ratio not between 0.8 and 1.2 are also eliminated, thus obtaining components with a rectangle size > 0.9, an aspect ratio between 0.8 and 1.2, and an area > 100 pixels. 2 The area.

[0049] Step A15: Based on the minimum bounding rectangle, the filtered area, the rectangularity, and the aspect ratio, obtain the region that conforms to the geometry of the component, and use the region as the target candidate region.

[0050] In practice, based on the filtered geometric feature parameters and the minimum bounding rectangle information, it can be comprehensively determined which regions meet the geometric shape requirements of the target element. For example, if a candidate region, after filtering, meets the preset screening conditions in terms of area, rectangularity, and aspect ratio, and its minimum bounding rectangle matches the expected shape of the element, then that region can be identified as a target candidate region. This step effectively narrows the scope of subsequent fitting processing, reduces computational load, and improves the accuracy of localization.

[0051] Step S60: Perform multi-directional edge co-fitting on the contour points of the target candidate region to obtain the parameter information of the element.

[0052] After identifying the target candidate region, the next step is to perform precise edge fitting to obtain detailed parameter information of the component. This embodiment employs a multi-directional edge co-fitting method. By fitting the contour points of the target candidate region in different directions, the edge features of the component can be captured more accurately. Specifically, fitting functions in the OpenCV library, such as least squares fitting of lines or circles, can be used to fit the contour points of the target candidate region in multiple directions. By comparing the fitting results in different directions, the optimal fitting parameters can be selected to obtain the component's parameter information, including the component's precise position and shape parameters. Shape parameters may include center coordinates, radius, angle, etc.

[0053] In one feasible implementation, step S60 may include steps B11 to B15: Step B11: Merge the contour points of the target candidate region to obtain the edge point set; In practical implementation, since directly fitting all edge points is easily affected by noise, it is necessary to separate edge points in different directions. Therefore, the Robin algorithm can be used for fitting. Specifically, the contour points of all selected target candidate regions can be merged into an edge point set allEdgePoints to reduce redundant calculations.

[0054] Step B12: Calculate the mean center of the edge point set; In practice, the mean center of all edge points in the edge point set, meanPt, can be calculated. For example, cv::mean(allEdgePoints) can be used to calculate the mean center of all edge points. This mean center can be used as a reference point for subsequent fitting, which helps to improve the accuracy and stability of the fitting.

[0055] Step B13: Based on the deviation of each contour point from the mean center on the ordinate, separate the horizontal edge point set; A deviation threshold can be set, for example, to 5 pixels, or other values; this embodiment does not impose any restrictions on this. Edge points are separated using the deviation threshold.

[0056] Specifically, the deviation between the y-coordinates of each contour point and the mean center can be compared with the deviation threshold. Points whose y-coordinate deviation from the mean center meanPt is less than 5 pixels, i.e., points whose abs(pt.y - meanPt.y) < 5, are taken as horizontal points. The horizontal edge point set is obtained by summarizing the points, and the horizontal edge point set corresponds to the horizontal edge of the element.

[0057] Step B14: Based on the deviation of each contour point from the mean center on the horizontal coordinate, separate the vertical edge point set; In practice, the deviation between each contour point and the x-coordinate of the mean center can be compared with the deviation threshold. Points with a deviation of less than 5 pixels from the mean center meanPt, i.e., points with abs(pt.x - meanPt.x) < 5, are taken as vertical points and summarized to obtain the vertical edge point set. The vertical edge point set corresponds to the horizontal edge of the element.

[0058] Step B15: Apply the random sampling consensus algorithm to the horizontal edge point set and the vertical edge point set respectively to fit a straight line, and obtain the horizontal fitted line and the vertical fitted line; It should be noted that the Random Sampling Consensus (RANSAC) algorithm can suppress outliers, such as noise points. Therefore, RANSAC can be used to fit the horizontal and vertical edge point sets separately to obtain the horizontal and vertical fitted lines.

[0059] During the fitting process, adjustable parameters can be set, such as a distance threshold of 0.01 pixels and a confidence threshold of 0.99 for the fitting result. When the confidence level of the fitting result reaches or exceeds 0.99, the fitted line is considered reliable. Through the iterative process of the RANSAC algorithm, the straight line model that best fits the data distribution—namely, the horizontal and vertical fitted lines—can be extracted from the set of noisy edge points. These two lines represent the edge features of the component in the horizontal and vertical directions, respectively, providing a basis for subsequent calculations of the component's precise position and shape parameters. For example, the slope of the horizontal fitted line reflects the component's tilt in the horizontal direction, while the slope of the vertical fitted line reflects its tilt in the vertical direction. Furthermore, by calculating the intersection of these two lines, the center coordinates of the component can be determined. Combined with the equation of the lines, shape parameters such as the component's angles can also be calculated. This parameter information is crucial for the precise positioning of the component and subsequent assembly and inspection operations.

[0060] Step B16: Determine the parameter information of the element based on the horizontal fitted line and the vertical fitted line.

[0061] It should be noted that the parameter information of the element can be calculated based on the horizontal and vertical fitted lines. The parameter information includes information such as center and angle.

[0062] In one feasible implementation, step B16 may include: finding the intersection point of the horizontal fitted line and the vertical fitted line, and using the intersection point as the geometric center of the element; calculating the horizontal line angle and the vertical line angle based on the horizontal fitted line and the vertical fitted line; calculating the angle of the element based on the horizontal line angle and the vertical line angle; and obtaining the parameter information of the element based on the geometric center of the element and the angle of the element.

[0063] Understandably, by solving for the intersection of the horizontal and vertical fitted lines, the geometric center of a component can be accurately located. This center point serves as a reference for the core position of the component on the plane, providing a crucial basis for subsequent positioning and assembly operations.

[0064] Specifically, the horizontal line parameters are ( h vx , h vy , h x0 , h y0 ), representing the direction vector ( h vx , h vy ), past the point ( h x0 , h y0 ), the vertical line parameters are ( v vx , v vy , v x0 , v y0 ), representing the direction vector ( v vx , v vy ), past the point ( v x0 , v y0 The coordinates of the center point are as follows: In the above formula, ( center x , center y Let be the geometric center coordinates of the element in question, where can be obtained through operations such as cross multiplication and transposition. center x and center y .

[0065] After obtaining the geometric center, the angles between the horizontal and vertical fitted lines and the coordinate axes can be calculated using their direction vectors. These angles are the horizontal angle and the vertical angle. For example, the horizontal angle... θ h = atan2( h vy , h vx ), vertical angle θ v= atan2( v vy , v vx Since the angle of a component is usually the angle relative to a reference direction (such as the horizontal direction), the angle of the component can be calculated based on the horizontal and vertical angles. For example, the angle of the horizontal or vertical line can be directly taken as the angle of the component. If the component is based on the horizontal direction, then the horizontal angle is taken. θ h As for the angle of a component, if the component is based on the vertical direction, then the angle of the vertical line is taken. θ v As for the angle of a component, if the component is rectangular, its angle is the supplementary angle between the horizontal line and the vertical line, and the angle is calculated as follows: In the above formula, The angle of the component is calculated by taking the angle θ of the horizontal line. h and the angle θ of the vertical line v The difference is obtained by taking the supplementary angle.

[0066] After obtaining the geometric center coordinates and angles of the component Then, by combining the expected shape and size information of the component, the complete parameter information of the component can be further determined. This parameter information includes not only the precise position of the component on the plane, determined by the geometric center coordinates, but also the shape characteristics of the component, such as angles and aspect ratios, thus obtaining the component's parameter information. This provides comprehensive and accurate data support for subsequent component assembly, quality inspection, and other operations.

[0067] Step S70: Obtain the positioning result of the component based on the parameter information of the component.

[0068] After obtaining the parameter information of the component, the positioning result of the component can be determined based on this information. For example, for a circular component, its specific position in the image can be determined based on its center coordinates and radius; for a rectangular component, its position and orientation can be determined based on its center coordinates, width, height, and angle. Through this step, accurate positioning of the component can be achieved, providing reliable position information for subsequent automated operations. Since the fitting result may be incorrect due to noise or missing feature points, it is necessary to quantify and verify the accuracy. Therefore, in a feasible implementation, after step S70, steps S71 to S74 are also included: Step S71: Obtain the width and height of the minimum bounding rectangle based on the geometric features of the outer contour; To ensure the accuracy and reliability of the positioning results, this embodiment also includes a step to verify the quantification accuracy of the positioning results. Specifically, the width and height of the smallest bounding rectangle among the geometric features can be obtained.

[0069] Step S72: Construct a fitted rotation rectangle based on the geometric center, the width and height, and the angle; It should be noted that the fitted rotated rectangle can be reconstructed using cv::RotatedRect with the fitted geometric center, angle, and the width and height of the minimum bounding rectangle. If the element is elliptical, the ellipse of the outer contour of the candidate region can also be fitted to extract the center and angle of the ellipse.

[0070] Step S73: Calculate the distance from the contour points of the target candidate region to the fitted rotation rectangle, and calculate the average distance based on the distance; In practice, `cv::pointPolygonTest` can be used to calculate the distance from each contour point of the target candidate region to the fitted rotation rectangle. Specifically, the calculation is `dist = cv::pointPolygonTest(fittedRect.vertices(), pt, true)`, where `true` indicates the distance from the point to the interior of the polygon, `fittedRect.vertices()` is the set of vertex coordinates of the fitted rotation rectangle, and `pt` is the coordinates of the contour points of the target candidate region. By iterating through all contour points, the distance from each point to the fitted rotation rectangle can be obtained, and then the average distance can be calculated based on these distances. This average distance reflects the overall deviation between the target candidate region and the fitted rotation rectangle. A smaller average distance indicates a better fit and more accurate positioning; a larger average distance may indicate errors in the fitting process, requiring further analysis and adjustment of the positioning results.

[0071] Step S74: When the average distance is less than a preset distance threshold and the number of valid points in the contour points of the target candidate region is greater than a preset number threshold, the positioning result is determined to be successful.

[0072] The preset distance threshold can be set according to the actual application scenario and accuracy requirements. For example, if the preset distance threshold is set to 0.5 pixels, and the number of effective points equals the total number of points in the contour points of the target candidate region, when the average distance is less than the preset distance threshold, it indicates that the target candidate region fits the fitted rotating rectangle well. Simultaneously, if the number of effective points in the contour points of the target candidate region is greater than the preset number threshold, it indicates that the number of edge points participating in the fitting is sufficient, and the fitting result has high reliability. Therefore, the positioning result can be determined as successful. If the average distance is greater than or equal to the preset distance threshold, or the number of effective points is less than or equal to the preset number threshold, it indicates that there may be a large error in the fitting process, possibly due to noise interference, missing feature points, or the component shape not matching expectations. In this case, it is necessary to adjust the threshold of the grayscale distribution dynamics to improve the positioning accuracy. Specifically, the overlap rate between the rectangle and the outer contour of the target candidate region can also be calculated. The overlap rate = overlapping area / outer contour area. If the overlap rate is greater than 90%, the positioning is successful; otherwise, the positioning fails.

[0073] This quantitative accuracy verification method effectively improves the reliability and stability of component positioning, providing more accurate position information for subsequent automated operations. It effectively avoids outputting incorrect coordinates, thus enhancing the accuracy and reliability of the entire component positioning process.

[0074] This embodiment provides a component localization method that converts the original BGR image into a grayscale image, helping to reduce the impact of illumination changes on image processing, reduce noise, and improve the efficiency of subsequent processing. Adaptive grayscale segmentation of the grayscale image automatically adjusts the threshold according to different regions of the image, thus better adapting to uneven illumination or complex backgrounds. This effectively improves the segmentation accuracy of component regions, avoids erroneous segmentation due to inappropriate thresholds, and ensures the accuracy of candidate regions. By extracting the contours of candidate regions and calculating their geometric features, the boundaries and shapes of components can be better identified. Further screening and confirmation of target regions by comprehensively considering geometric features, and eliminating regions that do not meet the criteria, improves localization accuracy. Especially in complex backgrounds or with multiple targets, it avoids misjudgment. Fitting multi-directional edge information to the contour points of the target candidate region effectively improves the accuracy of edge recognition, making the edge fitting of components more precise. Finally, through precise contour fitting and parameter calculation, the accurate position and orientation of the component can be obtained, improving the localization effect.

[0075] Based on the first embodiment of this application, in the second embodiment of this application, the content that is the same as or similar to that in the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 2 Step S30 includes steps S301 to S305: Step S301: Calculate the grayscale histogram of the grayscale image normalized to a preset range.

[0076] It should be noted that the preset interval is the [0,1] interval. First, the 256-bit histogram of the grayscale image can be calculated, and then the 256-bit histogram of the grayscale image can be normalized to the [0,1] interval. This maps the histogram values ​​to the [0,1] interval, eliminating the impact of differences in grayscale ranges of different images, such as exposure differences, on subsequent analysis.

[0077] By normalizing the 256-bit histogram of the grayscale image to the [0,1] interval, a grayscale histogram can be obtained. For example, if the grayscale of a certain component is concentrated in [50,150] in image A and in [100,200] in image B, after normalization, both will appear as [0.25,0.75], ensuring the robustness of the main peak detection algorithm.

[0078] Step S302: Determine the main peak based on the grayscale histogram, and determine the target valley value based on the main peak.

[0079] It should be noted that the main peak (mainPeak) represents the core region of the component's grayscale distribution. The main peak can be used as a reference to divide the grayscale range into left and right sections. The left valley corresponds to the lower limit of background noise, and the right valley corresponds to the upper limit of secondary targets; these two constitute a dynamic threshold window. Therefore, the main peak can be found on the grayscale histogram, and the target valley value can be determined based on the obtained main peak. The target valley value includes both the left and right valley values ​​of the main peak.

[0080] The left valley value of the main peak is the minimum histogram value to the left of the main peak, corresponding to the lower limit of background noise. The right valley value of the main peak is the minimum histogram value to the right of the main peak, corresponding to the upper limit of secondary targets. The left side of the main peak is from 0 to mainPeak, and the right side of the main peak is from mainPeak to 255.

[0081] In one feasible implementation, step S302 may include steps C11 to C16: Step C11: Traverse the grayscale histogram to obtain local maxima; It should be noted that the grayscale histogram can be traversed to filter local maxima. A local maximum is defined as the frequency of a certain grayscale bin (i.e., the histogram value) of a local maximum in the grayscale histogram being strictly greater than the frequency of its left and right neighboring grayscale bins. In other words, the current bin value > the values ​​of its left and right neighboring bins.

[0082] Step C12: Sort the peak heights corresponding to the local maxima points, and obtain the first peak and the second peak based on the sorted peak heights; In practice, after selecting multiple local maxima, they can be sorted according to the peak height corresponding to the local maxima. The peak height is the size of the histogram value. The sorting method is descending order, thereby selecting the two largest peaks, namely the first peak and the second peak.

[0083] Step C13: Obtain the minimum histogram value corresponding to the left and the minimum histogram value corresponding to the right of the first peak and the second peak, so as to obtain the left valley value and right valley value of the first peak and the left valley value and right valley value of the second peak; In practice, the minimum histogram value corresponding to the left and right sides of the first peak can be obtained respectively, and the minimum histogram value corresponding to the left and right sides of the second peak can be obtained, thus obtaining the left and right valley values ​​of the first peak and the left and right valley values ​​of the second peak.

[0084] Step C14: Calculate a first ratio based on the left valley value of the first peak and the first peak value, and calculate a second ratio based on the left valley value of the second peak and the second peak value; In specific implementation, the depth of the left valley value of the first peak can be obtained, and a first ratio can be calculated based on the depth of the left valley value of the first peak and the height of the first peak. The first ratio = the height of the first peak / the depth of the left valley value of the first peak. A second ratio can be calculated based on the depth of the left valley value of the second peak and the height of the second peak. The second ratio = the height of the second peak / the depth of the left valley value of the second peak.

[0085] Step C15: Determine the target ratio from the first ratio and the second ratio; It should be noted that the target ratio is the larger of the first ratio and the second ratio. For example, if the first ratio is greater than the second ratio, then the target ratio is the first ratio.

[0086] Step C16: Take the peak value corresponding to the target ratio as the main peak, and take the left valley value and right valley value corresponding to the peak value as the target valley value.

[0087] In practical implementation, the peak value corresponding to the target ratio can be taken as the main peak. For example, if the target ratio is the first ratio, then the first peak value is the main peak. Furthermore, the left and right valley values ​​of the first peak value are the target valley values.

[0088] Step S303: Determine the dynamic segmentation grayscale threshold based on the preset scaling factor and the target valley value.

[0089] In practice, the preset scaling factor can be set in advance, for example, to 0.5. The dynamic segmentation grayscale threshold can be calculated by using the preset scaling factor and the target valley value.

[0090] Specifically, the left valley value of the target valley can be multiplied by 0.5, and the right valley value of the target valley can be multiplied by 0.5 to obtain T_low = left valley value * 0.5 and T_high = right valley value * 0.5. (T_low, T_high) is used as the dynamic grayscale threshold for segmentation, so as to retain the grayscale information of the main body of the component while filtering background noise.

[0091] Step S304: Binarize the grayscale image according to the dynamic segmentation grayscale threshold to obtain the initial candidate region mask.

[0092] It should be noted that the grayscale image can be binarized according to the determined dynamic segmentation threshold, thereby converting the grayscale image into a black and white mask through (T_low, T_high), with white as the candidate region and black as the background, to obtain the initial candidate region mask.

[0093] Step S305: Perform morphological operations of opening and closing operations sequentially on the initial candidate region mask to obtain candidate regions including elements.

[0094] Morphological operations optimize the initial candidate region mask obtained from the binarization result, ensuring the integrity and connectivity of the candidate region by eliminating noise and filling holes.

[0095] Specifically, morphological operations include opening and closing operations. First, a 3×3 rectangular kernel is used to open the initial candidate region mask to remove isolated noise points. Then, a closing operation is used to connect the broken candidate regions, ultimately obtaining the candidate region containing the element. The grayscale image is binarized by dynamically segmenting the grayscale threshold, and morphological operations are performed on the binarized initial candidate region mask. This can adapt to different lighting / batch conditions and accurately segment the candidate region containing the element, avoiding the defects of fixed thresholds.

[0096] This embodiment normalizes the grayscale values ​​of the grayscale image, which unifies the illumination variations in the image, reduces the influence of ambient light, and makes subsequent histogram analysis more reliable. The normalized grayscale histogram effectively reflects the brightness distribution characteristics in the image, providing data support for determining a suitable threshold. By analyzing the peaks and valleys of the grayscale histogram, a suitable threshold can be automatically determined. This automated method avoids the limitations of manually setting fixed thresholds and can better adapt to variations in different images, especially under conditions of significant changes in illumination or object shape, ensuring the accuracy of segmentation. By combining the analysis results of the grayscale histogram and considering a preset scaling factor, the segmentation threshold is dynamically adjusted. This method not only improves the adaptability of image segmentation but also accurately identifies object regions under various environmental conditions, avoiding errors that may be caused by static threshold settings. After binarizing the grayscale image using a dynamic segmentation threshold, the foreground and background can be effectively distinguished, thereby generating an initial candidate region mask. Based on the initial candidate region mask, opening and closing operations are performed to further clean up noise, fill holes, and smooth edges, improving the connectivity and accuracy of the segmented region. Through a series of adaptive segmentation and morphological operations, precise candidate regions including components can be obtained. This provides accurate regions for subsequent target detection and localization, feature extraction, and other operations, avoiding missed or false detections and improving the robustness and stability of the entire process.

[0097] Based on the first embodiment of this application, in the third embodiment of this application, the content that is the same as or similar to that in the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 3 Step S40 includes steps S401 to S406: Step S401: Extract the outermost boundary point set of each connected foreground region in the binary mask image of the candidate region using the external contour extraction algorithm to obtain the external contour.

[0098] It should be noted that since candidate regions may contain noise, non-target regions need to be filtered using geometric features. Specifically, an external contour extraction algorithm can be used to extract the outermost boundary point set of each connected foreground region in the binarized mask image of the candidate region, thereby obtaining the external contour. The external contour extraction algorithm can be the Suzuki85 contour extraction algorithm, which can accurately and efficiently extract the outermost boundary of connected regions in a binary image. By applying this algorithm, a precise set of external contour points for each candidate region can be obtained, and these point sets define the basic shape boundaries of the elements in the image.

[0099] Step S402: For each of the outer contours, calculate the area, center, width, height, and rotation angle of the outer contour.

[0100] In practice, for each contour (cnt), the area, center, width, height, and selected angle of each external contour can be calculated.

[0101] Step S403: Obtain the minimum bounding rectangle of the outer contour based on the center, the width and height, and the rotation angle.

[0102] In practical implementation, the minimum bounding rectangle of the outer contour, i.e. the minimum circumscribed rectangle, can be obtained based on the center, width, height, and rotation angle.

[0103] Step S404: Calculate the degree of closeness between the outer contour and the rectangle based on the area and the minimum bounding rectangle to obtain the rectangularity.

[0104] The degree of closeness between the outer contour and the minimum bounding rectangle can be calculated based on the width, height, and area of ​​the minimum bounding rectangle. The closeness is calculated as area / (minRect.width × minRect.height), where area is the area, minRect.width is the width of the minimum bounding rectangle, and minRect.height is the height of the minimum bounding rectangle. The rectangularity is then used to measure the closeness between the outer contour and the rectangle.

[0105] Step S405: Calculate the aspect ratio based on the width and height of the minimum bounding rectangle.

[0106] Understandably, the aspect ratio can be calculated based on the width and height of the smallest bounding rectangle. Specifically, the maximum width, maximum height, minimum width, and minimum height within the smallest bounding rectangle can be obtained to calculate the aspect ratio, as follows: Step S406: Obtain the geometric features of the outer contour based on the minimum bounding rectangle, the area, the rectangularity, and the aspect ratio.

[0107] In practical implementation, the minimum bounding rectangle, area, rectangularity, and aspect ratio can be used together as the geometric features of the external contour.

[0108] For circular elements, the circularity (4*π*area / perimeter², >0.9 is considered circular) can be calculated to replace the rectangularity and aspect ratio, thereby filtering out circular candidate areas.

[0109] This embodiment utilizes an external contour extraction algorithm to extract the outermost boundary point set of each connected foreground region from a binarized image. This step ensures accurate extraction of the object's shape and contour, providing a reliable foundation for subsequent analysis. Calculating the area, center, width, height, and rotation angle of the external contour comprehensively describes the object's shape and position. Based on the center, width, height, and rotation angle of the external contour, the minimum bounding rectangle is obtained. The minimum bounding rectangle effectively defines the object's spatial extent and provides a standardized reference frame. By calculating the proximity between the external contour and the minimum bounding rectangle, the regularity of the object's shape can be assessed. Calculating the aspect ratio based on the width and height of the minimum bounding rectangle allows for rapid differentiation of the object's geometric features. By combining multiple geometric features such as the minimum bounding rectangle, area, rectangularity, and aspect ratio, a multi-dimensional and comprehensive evaluation of the object's contour can be achieved.

[0110] For example, to help understand the implementation flow of the component positioning method obtained by combining this embodiment with the above embodiment one, please refer to... Figure 4 , Figure 4 A simplified flowchart of a component localization method is provided. Specifically: image acquisition begins, followed by grayscale conversion, Gaussian filtering, and calculation of the grayscale histogram. Then, the peak and valley values ​​are calculated for dynamic threshold binarization. Morphological operations are performed to extract the external contour, geometric feature filtering is conducted, edge points are merged, and horizontal and vertical points are separated. A straight line is fitted using the RANSAC algorithm, and the center and angle of the component are calculated based on the fitted line for distance verification. The final localization result is obtained based on the verification results.

[0111] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the component positioning method of this application. Any simple modifications based on this technical concept are within the protection scope of this application.

[0112] This application also provides a component positioning device, please refer to... Figure 5 The component positioning device includes: The acquisition module 10 is used to acquire the raw BGR image of the component captured by the industrial camera under a ring light source; Preprocessing module 20 is used to preprocess the original BGR image to obtain a grayscale image; The segmentation module 30 is used to perform adaptive grayscale range segmentation on the grayscale image to obtain candidate regions including elements; Extraction module 40 is used to extract the outer contour of the candidate region and calculate the geometric features of the outer contour; Determining module 50 is used to determine the target candidate region based on the geometric features; The fitting module 60 is used to perform multi-directional edge co-fitting on the contour points of the target candidate region to obtain the parameter information of the element; The acquisition module 10 is also used to obtain the positioning result of the component based on the parameter information of the component.

[0113] The component positioning device provided in this application, employing the component positioning method in the above embodiments, can solve the technical problems of current component positioning methods that use fixed thresholds, which cannot adapt to dynamic environments and are easily affected by noise interference during geometric feature extraction, resulting in poor positioning accuracy. Compared with the prior art, the beneficial effects of the component positioning device provided in this application are the same as those of the component positioning method provided in the above embodiments, and other technical features in the component positioning device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.

[0114] This application provides a component positioning device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the component positioning method in Embodiment 1 above.

[0115] The following is for reference. Figure 6 The diagram illustrates a structural schematic of a component positioning device suitable for implementing embodiments of this application. The component positioning device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 6 The component positioning device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0116] like Figure 6As shown, the component positioning device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in ROM (Read Only Memory) 1002 or a program loaded from storage device 1003 into RAM (Random Access Memory) 1004. RAM 1004 also stores various programs and data required for the operation of the component positioning device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via bus 1005. Input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, touch screens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, LCDs (Liquid Crystal Displays), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the component positioning device to communicate wirelessly or wiredly with other devices to exchange data. Although the figure shows component positioning devices with various systems, it should be understood that implementation or possession of all the systems shown is not required. More or fewer systems may be implemented alternatively.

[0117] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.

[0118] The component positioning device provided in this application, employing the component positioning method described in the above embodiments, can solve the technical problems of current component positioning methods that use fixed thresholds, which cannot adapt to dynamic environments and are easily affected by noise interference during geometric feature extraction, resulting in poor positioning accuracy. Compared with the prior art, the beneficial effects of the component positioning device provided in this application are the same as those of the component positioning method provided in the above embodiments, and other technical features of this component positioning device are the same as those disclosed in the previous embodiment method, and will not be repeated here.

[0119] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.

[0120] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations 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. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0121] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the component positioning method in the above embodiments.

[0122] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, RAM (Random Access Memory), ROM (Read Only Memory), EPROM (Erasable Programmable Read Only Memory or Flash Memory), optical fibers, CD-ROM (CD-Read Only Memory), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.

[0123] The aforementioned computer-readable storage medium may be included in the component positioning device; or it may exist independently and not assembled into the component positioning device.

[0124] The aforementioned computer-readable storage medium carries one or more programs that, when executed by the component positioning device, cause the component positioning device to: acquire an original BGR image of the component captured by an industrial camera under a ring light source; preprocess the original BGR image to obtain a grayscale image; perform adaptive grayscale range segmentation on the grayscale image to obtain candidate regions including the component; extract the outer contour of the candidate regions and calculate the geometric features of the outer contour; determine a target candidate region based on the geometric features; perform multi-directional edge co-fitting on the contour points of the target candidate region to obtain parameter information of the component; and obtain the positioning result of the component based on the parameter information of the component.

[0125] Computer program code for performing the operations of this application can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including LAN (Local Area Network) or WAN (Wide Area Network)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0126] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0127] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

[0128] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described component positioning method. This solves the technical problems of current component positioning methods, which use fixed thresholds and are unable to adapt to dynamic environments, and are easily affected by noise interference during geometric feature extraction, resulting in poor positioning accuracy. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the component positioning method provided in the above embodiments, and will not be repeated here.

[0129] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the component positioning method described above.

[0130] The computer program product provided in this application can solve the technical problems of current component positioning methods that use fixed thresholds, which cannot adapt to dynamic environments and are easily affected by noise interference during geometric feature extraction, resulting in poor positioning accuracy. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the component positioning method provided in the above embodiments, and will not be repeated here.

[0131] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.

Claims

1. A component positioning method characterized by comprising: The element positioning method comprises: An original BGR image of an element collected by an industrial camera under a ring light source is acquired; The original BGR image is preprocessed to obtain a grayscale image; The grayscale image is adaptively segmented by a grayscale range to obtain a candidate region including the element; An external contour of the candidate region is extracted, and geometric features of the external contour are calculated; A target candidate region is determined according to the geometric features; Parameter information of the element is obtained by performing multi-directional edge collaborative fitting on contour points of the target candidate region; A positioning result of the element is obtained according to the parameter information of the element.

2. The method of claim 1, wherein, The step of adaptively segmenting the grayscale image by a grayscale range to obtain a candidate region including the element comprises: A grayscale histogram of the grayscale image normalized to a preset interval is calculated; A main peak is determined according to the grayscale histogram, and a target valley value is determined according to the main peak; A dynamic segmentation grayscale threshold value is determined according to a preset proportion coefficient and the target valley value; The grayscale image is binarized according to the dynamic segmentation grayscale threshold value to obtain an initial candidate region mask; Morphological operations of open operation and close operation are sequentially performed on the initial candidate region mask to obtain a candidate region including the element.

3. The method of claim 2, wherein, The step of determining a main peak according to the grayscale histogram and determining a target valley value according to the main peak comprises: Local maximum points are obtained by traversing the grayscale histogram; Peak value heights corresponding to the local maximum points are sorted, and a first peak value and a second peak value are obtained according to the sorted peak value heights; Minimum histogram values corresponding to the left side and the right side of the first peak value and the second peak value are obtained, to obtain left and right valley values of the first peak value and left and right valley values of the second peak value; A first ratio value is calculated according to the left valley value of the first peak value and the first peak value, and a second ratio value is calculated according to the left valley value of the second peak value and the second peak value; A target ratio value is determined from the first ratio value and the second ratio value; The peak value corresponding to the target ratio value is taken as the main peak, and the left and right valley values corresponding to the peak value are taken as the target valley value.

4. The method of claim 1, wherein, The step of extracting an external contour of the candidate region and calculating geometric features of the external contour comprises: The outermost boundary point set of each connected foreground region in the binarization mask image of the candidate region is extracted by an external contour extraction algorithm to obtain an external contour; For each external contour, the area, center, width and height, and rotation angle of the external contour are calculated; A minimum circumscribed rectangle of the external contour is obtained according to the center, the width and height, and the rotation angle; The proximity between the external contour and the rectangle is calculated based on the area and the minimum circumscribed rectangle to obtain a rectangle degree; The aspect ratio is calculated according to the width and height of the minimum circumscribed rectangle; The geometric features of the external contour are obtained according to the minimum circumscribed rectangle, the area, the rectangle degree, and the aspect ratio.

5. The method of claim 1, wherein, The step of determining a target candidate region according to the geometric features comprises: The aspect ratio, the area, the rectangle degree, and the minimum circumscribed rectangle are obtained according to the geometric features; An element type of the element is acquired; The screening condition is determined according to the element type, and the screening condition includes an area screening threshold, a rectangular degree screening threshold, and an aspect ratio screening threshold; The area, the rectangular degree, and the aspect ratio are filtered according to the screening condition to obtain filtered area, rectangular degree, and aspect ratio; An area meeting the element geometric shape is obtained according to the minimum circumscribed rectangle, the filtered area, the rectangular degree, and the aspect ratio, and the area is taken as a target candidate area.

6. The method of claim 1, wherein, The step of performing multi-directional edge collaborative fitting on the contour points of the target candidate area to obtain the parameter information of the element includes: The contour points of the target candidate area are merged to obtain an edge point set; A mean center of the edge point set is calculated; Horizontal edge point sets are separated according to deviations of the contour points in the vertical coordinates of the mean center; Vertical edge point sets are separated according to deviations of the contour points in the horizontal coordinates of the mean center; Straight lines are fitted on the horizontal edge point sets and the vertical edge point sets respectively by using a random sample consensus algorithm to obtain horizontal fitting straight lines and vertical fitting straight lines; The parameter information of the element is determined according to the horizontal fitting straight lines and the vertical fitting straight lines.

7. The method of claim 6, wherein, The step of determining the parameter information of the element according to the horizontal fitting straight lines and the vertical fitting straight lines includes: An intersection of the horizontal fitting straight lines and the vertical fitting straight lines is solved, and the intersection is taken as a geometric center of the element; Horizontal line angles and vertical line angles are calculated according to the horizontal fitting straight lines and the vertical fitting straight lines; An angle of the element is calculated according to the horizontal line angles and the vertical line angles; The parameter information of the element is obtained according to the geometric center of the element and the angle of the element.

8. The method of claim 7, wherein, After the step of obtaining the positioning result of the element according to the parameter information of the element, the method further includes: A width and a height of the minimum circumscribed rectangle are obtained according to the geometric features of the external contour; A fitting rotating rectangle is constructed according to the geometric center, the width and the height, and the angle; Distances of the contour points of the target candidate area to the fitting rotating rectangle are calculated, and an average distance is calculated according to the distances; When the average distance is less than a preset distance threshold and a number of effective points in the contour points of the target candidate area is greater than a preset number threshold, it is determined that the positioning result is successful.

9. An element positioning device, characterized by The device includes: An acquisition module is configured to acquire an original BGR image of an element collected by an industrial camera under a ring-shaped light source; A preprocessing module is configured to perform preprocessing on the original BGR image to obtain a grayscale image; A segmentation module is configured to perform adaptive grayscale range segmentation on the grayscale image to obtain a candidate area including the element; An extraction module is configured to extract an external contour of the candidate area and calculate geometric features of the external contour; A determination module is configured to determine a target candidate area according to the geometric features; A fitting module is configured to perform multi-directional edge collaborative fitting on contour points of the target candidate area to obtain parameter information of the element; The acquisition module is further configured to obtain a positioning result of the element according to the parameter information of the element.

10. A storage medium, characterized by The storage medium is a computer readable storage medium, and the storage medium stores a computer program. The computer program is executed by a processor to implement the steps of the element positioning method in any one of claims 1 to 8.