PCB defect image generation method and device, computer equipment and storage medium
Through the automation steps, the target area and sub-region are filtered out, and defect images matching the defect type are generated at the defect location determined by the target sub-region, which solves the problem of low efficiency in PCB defect image generation in the prior art and realizes efficient automated generation.
Patent Information
- Application Number
- CN202411491122.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2025-02-25
AI Technical Summary
In the prior art, the efficiency of manually adjusting the PCB image is low in generation of PCB defective images using image processing software.
A PCB defect image generation method is provided, which automatically determines the defect type by responding to defect generation trigger events, acquires the target PCB image, filters out the target area and the sub-region, and generates a defect image matching the defect type at the defect location determined by the target sub-region.
The automated PCB defect image generation process is realized, which improves the generation efficiency without manual operation, and the generated defect image meets expectations.
Smart Images

Figure CN119516015A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a PCB defect image generation method, device, computer equipment and storage medium. Background Art
[0002] With the development of modern electronic information industry, printed circuit board (PCB) has become the core component of various electronic information products. In the manufacturing process of PCB, some defects will occur, such as poor welding, broken circuit, etc. These defects will lead to adverse effects. Therefore, PCB defect detection is particularly important. In recent years, neural networks are trained to identify defect images in PCB images to perform PCB defect detection. When training neural networks, since there are few real PCB defect images, PCB defect images need to be generated to increase training samples. In the prior art, PCB images are usually manually adjusted using image processing software to generate PCB defect images.
[0003] However, the method of manually adjusting the PCB image using image processing software to generate the PCB defect image has the problem of low efficiency in generating the PCB defect image. Summary of the invention
[0004] Based on this, it is necessary to provide a PCB defect image generation method, device, computer equipment, computer readable storage medium and computer program product to address the above technical problems, which can improve the efficiency of PCB defect image generation.
[0005] In a first aspect, the present application provides a method for generating a PCB defect image, comprising:
[0006] In response to a defect generation triggering event, determining a defect type indicated by the defect generation triggering event;
[0007] Acquire a target PCB image, and determine a plurality of candidate regions in the target PCB image for accommodating defect images; each candidate region includes sub-regions;
[0008] Filter out the target area from multiple candidate areas;
[0009] Filtering out a target sub-region from the sub-regions included in the target region;
[0010] In the target PCB image, at the defect position that matches the defect type determined based on the target sub-region, a defect image that matches the defect type is generated to obtain a PCB defect image.
[0011] In a second aspect, the present application provides a PCB defect image generating device, comprising:
[0012] a trigger module, configured to, in response to a defect generation trigger event, determine a defect type indicated by the defect generation trigger event;
[0013] A determination module is used to obtain a target PCB image and determine a plurality of candidate regions in the target PCB image for accommodating defect images; each candidate region includes a sub-region;
[0014] A screening module is used to screen out a target area from multiple candidate areas; and to screen out a target sub-area from sub-areas included in the target area;
[0015] The generation module is used to generate a defect image matching the defect type at a defect position matching the defect type determined based on the target sub-region in the target PCB image, so as to obtain a PCB defect image.
[0016] In a third aspect, the present application provides a computer device, the computer device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the steps in the above method when executing the computer program.
[0017] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the above method when executed by a processor.
[0018] In a fifth aspect, the present application provides a computer program product, which includes a computer program, and the computer program implements the steps in the above method when executed by a processor.
[0019] The above-mentioned PCB defect image generation method, device, computer equipment, computer-readable storage medium and computer program product can automatically start generating a PCB defect image in response to a defect generation trigger event, and sequentially filter out a target area from the target PCB image, and filter out a target sub-area from the sub-area included in the target area, and then, at a defect position that matches the defect type determined based on the target sub-area, generate a defect image that matches the defect type. In this way, after the defect generation trigger event is triggered, through a series of automated steps, a defect image that matches the defect type can be generated at a defect position that matches the defect type, and the obtained PCB defect image meets expectations and does not require manual operation, thereby improving the efficiency of PCB defect image generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] FIG1 is an application environment diagram of a PCB defect image generation method provided by an embodiment of the present application;
[0021] FIG2 is a schematic diagram of a flow chart of a method for generating a PCB defect image provided in an embodiment of the present application;
[0022] Figure 3 A schematic diagram of a PCB defect image generation framework provided in an embodiment of the present application;
[0023] Figure 4 A schematic diagram of a PCB defect image generation process provided in an embodiment of the present application;
[0024] Figure 5 An exemplary schematic diagram of a target area and a target sub-area provided in an embodiment of the present application;
[0025] Figure 6 A schematic diagram of a before-and-after comparison example of a defect image of a raised area type provided in an embodiment of the present application;
[0026] Figure 7 A schematic diagram of a before-and-after comparison example of generating a defect image of a local color anomaly type provided in an embodiment of the present application;
[0027] Figure 8 A schematic diagram of a before-and-after comparison example of generating a scratch-type defect image provided in an embodiment of the present application;
[0028] Fig. 9 A structural block diagram of a PCB defect image generating device provided in an embodiment of the present application;
[0029] FIG10 is an internal structure diagram of a computer device provided in an embodiment of the present application;
[0030] FIG11 is an internal structure diagram of another computer device provided in an embodiment of the present application;
[0031] Fig.12 An internal structure diagram of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] 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.
[0033] The PCB defect image generation method provided in the embodiment of the present application can be applied in the application environment as shown in Figure 1. Among them, the terminal 102 communicates with the server 104 through a communication network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. It can be understood that the PCB defect image generation method provided in the present application can also be independently applied to the terminal 102 or the server 104. Among them, the terminal 102 can be a personal computer, a laptop computer, a smart phone, a tablet computer, an Internet of Things device, and a portable wearable device. The server 104 can be implemented with an independent server or a server cluster consisting of multiple servers.
[0034] As shown in FIG2 , the embodiment of the present application provides a method for generating a PCB defect image, and the method is described by taking the method applied to the terminal 102 or the server 104 in FIG1 as an example. It can be understood that the computer device can include at least one of a terminal and a server. The method includes the following steps:
[0035] S202: In response to a defect generation triggering event, determine a defect type indicated by the defect generation triggering event.
[0036] Among them, the defect generation trigger event is an event that triggers the generation of a PCB defect image through a series of automatically executed steps. The defect generation trigger event can be an automatic trigger event, for example, when a timed task for generating a PCB defect image is created, the defect generation trigger event is automatically triggered when the timed time of the timed task is reached. The defect generation trigger event can also be a manual trigger operation.
[0037] The defect type is the type of defect image to be generated. The defect type may be an area encroachment type, a color anomaly type, a foreign matter type, etc. The defect type may also be a specific type included in the area encroachment type, the color anomaly type, the foreign matter type, etc. For example, the area encroachment type may include an area depression type, an area protrusion type, and others, the color anomaly type may include a global color anomaly type, a local color anomaly type, and others, and the foreign matter type may include a scratch type, a stain type, and others.
[0038] Exemplarily, the terminal or server may determine the defect generation configuration information indicated by the defect generation trigger event in response to the defect generation trigger event, and when the defect generation configuration information includes a specified defect type, the specified defect type is determined as the defect type indicated by the defect generation trigger event. The defect generation configuration information is the configuration information configured before the defect generation trigger event is triggered and is used to indicate the generation of a PCB defect image. The defect generation configuration information may include configuration information of multiple configuration items, and the configuration information in each configuration item may be information input by the user or default information. The defect type in the defect generation configuration information may be the configuration information of the defect type configuration item in the multiple configuration items.
[0039] In some embodiments, when the defect generation configuration information does not include a specified defect type, the terminal or the server may randomly select a preset defect type from a plurality of preset defect types to determine as the defect type indicated by the defect generation trigger event.
[0040] S204, acquiring a target PCB image, and determining a plurality of candidate regions in the target PCB image for accommodating defect images; each candidate region includes a sub-region.
[0041] Among them, PCB is a plate-like product formed by laminating structures such as conductors and electronic components together through printing technology, which is used to support and connect various electronic components. The target PCB image is a PCB image used to accommodate the defect image to be generated. The target PCB image can be a real PCB image or a historically generated PCB defect image. The real PCB image can be an image obtained by further image enhancement processing of the entire image obtained by taking a real PCB. The real PCB can be a qualified PCB without defects or an unqualified PCB with defects.
[0042] A sub-region is a local region in a candidate region. A defect image is an image block that represents a defect. A defect image can be a regular or irregular image block. An image block refers to a small image area. For example, a scratch may exist in a PCB, and in a PCB image, a defect image may be a small image area that represents the scratch.
[0043] Exemplarily, the terminal or the server may randomly select a PCB image from a plurality of pre-stored PCB images as the target PCB image.
[0044] In some embodiments, the terminal or server may obtain the target PCB image indicated by the defect generation trigger event. Specifically, the defect generation configuration information indicated by the defect generation trigger event may be obtained, and the target PCB image may be obtained according to the defect generation configuration information. For example, the defect generation configuration information may include a specified image path, and the target PCB image may be obtained according to the image path. The specified image path may be configuration information of an image path configuration item in a plurality of configuration items.
[0045] In some embodiments, the terminal or server may obtain a PCB design drawing preconfigured for the target PCB image, and from the areas corresponding to the preset defect types divided in the PCB design drawing, the areas corresponding to the preset defect types that are the same as the defect type indicated by the defect generation trigger event are determined as multiple candidate areas in the target PCB image. The PCB design drawing is a grayscale image used to mark the areas corresponding to the preset defect types in the PCB design file. Each pixel in the PCB design drawing can be assigned to an area corresponding to a preset defect type.
[0046] In some embodiments, each pixel in the PCB design may also be allocated as a sub-region corresponding to one of a plurality of preset region types. In this embodiment, the specified region type may be obtained from the defect generation configuration information indicated by the defect generation trigger event, and for each of the plurality of candidate regions determined, a sub-region formed by pixels corresponding to the preset region type that is the same as the specified region type may be determined.
[0047] Among them, the region type is the type of the sub-region. The region type can be a metal (gold) type or an ink (ink) type. The metal type sub-region is such as the image formed on the surface of the metal component in the PCB. The ink type sub-region refers to the image of the inkjet printed area in the PCB. The specified region type can be the configuration information of the region type configuration item in multiple configuration items. The metal type sub-region can also be called a connected component.
[0048] In some embodiments, the terminal or server may obtain a specified area type from the defect generation configuration information indicated by the defect generation trigger event, determine a segmentation threshold that corresponds to the PCB grayscale image of the target PCB image and matches the specified area type, perform global threshold segmentation processing on the PCB grayscale image according to the segmentation threshold, and obtain a binary image with the area matching the area type as the foreground area; divide the target PCB image into multiple pending areas of preset sizes, and determine a sub-area in the target PCB image according to each foreground area in the binary image, and determine the pending area containing the sub-area as a candidate area in the target PCB image.
[0049] Among them, the PCB grayscale image can be obtained by grayscale processing the target PCB image. The segmentation threshold is a threshold used to segment the area in the PCB grayscale image that matches the specified area type. For example, the pixel value range of the PCB grayscale image can be from 0 to 255, wherein the pixel value of the metal type sub-area can be greater than 160, then 160 can be used as the segmentation threshold, and the pixel value greater than 160 is assigned to 1, and the pixel value not greater than 160 is assigned to 0. In the binary image obtained in this way, the metal type sub-area is the foreground area, and the other areas are the background. The segmentation threshold can be pre-configured for the specified area type, or it can be obtained by identifying the PCB grayscale image. For example, the metal type sub-area in the PCB grayscale image can be identified, and then the segmentation threshold that can separate the metal type sub-area from other areas is determined. If the specified area type is ink type, the sub-area in the candidate area can be considered as one.
[0050] The preset size is the preset width and height of the candidate area, for example, it can be 800*800. It can be understood that the size of the binary image is the same as the size of the target PCB image. In this way, the pixel positions of the binary image and the target PCB image correspond one to one. Then, according to the pixel positions occupied by each foreground area in the binary image, the sub-areas in each undetermined area in the target PCB image can be correspondingly determined.
[0051] S206: Filter out a target area from multiple candidate areas.
[0052] The target area is used to accommodate the defect image in this PCB defect image generation.
[0053] Exemplarily, the terminal or the server may obtain the region screening condition from the defect generation configuration information indicated by the defect generation triggering event, and screen out the target region from multiple candidate regions according to the region screening condition.
[0054] Among them, the area screening condition in the defect generation configuration information may be the configuration information of the area screening configuration item in the multiple configuration items. The area screening condition may be, for example, that the sum of the areas of the sub-areas contained in the target area accounts for a proportion of the target area greater than a preset proportion, or that the sum of the areas of the sub-areas contained in the target area accounts for a proportion of the target PCB image greater than a preset proportion, or that the number of sub-areas contained in the target area is greater than a preset number. The preset proportion may be 20%, 50% or others. The preset number may be 3, 5, 10 or others.
[0055] In some embodiments, the terminal or the server may obtain an area screening condition adapted to the specified area type from the defect generation configuration information indicated by the defect generation trigger event, and screen out a target area from multiple candidate areas according to the area screening condition.
[0056] Among them, the region screening condition adapted to the specified region type refers to the region screening condition specifically applicable to the specified region type. For example, in the case where the specified region type is a metal type, it is required in the actual scene that there are more sub-regions representing metal in the target region, then the region screening condition may be that the number of sub-regions contained in the target region is greater than a preset number. For another example, in the case where the specified region type is an ink type, if an oil stain defect image is generated in the sub-region of the ink type, it is required that the sum of the areas of the sub-regions contained in the target region accounts for a larger proportion of the target PCB image, then the region screening condition may be that the sum of the areas of the sub-regions contained in the target region accounts for a larger proportion of the target PCB image.
[0057] S208: Filter out a target sub-region from the sub-regions included in the target region.
[0058] Exemplarily, the terminal or the server may obtain a sub-region screening condition from the defect generation configuration information indicated by the defect generation triggering event, and screen out a target sub-region from the sub-regions included in the target region according to the sub-region screening condition.
[0059] Among them, the sub-region screening conditions include, for example, that the absolute area of the target sub-region is greater than a preset area value, or that the relative area of the target sub-region relative to the target region is greater than a preset ratio value, or that the center point of the target sub-region is within a given area, or that there is no marked defect image in the target sub-region.
[0060] The preset area value may be 500*500. The given area is, for example, an area obtained by retreating 50 degrees from each of the two sides in the width direction and 30 degrees from each of the two sides in the height direction of the target area. The marked defect image may be a defect image generated historically or a real defect image.
[0061] S210. In the target PCB image, at the defect position that matches the defect type determined based on the target sub-region, a defect image that matches the defect type is generated to obtain a PCB defect image.
[0062] The defect position may be the position of the target point of the defect image to be generated in the target PCB image, or may be an area containing the defect image to be generated. The target point may be the center point, endpoint or other point of the defect image to be generated. The endpoint may be understood as any point of the two points when the line segment connecting two different points at the boundary of the defect image to be generated is the largest.
[0063] Exemplarily, when the defect type belongs to the area encroachment type, the terminal or server can determine the closed shape according to the size of the target sub-area; determine the defect position in the target PCB image based on the target sub-area and the relative position relationship between the defect image to be generated determined according to the defect type and the target sub-area; at the defect position, generate a defect image that matches the defect type and the closed shape to obtain a PCB defect image.
[0064] The size of the closed shape may be smaller than the size of the target sub-region. Specifically, the ratio between the size of the closed shape and the size of the target sub-region may be within a preset ratio range. The maximum value of the preset ratio range may be less than 1. The preset ratio range may be, for example, 0.1 to 0.2, 0.3 to 0.5 or other. The preset ratio range may be configured in a configuration item in the defect generation configuration information indicated by the defect generation trigger event. The closed shape may be a randomly generated shape or may be selected from pre-stored shapes. The pre-stored shapes may be, for example, extracted from an existing defect image.
[0065] In some embodiments, when the defect type is a global color anomaly type, the terminal or server may determine the target sub-region as a defect position matching the global color anomaly type, and adjust the pixel value of the target sub-region in the target PCB image to generate a defect image matching the global color anomaly type, thereby obtaining a PCB defect image. When adjusting the pixel value of the target sub-region, the pixel value of the target sub-region may be multiplied by a value greater than 1 to increase the pixel value, or multiplied by a value less than 1 to decrease the pixel value.
[0066] It can be seen that in the embodiment of the present application, in response to a defect generation trigger event, the generation of a PCB defect image can be automatically started, and the target area is screened out from the original PCB image, and the target sub-area is screened out from the sub-area included in the target area in turn. Then, at the defect position that matches the defect type determined based on the target sub-area, a defect image that matches the defect type is generated. In this way, after the defect generation trigger event is triggered, through a series of automated steps, a defect image that matches the defect type can be generated at the defect position that matches the defect type. The obtained PCB defect image meets expectations and does not require manual operation, thereby improving the efficiency of PCB defect image generation.
[0067] In some embodiments, the defect type is of area encroachment type, and step 210 includes:
[0068] Generate random closed shapes based on the size of the target sub-region;
[0069] According to the defect type, determine the relative position relationship between the defect image to be generated and the target sub-area;
[0070] Determine the defect location in the target PCB image based on the target sub-area and relative position relationship;
[0071] At the defect location, a defect image matching the defect type and closed shape is generated to obtain a PCB defect image.
[0072] Among them, the area encroachment type may include an area depression type, an area protrusion type, and others. The defect image of the area depression type may be understood as a defect image formed by the area adjacent to the target sub-area encroaching the target sub-area. The defect image of the protrusion type may be understood as a defect image formed by the target sub-area encroaching the adjacent area. A closed shape is a figure that is in a closed state in its dimension. For example, a plane figure that is closed in two dimensions. The target sub-area may be rectangular, and the size of the target sub-area may be at least one of the width and height of the target sub-area, or the area occupied by the target sub-area.
[0073] The relative position relationship can be that the defect image to be generated is inside or outside the target sub-region. It can be understood that when the defect type is a regional depression type, the defect image to be generated can be inside the target sub-region; when the defect type is a regional protrusion type, the defect image to be generated can be outside the target sub-region. The defect position can be the position of the target point in the defect image to be generated in the target PCB image, or it can be the area occupied by the defect image to be generated in the target PCB image.
[0074] It can be seen that in this embodiment, the relative position relationship is determined according to the defect type, and then the defect position is determined, creating conditions for generating defects that meet the expectations. Moreover, a random closed shape is generated based on the size of the target sub-area, and a defect image matching the defect type and the closed shape is generated. The defect image is not limited to a known shape, which can improve the diversity of the defect image, and then improve the diversity of the PCB defect image, and can provide diverse samples for the task of defect detection through a neural network, thereby creating conditions for improving the generalization ability of the neural network to improve the accuracy of defect detection.
[0075] In some embodiments, determining the defect position in the target PCB image based on the target sub-region and the relative position relationship includes:
[0076] Starting from the boundary of the target sub-region, the local occupied area in the target PCB image is determined according to the relative position relationship and the closed shape, and the local occupied area is determined as the defect position in the target PCB image.
[0077] Among them, the ratio between the size of the local occupied area and the size of the target sub-area may be within a preset ratio range, the maximum value of the preset ratio range may be less than 1, and the preset ratio range may be, for example, 0.1 to 0.2, 0.3 to 0.5 or others.
[0078] Exemplarily, starting from the boundary of the target sub-region, determining the local occupied area in the target PCB image according to the relative position relationship and the closed shape includes:
[0079] When the relative position relationship is that the defect image to be generated is inside the target sub-region, starting from the boundary of the target sub-region, a local encroachment area identical to the closed shape is determined inside the target sub-region; or,
[0080] When the relative position relationship is that the defect image to be generated is outside the target sub-region, starting from the boundary of the target sub-region, a local occupied area with the same closed shape is determined outside the target sub-region and inside the target PCB image.
[0081] The local encroachment area may be tangent to or intersect with part of the boundary of the target sub-area. The target sub-area may be a rectangle, the boundary of the target sub-area may be the edge of the target sub-area, and the part of the boundary may be a line segment on the edge of the target sub-area. At the same time, the location of the local encroachment area may also be restricted by the configuration information of a configuration item in the defect generation configuration information indicated by the defect generation trigger event and the configuration item for the area encroachment type. For example, the configuration information of the configuration item may be the non-edge area of the defect image to be generated in the target PCB image. The non-edge area may be the area obtained by retreating 50 from each of the two edges in the width direction and 30 from each of the two edges in the height direction of the target PCB image.
[0082] Exemplarily, at the defect location, a defect image matching the defect type and the closed shape is generated to obtain a PCB defect image, including:
[0083] According to the defect type, an image block matching the size of the local occupied area is obtained in the target PCB image, and the pixel value of the obtained image block is replaced with the pixel value of the local occupied area, so that the obtained image block is pasted to the local occupied area to obtain a defect image at the defect position that matches the defect type and the closed shape, thereby obtaining a PCB defect image.
[0084] Exemplarily, according to the defect type, an image block matching the size of the local occupied area is obtained in the target PCB image, including:
[0085] When the defect type is a regional depression type, an image block matching the local encroachment area is obtained inside the target PCB image and outside the target sub-area; or,
[0086] When the defect type is a regional protrusion type, an image block matching the local encroachment area is obtained inside the target sub-region.
[0087] The image block that matches the local occupied area may be an image block that has the same shape as the local occupied area, and may be understood as an image block that matches a closed shape.
[0088] In some embodiments, the defect type is a local color abnormality type, and step 210 includes:
[0089] Generate random closed shapes based on the size of the target sub-region;
[0090] Determine the defect position determined according to the closed shape in the target sub-region as the defect position matched with the defect type determined based on the target sub-region;
[0091] The pixel value at the defect position in the target PCB image is adjusted to generate a defect image matching the defect type and obtain a PCB defect image.
[0092] Among them, the defect position determined according to the closed shape can be a local area that is the same as the closed shape, that is, the shape of the local area is the same as the closed shape; it can also be a local area that is the same as the shape after the closed shape is scaled, and the local area is still in the target sub-area; wherein, the scaling of the closed shape can be limited by the pre-configured defect area in the defect generation configuration information indicated by the defect generation trigger event, and the area of the shape after the closed shape is scaled is smaller than the pre-configured defect area, such as the pre-configured defect area can be 100.
[0093] In the above-mentioned aspect of adjusting the pixel value at the defect position in the target PCB image, the pixel value of the target sub-area may be multiplied by a value greater than 1 to increase the pixel value, or multiplied by a value less than 1 to decrease the pixel value.
[0094] In terms of adjusting the pixel value at the defect position in the target PCB image mentioned above, adjustments can also be made according to the configuration information of some configuration items in the defect generation configuration information indicated by the defect generation trigger event and the configuration information of some configuration items in the various configuration items of the color abnormality type. For example, the configuration information may include the referenced preset defect image (taking the pixel value of the preset defect image as the pixel value to be adjusted), the pixel value variation range (the value range of the pixel value to be adjusted), the smoothing range of the edge of the defect image, configuration information indicating that the value of ksize is adaptively set according to the size of the defect position to control the degree of edge smoothing, or others.
[0095] In some embodiments, generating a random closed shape based on the size of the target sub-region includes:
[0096] Based on the size of the target sub-region, N points are randomly determined; N is a positive integer greater than 2;
[0097] Determine N point pairs among the N points, and the line segment formed by each point pair is an edge of the N-gon formed by the N points;
[0098] For each of the N point pairs, connect them with a straight line or a curve to obtain a closed shape.
[0099] Among them, the position of each point in the N points is different. The line segment formed by each point pair in the N point pairs is an edge of the N-gon formed by the N points, so that when the point pairs are subsequently connected, a closed shape can be formed and there is no line inside the closed shape. For example, if N is 4, 4 point pairs can be determined, each point pair includes two points, and the line segment formed by each point pair is an edge of the quadrilateral formed by the 4 points. Each point pair in the N point pairs can be connected only by straight lines, can be connected partially by straight lines and the other part by curves, or can be connected only by curves.
[0100] It can be seen that in this embodiment, N points are randomly determined based on the size of the target sub-area, creating conditions for the randomness of the subsequently generated closed shape, and the line segment formed by each of the N point pairs is an edge of the N-gon formed by the N points. For each point pair, a random closed shape can be obtained by connecting them through a straight line or a curve.
[0101] In some embodiments, N may be 2, and based on the size of the target sub-region, a random closed shape is generated, including:
[0102] Based on the size of the target sub-region, two points are randomly determined, and two non-repetitive connections are performed on the two points, and at least one connection is through a curve to obtain a closed shape.
[0103] The two connections may be one through a straight line and the other through a curve, or both through curves, and the curves of the two connections are different.
[0104] In some embodiments, when point pairs are connected by curves, the connection may be performed by generating a Bezier curve, a B-spline curve, or other curves.
[0105] In some embodiments, for each of the N point pairs, a straight line or a curve is connected to obtain a closed shape, including:
[0106] For each point pair among the N point pairs, M points including the point pair are randomly determined from the N points, and the M points are determined as the corresponding control points of the point pair; M is a positive integer greater than 2 and not greater than N;
[0107] Taking the point pair as two endpoints and under the control of the corresponding control points of the point pair, a Bezier curve between the point pair is generated to connect the point pair through the curve;
[0108] After each of the N point pairs is connected by a curve, a closed shape is obtained.
[0109] The control points are used to control the shape and curvature of the Bezier curve. In the process of generating a Bezier curve, the Bezier curve can start from one of the two endpoints and end at the other, and approach each control point other than the two endpoints among the M control points, but not pass through the control points. In the process of generating a Bezier curve, the points of the Bezier curve can be determined by the (M-1) order Bezier curve equation, so that the Bezier curve can be generated.
[0110] It can be seen that in this embodiment, by randomly determining M points including a point pair from N points and determining the M points as control points corresponding to the point pair, the generated Bezier curve can be controlled, thereby further improving the randomness of the closed shape.
[0111] In some embodiments, for each of the N point pairs, a straight line or a curve is connected to obtain a closed shape, including:
[0112] With the point pair as two endpoints and under the control of N points as control points, a Bezier curve between the point pairs is generated to connect the point pairs through the curve. After each point pair in the N point pairs is connected through the curve, a closed shape is obtained.
[0113] In some embodiments, the defect type is a foreign object type, and step 210 includes:
[0114] Acquire multiple preset defect images matching the defect types; the preset defect images are obtained by segmenting the real PCB defect images;
[0115] A target preset defect image is selected from a plurality of preset defect images, and a histogram similarity between the target preset defect image and the target sub-region meets a similarity determination condition;
[0116] Determine the defect position determined in the target sub-region as a defect position that matches the defect type determined based on the target sub-region;
[0117] The target preset defect image is pasted to the defect position in the target PCB image to generate a defect image matching the defect type and obtain a PCB defect image.
[0118] The real PCB defect image is an image taken of a defective unqualified PCB. Before generating the PCB defect image, multiple real PCB defect images can be obtained, and a preset defect image can be segmented from each real PCB defect image, and the preset defect image is annotated with a specific defect type under the foreign matter type, such as a scratch type, a stain type or others.
[0119] Histogram similarity is the similarity between two grayscale histograms, specifically the similarity between the grayscale histogram of a preset defect image and the grayscale histogram of a target sub-region. Grayscale histogram is used to represent the grayscale distribution of an image or a region in an image. Grayscale distribution refers to the number of pixels in each grayscale level. The grayscale level can be obtained by dividing 0 to 255. For example, according to one level for every 10 pixel values, the grayscale level can be 0 to 10, 11 to 20 or others. Histogram similarity can be the result of calculating the vector distance between two grayscale histograms. The vector distance can specifically be Euclidean distance, Bhattacharyya distance or others.
[0120] The similarity determination condition is a condition for determining whether two grayscale histograms are similar based on the histogram similarity. The similarity determination condition may be that the histogram similarity is greater than a preset similarity, less than a preset similarity, or close to a preset similarity. The similarity determination condition may be determined specifically according to the method for determining the histogram similarity. For example, the histogram similarity may be the result of calculating the Bhattacharyya distance, where the Bhattacharyya distance ranges from 0 to 1, and the closer to 0, the more similar. The similarity determination condition may be that the histogram similarity is less than a preset similarity, and the preset similarity may be 0.2, 0.3 or others.
[0121] The defect position determined in the target sub-region may be determined in the target sub-region according to the configuration information of some configuration items in the defect generation configuration information indicated by the defect generation trigger event. Specifically, the configuration information of some configuration items may include the configuration information of each configuration item for the foreign body type, for example, the defect image to be generated is in the non-edge area of the target PCB image, and the non-edge area may be the area obtained by retreating 50 from each of the two sides in the width direction and 30 from each of the two sides in the height direction of the target PCB image. The defect position may be a coordinate point, and when pasting, the defect position is pasted as the center point of the target preset defect image.
[0122] It can be seen that in this embodiment, a target preset defect image is screened out from multiple preset defect images, and the histogram similarity between the target preset defect image and the target sub-region meets the similarity judgment condition. In this way, the target preset defect image is pasted to the defect position, which can be better integrated with the target sub-region, making the generated defect image more realistic, thereby improving the authenticity of the PCB defect image.
[0123] In some embodiments, the terminal or server may select a target preset defect image from a plurality of preset defect images, the histogram similarity between the target preset defect image and the target sub-region meets the similarity determination condition, and the target preset defect image is larger than a preconfigured area value. The preconfigured area value may be one of the configuration information of each configuration item for the foreign body type.
[0124] In some embodiments, after the terminal or server pastes the target preset defect image to the defect position in the target PCB image, the target preset defect image is fused with the target sub-region according to the preconfigured fusion method to generate a defect image matching the defect type, thereby obtaining a PCB defect image. The preconfigured fusion method may be one of the configuration information of each configuration item for the foreign body type, specifically Alpha fusion (the process of superimposing the foreground on the background through transparency), Poisson fusion, or others. The configuration information of each configuration item for the foreign body type may also include the alpha value (transparency) and ksize (used to control the smoothing range of the edge of the defect image) configured for Alpha fusion.
[0125] In some embodiments, the terminal or server may perform color enhancement and position enhancement on the target preset defect image and paste it to the defect position in the target PCB image. Color enhancement may be to increase saturation, increase brightness or other. Position enhancement may be to rotate, scale or other.
[0126] In some embodiments, see Figure 3 The schematic diagram of the PCB defect image generation framework shown in FIG. Figure 4 The schematic flow chart of the PCB defect image generation steps is shown. The above-mentioned PCB defect image generation method may specifically include the following steps.
[0127] The server can obtain multiple real PCB defect images (NG data), and cut out a preset defect image (defect patch) from each real PCB defect image. The real PCB defect image can be marked with each preset defect image.
[0128] The server may determine, in response to the defect generation trigger event, a defect type indicated by the defect generation trigger event, wherein the defect type may be selected by a user.
[0129] The server may acquire a target PCB image, wherein the target PCB image may be selected from NG data or OK data (a PCB image of a qualified PCB without defects).
[0130] The server can obtain the specified area type, determine the segmentation threshold corresponding to the PCB grayscale image of the target PCB image and matching the specified area type, perform global threshold segmentation processing on the PCB grayscale image according to the segmentation threshold, and obtain a binary image with the area matching the area type as the foreground area; divide the target PCB image into multiple pending areas of preset sizes, and determine the sub-areas in the target PCB image according to each foreground area in the binary image, determine the pending area containing the sub-area as the candidate area in the target PCB image, and obtain multiple candidate areas for accommodating defective images.
[0131] The server may obtain an area screening condition from the defect generation configuration information indicated by the defect generation trigger event, and screen out a target area from multiple candidate areas according to the area screening condition. The server may obtain a sub-area screening condition from the defect generation configuration information indicated by the defect generation trigger event, and screen out a target sub-area from sub-areas included in the target area according to the sub-area screening condition.
[0132] Among them, the regional screening conditions and sub-region screening conditions involved in the defect generation configuration information can be found in the regional screening configuration information table in Table 1 below. The "image" column in Table 1 is used to configure the regional screening conditions, and the "blob" column is used to configure the sub-region screening conditions. The two rows in the "image" column can be set as two regional screening conditions. For example, "the proportion of the foreground area (white pixels) in the region_mask to the entire image is greater than this value" can be used to construct a regional screening condition that the sum of the areas of the sub-regions contained in the target area accounts for a proportion of the target PCB image greater than a preset proportion. An additional column can be set in Table 1 to input the preset proportion. For another example, "the number of foreground connected components in region_mask is greater than this value" can be used to construct a regional screening condition that the number of sub-regions contained in the target area is greater than a preset number.
[0133] The four rows in the "blob" column can be set as four sub-region filtering conditions. For example, "blob absolute area is greater than this value" can be used to construct a sub-region filtering condition that the absolute area of the target sub-region is greater than the preset area value. Another example is "blob relative area is greater than this value (blob / region_mask)". The sub-region filtering condition can be constructed as the relative area of the target sub-region relative to the target region is greater than the preset ratio value. Another example is "the center of the blob is not allowed to appear on the surrounding edges". The sub-region filtering condition can be constructed as the center point of the target sub-region is within the given area. Another example is "if the intersection of a blob and occupied_mask is not 0 (the defect has been marked on the blob), it will be discarded directly". The sub-region filtering condition can be constructed as "there is no marked defect image in the target sub-region".
[0134] Table 1 Area screening configuration information table
[0135]
[0136] An example schematic diagram of the relationship between the target area and the target sub-area can be shown as follows: Figure 5 As shown, Figure 5 The following may include three figures as indicated by (a), (b), and (c), wherein: Figure 5 (a) can be a schematic diagram of a target area. Figure 5 (b) can be Figure 5 (a) Binary image of the target area, Figure 5 (c) can be from Figure 5 (b) The binary image obtained after the target sub-region is filtered out is Figure 5 The white area obtained in (c) corresponds to Figure 5 In (a), the target sub-region can be determined.
[0137] When the defect type belongs to the area encroachment type, the server can generate a random closed shape based on the size of the target sub-area; determine the relative position relationship between the defect image to be generated and the target sub-area according to the defect type; determine the defect position in the target PCB image based on the target sub-area and the relative position relationship; at the defect position, generate a defect image that matches the defect type and the closed shape to obtain a PCB defect image. Among them, starting from the boundary of the target sub-area, the local encroachment area in the target PCB image can be determined according to the relative position relationship and the closed shape, and the local encroachment area can be determined as the defect position in the target PCB image. The area encroachment type can include an area depression type and an area protrusion type. See, for example Figure 6 The diagram shows an example of a before-and-after comparison of defect images of the type of raised area generated. Figure 6 (a) may be a schematic diagram of a target area in a target PCB image before generating a defect image of a raised area type. Figure 6 (b) can be based on Figure 6 Schematic diagram of the target sub-region in (a) after generating a defect image of a regional convex type.
[0138] When the defect type is a global color anomaly type, the server may determine the target sub-region as a defect position that matches the global color anomaly type, and adjust the pixel value of the target sub-region in the target PCB image to generate a defect image that matches the global color anomaly type, thereby obtaining a PCB defect image.
[0139] When the defect type is a local color anomaly type, the server can generate a random closed shape based on the size of the target sub-region; determine the defect position in the target sub-region determined according to the closed shape as the defect position that matches the defect type determined based on the target sub-region; adjust the pixel value at the defect position in the target PCB image to generate a defect image that matches the defect type, and obtain a PCB defect image. See, for example, Figure 7 The following is a schematic diagram showing a before-and-after comparison of defect images of local color anomaly type. Figure 7 (a) may be a schematic diagram of a target sub-area in a target PCB image before generating a defect image of a local color anomaly type. Figure 7 (b) can be based on Figure 7 The schematic diagram obtained after the target sub-region in (a) generates a defect image of a local color anomaly type, as shown in Figure 7 In (b), the darker area in the upper right corner may indicate local color anomaly.
[0140] When the defect type belongs to the foreign body type, the server can obtain multiple preset defect images that match the defect type; the preset defect image is obtained by segmenting the real PCB defect image; the target preset defect image is screened out from the multiple preset defect images, and the histogram similarity between the target preset defect image and the target sub-region meets the similarity judgment condition; the defect position determined in the target sub-region is determined as the defect position that matches the defect type determined based on the target sub-region; the target preset defect image is pasted to the defect position in the target PCB image to generate a defect image that matches the defect type and obtain a PCB defect image. See, for example, Figure 8 The diagram shows an example of a before-and-after comparison of a scratch-type defect image. Figure 8 (a) may be a schematic diagram of a target sub-area in a target PCB image before a scratch type defect image is generated. Figure 8 (b) can be based on Figure 8 (a) is a schematic diagram obtained after generating a scratch type defect image, as shown in Figure 8 (b), compared to Figure 8 (a) has an extra scratch on the left side.
[0141] In the process of generating various types of defect images, the generation of defect images can also be generated according to the configuration information of various configuration items set for foreign body type, color abnormality type, and region invasion type in the defect generation configuration information indicated by the defect generation trigger event. See Table 2 below for the configuration information table related to defect image generation of defect types. In Table 2, the "CopyPasteMethod" column can correspond to the foreign body type, the "ColorChangeMethod" column can correspond to the color abnormality type, and the "RegionInvadeMethod" column can correspond to the region invasion type.
[0142] Table 2 Configuration information table related to defect image generation of defect types
[0143]
[0144] Among them, in the "CopyPasteMethod" column, each row can form the configuration information of a configuration item under the foreign body type. Specifically, "the area of the defect must be greater than this value", which can be understood as the target preset defect image is greater than the pre-configured area value, "the score of the defect and the blob based on the color histogram must be greater than this value", which can be understood as the histogram similarity between the target preset defect image and the target sub-area is greater than the preset similarity. "The defect will not be synthesized in the edge area of the image", which can be understood as the non-edge area of the defect image to be generated in the target PCB image. "The fusion method of the foreground (defect) and the background supports alpha_blend and poisson_blend", which can be understood as the method of fusion of the target preset defect image (foreground) with the target sub-area (background) can be either Alpha fusion or Poisson fusion. "When blend_method is alpha_blend, this configuration will take effect. It is used to control the range of edge smoothing", which can be understood as when the fusion method is Alpha fusion, the set ksize value will take effect, which is used to control the smoothing range of the edge of the defect image. "When bend_method is alpha_blend, this configuration will take effect. It is used to control the alpha value of the foreground during fusion." It can be understood that when the fusion method is Alpha fusion, the set alpha value will take effect and is used to control the transparency of the foreground.
[0145] In the "ColorChangeMethod" column, each row can form the configuration information of a configuration item under the foreign body type. Specifically, "Does the defect occur globally or locally? (Here global and local refer to the blob level)" can be understood as selecting the defect type as a global color anomaly type or a local color anomaly type. "Whether referpatch is required" can be understood as whether a preset defect image needs to be referenced. "This item takes effect when is_occur_1ocal is True, and is used to control the defect area." It can be understood that when the defect type is a local color anomaly type, the area of the defect image to be generated is smaller than the preset value set for this item. "Brightness variation range" can be understood as the value range of the pixel value to be adjusted. "When is_occur_local is True and is_ksize_adapt is Falses, this item takes effect and is used to control the degree of defect edge smoothness." It can be understood that when the defect type is a local color anomaly type, if the value of the "is_ksize_adapt" item is "Falses", the edge smoothness of the defect image is adjusted according to the given ksize value. "This item takes effect when is_occur_local is True, and the corresponding ksize is generated according to the defect mask size." It can be understood that when the defect type is a local color anomaly type, if the value of the "is_ksize_adapt" item is "True", the ksize value is adaptively set according to the size of the defect position to control the smoothness of the defect image edge.
[0146] In the "RegionInvadeMethod" column, each row can form the configuration information of a configuration item under the foreign body type. Specifically, "Defects will not be synthesized in the edge area of the image" can be understood as the defect image to be generated in the non-edge area of the target PCB image. "Type of regional invasion. Concave and Convex are optional" can be understood as selecting the defect type as a regional concave type or a regional convex type. "The proportion of convex / concave area to blob" indicates the proportion of the convex area or the concave area to the target sub-area, which can be used to configure the ratio between the area of the above-mentioned local invasion area and the area of the target sub-area to be within a preset ratio range.
[0147] It should be understood that, although the steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indications of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0148] Based on the same inventive concept, the embodiment of the present application also provides a PCB defect image generation device. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more PCB defect image generation device embodiments provided below can refer to the limitations of the PCB defect image generation method above, and will not be repeated here.
[0149] like Fig. 9 As shown, the embodiment of the present application provides a PCB defect image generating device 900, comprising:
[0150] A trigger module 902, configured to determine, in response to a defect generation trigger event, a defect type indicated by the defect generation trigger event;
[0151] The determination module 904 is used to obtain the target PCB image and determine a plurality of candidate regions in the target PCB image for accommodating defect images; each candidate region includes a sub-region;
[0152] A screening module 906 is used to screen out a target region from multiple candidate regions; and screen out a target subregion from subregions included in the target region;
[0153] The generating module 908 is used to generate a defect image matching the defect type at the defect position matching the defect type determined based on the target sub-region in the target PCB image, so as to obtain a PCB defect image.
[0154] In some embodiments, the defect type belongs to the area encroachment type. In the target PCB image, at the defect position matching the defect type determined based on the target sub-region, a defect image matching the defect type is generated. In terms of obtaining the PCB defect image, the generation module 908 is specifically used to:
[0155] Generate random closed shapes based on the size of the target sub-region;
[0156] According to the defect type, determine the relative position relationship between the defect image to be generated and the target sub-area;
[0157] Determine the defect location in the target PCB image based on the target sub-area and relative position relationship;
[0158] At the defect location, a defect image matching the defect type and closed shape is generated to obtain a PCB defect image.
[0159] In some embodiments, the defect type is a local color anomaly type. In the target PCB image, at the defect position matching the defect type determined based on the target sub-region, a defect image matching the defect type is generated. In terms of obtaining the PCB defect image, the generation module 908 is specifically used to:
[0160] Generate random closed shapes based on the size of the target sub-region;
[0161] Determine the defect position determined according to the closed shape in the target sub-region as the defect position matched with the defect type determined based on the target sub-region;
[0162] The pixel value at the defect position in the target PCB image is adjusted to generate a defect image matching the defect type and obtain a PCB defect image.
[0163] In some embodiments, in terms of generating a random closed shape based on the size of the target sub-region, the generating module 908 is specifically configured to:
[0164] Based on the size of the target sub-region, N points are randomly determined; N is a positive integer greater than 2;
[0165] Determine N point pairs among the N points, and the line segment formed by each point pair is an edge of the N-gon formed by the N points;
[0166] For each of the N point pairs, connect them with a straight line or a curve to obtain a closed shape.
[0167] In some embodiments, in terms of connecting each of the N point pairs through a straight line or a curve to obtain a closed shape, the generating module 908 is specifically configured to:
[0168] For each point pair among the N point pairs, M points including the point pair are randomly determined from the N points, and the M points are determined as the corresponding control points of the point pair; M is a positive integer greater than 2 and not greater than N;
[0169] Taking the point pair as two endpoints and under the control of the corresponding control points of the point pair, a Bezier curve between the point pair is generated to connect the point pair through the curve;
[0170] After each of the N point pairs is connected by a curve, a closed shape is obtained.
[0171] In some embodiments, the defect type belongs to a foreign body type. In the target PCB image, at a defect position matching the defect type determined based on the target sub-region, a defect image matching the defect type is generated. In terms of obtaining the PCB defect image, the generation module 908 is specifically used to:
[0172] Acquire multiple preset defect images matching the defect types; the preset defect images are obtained by segmenting the real PCB defect images;
[0173] A target preset defect image is selected from a plurality of preset defect images, and a histogram similarity between the target preset defect image and the target sub-region meets a similarity determination condition;
[0174] Determine the defect position determined in the target sub-region as a defect position that matches the defect type determined based on the target sub-region;
[0175] The target preset defect image is pasted to the defect position in the target PCB image to generate a defect image matching the defect type and obtain a PCB defect image.
[0176] Each module in the above-mentioned PCB defect image generation device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the corresponding operations of each of the above modules.
[0177] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be shown in FIG10. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data to be stored when executing the above-mentioned PCB defect generation method. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in the above-mentioned PCB defect generation method are implemented.
[0178] In some embodiments, a computer device is provided, which may be a terminal, and its internal structure diagram may be shown in FIG11. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected via a system bus, and the communication interface, the display unit, and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner may be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, the steps in the above-mentioned PCB defect image generation method are implemented. The display unit of the computer device is used to form a visually visible picture, which may be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen; the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0179] Those skilled in the art will understand that the structure shown in FIG. 10 or FIG. 11 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0180] In some embodiments, a computer device is provided. The computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps in the above method embodiments are implemented.
[0181] In some embodiments, Fig.12 The figure shows an internal structure diagram of a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0182] In some embodiments, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0183] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0184] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0185] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0186] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for generating a PCB defect image, characterized in that: include: In response to a defect generation triggering event, determining a defect type indicated by the defect generation triggering event; Acquire a target PCB image, and determine a plurality of candidate regions in the target PCB image for accommodating defect images; each of the candidate regions includes a sub-region; Selecting a target region from the plurality of candidate regions; Filtering out a target sub-region from the sub-regions included in the target region; In the target PCB image, at the defect position that matches the defect type determined based on the target sub-region, a defect image that matches the defect type is generated to obtain a PCB defect image.
2. The method according to claim 1, characterized in that The defect type belongs to the area encroachment type, and in the target PCB image, at the defect position matching the defect type determined based on the target sub-region, a defect image matching the defect type is generated to obtain a PCB defect image, including: generating a random closed shape based on the size of the target sub-region; According to the defect type, determining the relative position relationship between the defect image to be generated and the target sub-region; Based on the target sub-area and the relative position relationship, determining the defect position in the target PCB image; At the defect position, a defect image matching the defect type and the closed shape is generated to obtain a PCB defect image.
3. The method according to claim 1, characterized in that The defect type is a local color abnormality type, and in the target PCB image, at a defect position matching the defect type determined based on the target sub-region, a defect image matching the defect type is generated to obtain a PCB defect image, including: generating a random closed shape based on the size of the target sub-region; Determine the defect position determined according to the closed shape in the target sub-region as the defect position matched with the defect type determined based on the target sub-region; The pixel value at the defect position in the target PCB image is adjusted to generate a defect image matching the defect type, thereby obtaining a PCB defect image.
4. The method according to claim 2 or 3, characterized in that: The generating a random closed shape based on the size of the target sub-region comprises: Based on the size of the target sub-region, N points are randomly determined; N is a positive integer greater than 2; Determine N point pairs among the N points, where a line segment formed by each point pair is a side of an N-gon formed by the N points; Each of the N point pairs is connected by a straight line or a curve to obtain a closed shape.
5. The method according to claim 4, characterized in that The step of connecting each of the N point pairs by a straight line or a curve to obtain a closed shape includes: For each point pair of the N point pairs, randomly determine M points including the point pair from the N points, and determine the M points as control points corresponding to the point pair; M is a positive integer greater than 2 and not greater than N; Taking the point pair as two endpoints and under the control of the control points corresponding to the point pair, generating a Bezier curve between the point pair, so as to connect the point pair through the curve; After each of the N point pairs is connected by a curve, a closed shape is obtained.
6. The method according to claim 1, characterized in that The defect type belongs to a foreign body type, and in the target PCB image, at a defect position matching the defect type determined based on the target sub-region, a defect image matching the defect type is generated to obtain a PCB defect image, including: Acquire multiple preset defect images matching the defect type; the preset defect images are obtained by segmenting from real PCB defect images; Filtering out a target preset defect image from the plurality of preset defect images, wherein the histogram similarity between the target preset defect image and the target sub-region meets a similarity determination condition; Determine the defect position determined in the target sub-region as a defect position matched with the defect type determined based on the target sub-region; The target preset defect image is pasted to the defect position in the target PCB image to generate a defect image matching the defect type, thereby obtaining a PCB defect image.
7. A PCB defect image generating device, characterized in that: include: A trigger module, configured to determine, in response to a defect generation trigger event, a defect type indicated by the defect generation trigger event; A determination module, used to acquire a target PCB image and determine a plurality of candidate regions in the target PCB image for accommodating defect images; each of the candidate regions includes a sub-region; A screening module, used to screen out a target area from the multiple candidate areas; and screen out a target sub-area from the sub-areas included in the target area; A generation module is used to generate a defect image matching the defect type at a defect position matching the defect type determined based on the target sub-region in the target PCB image, so as to obtain a PCB defect image.
8. The device according to claim 7, characterized in that The defect type belongs to the area encroachment type; in the target PCB image, at the defect position matching the defect type determined based on the target sub-region, a defect image matching the defect type is generated to obtain a PCB defect image, and the generation module is specifically used for: generating a random closed shape based on the size of the target sub-region; According to the defect type, determining the relative position relationship between the defect image to be generated and the target sub-region; Based on the target sub-area and the relative position relationship, determining the defect position in the target PCB image; At the defect position, a defect image matching the defect type and the closed shape is generated to obtain a PCB defect image.
9. A computer device, comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Cited By
PCB defect image generation method
CN121353246A