A connector feeding error prevention detection method based on Halcon
Through the image processing and multi-template iterative matching method of Halcon software, the problem of low efficiency of manual inspection in automated connector assembly is solved, and efficient automated error-proofing detection is achieved.
Patent Information
- Application Number
- CN202211489634.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-25
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2042-11-25
AI Technical Summary
The connector outer surfaces are similar in shape and small in size, resulting in low manual inspection efficiency and prone to errors. Automatic loading using a vibration plate is not possible, making automated assembly difficult.
Halcon software is used for image processing, creating multiple templates and iterative matching. Grayscale processing and image enhancement are used to identify the coordinate values of the connector, distinguish abnormal materials, and use multiple templates for iterative matching to quickly detect abnormal materials and provide row and column information.
It improves the detection rate of small-sized and large-quantity materials, quickly identifies abnormal materials and gives their location on the pallet, reduces the quality requirements of the collected images, and realizes automated error-proofing detection.
Smart Images

Figure CN115861211B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of automated machine vision detection, and in particular to a Halcon-based connector feeding error-proofing detection method. Background Art
[0002] Connectors have high requirements for their outer surface, preventing friction with objects, making automated loading impossible using a vibrating tray. Furthermore, the two end faces are highly similar in shape (four-petal and six-petal), and the assembly process requires facing forward and backward (four-petal facing downward, six-petal facing upward). To accommodate automated assembly, workers must remove the materials from their packaging, visually inspect them, and place them neatly on a tray before feeding them into the automated assembly line. Due to the small size of connectors and the large number of connectors placed, manual inspection is inefficient and prone to errors when relying on visual inspection for extended periods. Therefore, a Halcon-based connector loading error detection method was proposed.
[0003] In view of the above-mentioned defects, the inventors of the present invention finally obtained the present invention after a long period of research and practice. Summary of the Invention
[0004] In order to solve the above technical defects, the purpose of the present invention is to provide a connector feeding error prevention detection method based on Halcon.
[0005] A Halcon-based connector loading error prevention detection method includes the following steps:
[0006] S1: Image Processing
[0007] Use Halcon software to read the collected images and perform grayscale processing;
[0008] S2: Create a template
[0009] Create a first template, a second template, and a third template in sequence according to the grayscale processed image;
[0010] S3: Calculate the coordinate values of all materials
[0011] Collect the image again and use it as the test image, perform image enhancement and grayscale processing on the test image;
[0012] Matching the processed test image with the third template to obtain the coordinate values of all materials;
[0013] S4: Complete material matching
[0014] Matching the test image processed in step S3 with the first template to obtain coordinate values of the matching material;
[0015] Segment the matching materials, segment the unmatched area images, and match the unmatched area images with the first template again until all materials are matched;
[0016] S5: Identify abnormal materials
[0017] Match the materials matched in step S4 with the second template in sequence, and distinguish abnormal materials based on the matching results;
[0018] S6: Find the coordinates of the abnormal material and the row information
[0019] Match the abnormal material with the third template to obtain the coordinate value of the abnormal material;
[0020] The coordinate values of the abnormal material are matched with the coordinate values of all materials in step S3 to obtain the row and column information of the abnormal material on the pallet.
[0021] Furthermore, the step S1 includes the following steps:
[0022] S11: Use the read_image operator to read the collected image and use it as the template image;
[0023] S12: Use the rgb1_to_gray operator to perform grayscale processing on the template image image to obtain a grayscale image GrayImage.
[0024] Furthermore, step S2 includes the following steps:
[0025] S21: Creating a first template, where the first template is an annular region image formed by six petals;
[0026] S22: creating a second template, where the second template is a rectangular area image formed by one petal;
[0027] S23: Create a third template, where the third template is a regional image formed by one petal and the middle circle.
[0028] Furthermore, the step S21 includes the following steps:
[0029] S211: Region Segmentation
[0030] Use the operator gen_circle to create a circle Circle000 on the grayscale processed image GrayImage; the center coordinates and radius of Circle000 are both set values;
[0031] Use the boundary operator to extract the edge from the circle Circle000 and obtain a boundary region RegionBorder;
[0032] Use the circular structure dilation operator dilation_circle to dilate RegionBorder inward to obtain the regional image RegionDilation000;
[0033] Use the operator reduce_domain to separate RegionDilation000 from the grayscale image GrayImage to obtain the circular region image ImageReduced000;
[0034] S212: Create the first template
[0035] Use the operator create_shape_model to create the first template ModelID on the annular region image ImageReduced000;
[0036] Use the operator get_shape_model_contours to obtain the contour ModelContours of the first template ModelID.
[0037] Furthermore, step S22 includes the following steps:
[0038] S221: Region Segmentation
[0039] Use the operator gen_rectangle1 to create a rectangular area Rectangle100; the horizontal and vertical coordinate values of the starting point and the diagonal point of the rectangular area Rectangle100 are both set values;
[0040] Use the operator reduce_domain to separate the rectangular region Rectangle100 from the grayscale image GrayImage to obtain the rectangular region image ImageReduced100;
[0041] S222: Create the second template
[0042] The operator create_shape_model is used to create the second template ModelID1 on the rectangular area image ImageReduced100.
[0043] Furthermore, the step S23 includes the following steps:
[0044] S231: Region Segmentation
[0045] Use the operator gen_circle to create a circle Circle200, where the center coordinates and radius of Circle200 are both set values;
[0046] Use the operator gen_rectangle1 to create a rectangular area Rectangle200. The horizontal and vertical coordinates of the starting point and the diagonal point of the rectangular area Rectangle200 are both set values.
[0047] Use the operator reduce_domain to separate the circle Circle200 from the grayscale image GrayImage to obtain the circular region image ImageReduced200;
[0048] Use the operator reduce_domain to separate the rectangle Rectangle200 from the grayscale image GrayImage to obtain the rectangular region image ImageReduced201;
[0049] Use the union2 operator to merge the circular region image ImageReduced200 and the rectangular region image ImageReduced201 to obtain the merged region image RegionUnion;
[0050] Use the reduce_domain operator to separate RegionUnion from the grayscale image GrayImage to obtain the regional image ImageReduced202;
[0051] S232: Create the third template
[0052] The operator create_shape_model is used to create a third template ModelID2 on the region image ImageReduced202.
[0053] Furthermore, step S3 includes the following steps:
[0054] S31: Processing test images
[0055] Read the image: Use the operator read_image to read the test image Image1;
[0056] Image enhancement: Use the emphasize operator to enhance the contrast of the test image Image1 to obtain the enhanced image ImageEmphasize1;
[0057] Grayscale processing: Use the operator rgb1_to_gray to perform grayscale processing on the enhanced image ImageEmphasize1 to obtain the grayscale image GrayImage2;
[0058] S32: Match the grayscale processed test image with the third template to obtain the coordinate values of all materials
[0059] Use the find_shape_model operator to match the grayscale image GrayImage2 with the third template ModelID2 to obtain the coordinate value arrays RowMatch200 and ColumnMatch200 of the matching material;
[0060] Use the operator tuple_gen_const to create a tuple Length1 with a length of |RowMatch200| and an element of the set value;
[0061] Use the gen_circle operator to create a circular area Circle201 with the horizontal coordinate of the circle center as RowMatch200, the vertical coordinate as ColumnMatch200, and the radius as Length1. The circular area Circle201 returns all matched materials.
[0062] Furthermore, step S4 includes the following steps:
[0063] S41: Match the processed test image with the first template to obtain the coordinate value of the matching material
[0064] Use the find_shape_model operator to match the grayscale image GrayImage2 with the first template ModelID to obtain the coordinate values of the matching material in the RowMatch000 and ColumnMatch000 arrays.
[0065] Use the operator gen_circle to create a circle Circle001 with the coordinates of RowMatch000, ColumnMatch000 as the center and the radius as the set value;
[0066] Use the boundary operator to expand the circle Circle001 inward to obtain the region image RegionBorder001;
[0067] Use the operator dilation_circle to dilate the region image RegionBorder001 inward to obtain the dilated circular region image RegionDilation001, where the dilation distance is the set value;
[0068] Use the union1 operator to merge all the annular regions RegionDilation001 into an independent region and save it as the annular region RegionUnion000;
[0069] Use the operator reduce_domain to separate the merged circular region RegionUnion000 from the grayscale image GrayImage2 to obtain the circular region image ImageReduced001, and the circular region image ImageReduced001 is used as feedback of the first template matching result;
[0070] S42: Segmentation of unmatched area images
[0071] Use the operator gen_circle to create a circular area Circle002 with the coordinates of RowMatch000 and ColumnMatch000 as the center and the radius as the set value;
[0072] Use the union1 operator to merge all the circle regions Circle002 into an independent region and save it as the ring region RegionUnion001;
[0073] Use the operator reduce_domain to separate the merged annular region RegionUnion001 from the grayscale image GrayImage2 to obtain the annular region image ImageReduced002;
[0074] Use the operator gen_rectangle1 to create a rectangular area Rectangle001. The horizontal and vertical coordinate values of the starting point and the diagonal point of the rectangular area Rectangle001 are both set values.
[0075] Use the operator reduce_domain to separate the rectangular area Rectangle001 from the grayscale image GrayImage2 to obtain the rectangular area image ImageReduced003;
[0076] Use the operator difference to calculate the difference between the rectangular region image ImageReduced003 and the circular region image ImageReduced002 to obtain the unmatched region RegionDifference;
[0077] Use the operator reduce_domain to separate the unmatched region RegionDifference from the grayscale image GrayImage2 to obtain the unmatched region image ImageReduced004;
[0078] S43: Matching the unmatched region image with the first template again
[0079] Use the operator find_shape_model to continue matching the unmatched area image ImageReduced004 with the first template ModelID, adjust the size of the matching parameters, segment the matched image each time, further adjust the size of the matching parameters, and continue matching the unmatched area images until all materials are matched.
[0080] Furthermore, step S5 includes the following steps:
[0081] S51: Match the materials matched by the first template with the second template
[0082] Use the operator gen_circle to create a circular area Circle100 with RowMatch000[i], ColumnMatch000[i] as the center and a radius of the set value, where i is the number of elements in the array from 0 to RowMatch000;
[0083] Use the boundary operator to extract the edge from the inside of Circle100 and obtain a boundary region RegionBorder100;
[0084] Use the circular structure dilation operator dilation_circle to dilate the boundary region RegionBorder100 inward to obtain the regional image RegionDilation100; where the dilation distance is a set value;
[0085] Use the operator reduce_domain to separate the region image RegionDilation100 from the grayscale image GrayImage2 to obtain the circular region image ImageReduced103;
[0086] Use the find_shape_model operator to match the annular region image ImageReduced103 with the second template ModelID1 to obtain the coordinate value arrays RowMatch101 and ColumnMatch101 and the inclination angle AngleMatch101 of the matching material;
[0087] Use the operator gen_rectangle2 to create a rectangular area Rectangle101 with RowMatch101 and ColumnMatch101 as the center, the length and width are the set values, and the inclination angle is AngleMatch101. The matching result between the circular area image ImageReduced103 and the second template ModelID1 is fed back through the rectangular area Rectangle101;
[0088] S52: Distinguish abnormal materials based on matching results
[0089] A threshold n is set according to the number of rectangles of normal materials and abnormal materials, and the number of matching result rectangles is compared with the threshold n. If the number is less than the threshold n, it is an abnormal material, and if it is greater than the threshold n, it is a normal material.
[0090] Furthermore, step S6 includes the following steps:
[0091] S61: Match the abnormal material with the third template and calculate the coordinate value of the abnormal material
[0092] Use the operator gen_circle to create a circular area Circle101 with RowMatch000[i], ColumnMatch000[i] as the center and the radius as the set value;
[0093] Use the operator reduce_domain to separate the circular region Circle101 from the grayscale image GrayImage2 to obtain the grayscale image ImageReduced104;
[0094] The grayscale image ImageReduced104 is cropped using the operator crop_domain to obtain the grayscale image ImagePart101;
[0095] Use the find_shape_model operator to match the grayscale image ImageReduced104 with the third template ModelID2 to obtain the coordinate value arrays RowMatch202 and ColumnMatch202 of the abnormal material;
[0096] S62: Match the coordinate values of the abnormal material with the coordinate values of all materials in step S32 to obtain the row and column information of the abnormal material. Sort the array RowMatch200 from small to large and divide it into groups of x, totaling y groups, i.e., y rows.
[0097] Sort the array ColumnMatch200 from small to large and divide it into x groups of y items, which are x columns.
[0098] Then, the abnormal material coordinate matching values RowMatch202 and ColumnMatch202 are searched and matched in the RowMatch200 and ColumnMatch200 arrays respectively to obtain the row and column information of the abnormal material on the pallet.
[0099] Compared with the prior art, the beneficial effects of the present invention are:
[0100] 1. For the detection of large quantities and small sizes of materials, the iterative detection using multiple image enhancement parameters appropriately reduces the requirements for the quality of the acquired images and improves the detection rate of the materials;
[0101] 2. Using multiple templates for iterative matching can quickly detect abnormal materials and provide the row and column information of the pallet where the abnormal materials are located, making it easy to find them quickly. BRIEF DESCRIPTION OF THE DRAWINGS
[0102] Figure 1 This is a flow chart of connector loading error prevention detection in the present invention;
[0103] Figure 2 It is a figure showing the shapes of two end faces of a single connector in the present invention;
[0104] Figure 3 These are three template diagrams created in the connector detection process of the present invention;
[0105] Figure 4 The present invention contains multiple connector test diagrams;
[0106] Figure 5 The present invention is a test diagram containing multiple connectors using a third template matching result feedback diagram;
[0107] Figure 6 It is a graph of all circular areas matched by the first template in the present invention containing multiple connector test patterns;
[0108] Figure 7 It is a feedback diagram of the matching result of the two end faces of a single connector using the second template in the present invention;
[0109] Figure 8 This is the final output result diagram of the test diagram containing multiple connectors in the present invention. DETAILED DESCRIPTION
[0110] The above and other technical features and advantages of the present invention are described in more detail below with reference to the accompanying drawings.
[0111] In this embodiment, if Figure 1 As shown, Figure 1 A flow chart for connector loading error detection; a Halcon-based connector loading error detection method, comprising the following steps:
[0112] S1: Image Processing
[0113] Use Halcon software to read the collected images and perform grayscale processing;
[0114] S2: Create a template
[0115] Create a first template, a second template, and a third template in sequence according to the grayscale processed image;
[0116] S3: Calculate the coordinate values of all materials
[0117] Capture the image again and use it as a test image, and process the test image;
[0118] Matching the processed test image with the third template to obtain the coordinate values of all materials;
[0119] S4: Complete material matching
[0120] Matching the processed test image with the first template to obtain coordinate values of the matching material;
[0121] Segment the matching materials, segment the unmatched area images, and match the unmatched area images with the first template again until all materials are matched;
[0122] S5: Identify abnormal materials
[0123] Match the materials matched in step S3 with the second template in sequence, and distinguish abnormal materials based on the matching results;
[0124] S6: Calculate the coordinates of abnormal materials and obtain row and column information
[0125] Match the abnormal material with the third template to obtain the coordinate value of the abnormal material;
[0126] The coordinate values of the abnormal material are matched with the coordinate values of all materials in step S3 to obtain the row and column information of the abnormal material on the pallet.
[0127] In the step S1, it includes the following steps:
[0128] S11: Use the read_image operator to read the collected image and use it as the template image;
[0129] S12: Use the rgb1_to_gray operator to perform grayscale processing on the template image to obtain a grayscale image GrayImage.
[0130] In the step S2, it includes the following steps:
[0131] S21: Create a first template, which is an annular region image formed by 6 petals
[0132] Region segmentation:
[0133] Use the operator gen_circle(Circle000,1484.5,2891.5,30) to create a circle Circle000 with (1484.5,2891.5) as the center and a radius of 30 on the grayscale processed image GrayImage;
[0134] Use the operator boundary(Circle000,RegionBorder,'inner') to extract the edge from the inside of Circle000 and obtain a boundary region RegionBorder, where 'inner' is the inner boundary;
[0135] Use the operator dilation_circle(RegionBorder,RegionDilation000,6) to expand RegionBorder inward by 6 to obtain the regional image RegionDilation000, where 6 is the size of the expanded structure element;
[0136] Use the operator reduce_domain(GrayImage,RegionDilation000,ImageReduced000) to separate the region image RegionDilation000 from the grayscale image GrayImage to obtain the ring region image ImageReduced000;
[0137] Create the first template:
[0138] Use the operator create_shape_model(ImageReduced000,4,0.4,6.29,'auto','none','use_polarity',30,10,ModelID) to create the first template ModelID on the annular area image ImageReduced000; where 4 is the number of pyramid layers, 0.4 is the starting angle of template rotation, 6.29 is the template rotation angle range, 'auto' is the rotation angle step size, 'none' is used to set the template optimization and template creation method, and 'use_polarity' is used to set the matching method; 30 is used to set the contrast, and 10 is used to set the minimum contrast;
[0139] Use the operator get_shape_model_contours(ModelContours,ModelID,4) to obtain the contour of the first template ModelID, where ModelContours is the obtained contour XLD and 4 is the number of corresponding pyramid levels.
[0140] S22: creating a second template, where the second template is a rectangular area image formed by one petal;
[0141] Region segmentation:
[0142] Use the operator gen_rectangle1(Rectangle100,904,2885,920,2912) to create the rectangular area Rectangle100; where 904 is the row coordinate value of the rectangle starting point, 2885 is the column coordinate value of the rectangle starting point, 920 is the row coordinate value of the diagonal point of the rectangle starting point, and 2912 is the column coordinate value of the diagonal point of the rectangle starting point;
[0143] Use the operator reduce_domain(GrayImage,Rectangle100,ImageReduced100) to separate the rectangular region Rectangle100 from the grayscale image GrayImage to obtain the rectangular region image ImageReduced100;
[0144] Create the second template:
[0145] Use the operator create_shape_model(ImageReduced100,4,0.4,6.29,'auto','none','use_polarity',30,10,ModelID1) to create the second template ModelID1 on the rectangular area image ImageReduced100.
[0146] S23: Create a third template, where the third template is a regional image formed by one petal and the middle circle.
[0147] Region segmentation:
[0148] Use the operator gen_circle(Circle200,1484.5,2891.5,25) to create a circle Circle200 with (1484.5,2891.5) as the center and a radius of 25;
[0149] Use the operator gen_rectangle1(Rectangle200,1449,2873,1458,2902) to create rectangle Rectangle200;
[0150] Use the operator reduce_domain(GrayImage,Circle200,ImageReduced200) to separate the circle Circle200 from the grayscale image GrayImage to obtain the circular region image ImageReduced200;
[0151] Use the operator reduce_domain(GrayImage,Rectangle200,ImageReduced201) to separate the rectangle Rectangle200 from GrayImage to obtain the rectangular region image ImageReduced201;
[0152] Use the operator union2(ImageReduced200,ImageReduced201,RegionUnion) to merge the circular region image ImageReduced200 and the rectangular region image ImageReduced201 to obtain the merged region image RegionUnion;
[0153] Use the operator reduce_domain(GrayImage,RegionUnion,ImageReduced202) to separate RegionUnion from GrayImage to obtain the regional image ImageReduced202;
[0154] Create the third template:
[0155] Use the operator create_shape_model(ImageReduced202,4,0.4,6.29,'auto','none','use_polarity',30,10,ModelID2) to create the third template ModelID2 on the region image ImageReduced202.
[0156] In the step S3, it includes the following steps:
[0157] S31: Processing test images
[0158] Read the image: Use the operator read_image to read the test image Image1;
[0159] Image enhancement: Use the operator emphasize(Image1,ImageEmphasize1,22,22,i) to enhance the test image Image1 to obtain the enhanced image ImageEmphasize1; where 22 and 22 are the width and height of the low-pass mask respectively, and the enhancement parameter i is 2, 2.5, and 3 respectively;
[0160] Grayscale processing: Use the operator rgb1_to_gray(ImageEmphasize1, GrayImage2) to perform grayscale processing on the enhanced test image ImageEmphasize1 to obtain the grayscale image GrayImage2;
[0161] S32: Match the processed test image with the third template to obtain the coordinate values of all materials
[0162] Use the operator find_shape_model(GrayImage2,ModelID2,0.4,rad(360),0.4,0,0,'least_squares',5,1,RowMatch200,ColumnMatch200,AngleMatch200,Score200) to match the grayscale image GrayImage2 with the third template ModelID2, and obtain the coordinate values RowMatch200, ColumnMatch200 arrays of all materials; among them, 0.4 is the search starting angle; rad(360) is the end angle during the search, 0.4 is the minimum score of the template found, that is, it must be greater than or equal to this value to be matched; 0 is the maximum number of template instances to be found; 0 is the maximum overlap of template instances to be found; least_squares is the setting of calculation accuracy, 5 is the number of layers of the pyramid during the search, RowMatch200, ColumnMatch200, AngleMatch200, Score200 are the row and column coordinates, angles, and scores of the output matching positions respectively;
[0163] Use the operator tuple_gen_const(|RowMatch200|,20,Length1) to create a new tuple Length1 with a length of |RowMatch200| and 20 elements; where |RowMatch200| is the length of the specific tuple to be generated, 20 is the constant for initializing the tuple elements, and Length1 is the new tuple;
[0164] Use the operator gen_circle(Circle201,RowMatch200,ColumnMatch200,Length1) to create a circular area Circle201 with the horizontal coordinate of the circle center as RowMatch200, the vertical coordinate as ColumnMatch200, and the radius as Length1. The circular area Circle201 returns all the matched materials.
[0165] In the step S4, it includes the following steps:
[0166] S41: Match the processed test image with the first template to obtain the coordinate value of the matching material
[0167] Use the operator find_shape_model(GrayImage2,ModelID,0.4,rad(360),0.35,0,0,'least_squares',5,1,RowMatch000,ColumnMatch000,AngleMatch000,Score000) to match the grayscale image GrayImage2 with the first template ModelID and obtain the coordinate values of the matching material in the RowMatch000 and ColumnMatch000 arrays.
[0168] Use the operator gen_circle(Circle001,RowMatch000,ColumnMatch000,32.7) to draw a circle Circle001 with a radius of 32.7 and the coordinates of RowMatch000 and ColumnMatch000 as the center;
[0169] Use the operator boundary(Circle001,RegionBorder001,'inner') to expand the circle Circle001 inward to obtain the region image RegionBorder001; where 'inner' is the boundary area; use the operator dilation_circle(RegionBorder001,RegionDilation001,4.5) to expand the region image RegionBorder001 inward by 4.5 to obtain the expanded circular region image RegionDilation001, where 4.5 is the dilation distance;
[0170] Use the operator union1(RegionDilation001,RegionUnion000) to merge all the annular regions RegionDilation001 into an independent region and save it as the annular region RegionUnion000;
[0171] Use the operator reduce_domain(GrayImage2,RegionUnion000,ImageReduced001) to separate the annular region RegionUnion000 from the grayscale image GrayImage2 to obtain the annular region image ImageReduced001, and the annular region image ImageReduced001 is used as the feedback of the first template matching result;
[0172] S42: Segmentation of unmatched area images
[0173] Use the operator gen_circle(Circle002,RowMatch000,ColumnMatch000,48) to create a circle area with RowMatch000, ColumnMatch000 as the center and a radius of 48;
[0174] Use the operator union1(Circle002,RegionUnion001) to merge all the circular regions Circle002 into an independent region and save it as the circular region RegionUnion001;
[0175] Use the operator reduce_domain(GrayImage2,RegionUnion001,ImageReduced002) to separate the merged circular region RegionUnion001 from the grayscale image GrayImage2 to obtain the circular region image ImageReduced002;
[0176] Use the operator gen_rectangle1(Rectangle001,0,0,3644,5633) to draw the rectangular area Rectangle001;
[0177] Use the operator reduce_domain(GrayImage2,Rectangle001,ImageReduced003) to separate the rectangular area Rectangle001 from the grayscale image GrayImage2 to obtain the rectangular area image ImageReduced003;
[0178] Use the operator difference(ImageReduced003,ImageReduced002,RegionDifference) to calculate the difference between the rectangular region image ImageReduced003 and the circular region image ImageReduced002 to obtain the unmatched region RegionDifference;
[0179] Use the operator reduce_domain(GrayImage2,RegionDifference,ImageReduced004) to separate the unmatched region RegionDifference from the grayscale image GrayImage2 to obtain the unmatched region image ImageReduced004;
[0180] S43: Matching the unmatched region image with the first template again
[0181] Use the operator find_shape_model e_model to continue matching the unmatched area image ImageReduced004 with the first template ModelID. Taking the parameters of the grayscale image GrayImage2 matching the first template ModelID as the benchmark, adjust the minimum matching value MinScore in the operator and set MinScore to a smaller value. Each time the matched image is segmented, the MinScore is then set to a smaller value to continue matching the remaining unmatched area images until all materials are matched.
[0182] The specific implementation parameter minimum matching value MinScore is set to 0.3 and 0.25.
[0183] In the step S5, it includes the following steps:
[0184] S51: Match the materials matched by the first template with the second template
[0185] Use the operator gen_circle(Circle100,RowMatch000[i],ColumnMatch000[i],32.7) to draw a circle area, where i is the number of elements in the array from 0 to RowMatch000;
[0186] Use the operator boundary(Circle100,RegionBorder100,'inner') to extract the edge from the inside of Circle100 and obtain a boundary region RegionBorder100;
[0187] Use the circular structure dilation operator dilation_circle(RegionBorder100,RegionDilation100,4.5) to dilate the boundary region RegionBorder100 inward by 4.5 to obtain the regional image RegionDilation100, where 4.5 is the dilation distance;
[0188] Use the operator reduce_domain(GrayImage2,RegionDilation100,ImageReduced103) to separate the region image RegionDilation100 from the grayscale image GrayImage2 to obtain the ring region image ImageReduced103;
[0189] Use the operator find_shape_model(ImageReduced103,ModelID1,0.1,rad(360),0.09,0,0,'least_squares',5,1,RowMatch101,ColumnMatch101,AngleMatch101,Score101) to match the annular area image ImageReduced103 with the second template ModelID1, and obtain the coordinate value arrays RowMatch101, ColumnMatch101 and the tilt angle AngleMatch101 of the matching material;
[0190] Use the operator gen_rectangle2(Rectangle101,RowMatch101,ColumnMatch101,AngleMatch101,6,6) to create a rectangular area Rectangle101 with RowMatch101 and ColumnMatch101 as the center, a length and width of 6, and an inclination angle of AngleMatch101. The matching result between the circular area image ImageReduced103 and the second template ModelID1 is fed back through the rectangular area Rectangle101.
[0191] S52: Distinguish abnormal materials based on matching results
[0192] The number of petals of the two connectors is 4 and 6 respectively. The threshold n is set to 5. The number of petals (the number of matching result rectangles) is compared with 5. If the number is less than 5, it is a connector with 4 petals on the end face, that is, an abnormal material. Otherwise, it is a normal material. If it is an abnormal material, its coordinates are further determined.
[0193] In the step S6, it includes the following steps:
[0194] S61: Match the abnormal material with the third template and calculate the coordinate value of the abnormal material
[0195] Use the operator gen_circle(Circle101,RowMatch000[i],ColumnMatch000[i],35)
[0196] Create a circular area Circle101 with RowMatch000[i], ColumnMatch000[i] as the center and a radius of 35;
[0197] Use the operator reduce_domain(GrayImage2,Circle101,ImageReduced104) to separate the circular area Circle101 from the grayscale image GrayImage2 to obtain the grayscale image ImageReduced104;
[0198] Use the operator crop_domain(ImageReduced104,ImagePart101) to crop the grayscale image ImageReduced104 to obtain the grayscale image ImagePart101;
[0199] Use operator find_shape_model(ImageReduced104,ModelID2,0.1,rad(360),0.4,0,0,'least_squares',5,1,RowMatch202,ColumnMatch202,AngleMatch202,Score202)
[0200] Match the grayscale image ImageReduced104 with the third template ModelID2 to obtain the coordinate value arrays RowMatch202 and ColumnMatch202 of the abnormal material;
[0201] S62: Match the abnormal material coordinate value with all material coordinate values in step S32 to obtain the row and column information of the abnormal material
[0202] Sort the array RowMatch200 from smallest to largest and divide it into 16 groups of 18, which is 16 rows.
[0203] Sort the array ColumnMatch200 from small to large and divide it into 18 groups of 16, that is, 18 columns;
[0204] Then, the coordinate matching values (RowMatch202, ColumnMatch202) of the abnormal material are searched and matched in the RowMatch200, ColumnMatch200 arrays respectively to obtain the row and column information of the abnormal material on the pallet.
[0205] Preferably, three enhancement parameters (enhancement parameters i are 2, 2.5 and 3 respectively) are used to enhance the test image in step S31. Each enhancement parameter brings different detection results. Finally, the detection results of the three different enhancement parameters are spliced together as the final detection result, thereby improving the reliability of the detection results and correctly identifying and distinguishing materials.
[0206] like Figure 2 As shown, Figure 2 This is a diagram of the two end faces of a single connector. One end face has 4 lobes and the other end face has 6 lobes. The 4-lobed lobe and the 6-lobed lobe have the same shape but different sizes. The middle part of the two end faces has the same features.
[0207] like Figure 3 As shown, Figure 3 These are three template images created during the connector inspection process. The first template is an image of the circular area containing the six petals, the second template is an image of the rectangular area containing one of the six petals, and the third template is an image of one of the six petals and the central circular area. The first template serves as the key feature area for distinguishing whether a material is abnormal. The second template can match the values of the petals in the annular area around the outer ring of the material. The third template can match all materials on the pallet at once while filtering out the mounting holes on the material pallet 5. This facilitates the establishment of location information for all material inspections and facilitates the identification of row and column information for abnormal material inspections.
[0208] like Figure 4 As shown, Figure 4 It is a test image containing multiple connectors. The test image contains 288 connectors in 16 rows and 18 columns.
[0209] like Figure 5 As shown, Figure 5 This is a test diagram containing multiple connectors and using the third template matching result feedback diagram. By drawing a circular area as the feedback of the matching result, the results show that all 288 connectors are matched.
[0210] like Figure 6 As shown, Figure 6 This is a collection of all circular areas in a test diagram containing multiple connectors matched using the first template. There are 282 circular areas in total, indicating that 282 connectors were matched after the first template matching, and the remaining 6 unmatched connectors were matched a second time using different matching parameters.
[0211] like Figure 7 As shown, Figure 7 This is a feedback diagram of the matching results of the two end faces of a single connector using the second template. Rectangles are drawn as feedback of the matching results. When the end face has 6 petals, there are 6 rectangles, and when the end face has 4 petals, there are 4 rectangles.
[0212] like Figure 8 As shown, Figure 8 It is the final output result diagram containing multiple connector test diagrams. The test results of three different enhanced parameters are spliced together as the final test result, and the row and column information of abnormal materials and the pallet where the abnormal materials are located is output.
[0213] The above description is merely a preferred embodiment of the present invention and is intended to be illustrative rather than restrictive of the present invention. Those skilled in the art will appreciate that many changes, modifications, and even equivalents may be made to the present invention within the spirit and scope of the claims, all of which fall within the scope of protection of the present invention.
Claims
1. A connector feeding error prevention detection method based on Halcon, characterized in that: The following steps are involved: S1: Image Processing Use Halcon software to read the collected images and perform grayscale processing; S2: Create a template Create a first template, a second template, and a third template in sequence according to the grayscale processed image; S3: Calculate the coordinate values of all materials Collect the image again and use it as the test image, perform image enhancement and grayscale processing on the test image; Matching the processed test image with the third template to obtain the coordinate values of all materials; S4: Complete material matching Matching the test image processed in step S3 with the first template to obtain coordinate values of the matching material; Segment the matching materials, segment the unmatched area images, and match the unmatched area images with the first template again until all materials are matched; S5: Identify abnormal materials Match the materials matched in step S4 with the second template in sequence, and distinguish abnormal materials based on the matching results; S6: Find the coordinates of the abnormal material and the row information Match the abnormal material with the third template to obtain the coordinate value of the abnormal material; The coordinate values of the abnormal material are matched with the coordinate values of all materials in step S3 to obtain the row and column information of the abnormal material on the pallet.
2. The connector feeding error prevention detection method based on Halcon according to claim 1, characterized in that: The step S1 comprises the following steps: S11: Use the read_image operator to read the collected image and use it as the template image; S12: Use the rgb1_to_gray operator to perform grayscale processing on the template image image to obtain a grayscale image GrayImage.
3. The Halcon-based connector loading error detection method according to claim 2, characterized in that: The step S2 comprises the following steps: S21: Creating a first template, where the first template is an annular region image formed by six petals; S22: creating a second template, where the second template is a rectangular area image formed by one petal; S23: Create a third template, where the third template is a regional image formed by one petal and the middle circle.
4. The Halcon-based connector loading error detection method according to claim 3, characterized in that: The step S21 includes the following steps: S211: Region Segmentation Use the operator gen_circle to create a circle Circle000 on the grayscale processed image GrayImage, where the center coordinates and radius of Circle000 are both set values; Use the boundary operator to extract the edge from the circle Circle000 and obtain a boundary region RegionBorder; Use the circular structure dilation operator dilation_circle to dilate RegionBorder inward to obtain the regional image RegionDilation000; Use the operator reduce_domain to separate RegionDilation000 from the grayscale image GrayImage to obtain the circular region image ImageReduced000; S212: Create the first template Use the operator create_shape_model to create the first template ModelID on the annular region image ImageReduced000; Use the operator get_shape_model_contours to obtain the contour ModelContours of the first template ModelID.
5. The Halcon-based connector loading error detection method according to claim 4, characterized in that: The step S22 includes the following steps: S221: Region Segmentation Use the operator gen_rectangle1 to create a rectangular area Rectangle100, where the horizontal and vertical coordinate values of the starting point and the diagonal point of the rectangular area Rectangle100 are both set values; Use the operator reduce_domain to separate the rectangular region Rectangle100 from the grayscale image GrayImage to obtain the rectangular region image ImageReduced100; S222: Create the second template The operator create_shape_model is used to create the second template ModelID1 on the rectangular area image ImageReduced100.
6. The Halcon-based connector loading error detection method according to claim 4, characterized in that: The step S23 includes the following steps: S231: Region Segmentation Use the operator gen_circle to create a circle Circle200, where the center coordinates and radius of Circle200 are both set values; Use the operator gen_rectangle1 to create a rectangular area Rectangle200. The horizontal and vertical coordinates of the starting point and the diagonal point of the rectangular area Rectangle200 are both set values. Use the operator reduce_domain to separate the circle Circle200 from the grayscale image GrayImage to obtain the circular region image ImageReduced200; The reduce_domain operator is used to separate the rectangle Rectangle200 from the grayscale image GrayImage to obtain the rectangular region image ImageReduced201; Use the union2 operator to merge the circular region image ImageReduced200 and the rectangular region image ImageReduced201 to obtain the merged region image RegionUnion; Use the reduce_domain operator to separate RegionUnion from the grayscale image GrayImage to obtain the regional image ImageReduced202; S232: Create the third template The operator create_shape_model is used to create a third template ModelID2 on the region image ImageReduced202.
7. The Halcon-based connector loading error detection method according to claim 1, characterized in that: The step S3 comprises the following steps: S31: Processing test images Read image: Use the operator read_image to read the test image Image1; Image enhancement: Use the emphasize operator to enhance the contrast of the test image Image1 to obtain the enhanced image ImageEmphasize1; Grayscale processing: Use the operator rgb1_to_gray to perform grayscale processing on the enhanced image ImageEmphasize1 to obtain the grayscale image GrayImage2; S32: Match the grayscale processed test image with the third template to obtain the coordinate values of all materials Use the find_shape_model operator to match the grayscale image GrayImage2 with the third template ModelID2 to obtain the coordinate value arrays RowMatch200 and ColumnMatch200 of the matching material; Use the operator tuple_gen_const to create a tuple Length1 with a length of |RowMatch200| and an element of the set value; Use the gen_circle operator to create a circular area Circle201 with the horizontal coordinate of the circle center as RowMatch200, the vertical coordinate as ColumnMatch200, and the radius as Length1. The circular area Circle201 returns all matched materials.
8. The Halcon-based connector loading error detection method according to claim 7, characterized in that: The step S4 comprises the following steps: S41: Match the processed test image with the first template to obtain the coordinate value of the matching material Use the find_shape_model operator to match the grayscale image GrayImage2 with the first template ModelID to obtain the coordinate values of the matching material in the RowMatch000 and ColumnMatch000 arrays. Use the operator gen_circle to create a circle Circle001 with the coordinates of RowMatch000, ColumnMatch000 as the center and the radius as the set value; Use the boundary operator to expand the circle Circle001 inward to obtain the region image RegionBorder001; Use the operator dilation_circle to expand the region image RegionBorder001 inward to obtain the expanded circular region image RegionDilation001; Use the union1 operator to merge all the annular regions RegionDilation001 into an independent region and save it as the annular region RegionUnion000; Use the operator reduce_domain to separate the merged circular region RegionUnion000 from the grayscale image GrayImage2 to obtain the circular region image ImageReduced001, and the circular region image ImageReduced001 is used as feedback of the first template matching result; S42: Segmentation of unmatched area images Use the operator gen_circle to create a circular area Circle002 with the coordinates of RowMatch000, ColumnMatch000 as the center and the radius as the set value; Use the union1 operator to merge all the circle regions Circle002 into an independent region and save it as the ring region RegionUnion001; Use the operator reduce_domain to separate the merged annular region RegionUnion001 from the grayscale image GrayImage2 to obtain the annular region image ImageReduced002; Use the operator gen_rectangle1 to create the rectangular area Rectangle001. The horizontal and vertical coordinates of the starting point and the diagonal point of the rectangular area Rectangle200 are both set values. Use the operator reduce_domain to separate the rectangular area Rectangle001 from the grayscale image GrayImage2 to obtain the rectangular area image ImageReduced003; Use the operator difference to calculate the difference between the rectangular region image ImageReduced003 and the circular region image ImageReduced002 to obtain the unmatched region RegionDifference; Use the operator reduce_domain to separate the unmatched region RegionDifference from the grayscale image GrayImage2 to obtain the unmatched region image ImageReduced004; S43: Matching the unmatched region image with the first template again Use the operator find_shape_model to continue matching the unmatched area image ImageReduced004 with the first template ModelID, adjust the size of the matching parameters, segment the matched image each time, further adjust the size of the matching parameters, and continue matching the unmatched area images until all materials are matched.
9. The Halcon-based connector loading error detection method according to claim 8, characterized in that: The step S5 comprises the following steps: S51: Match the materials matched by the first template with the second template Use the operator gen_circle to create a circular area Circle100 with RowMatch000[i], ColumnMatch000[i] as the center and a radius of the set value, where i is the number of elements in the array from 0 to RowMatch000; Use the boundary operator to extract the edge from the inside of Circle100 and obtain a boundary region RegionBorder100; Use the circular structure dilation operator dilation_circle to dilate the boundary region RegionBorder100 inward to obtain the regional image RegionDilation100, where the dilation distance is a set value; Use the operator reduce_domain to separate the region image RegionDilation100 from the grayscale image GrayImage2 to obtain the circular region image ImageReduced103; Use the find_shape_model operator to match the annular region image ImageReduced103 with the second template ModelID1 to obtain the coordinate value arrays RowMatch101 and ColumnMatch101 and the inclination angle AngleMatch101 of the matching material; Use the operator gen_rectangle2 to create a rectangular area Rectangle101 with RowMatch101 and ColumnMatch101 as the center, the length and width are the set values, and the inclination angle is AngleMatch101. The matching result between the circular area image ImageReduced103 and the second template ModelID1 is fed back through the rectangular area Rectangle101; S52: Distinguish abnormal materials based on matching results A threshold n is set according to the number of rectangles of normal materials and abnormal materials, and the number of matching result rectangles is compared with the threshold n. If the number is less than the threshold n, it is an abnormal material, and if it is greater than the threshold n, it is a normal material.
10. The connector feeding error prevention detection method based on Halcon according to claim 9, characterized in that: The step S6 comprises the following steps: S61: Match the abnormal material with the third template and calculate the coordinate value of the abnormal material Use the operator gen_circle to create a circular area Circle101 with RowMatch000[i], ColumnMatch000[i] as the center and the radius as the set value; Use the operator reduce_domain to separate the circular region Circle101 from the grayscale image GrayImage2 to obtain the grayscale image ImageReduced104; The grayscale image ImageReduced104 is cropped using the operator crop_domain to obtain the grayscale image ImagePart101; Use the find_shape_model operator to match the grayscale image ImageReduced104 with the third template ModelID2 to obtain the coordinate value arrays RowMatch202 and ColumnMatch202 of the abnormal material; S62: Match the coordinate values of the abnormal material with the coordinate values of all materials in step S32 to obtain the row and column information of the abnormal material. Sort the array RowMatch200 from small to large and divide it into groups of x, totaling y groups, i.e., y rows. Sort the array ColumnMatch200 from small to large and divide it into x groups of y items, which are x columns. Then, the abnormal material coordinate matching values RowMatch202 and ColumnMatch202 are searched and matched in the RowMatch200 and ColumnMatch200 arrays respectively to obtain the row and column information of the abnormal material on the pallet.
Citation Information
Patent Citations
Feeding anomaly detection method in industrial automatic detection scene
CN113762427A
Machine vision-based detecting method and system for glass bottle bottom defects
WO2022027949A1