Method and device for detecting surface defects of electric connector shell and storage medium

By using OCR character recognition, template matching and pattern interference processing in electrical connector detection, the problems of inaccurate detection and limited applicability in the prior art are solved, and accurate detection and efficient identification of surface defects of the electrical connector housing are achieved.

CN119559115AActive Publication Date: 2025-03-04TSINGHUA UNIVERSITY
View PDF 10 Cites 0 Cited by

Patent Information

Application Number
CN202411420529.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2023-12-08
Filing Date
2024-10-12
Publication Date
2025-03-04
Estimated Expiration
2044-10-12

AI Technical Summary

Technical Problem

In the prior art, when detecting defects in the electrical connector housing surface, it is difficult to effectively remove interference targets on the connector surface, resulting in inaccurate detection results and limited applicability.

Method used

Using an interference removal detection method, through technologies such as OCR character recognition, template matching and shape interference processing, the interference target on the surface of the electrical connector is extracted and removed, and the defect area is then extracted.

Benefits of technology

Accurate detection of surface defects of the electrical connector housing is realized, the reliability and applicability of the inspection is improved, labor costs are saved, and identification efficiency is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119559115A_ABST
    Figure CN119559115A_ABST
Patent Text Reader

Abstract

The invention provides a method for detecting surface defects of an electric connector shell. The method comprises the following steps: acquiring an original image containing a background and an electric connector; extracting an ROI region of the electric connector in the image, and generating a RoiImage from a region covered by the ROI region in the original image; extracting a total interference area in the RoiImage, wherein the total interference area is composed of a letter and number type interference area, a symbol type interference area, a cap-shaped interference area and a stripe-shaped interference area on the surface of the electric connector shell; extracting an area Error1 corresponding to scratches and block-shaped defects on the surface of the shell of the electric connector in the RoiImage by utilizing threshold segmentation and line segment detection; and performing difference on the Error1 and the total interference area to obtain a defect area Error2 after the interference area is removed, deleting an area which is smaller than the detection precision from the Error2 to obtain a defect area Error3, and deleting an area corresponding to a mechanical scratch in the Error3 to obtain a detection result of the surface defect of the electric connector shell. The interference of surface defects of the electric connector can be effectively removed, and the detection efficiency and accuracy are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure belongs to the technical field of defect detection, and in particular relates to a method, device and storage medium for detecting surface defects of an electrical connector housing based on interference removal. Background Art

[0002] Electrical connectors are widely used in various aircraft and weapons and equipment, and the number of them used on aircraft is the most amazing. This is because in modern aircraft, a large number of electrical equipment needs to be connected and controlled through electrical connectors, such as flight instruments, radars, communication equipment, navigation systems, etc. In addition to meeting general performance requirements, electrical connectors also need to meet strict requirements in terms of good contact, reliable operation, and convenient maintenance. Whether they work reliably directly affects the normal operation of the aircraft circuit and involves the safety of the entire aircraft. In actual use, scratches, pollution, rust and other defects on the appearance of electrical connectors not only affect the appearance of the product, but also have a certain impact on its performance. Relying on manual identification of defects will inevitably be mixed with personal subjective feelings, resulting in non-objective testing standards, and manual testing generally takes a long time, which seriously affects the production efficiency of the company and the reliability of the product.

[0003] At present, researchers have invented some methods to detect surface defects of electrical connector shells. The literature (Gao Wenbin, Zhuang Shenle, Wang Xiujian, et al. Research on shell surface defect detection based on machine vision technology [J]. Electromechanical Components, 2022, 42(01):42-46.) uses image enhancement, defect image segmentation, and defect feature extraction to detect connector defects. The literature (Du Juan, Yang Junzhi. 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, which realizes small sample learning in the case of data scarcity and has good detection effect. The literature (Xu Zhenying, Li Jiankang, Ling Jun, et al. Design of electrical connector shell defect detection system based on Halcon [J]. Manufacturing Automation, 2015, 37(18):135-138.) realizes the detection and classification of connector defects through multiple steps such as preprocessing, feature detection, and feature recognition.

[0004] However, the existing methods also have some shortcomings. Most of the current methods only intercept the local area where the defects exist for experiments, while in actual applications, the detection is generally carried out on the entire surface of the connector. There are many interference targets on the surface of the connector, such as connector numbers, manufacturer symbols, nuts, textures, etc. In addition, the types of interference on the surfaces of different connectors in China are not the same, and the reflection intensity of light by the shell material is also different. The existing connector defect detection methods are mostly for a specific type of connector, and the defect detection methods for other types of connectors need to be studied. Summary of the invention

[0005] In order to overcome the shortcomings of the prior art, the present invention provides an electrical connector defect detection method based on interference removal, firstly obtaining a connector image; then extracting the image ROI (Region of Interest); on this basis, using OCR (Optical Character Recognition) character recognition, template matching, shape interference processing and other methods to extract the interference area on the surface of the connector shell; then removing the interference on the connector surface; and finally extracting the connector defect. The present invention establishes an interference processing mechanism based on the prior art, which can effectively remove the interference target on the connector surface and is more reliable and applicable in practical applications.

[0006] The method of the present invention can realize the detection of surface defects of connector housings, save labor costs, improve recognition efficiency, ensure product reliability, and provide an effective means for detecting surface defects of connector housings in industrial scenarios.

[0007] The technical solution adopted by the present invention to solve the technical problem includes the following steps:

[0008] A first aspect of the present disclosure provides a method for detecting surface defects of an electrical connector housing, comprising:

[0009] Step 1: Get the original image Image1 containing the background and the electrical connector;

[0010] Step 2: extracting the ROI region RoiRegion of the electrical connector in the original image Image1, and generating an image RoiImage from the region covered by the region RoiRegion in the original image Image1;

[0011] Step 3: extracting the total interference area Interfere in the image RoiImage, wherein the total interference area Interfere is composed of the letter and number interference area OCR, the symbol interference area Mark, and the cap-shaped interference area Circularity and the stripe-shaped interference area Rectlen on the surface of the electrical connector housing, wherein the letter and number interference area OCR is obtained by performing optical character recognition detection on the image RoiImage, the symbol interference area Mark is obtained by performing shape-based template matching on the image RoiImage, and the cap-shaped interference area Circularity and the stripe-shaped interference area Rectlen are obtained by performing threshold segmentation on the image RoiImage and then screening using shape size;

[0012] Step 4: Process the image RoiImage by using threshold segmentation and line segment detection to obtain a total defect area Error1 corresponding to scratches and block defects on the surface of the electrical connector housing in the image RoiImage;

[0013] Step 5: Differentiate the total defect area Error1 from 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 scratches in the defect area Error3, and obtain the detection result Result of the surface defects of the electrical connector shell.

[0014] In some embodiments, an xy coordinate system is defined, with the upper left corner of the original image Image1 as the origin O of the xy coordinate system, the horizontal rightward direction as the positive direction of the x-axis, and the vertical downward direction as the positive direction of the y-axis;

[0015] The step 2 specifically includes the following steps:

[0016] Step 2-1: Perform edge extraction on the original image Image1 to obtain a number of lines Line1, merge all the lines Line1 whose direction deviation is less than angle1 and whose distance is less than distance1, select the line Line2 whose length is greater than length1, set the gray value of the area covered by the line Line2 on the original image Image1 to 0, and generate image Image2; wherein 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 line;

[0017] Step 2-2: using threshold segmentation to segment the region in the image Image2 whose grayscale value is greater than threshold1 into region Region1, where threshold1 is set according to the average grayscale value of the surface of the electrical connector housing;

[0018] Step 2-3: extracting a selected region SelectedRegion1 from the region Region1;

[0019] Step 2-4: Generate a region SelectedRegion2 corresponding to the minimum circumscribed rectangle of the region SelectedRegion1, where SelectedRegion2 is a part of the ROI region of the electrical connector, obtain an angle phi1∈[-90°,90°] between the region SelectedRegion2 and the x-axis, and rotate the original image Image1 and the region SelectedRegion2 by an angle of -phi1 around the center of the original image Image1;

[0020] Step 2-5: Obtain the ordinate row1 and abscissa of the region SelectedRegion2, and determine whether the region SelectedRegion2 is inverted by judging the size of row1 and b / 2, where b is the size of the original image Image1 along the y-axis. If row1>b / 2, it means that the region SelectedRegion2 is not inverted, and execute step 2-6; if row1≤b / 2, it means that 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, and obtain the angle phi2, the center ordinate row2, and the center abscissa column2 of the rotated region SelectedRegion2;

[0021] Step 2-6: According to the center coordinates (row2, column2) of the area SelectedRegion2, translate the center of the area SelectedRegion2 by rowy along the y-axis direction to the center of another ROI area of ​​the electrical connector (row3, column2), where the size of rowy is determined by the relative position relationship between the area SelectedRegion2 and the other ROI area of ​​the electrical connector, generate area SelectedRegion3 according to (row3, column2) and the length and width of the area of ​​the electrical connector corresponding to the other ROI area of ​​the electrical connector, merge the area SelectedRegion2 and the area SelectedRegion3 to obtain the ROI area RoiRegion of the connector, and generate the image RoiImage from the area covered by the area RoiRegion in the original image Image1.

[0022] In some embodiments, in step 3, the step of extracting the letter and number interference area OCR includes:

[0023] The region CharRegion is generated according to the relative position of the region SelectedRegion2 and the region where characters and numbers exist on the surface of the electrical connector shell, and the image CharImage where the characters exist is segmented from the image RoiIamge according to the region CharRegio; optical character recognition detection is performed in the image CharImage to extract the letter and number interference area OCR on the surface of the electrical connector shell.

[0024] In some embodiments, in step 3, the step of extracting the symbolic interference area Mark includes:

[0025] Read the template image ImageModle, find the symbol area RegionModle to be detected on the surface of the electrical connector shell in the template image ImageModle; generate a matching template Modle according to the template image ImageModle and the symbol area RegionModle; use the matching template Modle in the image RoiImage to perform template matching, and detect the symbol-type interference area Mark on the surface of the electrical connector shell.

[0026] In some embodiments, in step 3, the step of extracting the cap-shaped interference area Circularity and the stripe-shaped interference area Rectlen includes:

[0027] Threshold segmentation is used to extract region Region2 whose grayscale value is greater than the segmentation threshold from the image RoiImage; the region Region2 is filled to obtain a filled region Region2f; the region Region2f is differentiated from the region Region2 to obtain a partial block defect and a cap and stripe interference region RegionDifference in the surface of the electrical connector housing; the region Circularity whose circular parameter>c1 and area is between -10% and +10% of the circular interference area in the region RegionDifference is selected, and the region Circularity is the cap interference area; the region Rectlen whose length and width of the circumscribed rectangle are between -10% and +10% of the length and width of the long strip interference in the region RegionDifference is selected, and the region Rectlen is the stripe interference area.

[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 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 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-scale values 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 circumscribed rectangle is > length2, the width is < width2, and the radian direction of the minimum circumscribed 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 defect on the surface of the electrical connector housing.

[0037] In some embodiments, step 5 further includes the following steps:

[0038] Step 5-5: Print the detection result Result onto the original image and output the number of defects ErrorNumber and the total area ErrorArea.

[0039] A detection device for implementing the detection method according to any one of the embodiments of the first aspect of the present disclosure provided by the second aspect of the present disclosure includes:

[0040] The original image acquisition module is used to acquire the original image Image1 containing the background and the electrical connector;

[0041] An electrical connector image of interest 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] a total interference region extraction module, for extracting a total interference region Interfere in the image RoiImage, wherein the total interference region Interfere is composed of a letter and number interference region OCR, a symbol interference region Mark, and a cap-shaped interference region Circularity and a stripe-shaped interference region Rectlen on the surface of the electrical connector housing, wherein the letter and number interference region OCR is obtained by performing optical character recognition detection on the image RoiImage, the symbol interference region Mark is obtained by performing shape-based template matching on the image RoiImage, and the cap-shaped interference region Circularity and the stripe-shaped interference region Rectlen are obtained by performing threshold segmentation on the image RoiImage and then screening using shape size;

[0043] A scratch and block defect region extraction module is used to process the image RoiImage by using threshold segmentation and line segment detection to obtain a total defect region Error1 corresponding to 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 differentiate the total defect area Error1 from 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 scratches in the defect area Error3, and obtain the detection result Result of the surface defect of the electrical connector shell.

[0045] A third aspect of the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the detection method described in any embodiment of the first aspect of the present disclosure.

[0046] The present disclosure has the following characteristics and beneficial effects:

[0047] The present disclosure can remove interference from different interference targets on the surface of different electrical connector housings, is more reliable and applicable in practical applications, and can better adapt to different types of electrical connectors and environmental conditions. The present disclosure can realize automatic processing and analysis of electrical connector images by using technologies such as optical character recognition and template matching, reducing the need for manual intervention and improving efficiency. The present disclosure also has good scalability, and the algorithm can be customized and improved as needed to meet the needs of different types of electrical connector defect detection.

[0048] In summary, the present disclosure can realize connector defect detection, save labor costs, improve identification efficiency, ensure product reliability, and provide an effective means for high-accuracy detection of connector defects in industrial scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 An overall flow chart of a method for detecting surface defects of an electrical connector housing provided in an embodiment of the present disclosure.

[0050] Figure 2 This is the image Image2 obtained in step 2-1 of the detection method provided in the embodiment of the present disclosure.

[0051] Figure 3 The region SelectedRegion1 obtained in steps 2-3 of the detection method provided in the embodiment of the present disclosure.

[0052] Figure 4 The image Image1 and the region SelectedRegion2 obtained in steps 2-5 in the detection method provided in the embodiment of the present disclosure.

[0053] Figure 5 It is the region RoiRegion obtained in steps 2-6 of the detection method provided in the embodiment of the present disclosure.

[0054] Figure 6 It is the image RoiImage obtained in steps 2-6 of the detection method provided in the embodiment of the present disclosure.

[0055] Figure 7 The OCR of the letter and number interference area obtained in step 3-1-2 of the detection method provided in the embodiment of the present disclosure.

[0056] Figure 8 It is the symbolic interference area Mark obtained in step 3-2-3 of the detection method provided in the embodiment of the present disclosure.

[0057] Fig. 9The cap-shaped interference area Circularity and the stripe-shaped interference area Rectle obtained in step 3-3-4 and step 3-3-5 in the detection method provided in the embodiment of the present disclosure.

[0058] Fig.10 It is the total defect area Error1 obtained in step 4-3 in the detection method provided in the embodiment of the present disclosure.

[0059] Fig.11 This is the final test result obtained in step 5 of the test method provided in the embodiment of the present disclosure.

[0060] Fig.12 A diagram of the software interface designed for the detection method provided in the embodiment of the present disclosure.

[0061] Fig.13 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0062] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0063] On the contrary, the present application covers any substitution, modification, equivalent method and scheme made on the essence and scope of the present application as defined by the claims. Further, in order to make the public have a better understanding of the present application, some specific details are described in detail in the detailed description of the present application below. Those skilled in the art can fully understand the present application without the description of these details.

[0064] See also Figure 1 The present disclosure provides a method for detecting surface defects of an electrical connector housing, comprising the following steps:

[0065] Step 1: Get the original image Image1 containing the background and the electrical connector;

[0066] Step 2: extracting the ROI region RoiRegion of the electrical connector in the original image Image1, and generating an image RoiImage from the region covered by the region RoiRegion in the original image Image1;

[0067] Step 3: extract the total interference area Interfere in the image RoiImage, which is composed of the letter and number interference area OCR, the symbol interference area Mark, and the cap-shaped interference area Circularity and the stripe-shaped interference area Rectlen on the surface of the electrical connector housing; wherein the letter and number interference area OCR is obtained by performing optical character recognition detection on the image RoiImage, the symbol interference area Mark is obtained by performing shape-based template matching on the image RoiImage, and the cap-shaped interference area Circularity and the stripe-shaped interference area Rectlen are obtained by performing threshold segmentation on the image RoiImage and then screening using shape size;

[0068] Step 4: Process the image RoiImage by using threshold segmentation and line segment detection to obtain the region Error1 corresponding to the scratches and block defects on the surface of the electrical connector housing in the image RoiImage;

[0069] Step 5: Differentiate the area Error1 from 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 scratches in the defect area Error3, and obtain the detection result Result of the surface defect of the electrical connector shell.

[0070] The present disclosure is further described below with reference to the accompanying drawings and embodiments.

[0071] The present disclosure provides a method for detecting surface defects of an electrical connector housing, which specifically includes the following steps:

[0072] Step 1: Get the connector image

[0073] Prepare the connector to be inspected, the defect detection shooting device and the PC with the corresponding software installed, connect the industrial camera used to shoot the connector to the PC, start the corresponding software, and successfully display the corresponding camera imaging image. The image format is .bmp, and the image size is a*b. In this embodiment, a is 4024 and b is 3036. 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 direction of the x axis, and the vertical downward direction as the positive direction of the y axis.

[0074] Step 2: Extract the connector ROI area:

[0075] The variables used in this step are defined as follows:

[0076] Image1: The original image, which is a two-dimensional matrix (dimension is 4024*3036).

[0077] Line1: The line generated after line segment extraction from the original image Image1.

[0078] Line2: merge the lines in Line1 whose arc direction difference is less than angle1 and whose distance is less than distance1, and select the lines whose length is greater than length1, which correspond to the lines dividing the electrical connector into the base and the upper body.

[0079] Image2: Set the grayscale value of the area where line Line2 is located in the original image Image1 to 0, generating image Image2, which is separated by line Line2.

[0080] Region1: The region obtained by segmenting the image Image2 through threshold segmentation, 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 minimum enclosing rectangle generated based on the region SelectedRegion1.

[0083] phi1: The angle of region SelectedRegion2, phi1∈[-90°,90°], defined as the angle between the long side of region SelectedRegion2 and the x-axis.

[0084] row1: the vertical coordinate of SelectedRegion2 after rotating it by an angle of -phi1.

[0085] phi2: The angle of SelectedRegion2 after rotating it 180°.

[0086] row2: the vertical coordinate of SelectedRegion2 after rotating it by angle phi2.

[0087] column2: the horizontal coordinate of SelectedRegion2 after SelectedRegion2 is rotated 180°.

[0088] RoiRegion: The Roi region generated based on the angle phi2, the ordinate row2, the abscissa column2, and the relative coordinates of the region SelectedRegion2 and another ROI region of the electrical connector.

[0089] RoiImage: Generates an image from the area covered by the region RoiRegion in the original image Image1.

[0090] Step 2-1: The housing of an electrical connector is usually divided into two or three blocks, and the boundaries between these blocks are sometimes not obvious. The housing of the electrical connector in this embodiment 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 to obtain a number of lines Line1. The union_collinear_contours_xld operator is used to merge all the lines Line1 whose arc direction is less than angle1 and whose distance is less than distance1, and select the line Line2 whose length is greater than length1. The grayscale value of the area where the line Line2 is located on the original image Image1 is set to 0 to generate an image Image2, where angle1 and distance1 are the maximum angle deviation and the maximum distance difference between the lines, respectively. In this embodiment, they are 0.3 and 200. length1 is the minimum length of the merged line. In this embodiment, it is 500. The generated image Image2 is as follows: Figure 2 As shown;

[0091] Step 2-2: Use threshold segmentation to segment the area in the image Image2 where the grayscale value is greater than threshold1 into region Region1. In this example, threshold1 is 200; this region is the area on the surface of the electrical connector housing where the grayscale value is greater than 200 and is a brighter area.

[0092] Step 2-3: Find a region SelectedRegion1 set in region Region1 (the region corresponds to the base of the electrical connector) according to the area or length of region Region1. The region SelectedRegion1 obtained in this embodiment is as follows: Figure 3 The range shown in the dotted box;

[0093] Step 2-4: Generate the region SelectedRegion2 corresponding to the minimum circumscribed rectangle of the region SelectedRegion1 according to the gen_rectangle2_contour_xld operator, the 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 the region SelectedRegion2, and rotate the original image Image1 and the region SelectedRegion2 by an angle of -phi1 around the center of the original image;

[0094] Step 2-5: Get the ordinate row1 of the region SelectedRegion2, and determine whether the region SelectedRegion2 is inverted by judging the size of row1 and b / 2. If row1>b / 2, it means that the region SelectedRegion2 is not inverted, and execute step 2-6; if row1≤b / 2, it means that 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, and obtain the angle phi2, the center ordinate row2 and the center abscissa column2 of the rotated region SelectedRegion2. The original image Image1 and the region SelectedRegion2 after the rotation in this embodiment are as follows: Figure 4 As shown, Figure 4 The range shown in the dotted box is the region SelectedRegion2;

[0095] Step 2-6: According to the center coordinates (row2, column2) of the region SelectedRegion2, the center of the region SelectedRegion2 is translated rowy along the y-axis direction to the center of another ROI region of the electrical connector (row3, column2), the size of rowy is determined by the relative position relationship between the region SelectedRegion2 and the other ROI region of the electrical connector, and the region SelectedRegion3 is generated according to (row3, column2) and the length and width of the electrical connector region corresponding to the other ROI region of the electrical connector, and the region SelectedRegion2 and the region SelectedRegion3 are merged to obtain the ROI region RoiRegion of the connector, and the region covered by the region RoiRegion in the original image Image1 is used to generate the image RoiImage. The region RoiRegion and the image RoiImage generated in this embodiment are respectively as shown in Figure 5 , Figure 6 As shown;

[0096] Step 3: Extract the total interference area in the image RoiImage

[0097] In this embodiment, the total interference area in the image RoiImage is defined as Interfere, which is composed of the letter and number interference area OCR, the symbol interference area Mark, the cap-shaped interference area Circularity and the stripe-shaped interference area Rectlen on the surface of the electrical connector housing. The extraction process of each type of interference area is described separately:

[0098] Step 3-1: Extract the letter and number interference areas in the image RoiImage

[0099] The variables used in this step are defined as follows:

[0100] CharRegion: The character ROI area is generated based on the angle phi2, the ordinate row2, the abscissa column2, and the relative coordinates of the area SelectedRegion2 and the areas where letters and numbers are located.

[0101] CharImage: The image generated by the area covered by the region CharRegion in the image RoiImage.

[0102] OCR.omc: OCR training file.

[0103] OCR: Alphanumeric interference area on the surface of the electrical connector housing

[0104] Step 3-1-1: Generate region CharRegion according to the relative position of region SelectedRegion2 and the region where characters and numbers exist, and segment the image CharImage where characters exist in image RoiIamge according to region CharRegio;

[0105] Step 3-1-2: Use the create_text_model_reader operator to create a character template and set parameters (including character size, character shape, symbol segment size, text direction and text layout, etc.), use the read_ocr_class_mlp operator to read the pre-trained file OCR.omc (the pre-trained file is obtained by training through halcon software and related data), perform OCR detection on the image CharImage where the characters exist, and detect the OCR of the letter and number interference area on the surface of the electrical connector housing. The OCR of the letter and number interference area extracted in this embodiment is as follows Figure 7 As shown;

[0106] Step 3-2: Extract the symbolic interference region in the image RoiImage

[0107] The variables used in this step are defined as follows:

[0108] ImageModle: Template image for template matching.

[0109] RegionModle: Template generation region.

[0110] Modle: Shape-based matching templates.

[0111] Mark: Template matching result, i.e. symbolic interference.

[0112] Step 3-2-1: Read the template image ImageModle and find the symbol region RegionModle to be detected in ImageModle;

[0113] Step 3-2-2: Use the create_shape_model operator to generate the matching template Modle of the symbol according to 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 image RoiImage using the matching template Modle to detect the symbolic interference area Mark on the surface of the electrical connector housing. The symbolic interference area extracted in this embodiment is as follows: Figure 8 As shown;

[0115] Step 3-3: Extract the cap interference area and stripe interference area in the image RoiImage

[0116] The variables used in this step are defined as follows:

[0117] Region2: The region in the image RoiImage extracted using threshold segmentation where the grayscale value is greater than the segmentation threshold.

[0118] Region2f: The fill area of ​​region Region2.

[0119] RegionDifference: The region obtained by differentiating region Region2f from region Region2.

[0120] Circularity: The approximately circular interference area on the surface of the electrical connector housing, that is, the cap interference area.

[0121] Rectlen: A striped interference area on the surface of an electrical connector housing.

[0122] Step 3-3-1: Use threshold segmentation to extract the area in the image RoiImage whose grayscale value is greater than the segmentation threshold to obtain region Region2;

[0123] Step 3-3-2: Use the fill_up operator to fill the region Region2 to obtain the filled region Region2f;

[0124] Step 3-3-3: Differentiate region Region2f from region Region2 to obtain some larger block defects and caps, as well as stripe interference RegionDifference on the surface of the electrical connector housing;

[0125] Step 3-3-4: select the region RegionDifference with the circular parameter > c1 (c1 is set according to the similarity between the circular interference region on the surface of the electrical connector housing and the circle, and c1 is 0.5 in this embodiment) and the region Circularity with an area between -10% and +10% of the circular interference region of the electrical connector (adjusted according to the electrical connector model), and Circularity is the cap-shaped interference region on the surface of the electrical connector housing;

[0126] Step 3-3-5: Select the region Rectlen in which the length and width of the circumscribed rectangle in the region RegionDifference is between -10% and +10% of the length and width of the long strip interference region of the electrical connector according to the select_shape operator. Rectlen is the stripe interference region on the surface of the electrical connector housing. The interference regions Circularity and Rectle extracted in this embodiment are as follows: Fig. 9 As shown;

[0127] Step 4: Extract the total defects on the surface of the electrical connector housing

[0128] The variables used in this step are defined as follows:

[0129] Region3: The region with drastic edge changes obtained by using local threshold segmentation on the image RoiImage.

[0130] Line3: Use the calculate_lines_gauss_parameters operator to calculate the optimal parameters for line extraction and then extract lines from region Region3.

[0131] Line4: Merges the 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, to obtain block defects with grayscale less than threshold2 on the surface of the electrical connector housing. In this example, threshold2 is 100.

[0133] Error1: The part obtained by merging region Region3, line Line4 and region Region4, wherein the area formed by regions Region3 and Region4 together corresponds to the total block defect area.

[0134] Step 4-1: Use the local_threshold local threshold segmentation method to process the image RoiImage, and extract the area Region3 where the grayscale change on the surface of the electrical connector shell is large, that is, the area with drastic edge changes in the corresponding image RoiImage; use the calculate_lines_gauss_parameters operator to calculate the optimal parameters for extracting line Line3, and use the lines_gauss operator to extract the line to obtain line Line3; use the union_collinear_contours_xld operator to merge the lines in Line3 whose arc direction is less than angle2 and whose distance is less than distance2 to obtain Line4, angle2 and distance2 are set according to empirical values. In this example, angle2 and distance2 are taken as 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 whose gray value is between 0-threshold2 as Region4;

[0136] Step 4-3: Merge region Region3, line Line4 and region Region4 to obtain the total defect region Error1. The total defect region Error1 obtained in this embodiment is as follows: Fig.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 area in the defect area Error2 that is larger 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 is > length2, the width is < 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 housing during the production of the electrical connector.

[0142] Result: The result obtained by taking the difference between the defect area Error3 and the line Line5, 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 back 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: According to the select_shape operator, select 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: According to the select_shape operator, select the area Line5 in the defect area 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 -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 housing.

[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 Fig.11As described above, the number of defects ErrorNumber and the total area ErrorArea are output.

[0151] The various operators used in this embodiment are all functional modules that come with the halcon software.

[0152] The following is an example of the effect of implementing the above method:

[0153] The software is developed using C++ language, and the interface is developed using Qt. The entire interface is divided into three parts: upper, middle and lower. Fig.12 , the top is the function bar, which includes the electrical connector model and front and back selection, open the camera, upload pictures, history and other functions. The middle left part is the original image of the electrical connector to be tested, and the middle right part is the defect detection result image. The bottom is the output detection result.

[0154] The software is divided into ten modes, corresponding to the front and back sides of five electrical connectors.

[0155] Currently, there are 200 defect data of electrical connectors. First, the software is used to detect defects on the electrical connectors to be inspected. Then, the software detection results are verified through manual re-inspection, and the accuracy of abnormal identification of electrical connectors is calculated, and the inspection time of the device is counted. The accuracy of abnormal identification is required to be >95%, and the average detection time of one image is <0.5s. The experimental results are as follows:

[0156] Table 1 Experimental results statistics

[0157] match No match Accuracy Average detection time Defect detection results 195 5 97.5% 0.40

[0158] Through testing, the detection method of the embodiment of the present disclosure has an accuracy rate of 97.5%. The incorrect detection of the electrical connector is caused by factors such as uneven lighting, improper placement, and interference from the electrical connector's own texture. In specific industrial applications, the accuracy of defect detection can be improved by expanding the light source area and artificially placing the electrical connector at the imaging center. Therefore, the embodiment of the present disclosure is fully capable of detecting defects on the surface of the electrical connector housing.

[0159] In summary, this embodiment is aimed at defect detection on the surface of an electrical connector housing. In order to remove interference targets on the surface of the electrical connector and better extract defects, this disclosed embodiment proposes for the first time a method for detecting defects on the surface of an electrical connector housing based on interference removal. Multiple methods such as OCR character recognition, template matching, and shape interference processing are used to extract interference targets such as product numbers, manufacturer symbols, nuts, and textures on the surface of the connector, which reduces false detections, ensures the reliability of subsequent defect extraction, and is more suitable for industrial use.

[0160] In summary, the present invention establishes an interference target removal mechanism, which can more accurately locate the area of ​​the interference target and eliminate the remaining interference on the connector surface before defect extraction, thereby effectively improving the accuracy and reliability of defect detection.

[0161] The present disclosure also provides a detection device for implementing the above detection method, including:

[0162] The original image acquisition module is used to acquire the original image Image1 containing the background and the electrical connector;

[0163] An electrical connector image of interest generation module is used to extract the electrical connector ROI region RoiRegion in the original image Image1, and generate an image RoiImage from the region covered by the region RoiRegion in the original image Image1;

[0164] A total interference region extraction module is used to extract a total interference region Interfere in the image RoiImage, wherein the total interference region Interfere is composed of the letter and number interference region OCR, the symbol interference region Mark, and the cap-shaped interference region Circularity and the stripe-shaped interference region Rectlen on the surface of the electrical connector housing, wherein the letter and number interference region OCR is obtained by performing optical character recognition detection on the image RoiImage, the symbol interference region Mark is obtained by performing shape-based template matching on the image RoiImage, and the cap-shaped interference region Circularity and the stripe-shaped interference region Rectlen are obtained by performing threshold segmentation on the image RoiImage and then screening using shape size;

[0165] The scratch and block defect region extraction module is used to process the image RoiImage by 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 differentiate the total defect area Error1 from 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 scratches in the defect area Error3, and obtain the detection result Result of the surface defect of the electrical connector shell.

[0167] Furthermore, the detection result output module is also used to print the detection result Result into the original image, and output the number of defects ErrorNumber and the total area ErrorArea.

[0168] It should be noted that the above-mentioned explanation of the embodiment of the method for detecting surface defects of the electrical connector housing is also applicable to the detection device of this embodiment, and will not be repeated here.

[0169] In order to implement the above embodiment, the embodiment of the present disclosure further proposes a computer-readable storage medium on which a computer program is stored. The program is executed by a processor to execute the method for detecting surface defects of an electrical connector housing of the above embodiment.

[0170] Reference below Fig.13 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure. It should be noted that the electronic device in the embodiments of the present disclosure may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, servers, etc. Fig.13 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0171] like Fig.13 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processor, 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 to a random access memory (RAM) 103. In the RAM 103, various programs and data required for the operation of the electronic device are also stored. The processing device 101, the ROM 102, and the RAM 103 are connected to each other via a bus 104. An input / output (I / O) interface 105 is also connected to the bus 104.

[0172] Typically, the following devices may be connected to the I / O interface 105: an input device 106 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, etc.; an output device 107 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 108 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 109. The communication device 109 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Fig.13 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0173] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the present embodiment includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 109, or installed from the storage device 108, or installed from the ROM 102. When the computer program is executed by the processing device 101, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0174] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0175] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0176] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the method for detecting surface defects of the electrical connector housing.

[0177] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, python, and conventional procedural programming languages, such as "C-" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate 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 a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0178] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.

[0179] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.

[0180] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.

[0181] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purposes of this specification, a "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic devices), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or otherwise processing in a suitable manner if necessary, and then stored in a computer memory.

[0182] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0183] A person of ordinary skill in the art may understand that all or part of the steps carried out in the above-mentioned embodiment method may be completed by instructing the relevant hardware through a program, and the developed program may be stored in a computer-readable storage medium, which, when executed, includes one of the steps of the method embodiment or a combination thereof.

[0184] In addition, each functional unit in each embodiment of the present application may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.

[0185] The storage medium mentioned above may be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limiting the present application. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present application.

Claims

1. A method for detecting surface defects of an electrical connector housing, characterized in that: include: Step 1: Get the original image Image1 containing the background and the electrical connector; Step 2: extracting the ROI region RoiRegion of the electrical connector in the original image Image1, and generating an image RoiImage from the region covered by the region RoiRegion in the original image Image1; Step 3: extracting the total interference area Interfere in the image RoiImage, wherein the total interference area Interfere is composed of the letter and number interference area OCR, the symbol interference area Mark, and the cap-shaped interference area Circularity and the stripe-shaped interference area Rectlen on the surface of the electrical connector housing, wherein the letter and number interference area OCR is obtained by performing optical character recognition detection on the image RoiImage, the symbol interference area Mark is obtained by performing shape-based template matching on the image RoiImage, and the cap-shaped interference area Circularity and the stripe-shaped interference area Rectlen are obtained by performing threshold segmentation on the image RoiImage and then screening using shape size; Step 4: Process the image RoiImage by using threshold segmentation and line segment detection to obtain a total defect area Error1 corresponding to scratches and block defects on the surface of the electrical connector housing in the image RoiImage; Step 5: Differentiate the total defect area Error1 from 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 scratches in the defect area Error3, and obtain the detection result Result of the surface defects of the electrical connector shell.

2. The detection method according to claim 1, characterized in that: Define an 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 direction of the x axis, and the vertical downward direction as the positive direction of the y axis; The step 2 specifically includes the following steps: Step 2-1: Perform edge extraction on the original image Image1 to obtain a number of lines Line1, merge all the lines Line1 whose direction deviation is less than angle1 and whose distance is less than distance1, select the line Line2 whose length is greater than length1, set the gray value of the area covered by the line Line2 on the original image Image1 to 0, and generate image Image2; wherein 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 line; Step 2-2: using threshold segmentation to segment the region in the image Image2 whose grayscale value is greater than threshold1 into region Region1, where threshold1 is set according to the average grayscale value of the surface of the electrical connector housing; Step 2-3: extracting a selected region SelectedRegion1 from the region Region1; Step 2-4: Generate a region SelectedRegion2 corresponding to the minimum circumscribed rectangle of the region SelectedRegion1, where SelectedRegion2 is a part of the ROI region of the electrical connector, obtain an angle phi1∈[-90°,90°] between the region SelectedRegion2 and the x-axis, and rotate the original image Image1 and the region SelectedRegion2 by an angle of -phi1 around the center of the original image Image1; Step 2-5: Obtain the ordinate row1 and abscissa of the region SelectedRegion2, and determine whether the region SelectedRegion2 is inverted by judging the size of row1 and b / 2, where b is the size of the original image Image1 along the y-axis. If row1>b / 2, it means that the region SelectedRegion2 is not inverted, and execute step 2-6; if row1≤b / 2, it means that 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, and obtain the angle phi2, the center ordinate row2, and the center abscissa column2 of the rotated region SelectedRegion2; Step 2-6: According to the center coordinates (row2, column2) of the area SelectedRegion2, translate the center of the area SelectedRegion2 by rowy along the y-axis direction to the center of another ROI area of ​​the electrical connector (row3, column2), where the size of rowy is determined by the relative position relationship between the area SelectedRegion2 and the other ROI area of ​​the electrical connector, generate area SelectedRegion3 according to (row3, column2) and the length and width of the area of ​​the electrical connector corresponding to the other ROI area of ​​the electrical connector, merge the area SelectedRegion2 and the area SelectedRegion3 to obtain the ROI area RoiRegion of the connector, and generate the image RoiImage from the area covered by the area RoiRegion in the original image Image1.

3. The detection method according to claim 2, characterized in that: In step 3, the step of extracting the letter and number interference area OCR includes: The region CharRegion is generated according to the relative position of the region SelectedRegion2 and the region where characters and numbers exist on the surface of the electrical connector shell, and the image CharImage where the characters exist is segmented from the image RoiIamge according to the region CharRegio; optical character recognition detection is performed in the image CharImage to extract the letter and number interference area OCR on the surface of the electrical connector shell.

4. The detection method according to claim 2, characterized in that: In step 3, the step of extracting the symbolic interference area Mark includes: Read the template image ImageModle, find the symbol area RegionModle to be detected on the surface of the electrical connector shell in the template image ImageModle; generate a matching template Modle according to the template image ImageModle and the symbol area RegionModle; use the matching template Modle in the image RoiImage to perform template matching, and detect the symbol-type interference area Mark on the surface of the electrical connector shell.

5. The detection method according to claim 2, characterized in that: In step 3, the steps of extracting the cap-shaped interference area Circularity and the stripe-shaped interference area Rectlen include: Threshold segmentation is used to extract region Region2 whose grayscale value is greater than the segmentation threshold from the image RoiImage; the region Region2 is filled to obtain a filled region Region2f; the region Region2f is differentiated from the region Region2 to obtain a partial block defect and a cap and stripe interference region RegionDifference in the surface of the electrical connector housing; the region Circularity whose circular parameter>c1 and area is between -10% and +10% of the circular interference area in the region RegionDifference is selected, and the region Circularity is the cap interference area; the region Rectlen whose length and width of the circumscribed rectangle are between -10% and +10% of the length and width of the long strip interference in the region RegionDifference is selected, and the region Rectlen is the stripe interference area.

6. The detection method according to claim 1, characterized in that: The step 4 specifically comprises the following steps: Step 4-1: Process the image RoiImage using a local threshold segmentation method to extract a region Region3 where the grayscale of the surface of the electrical connector housing changes significantly, and extract a line Line3 from the region Region3 using line segment detection; merge the lines in the line Line3 whose arc direction is less than angle2 and whose distance is less than distance2 to obtain a line Line4 corresponding to the scratch defect on the surface of the electrical connector housing; Step 4-2: using a threshold segmentation method to extract a region Region4 corresponding to a block defect having a gray value between 0 and threshold2 in the image RoiImage; Step 4-3: The Region3, the Line4, and the Region4 form the total defect area Error1.

7. The detection method according to claim 1, characterized in that: The specific steps of Step 5 are as follows: 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; Step 5-2: Delete the part of the area Error2 with an area larger than area1 to obtain the defect area Error3; Step 5-3: Screen out the Line5 in the defect area Error3 where the length of the minimum circumscribed rectangle is > length2, the width is < width2, and the radian direction of the minimum circumscribed rectangle is between -angle and angle. The Line5 is the mechanical scratch generated on the surface of the electrical connector during the production process; Step 5-4: Take the difference between the defect area Error3 and the Line5 to obtain the detection result Result of the surface defect of the electrical connector housing.

8. The detection method according to claim 7, characterized in that: Step 5 also includes the following steps: Step 5-5: Print the detection result Result into the original image and output the number of defects ErrorNumber and the total area ErrorArea.

9. A detection device for implementing the detection method according to any one of claims 1 to 8, characterized in that: Including: An original image acquisition module for acquiring the original image Image1 containing the background and the electrical connector; An electrical connector region of interest image generation module for extracting the actual ROI region RoiRegion of the electrical connector in the original image Image1 and generating the image RoiImage from the region covered by the region RoiRegion in the original image Image1; A total interference area extraction module for extracting the total interference area Interfere in the image RoiImage. The total interference area Interfere is composed of the letter and number type interference area OCR, the symbol type interference area Mark, the cap-shaped interference area Circularity, and the stripe-shaped interference area Rectlen on the surface of the electrical connector housing. The letter and number type interference area OCR is obtained by performing optical character recognition detection on the image RoiImage. The symbol type interference area Mark is obtained by performing shape-based template matching on the image RoiImage. The cap-shaped interference area Circularity and the stripe-shaped interference area Rectlen are obtained by performing threshold segmentation on the image RoiImage and then screening using shape dimensions; A scratch and block defect area extraction module for processing the image RoiImage using threshold segmentation and line segment detection to obtain the total defect area 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 differentiate the total defect area Error1 from 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 scratches in the defect area Error3, and obtain the detection result Result of the surface defect of the electrical connector shell.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the detection method according to any one of claims 1 to 8.

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

  • Method for detecting defects of screen printing area of smart phone glass cover plate based on machine vision

    CN110672617A

  • Stator surface defect detection system and method based on machine vision

    CN110766684A

  • Defect detection method, device and equipment and storage medium

    CN112489002A