A method, apparatus and storage medium for detecting surface defects of an electrical connector housing
By removing interfering targets on the surface of electrical connectors through optical character recognition and template matching technology, and combining differential method and threshold segmentation, the problem of interference targets affecting existing detection methods is solved, and efficient and accurate defect detection is achieved.
Patent Information
- Application Number
- CN202411420529.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2023-12-08
- Filing Date
- 2024-10-12
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2044-10-12
AI Technical Summary
Existing methods for detecting defects in electrical connectors cannot effectively remove interfering targets from the connector surface, resulting in inaccurate detection and poor applicability, especially for connectors of different models and materials.
Interference areas on the surface of the electrical connector housing are extracted using technologies such as optical character recognition and template matching. After removing interference using the differential method, defect areas are extracted, including letters, numbers, symbols, caps, and stripe-like interference. Threshold segmentation and line segment detection are combined to improve detection accuracy.
It enables efficient and reliable defect detection of electrical connectors of different models and materials, reduces manual intervention, and improves detection efficiency and accuracy, making it suitable for industrial scenarios.
Smart Images

Figure CN119559115B_ABST
Abstract
Description
Technical Field
[0001] This disclosure belongs to the field of defect detection technology, and specifically relates to a method, apparatus and storage medium for detecting surface defects of electrical connector housings based on interference removal. Background Technology
[0002] Electrical connectors are widely used in various aircraft and weaponry, with their use in aircraft being particularly staggering. This is because modern aircraft require numerous electrical devices for connection and control via electrical connectors, such as flight instruments, radar, communication equipment, and navigation systems. Besides meeting general performance requirements, electrical connectors must also meet stringent requirements regarding good contact, reliable operation, and ease of maintenance. Their reliability directly affects the normal operation of the aircraft's circuitry, impacting the safety of the entire aircraft. In practical use, defects such as scratches, contamination, and corrosion on the appearance of electrical connectors not only affect the product's aesthetics but also its performance. Relying on manual defect identification inevitably introduces subjective biases, leading to inaccurate testing standards. Furthermore, manual inspection is generally time-consuming, severely impacting production efficiency and product reliability for enterprises.
[0003] Researchers have developed several methods for detecting surface defects in electrical connector housings. The literature (Gao Wenbin, Zhuang Shenle, Wang Xiujian, et al. Research on Surface Defect Detection of Housings Based on Machine Vision Technology [J]. Electromechanical Components, 2022, 42(01):42-46.) utilizes image enhancement, defect image segmentation, and defect feature extraction to detect connector defects. The literature (Du Juan, Yang Junzhi. A Small-Sample Connector Defect Detection Method Based on Transfer Learning [J]. Automation and Information Engineering, 2022, 43(05):1-7.) proposes a connector defect detection method based on YOLOv5 transfer learning, achieving small-sample learning with good detection results even with limited data. The literature (Xu Zhenying, Li Jiankang, Ling Jun, et al. Design of an Electrical Connector Housing Defect Detection System Based on Halcon [J]. Manufacturing Automation, 2015, 37(18):135-138.) achieves the detection and classification of connector defects through multiple steps such as preprocessing, feature detection, and feature recognition.
[0004] However, existing methods also have some drawbacks. Most current methods only test localized areas where defects exist, whereas in practical applications, inspection is typically performed on the entire surface of the connector. The connector surface contains various interfering factors such as connector serial numbers, manufacturer symbols, nuts, and textures. Furthermore, the types of interference on the surfaces of different connectors in China vary, and the light reflection intensity of the shell material also differs. Existing connector defect detection methods are mostly designed for specific connector models, and methods for detecting defects in other connector models require further research. Summary of the Invention
[0005] To overcome the shortcomings of existing technologies, this invention provides a method for detecting electrical connector defects based on interference removal. First, an image of the connector is acquired; then, the Region of Interest (ROI) is extracted from the image; based on this, various methods, including OCR (Optical Character Recognition) character recognition, template matching, and shape interference processing, are used to extract interference areas on the connector housing surface; next, interference on the connector surface is removed; finally, connector defects are extracted. This invention establishes an interference processing mechanism based on existing technologies, effectively removing interference targets from the connector surface, making it more reliable and applicable in practical applications.
[0006] The method of this invention can detect surface defects in connector housings, save labor costs, improve identification efficiency, and ensure product reliability, providing an effective means for detecting surface defects in connector housings in industrial scenarios.
[0007] The technical solution adopted by this invention to solve its technical problem includes the following steps:
[0008] The first aspect of this disclosure provides a method for detecting surface defects in an electrical connector housing, comprising:
[0009] Step 1: Obtain the original image Image1 containing the background and electrical connector;
[0010] Step 2: Extract the ROI region RoiRegion of the electrical connector in the original image Image1, and generate an image RoiImage from the area covered by the region RoiRegion in the original image Image1;
[0011] Step 3: Extract the total interference region Interfere from the image RoiImage. The total interference region Interfere is composed of the letter and number interference region OCR, the symbol interference region Mark, the cap-shaped interference region Circularity, and the stripe interference region Rectlen on the surface of the electrical connector housing. The letter and number interference region OCR is obtained by optical character recognition detection of the image RoiImage. The symbol interference region Mark is obtained by shape-based template matching of the image RoiImage. The cap-shaped interference region Circularity and the stripe interference region Rectlen are obtained by thresholding the image RoiImage and then filtering by shape size.
[0012] Step 4: Process the image RoiImage using threshold segmentation and line segment detection to obtain the total defect area Error1 corresponding to the scratches and blocky defects on the surface of the electrical connector housing in the image RoiImage;
[0013] Step 5: Divide the total defect area Error1 and the total interference area Interfere to obtain the defect area Error2 after removing the interference area. Delete the area less than the detection accuracy from the defect area Error2 to obtain the defect area Error3. Delete the area corresponding to the mechanical scratch in the defect area Error3 to obtain the detection result Result of the surface defect of the electrical connector housing.
[0014] In some embodiments, an xy coordinate system is defined, with the top left corner of the original image Image1 as the origin O of the xy coordinate system, the horizontal rightward direction as the positive x-axis, and the vertical downward direction as the positive y-axis.
[0015] Step 2 specifically includes the following steps:
[0016] Step 2-1: Extract edges from the original image Image1 to obtain several lines Line1. Merge all lines Line1 whose directional deviation is less than angle1 and whose distance is less than distance1, and select lines Line2 whose length is greater than length1. Set the grayscale value of the area covered by line Line2 on the original image Image1 to 0 to generate image Image2; where angle1 and distance1 are the maximum angular deviation and maximum distance difference between the lines, and length1 is the minimum length of the merged line.
[0017] Step 2-2: Use threshold segmentation to segment the region in the image Image2 with a gray value greater than threshold1 into region Region1. Threshold1 is set according to the average gray value of the surface of the electrical connector housing.
[0018] Steps 2-3: Extract a selected region, SelectedRegion1, from Region1;
[0019] Steps 2-4: Generate a region SelectedRegion2 corresponding to the minimum bounding rectangle of the region SelectedRegion1. SelectedRegion2 is a part of the ROI region of the electrical connector. Obtain the angle phi1 ∈ [-90°, 90°] between the region SelectedRegion2 and the x-axis. Rotate the original image Image1 and the region SelectedRegion2 around the center of the original image Image1 by an angle -phi1.
[0020] Step 2-5: Obtain the ordinate row1 and abscissa of the region SelectedRegion2. Determine whether the region SelectedRegion2 is inverted by comparing row1 with b / 2, where b is the dimension of the original image Image1 along the y-axis. If row1 > b / 2, the region SelectedRegion2 is not inverted, and proceed to step 2-6. If row1 ≤ b / 2, the region SelectedRegion2 is inverted, and the original image Image1 and the region SelectedRegion2 need to be rotated 180 degrees around the center of the original image Image1. Obtain the angle phi2, the center ordinate row2, and the center abscissa column2 of the rotated region SelectedRegion2.
[0021] Steps 2-6: Based on the center coordinates (row2, column2) of the selected region 2, translate the center of the selected region 2 along the y-axis direction by rowy to the center of another ROI region of the electrical connector (row3, column2). The size of rowy is determined by the relative positional relationship between the selected region 2 and the other ROI region of the electrical connector. Generate the selected region 3 based on (row3, column2) and the length and width dimensions of the electrical connector region corresponding to the other ROI region of the electrical connector. Merge the selected region 2 and the selected region 3 to obtain the ROI region RoiRegion of the connector. Generate the image RoiImage from the area covered by the region RoiRegion in the original image Image1.
[0022] In some embodiments, step 3, the extraction step of the alphanumeric interference region OCR includes:
[0023] Based on the relative position of the selected region 2 and the character and number areas on the surface of the electrical connector housing, a region CharRegion is generated. Based on the region CharRegion, an image CharImage containing characters is segmented from the image Router. Optical character recognition (OCR) is then performed on the image CharImage to extract the letter and number interference areas on the surface of the electrical connector housing.
[0024] In some embodiments, step 3, the extraction step of the symbolic interference region Mark, includes:
[0025] Read the template image ImageModle and find the symbol region RegionModle on the surface of the electrical connector housing in the template image ImageModle; generate a matching template Modle based on the template image ImageModle and the symbol region RegionModle; use the matching template Modle to perform template matching in the image RoiImage to detect the symbol-type interference region Mark on the surface of the electrical connector housing.
[0026] In some embodiments, step 3, the extraction steps of the cap-shaped interference region Circularity and the stripe-shaped interference region Rectlen, include:
[0027] Threshold segmentation is used to extract Region2, a region with a grayscale value greater than the segmentation threshold, from the image RoiImage. Region2 is then filled to obtain Region2f. The difference between Region2f and Region2 is calculated to obtain RegionDifference, a partial blocky defect, cap, and stripe interference region on the surface of the electrical connector housing. Circularity, a region within RegionDifference with a circular parameter > c1 and an area between -10% and +10% of the circular interference area, is selected as the cap-shaped interference region. Rectlen, a region within RegionDifference whose circumscribed rectangle's length and width are between -10% and +10% of the length and width of the stripe interference, is selected as the stripe interference region.
[0028] In some embodiments, step 4 specifically includes the following steps:
[0029] Step 4-1: Process the image RoiImage using the local threshold segmentation method to extract the region Region3 with significantly changing gray levels on the surface of the electrical connector housing. Extract the line Line3 from the region Region3 using line detection; merge the lines in Line3 with a radian direction less than angle2 and a distance less than distance2 to obtain the line Line4 corresponding to the scratch defect on the surface of the electrical connector housing;
[0030] Step 4-2: Use the threshold segmentation method to extract the region Region4 corresponding to the block defect with gray levels between 0 and threshold2 in the image RoiImage;
[0031] Step 4-3: The region Region3, the line Line4, and the region Region4 form the total defect region Error1.
[0032] In some embodiments, step 5 specifically includes the following steps:
[0033] Step 5-1: Take the difference between the total defect region Error1 and the total interference region Interfere to obtain the defect region Error2 after removing the interference region;
[0034] Step 5-2: Delete the part of the region Error2 with an area greater than area1 to obtain the defect region Error3;
[0035] Step 5-3: Screen out the line Line5 in the defect region Error3 where the length of the minimum bounding rectangle is > length2, the width is < width2, and the radian direction of the minimum bounding rectangle is between -angle and angle. The line Line5 is the mechanical scratch generated on the surface of the electrical connector housing during the production process;
[0036] Step 5-4: Take the difference between the defect region Error3 and the line Line5 to obtain the detection result Result of the defects on the surface of the electrical connector housing. <0000The raw image acquisition module is used to acquire the raw image Image1 containing the background and electrical connector;
[0041] The electrical connector ROI generation module is used to extract the actual ROI region RoiRegion of the electrical connector in the original image Image1, and generate an image RoiImage from the region covered by the region RoiRegion in the original image Image1;
[0042] The total interference region extraction module is used to extract the total interference region Interfere in the image RoiImage. The total interference region Interfere is composed of alphanumeric interference regions OCR, symbol interference regions Mark, cap-shaped interference regions Circularity, and stripe-shaped interference regions Rectlen on the surface of the electrical connector housing. The alphanumeric interference regions OCR are obtained by optical character recognition detection of the image RoiImage. The symbol interference regions Mark are obtained by shape-based template matching of the image RoiImage. The cap-shaped interference regions Circularity and stripe-shaped interference regions Rectlen are obtained by thresholding the image RoiImage and then filtering by shape and size.
[0043] The scratch and block defect region extraction module is used to process the image RoiImage using threshold segmentation and line segment detection to obtain the total defect region Error1 corresponding to the scratches and block defects on the surface of the electrical connector housing in the image RoiImage;
[0044] The detection result output module is used to perform a difference between the total defect area Error1 and the total interference area Interfere to obtain the defect area Error2 after removing the interference area. The area less than the detection accuracy is deleted from the defect area Error2 to obtain the defect area Error3. The area corresponding to the mechanical scratch in the defect area Error3 is deleted to obtain the detection result Result of the surface defect of the electrical connector housing.
[0045] A computer-readable storage medium is provided in the third aspect of this disclosure, the computer-readable storage medium storing computer instructions for causing the computer to perform a detection method according to any embodiment of the first aspect of this disclosure.
[0046] This disclosure has the following characteristics and beneficial effects:
[0047] This disclosure enables interference removal targeting different interference objects on the surface of various electrical connector housings, offering greater reliability and applicability in practical applications and better adaptability to different types of electrical connectors and environmental conditions. By utilizing technologies such as optical character recognition and template matching, this disclosure automates the processing and analysis of electrical connector images, reducing the need for manual intervention and improving efficiency. Furthermore, this disclosure offers good scalability, allowing the algorithm to be customized and improved as needed to meet the defect detection requirements of different types of electrical connectors.
[0048] In summary, this disclosure enables connector defect detection, saves labor costs, improves identification efficiency, and ensures product reliability, providing an effective means for high-accuracy connector defect detection in industrial scenarios. Attached Figure Description
[0049] Figure 1 This is an overall flowchart of a method for detecting surface defects in an electrical connector housing, provided in an embodiment of this disclosure.
[0050] Figure 2 Image2 is the image obtained in step 2-1 of the detection method provided in this embodiment of the disclosure.
[0051] Figure 3 SelectedRegion1 is the region obtained in steps 2-3 of the detection method provided in this embodiment of the disclosure.
[0052] Figure 4 The image Image1 and the region SelectedRegion2 obtained in steps 2-5 of the detection method provided in this embodiment are examples of the present disclosure.
[0053] Figure 5 The region RoiRegion is obtained in steps 2-6 of the detection method provided in the embodiments of this disclosure.
[0054] Figure 6 The image RoiImage obtained in steps 2-6 of the detection method provided in the embodiments of this disclosure.
[0055] Figure 7 The alphanumeric interference region OCR obtained in step 3-1-2 of the detection method provided in this embodiment of the present disclosure.
[0056] Figure 8 The symbolic interference region Mark is obtained in step 3-2-3 of the detection method provided in this embodiment of the present disclosure.
[0057] Figure 9The cap-shaped interference region Circularity and the striped interference region Rectle are obtained in steps 3-3-4 and 3-3-5 of the detection method provided in this embodiment of the disclosure.
[0058] Figure 10 The total defect area Error1 is obtained in step 4-3 of the detection method provided in this embodiment of the disclosure.
[0059] Figure 11 The final detection result obtained in step 5 of the detection method provided in this embodiment of the disclosure.
[0060] Figure 12 A software interface diagram for the detection method provided in the embodiments of this disclosure.
[0061] Figure 13 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation
[0062] To make the objectives, technical solutions, and advantages of this application clearer, the application will be described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely for explaining this application and are not intended to limit this application.
[0063] Conversely, this application covers any alternatives, modifications, equivalent methods, and schemes made within the spirit and scope of this application as defined by the claims. Furthermore, to provide the public with a better understanding of this application, certain specific details are described in detail below. However, this application can be fully understood by those skilled in the art even without these detailed descriptions.
[0064] See Figure 1 The present disclosure provides a method for detecting surface defects in an electrical connector housing, comprising the following steps:
[0065] Step 1: Obtain the original image Image1 containing the background and electrical connector;
[0066] Step 2: Extract the ROI region RoiRegion of the electrical connector in the original image Image1, and generate an image RoiImage from the area covered by the region RoiRegion in the original image Image1;
[0067] Step 3: Extract the total interference region Interfere from the RoiImage. This total interference region Interfere is composed of the alphanumeric interference region OCR, the symbol interference region Mark, the cap-shaped interference region Circularity, and the striped interference region Rectlen on the surface of the electrical connector housing. Among them, the alphanumeric interference region OCR is obtained by optical character recognition detection of the RoiImage, the symbol interference region Mark is obtained by shape-based template matching of the RoiImage, and the cap-shaped interference region Circularity and the striped interference region Rectlen are obtained by thresholding the RoiImage and then filtering by shape and size.
[0068] Step 4: Process the image RoiImage using threshold segmentation and line segment detection to obtain the region Error1 corresponding to the scratches and blocky defects on the surface of the electrical connector housing in the image RoiImage;
[0069] Step 5: Divide the region Error1 and the total interference region Interfere to obtain the defect region Error2 after removing the interference region. Delete the region less than the detection accuracy from the defect region Error2 to obtain the defect region Error3. Delete the region corresponding to the mechanical scratch in the defect region Error3 to obtain the detection result Result of the surface defect of the electrical connector housing.
[0070] The present disclosure will be further described below with reference to the accompanying drawings and embodiments.
[0071] This disclosure provides a method for detecting surface defects in an electrical connector housing, which specifically includes the following steps:
[0072] Step 1: Obtain connector image
[0073] Prepare the connector to be inspected, the defect detection imaging device, and a PC with the corresponding software installed. Connect the industrial camera used to photograph the connector to the PC, start the corresponding software, and successfully display the image from the camera. The image format is .bmp, and the image size is a*b. In this embodiment, a is 4024 and b is 3036. Define an xy coordinate system, with the upper left corner of the original image Image1 as the origin O, the horizontal direction to the right as the positive x-axis, and the vertical direction downwards as the positive y-axis.
[0074] Step 2: Extract the connector ROI region:
[0075] The variables used in this step are defined as follows:
[0076] Image1: The original image, which is a two-dimensional matrix (dimension 4024*3036).
[0077] Line1: The line generated after extracting line segments from the original image Image1.
[0078] Line2: Merge the lines in Line1 whose curvature direction difference is less than angle1 and whose distance is less than distance1, and select the line whose length is greater than length1. This line corresponds to dividing the electrical connector into a base and an upper main body.
[0079] Image2: Set the grayscale value of the area containing line Line2 in the original image Image1 to 0, and generate image Image2. Image Image2 is separated by line Line2.
[0080] Region1: The region obtained by segmenting Image2 using thresholding, corresponding to the area on the surface of the electrical connector where the gray value is greater than the threshold.
[0081] SelectedRegion1: The region selected in Region1 based on the size of the electrical connector base.
[0082] SelectedRegion2: The smallest bounding rectangle generated based on the region SelectedRegion1.
[0083] phi1: The angle of the region SelectedRegion2, phi1∈[-90°,90°], is defined as the angle between the direction of the long side of the region SelectedRegion2 and the x-axis.
[0084] row1: The ordinate of SelectedRegion2 after rotating it by an angle -phi1.
[0085] phi2: The angle of SelectedRegion2 after rotating it 180°.
[0086] row2: The ordinate of SelectedRegion2 after rotating it by an angle phi2.
[0087] column2: The x-coordinate of SelectedRegion2 after rotating it 180°.
[0088] RoiRegion: A Roi region generated based on angle phi2, ordinate row2, abscissa column2, and the relative coordinates of region SelectedRegion2 with another ROI region of the electrical connector.
[0089] RoiImage: Generates an image of the region covered by region RoiRegion in the original image Image1.
[0090] Step 2-1: The electrical connector housing is usually divided into two or three blocks, and the boundaries between these blocks are sometimes not obvious. In this embodiment, the electrical connector housing is divided into a base and an upper main structure. First, the lines_gauss operator is used to extract the edges in the original image Image1, resulting in several lines Line1. The union_collinear_contours_xld operator is used to merge all lines Line1 whose arc direction is less than angle1 and whose distance is less than distance1, and then selects the line Line2 whose length is greater than length1. The gray value of the area where line Line2 is located in the original image Image1 is set to 0, generating image Image2. Here, angle1 and distance1 are the maximum angular deviation and the maximum distance difference between the lines, respectively. In this embodiment, they are taken as 0.3 and 200. length1 is the minimum length of the merged line, which is taken as 500 in this embodiment. The generated image Image2 is as follows. Figure 2 As shown;
[0091] Step 2-2: Use threshold segmentation to divide the region in image Image2 with a gray value greater than threshold1 into region Region1. In this example, threshold1 is set to 200. This region is the area on the surface of the electrical connector housing with a gray value greater than 200, which is its brighter area.
[0092] Steps 2-3: Based on the area or length of Region1, find a designated region SelectedRegion1 within Region1 (this region corresponds to the base of the electrical connector). In this embodiment, the selectedRegion1 is as follows: Figure 3 The area indicated by the dashed box in the middle;
[0093] Steps 2-4: Generate the region SelectedRegion2 corresponding to the minimum bounding rectangle of region SelectedRegion1 according to the gen_rectangle2_contour_xld operator. This region SelectedRegion2 is a part of the ROI region of the electrical connector (specifically, the ROI region corresponding to the electrical connector base in this embodiment). Obtain the angle phi1 of region SelectedRegion2, and rotate the original image Image1 and region SelectedRegion2 around the center of the original image by an angle -phi1.
[0094] Steps 2-5: Obtain the ordinate row1 of region SelectedRegion2. Determine if region SelectedRegion2 is inverted by comparing row1 with b / 2. If row1 > b / 2, then region SelectedRegion2 is not inverted, and proceed to step 2-6. If row1 ≤ b / 2, then region SelectedRegion2 is inverted. In this case, the original image Image1 and region SelectedRegion2 need to be rotated 180 degrees around the center of the original image, and the angle phi2, center ordinate row2, and center abscissa column2 of region SelectedRegion2 after rotation are obtained. In this embodiment, the original image Image1 and region SelectedRegion2 after rotation are as follows: Figure 4 As shown, Figure 4 The area indicated by the dashed box is the SelectedRegion2 region;
[0095] Steps 2-6: Based on the center coordinates (row2, column2) of region SelectedRegion2, translate the center of region SelectedRegion2 along the y-axis by rowy to the center (row3, column2) of another ROI region of the electrical connector. The size of rowy is determined by the relative positional relationship between region SelectedRegion2 and the other ROI region of the electrical connector. Generate region SelectedRegion3 based on (row3, column2) and the length and width dimensions of the corresponding electrical connector region of the other ROI region of the electrical connector. Merge region SelectedRegion2 and region SelectedRegion3 to obtain the ROI region RoiRegion of the connector. Generate image RoiImage from the area covered by region RoiRegion in the original image Image1. In this embodiment, the generated region RoiRegion and image RoiImage are as follows: Figure 5 , Figure 6 As shown;
[0096] Step 3: Extract the total interference region from the RoiImage image.
[0097] In this embodiment, the total interference region in the image RoiImage is defined as Interfere, which is composed of the letter and number interference regions OCR, the symbol interference region Mark, the cap-shaped interference region Circularity, and the stripe-shaped interference region Rectlen on the surface of the electrical connector housing. The extraction process of each type of interference region is described below:
[0098] Step 3-1: Extract alphanumeric interference regions from the RoiImage image.
[0099] The variables used in this step are defined as follows:
[0100] CharRegion: A character ROI region generated based on angle phi2, ordinate row2, abscissa column2, and the relative coordinates of region SelectedRegion2 and the regions containing letters and numbers.
[0101] CharImage: The image generated from the region covered by the region CharRegion in the image RoiImage.
[0102] OCR.omc: OCR training file.
[0103] OCR: Letter and number interference areas on the surface of the electrical connector housing.
[0104] Step 3-1-1: Generate the region CharRegion based on the relative position of the region SelectedRegion2 and the regions where characters and numbers exist within it; and segment the image CharImage containing the characters in the image RoeIamge based on the region CharRegion.
[0105] Step 3-1-2: Create a character template using the `create_text_model_reader` operator and set parameters (including character size, character shape, symbol slice size, text direction, and text layout, etc.). Use the `read_ocr_class_mlp` operator to read the pre-trained file `OCR.omc` (this pre-trained file was obtained by training with Halcon software and related data). Perform OCR detection on the image `CharImage` where the characters exist to detect the alphanumeric interference areas on the surface of the electrical connector housing. The extracted alphanumeric interference areas OCR in this embodiment are shown below. Figure 7 As shown;
[0106] Step 3-2: Extract symbolic interference regions from the RoiImage image.
[0107] The variables used in this step are defined as follows:
[0108] ImageModle: Template image for template matching.
[0109] RegionModle: Template generation region.
[0110] Model: Shape-based matching template.
[0111] Mark: Template matching result, i.e. symbolic interference.
[0112] Step 3-2-1: Read the template image ImageModle and find the regionModle, which is the symbol to be detected, within ImageModle;
[0113] Step 3-2-2: Use the create_shape_model operator to generate a matching template Model for the symbol based on the template image ImageModle and the symbol region RegionModle;
[0114] Step 3-2-3: Use the find_shape_model operator to perform template matching in the RoiImage using the matching template Model to detect the symbolic interference region Mark on the surface of the electrical connector housing. The symbolic interference region extracted in this embodiment is as follows: Figure 8 As shown;
[0115] Step 3-3: Extract the capping interference region and stripe interference region from the RoiImage image.
[0116] The variables used in this step are defined as follows:
[0117] Region 2: Regions in the RoiImage extracted using threshold segmentation where the grayscale value is greater than the segmentation threshold.
[0118] Region2f: The filled region of Region2.
[0119] RegionDifference: The region obtained by subtracting region2f from region2.
[0120] Circularity: An approximately circular interference area on the surface of the electrical connector housing, also known as the cap interference area.
[0121] Rectlen: Striped interference area on the surface of the electrical connector housing.
[0122] Step 3-3-1: Use threshold segmentation to extract the regions in the image RoiImage whose gray values are greater than the segmentation threshold, and obtain region2;
[0123] Step 3-3-2: Use the fill_up operator to fill region 2, obtaining the filled region Region 2f;
[0124] Step 3-3-3: Difference between Region2f and Region2 to obtain some of the larger blocky defects and caps, as well as striped interference RegionDifference on the surface of the electrical connector housing;
[0125] Step 3-3-4: Select the region RegionDifference based on the select_shape operator. The circular parameter is greater than c1 (c1 is set according to the similarity between the circular interference area on the surface of the electrical connector housing and the circle. In this embodiment, c1 is 0.5) and the area Circularity (adjusted according to the electrical connector model) is between -10% and +10% of the area of the circular interference area of the electrical connector. Circularity is the cap-shaped interference area on the surface of the electrical connector housing.
[0126] Step 3-3-5: Based on the select_shape operator, select the region Rectlen within the RegionDifference whose bounding rectangle's length and width are between -10% and +10% of the length and width of the long strip interference region of the electrical connector. Rectlen is the stripe-like interference region on the surface of the electrical connector housing. In this embodiment, the extracted interference region Circularity and Rectlen are as follows: Figure 9 As shown;
[0127] Step 4: Extract total defects from the surface of the electrical connector housing.
[0128] The variables used in this step are defined as follows:
[0129] Region 3: Regions with drastic edge changes obtained by local thresholding of the RoiImage image.
[0130] Line3: The line extracted from Region3 is calculated using the calculate_lines_gauss_parameters operator to extract the optimal parameters.
[0131] Line4: Merges lines in Line3 whose arc direction difference is less than angle2 and whose distance is less than distance2.
[0132] Region4: (0, threshold2) Threshold segmentation image RoiImage, which obtains blocky defects with gray levels less than threshold2 on the surface of the electrical connector housing. In this example, threshold2 is set to 100.
[0133] Error 1: The part obtained by merging Region 3, Line 4, and Region 4. The area formed by Region 3 and Region 4 together corresponds to the total blocky defect area.
[0134] Step 4-1: The local threshold segmentation method is used to process the RoiImage image to extract Region3, which is the region with large gray-scale changes on the surface of the electrical connector housing. This corresponds to the region with drastic edge changes in the RoiImage image. The optimal parameters for extracting Line3 are calculated using the calculate_lines_gauss_parameters operator, and the lines_gauss operator is used to extract the line, resulting in Line3. The union_collinear_contours_xld operator is used to merge the lines in Line3 whose arc direction is less than angle2 and whose distance is less than distance2, resulting in Line4. Angle2 and distance2 are set according to empirical values. In this example, angle2 and distance2 are set to 0.2 and 50, respectively.
[0135] Step 4-2: Use the threshold segmentation method to process the image RoiImage and extract the region in the image where the gray value is between 0 and threshold2 as Region4;
[0136] Step 4-3: Merge Region 3, Line 4, and Region 4 to obtain the total defect area Error1. In this embodiment, the total defect area Error1 is as follows: Figure 10 As shown;
[0137] Step 5: Output the detection results
[0138] The variables used in this step are defined as follows:
[0139] Error2: The defect area obtained by subtracting the total defect area Error1 from the total interference area Interfere.
[0140] Error3: Filter out the areas in Error2 whose area is greater than the pixel size area1 corresponding to the defect detection accuracy.
[0141] Line 5: The length of the minimum bounding rectangle in the defect area Error3 > length2, the width < width2, and the area where the radian direction of the minimum bounding rectangle is between -angle3 and angle3. Line 5 is the mechanical scratch generated on the surface of the shell during the production of the electrical connector.
[0142] Result: The result obtained by taking the difference between the defect area Error3 and the line Line 5, that is, the final defect detection result.
[0143] ResultImage: Print the defect detection result Result onto the original image Image1, and rotate the original image to the starting position according to the angle phi1 and whether it is inverted.
[0144] ErrorNumber: The number of defects.
[0145] ErrorArea: The area of the defect.
[0146] Step 5-1: Take the difference between the total defect area Error1 and the total interference area Interfere to obtain the defect area Error2 after removing the interference area.
[0147] Step 5-2: Use the select_shape operator to screen out the part Error3 in the defect area Error2 where the area is greater than area1. In this example, area1 is taken as 100.
[0148] Step 5-3: Use the select_shape operator to screen out the area Line5 in the defect area Error3 where the length of the minimum bounding rectangle > length2, the width < width2, and the radian direction of the minimum bounding rectangle is between -angle3 and angle3. Line5 is the mechanical scratch generated during the production of the connector. length2, width2, and angle3 are determined according to the pixel size corresponding to the mechanical scratch. In this embodiment, length2 is taken as 40, width2 is taken as 5, and angle3 is taken as 0.05.
[0149] Step 5-4: Take the difference between the defect area Error3 and the line Line5 to obtain the defect detection result Result on the surface of the electrical connector shell.
[0150] Step 5-5: Print the defect detection result Result onto the original image Image1 to generate the image ResultImage, and rotate the image ResultImage to the correct position according to the angle phi1 and whether it is inverted in Step 2-5, and output the final image ResultImage, as Figure 11The function outputs the number of defects, ErrorNumber, and the total area, ErrorArea.
[0151] The operators used in this embodiment are all built-in functional modules of the Halcon software.
[0152] The following is an example of the effect of implementing the above method:
[0153] The software was developed using C++, with the user interface developed using Qt. The interface is divided into three parts: top, middle, and bottom. (See also...) Figure 12 The top section is a function bar, which includes options for selecting the electrical connector model and orientation, opening the camera, uploading images, and viewing history. The left side of the middle section displays the original image of the electrical connector to be inspected, while the right side displays the defect detection results. The bottom section shows the output inspection results.
[0154] The software is divided into ten modes, corresponding to the front and back sides of five types of electrical connectors.
[0155] Currently, there are 200 defect data points for electrical connectors. First, software is used to detect defects in the connectors to be inspected. Then, manual re-inspection is performed to verify the software's detection results. The accuracy rate of connector anomaly identification is calculated, and the inspection time of the device is statistically analyzed. The requirements are an anomaly identification accuracy rate > 95% and an average inspection time per image < 0.5 seconds. The experimental results are shown in the table below:
[0156] Table 1 Statistical table of experimental results
[0157] match Mismatch accuracy Average detection time Defect detection results 195 5 97.5% 0.40
[0158] Through testing, the detection method of this disclosure embodiment has an accuracy rate of 97.5%. The faulty electrical connectors were detected due to factors such as uneven illumination, improper placement, and interference from the connector's inherent texture. In specific industrial applications, the accuracy of defect detection can be improved by increasing the light source area and manually placing the electrical connector at the center of the imaging process. Therefore, this disclosure embodiment is fully capable of handling the defect detection problem on the surface of electrical connector housings.
[0159] In summary, this embodiment addresses defect detection on the surface of electrical connector housings. To remove interfering targets from the connector surface and improve defect extraction, this disclosure proposes for the first time a method for detecting defects on the surface of electrical connector housings based on interference removal. Multiple methods, including OCR character recognition, template matching, and shape interference processing, are employed to extract interfering targets such as product numbers, manufacturer symbols, nuts, and textures from the connector surface. This reduces false detections, ensures the reliability of subsequent defect extraction, and is more suitable for industrial applications.
[0160] In summary, this invention establishes an interference target removal mechanism that can more accurately locate the area of interference targets and eliminate other interference on the connector surface before defect extraction, thereby effectively improving the accuracy and reliability of defect detection.
[0161] This disclosure also proposes a detection apparatus for implementing the above-described detection method, comprising:
[0162] The raw image acquisition module is used to acquire the raw image Image1 containing the background and electrical connector;
[0163] The electrical connector ROI generation module is used to extract the electrical connector ROI region RoiRegion from the original image Image1, and generate an image RoiImage from the region covered by the region RoiRegion in the original image Image1;
[0164] The total interference region extraction module is used to extract the total interference region Interfere in the image RoiImage. The total interference region Interfere is composed of the letter and number interference region OCR, the symbol interference region Mark, the cap-shaped interference region Circularity, and the stripe interference region Rectlen on the surface of the electrical connector housing. Among them, the letter and number interference region OCR is obtained by optical character recognition detection of the image RoiImage, the symbol interference region Mark is obtained by shape-based template matching of the image RoiImage, and the cap-shaped interference region Circularity and the stripe interference region Rectlen are obtained by thresholding the image RoiImage and then filtering by shape size.
[0165] The scratch and block defect region extraction module is used to process the image RoiImage using threshold segmentation and line segment detection to obtain the total defect region Error1 corresponding to the scratches and block defects on the surface of the electrical connector housing in the image RoiImage;
[0166] The detection result output module is used to calculate the difference between the total defect area Error1 and the total interference area Interfere to obtain the defect area Error2 after removing the interference area. The area less than the detection accuracy is deleted from the defect area Error2 to obtain the defect area Error3. The area corresponding to the mechanical scratch in the defect area Error3 is deleted to obtain the detection result Result of the surface defect of the electrical connector housing.
[0167] Furthermore, the detection result output module is also used to print the detection result Result to the original image and output the number of defects ErrorNumber and the total area ErrorArea.
[0168] It should be noted that the aforementioned explanation of the method for detecting surface defects of electrical connector housings also applies to the detection device in this embodiment, and will not be repeated here.
[0169] To implement the above embodiments, this disclosure also proposes a computer-readable storage medium storing a computer program that is executed by a processor to perform the method for detecting surface defects of electrical connector housings as described above.
[0170] The following is for reference. Figure 13 The diagram illustrates a structural schematic of an electronic device suitable for implementing embodiments of the present disclosure. It should be noted that the electronic devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs, desktop computers, and servers. Figure 13 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0171] like Figure 13 As shown, the electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 101, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 102 or a program loaded from a storage device 108 into a random access memory (RAM) 103. The RAM 103 also stores various programs and data required for the operation of the electronic device. The processing unit 101, ROM 102, and RAM 103 are interconnected via a bus 104. An input / output (I / O) interface 105 is also connected to the bus 104.
[0172] Typically, the following devices can be connected to I / O interface 105: input devices 106 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, etc.; output devices 107 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 108 including, for example, magnetic tapes, hard disks, etc.; and communication devices 109. Communication device 109 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 13 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have alternatively.
[0173] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, this embodiment includes 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 an embodiment, the computer program can be downloaded and installed from a network via communication device 109, or installed from storage device 108, or installed from ROM 102. When the computer program is executed by processing device 101, it performs the functions defined above in the methods of embodiments of this disclosure.
[0174] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0175] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0176] The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform the aforementioned method for detecting surface defects in the electrical connector housing.
[0177] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and Python, 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 a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0178] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0179] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0180] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the function involved, as will be understood by those skilled in the art to which embodiments of this application pertain.
[0181] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which programs can be printed, because programs can be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.
[0182] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0183] Those skilled in the art will understand that implementing all or part of the steps of the methods in the above embodiments can be accomplished by instructing related hardware through a program. The developed program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.
[0184] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0185] The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc. Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of this application.
Claims
1. A method for detecting surface defects in an electrical connector housing, characterized in that, include: Step 1: Obtain the original image Image1 containing the background and electrical connector; Step 2: Extract the ROI region RoiRegion of the electrical connector in the original image Image1, and generate an image RoiImage from the area covered by the region RoiRegion in the original image Image1; Step 3: Extract the total interference region Interfere from the image RoiImage. The total interference region Interfere is composed of the letter and number interference region OCR, the symbol interference region Mark, the cap-shaped interference region Circularity, and the stripe interference region Rectlen on the surface of the electrical connector housing. The letter and number interference region OCR is obtained by optical character recognition detection of the image RoiImage. The symbol interference region Mark is obtained by shape-based template matching of the image RoiImage. The cap-shaped interference region Circularity and the stripe interference region Rectlen are obtained by thresholding the image RoiImage and then filtering by shape size. The extraction steps for the cap-shaped interference region Circularity and the striped interference region Rectlen include: Threshold segmentation is used to extract Region2, a region with a grayscale value greater than the segmentation threshold, from the image RoiImage. Region2 is then filled to obtain Region2f. The difference between Region2f and Region2 is calculated to obtain RegionDifference, a partial blocky defect, cap, and stripe interference region on the surface of the electrical connector housing. Circularity, a region within RegionDifference with a circular parameter > c1 and an area between -10% and +10% of the circular interference area, is selected as the cap-shaped interference region. Rectlen, a region within RegionDifference whose circumscribed rectangle's length and width are between -10% and +10% of the length and width of the stripe interference region, is selected as the stripe interference region. Step 4: Process the image RoiImage using threshold segmentation and line segment detection to obtain the total defect region Error1 corresponding to scratches and blocky defects on the surface of the electrical connector housing in the image RoiImage, including: Step 4-1: Process the image RoiImage using the local threshold segmentation method to extract the region Region3 with significant gray-scale changes on the surface of the electrical connector housing. Extract the line Line3 from the region Region3 using line detection; merge the lines in the line Line3 with a radian direction less than angle2 and a distance less than distance2 to obtain the line Line4 corresponding to the scratch defect on the surface of the electrical connector housing; Step 4-2: Use the threshold segmentation method to extract the region Region4 corresponding to the block defect with gray-scale values between 0 and threshold2 in the image RoiImage; Step 4-3: The region Region3, the line Line4, and the region Region4 form the total defect region Error1; Step 5: Take the difference between the total defect region Error1 and the total interference region Interfere to obtain the defect region Error2 after removing the interference region. Delete the regions smaller than the detection accuracy from the defect region Error2 to obtain the defect region Error3. Delete the region corresponding to the mechanical scratch in the defect region Error3 to obtain the detection result Result of the surface defect of the electrical connector housing; The step of deleting the region corresponding to the mechanical scratch in the defect region Error3 to obtain the detection result Result of the surface defect of the electrical connector housing includes: Select the line Line5 in the defect region Error3 where the length of the minimum bounding rectangle is > length2, the width is < width2, and the radian direction of the minimum bounding rectangle is between -angle and angle. The line Line5 is the mechanical scratch generated on the surface of the electrical connector housing during the production process; Take the difference between the defect region Error3 and the line Line5 to obtain the detection result Result of the surface defect of the electrical connector housing.
2. The detection method according to claim 1, characterized in that, Define the xy coordinate system, with the upper left corner of the original image Image1 as the origin O of the xy coordinate system, the horizontal right direction as the positive x-axis, and the vertical downward direction as the positive y-axis; The specific steps of step 2 are as follows: Step 2-1: Perform edge extraction on the original image Image1 to obtain a number of lines Line1. Merge the lines in all the lines Line1 with a direction deviation less than angle1 and a distance less than distance1, and select the lines Line2 with a length greater than length1. Set the gray-scale value of the region covered by the lines Line2 to 0 on the original image Image1 to generate the image Image2; where angle1 and distance1 are the maximum angle deviation and the maximum distance difference between the lines, and length1 is the minimum length of the merged lines; Step 2-2: Use threshold segmentation to segment the region in the image Image2 with a gray value greater than threshold1 into region Region1. Threshold1 is set according to the average gray value of the surface of the electrical connector housing. Steps 2-3: Extract a selected region, SelectedRegion1, from Region1; Steps 2-4: Generate a region SelectedRegion2 corresponding to the minimum bounding rectangle of the region SelectedRegion1. SelectedRegion2 is a part of the ROI region of the electrical connector. Obtain the angle phi1 between the region SelectedRegion2 and the x-axis ∈ [-90°, 90°], and rotate the original image Image1 and the region SelectedRegion2 around the center of the original image Image1 by an angle -phi1. Step 2-5: Obtain the ordinate row1 and abscissa of the region SelectedRegion2. Determine whether the region SelectedRegion2 is inverted by comparing row1 with b / 2, where b is the dimension of the original image Image1 along the y-axis. If row1 > b / 2, the region SelectedRegion2 is not inverted, and proceed to step 2-6. If row1 ≤ b / 2, the region SelectedRegion2 is inverted, and the original image Image1 and the region SelectedRegion2 need to be rotated 180 degrees around the center of the original image Image1. Obtain the angle phi2, the center ordinate row2, and the center abscissa column2 of the rotated region SelectedRegion2. Steps 2-6: Based on the center coordinates (row2, column2) of the selected region 2, translate the center of the selected region 2 along the y-axis direction by rowy to the center of another ROI region of the electrical connector (row3, column2). The size of rowy is determined by the relative positional relationship between the selected region 2 and the other ROI region of the electrical connector. Generate the selected region 3 based on (row3, column2) and the length and width dimensions of the electrical connector region corresponding to the other ROI region of the electrical connector. Merge the selected region 2 and the selected region 3 to obtain the ROI region RoiRegion of the connector. Generate the image RoiImage from the area covered by the region RoiRegion in the original image Image1.
3. The detection method according to claim 2, characterized in that, In step 3, the OCR extraction steps for the alphanumeric interference regions include: Based on the relative position of the selected region 2 and the character and number areas on the surface of the electrical connector housing, a region CharRegion is generated. Based on the region CharRegion, an image CharImage containing characters is segmented from the image Router. Optical character recognition (OCR) is then performed on the image CharImage to extract the letter and number interference areas on the surface of the electrical connector housing.
4. The detection method according to claim 2, characterized in that, In step 3, the extraction step of the symbolic interference region Mark includes: Read the template image ImageModle and find the symbol region RegionModle on the surface of the electrical connector housing in the template image ImageModle; generate a matching template Modle based on the template image ImageModle and the symbol region RegionModle; use the matching template Modle to perform template matching in the image RoiImage to detect the symbol-type interference region Mark on the surface of the electrical connector housing.
5. The detection method according to claim 1, characterized in that, In step 5, regions smaller than the detection precision are deleted from the defect region Error2 to obtain the defect region Error3, which includes: Delete the portion of the area in region Error2 that is larger than area1 to obtain the defective region Error3.
6. The detection method according to claim 1, characterized in that, Step 5 also includes the following steps: Print the detection result Result onto the original image and output the number of defects ErrorNumber and the total area ErrorArea.
7. A detection apparatus for implementing the detection method according to any one of claims 1 to 6, characterized in that, include: The raw image acquisition module is used to acquire the raw image Image1 containing the background and electrical connector; The electrical connector ROI generation module is used to extract the actual ROI region RoiRegion of the electrical connector in the original image Image1, and generate an image RoiImage from the region covered by the region RoiRegion in the original image Image1; The total interference region extraction module is used to extract the total interference region Interfere in the image RoiImage. The total interference region Interfere is composed of alphanumeric interference regions OCR, symbol interference regions Mark, cap-shaped interference regions Circularity, and stripe-shaped interference regions Rectlen on the surface of the electrical connector housing. The alphanumeric interference regions OCR are obtained by optical character recognition detection of the image RoiImage. The symbol interference regions Mark are obtained by shape-based template matching of the image RoiImage. The cap-shaped interference regions Circularity and stripe-shaped interference regions Rectlen are obtained by thresholding the image RoiImage and then filtering by shape and size. The scratch and block defect region extraction module is used to process the image RoiImage using threshold segmentation and line segment detection to obtain the total defect region Error1 corresponding to the scratches and block defects on the surface of the electrical connector housing in the image RoiImage; The detection result output module is used to perform a difference between the total defect area Error1 and the total interference area Interfere to obtain the defect area Error2 after removing the interference area. The area less than the detection accuracy is deleted from the defect area Error2 to obtain the defect area Error3. The area corresponding to the mechanical scratch in the defect area Error3 is deleted to obtain the detection result Result of the surface defect of the electrical connector housing.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to perform the detection method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Deformed steel bar surface defect detection method and system based on machine vision
CN110223296A
Ceramic hot-dip aluminum-plated surface defect detection method and device based on machine vision
CN110288584A