A detection method, device, electronic equipment and readable storage medium
By acquiring registered images under multiple exposure conditions and calculating similarity, a suitable threshold is determined, which solves the problem of product identification errors caused by inaccurate thresholds in existing technologies, and achieves accurate product type identification and simplified detection operations.
Patent Information
- Application Number
- CN202511324879.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-17
- Publication Date
- 2026-01-16
- Estimated Expiration
- 2045-09-17
AI Technical Summary
In existing technologies, detection systems sometimes misjudge products due to manually set thresholds.
By acquiring registered images under multiple exposure conditions, calculating similarity to determine an appropriate threshold, and combining this with the similarity of the image to be detected, the product type can be accurately determined.
It enables the determination of appropriate thresholds based on the actual condition of products on the production line, accurately identifies product types, reduces the requirements for operators, and simplifies testing operations.
Smart Images

Figure CN120823205B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the field of image technology, and particularly relates to a detection method and device, electronic equipment and a readable storage medium. BACKGROUND
[0002] At present, a detection system for detecting products on a production line is to acquire images of the products, analyze the products in the images, and determine the conditions of the products according to a threshold. The threshold is set artificially, and thus product determination errors may occur. SUMMARY
[0003] Embodiments of the present application provide a detection method, device, electronic equipment and readable storage medium, which can solve the problem of product determination errors caused by inaccurate threshold.
[0004] In a first aspect, embodiments of the present application provide a detection method, comprising:
[0005] In response to a first operation of a user, first registration images under at least two exposure conditions are acquired, the first registration images include image regions of qualified products, the at least two exposure conditions include an optimal exposure condition and at least one candidate exposure condition, the candidate exposure conditions are determined according to the optimal exposure condition, and parameters of the candidate exposure conditions are different;
[0006] In response to a second operation of the user, second registration images under at least two exposure conditions are acquired, the second registration images are background images not including products;
[0007] First similarities between the first registration images and the second registration images under the exposure conditions are calculated;
[0008] A first threshold is determined according to the first similarities of the exposure conditions;
[0009] A first to-be-detected image is acquired;
[0010] A second similarity between the first to-be-detected image and the first registration images is calculated;
[0011] A detection type to which the first to-be-detected image belongs is determined according to the first threshold and the second similarity.
[0012] In a second aspect, embodiments of the present application provide a detection device, comprising:
[0013] The processing module is configured to acquire a first registration image under at least two exposure conditions in response to a first operation of a user, the first registration image comprising an image region of a qualified product, the at least two exposure conditions comprising an optimal exposure condition and at least one candidate exposure condition, the candidate exposure condition being determined according to the optimal exposure condition, and parameters of the candidate exposure conditions being different from each other;
[0014] The processing module is further configured to acquire a second registration image under the at least two exposure conditions in response to a second operation of the user, the second registration image being a background image not comprising a product;
[0015] The detection calculation module is configured to calculate a first similarity between the first registration image and the second registration image under each exposure condition.
[0016] The detection calculation module is further configured to determine a first threshold value according to the first similarity of each exposure condition.
[0017] The detection evaluation module is configured to acquire a first to-be-detected image.
[0018] The detection evaluation module is further configured to calculate a second similarity between the first to-be-detected image and the first registration image.
[0019] The detection evaluation module is further configured to determine a detection type to which the first to-be-detected image belongs according to the first threshold value and the second similarity.
[0020] In a third aspect, an electronic device is provided, which includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and the processor implements the method according to any one of the first aspect when executing the computer program.
[0021] In a fourth aspect, a computer readable storage medium is provided, which stores a computer program, and the computer program implements the method according to any one of the first aspect when executed by a processor.
[0022] In a fifth aspect, a computer program product is provided, which, when executed on an electronic device, causes the electronic device to perform the method according to any one of the first aspect.
[0023] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0024] The embodiment of the present application can acquire the first registration map under at least two exposure conditions in response to the first operation of the user, the first registration map including the image area of the qualified product; acquire the second registration map under at least two exposure conditions in response to the second operation of the user, the second registration map being the background image not including the product; calculate the first similarity between the first registration map and the second registration map under each exposure condition; determine the first threshold value according to the first similarity of each exposure condition; can determine the appropriate threshold value according to the real situation of the product on the production line, provide the basis for accurately determining the type of the product, and acquire the first to-be-detected image; calculate the second similarity between the first to-be-detected image and the first registration map; determine the detection type to which the first to-be-detected image belongs according to the first threshold value and the second similarity, and realize accurate judgment of the condition of the product.
[0025] It can be understood that the beneficial effects of the above-mentioned second aspect to the fifth aspect can be referred to the related description in the above-mentioned first aspect, which will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or prior art description will be briefly introduced as follows. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.
[0027] Figure 1 is the first flowchart of the detection method provided by an embodiment of the present application;
[0028] Figure 2 is an example diagram of the initial image provided by an embodiment of the present application;
[0029] Figure 3 is the first example diagram of the first registration map provided by an embodiment of the present application;
[0030] Figure 4 is the second example diagram of the first registration map provided by an embodiment of the present application;
[0031] Figure 5 is an example diagram of the first to-be-detected image provided by an embodiment of the present application;
[0032] Figure 6 is the second flowchart of the detection method provided by an embodiment of the present application;
[0033] Figure 7 is the third example diagram of the first registration map provided by an embodiment of the present application;
[0034] Figure 8is a first example image of the second registration image provided by an embodiment of the present application;
[0035] Figure 9 is a first example image of the third registration image provided by an embodiment of the present application;
[0036] Figure 10 is a first example image of the second to-be-detected image provided by an embodiment of the present application;
[0037] Figure 11 is a second example image of the second to-be-detected image provided by an embodiment of the present application;
[0038] Figure 12 is a fourth example image of the first registration image provided by an embodiment of the present application;
[0039] Figure 13 is a second example image of the second registration image provided by an embodiment of the present application;
[0040] Figure 14 is a second example image of the third registration image provided by an embodiment of the present application;
[0041] Figure 15 is a third example image of the second to-be-detected image provided by an embodiment of the present application;
[0042] Figure 16 is a fourth example image of the second to-be-detected image provided by an embodiment of the present application;
[0043] Figure 17 is a fifth example image of the first registration image provided by an embodiment of the present application;
[0044] Figure 18 is a third example image of the second registration image provided by an embodiment of the present application;
[0045] Figure 19 is a third example image of the third registration image provided by an embodiment of the present application;
[0046] Figure 20 is a fifth example image of the second to-be-detected image provided by an embodiment of the present application;
[0047] Figure 21 is a sixth example image of the second to-be-detected image provided by an embodiment of the present application;
[0048] Figure 22 is a first example image of the detection condition provided by an embodiment of the present application;
[0049] Figure 23 is a second example image of the detection condition provided by an embodiment of the present application;
[0050] Figure 24 is a structural schematic diagram of a detection device provided by an embodiment of the present application;
[0051] Figure 25 is a structural schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0052] In the following description, for the purposes of explanation and not limitation, specific details are set forth, such as particular system configurations, techniques, etc., in order to provide a thorough understanding of the embodiments of the application. However, it will be apparent to those skilled in the art that the application can be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known methods, devices, circuits, and
[0053] It should be understood that the term "comprises" when used in this specification and the appended claims, specifies the presence of stated features, integers, steps, operations, elements, and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0054] It should also be understood that the term "and / or" when used in this specification and the appended claims, means any one or more of the associated listed items can be present, and includes multiples of any item, and permutations of those multiples.
[0055] As used in this specification and the appended claims, the term "if" can be interpreted as meaning "when," or "once," or "in response to determining," or "in response to detecting," depending on the context. Similarly, the phrase "if it is determined" or "if [a described condition or event] is detected" can be interpreted to mean "once it is determined," or "in response to determining," or "once [the described condition or event] is detected," or "in response to detecting [the described condition or event]," depending on the context.
[0056] In addition, the terms "first," "second," "third," etc. are used herein only to describe different instances of elements, and are not intended to imply or suggest relative importance of the elements.
[0057] Reference throughout this application to "one embodiment" or "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment. Thus, the appearances of the phrase "in one embodiment" or "in an embodiment" in various places throughout this specification are not necessarily all referring to the same embodiment, but can refer to one or more, but not all, embodiments. The terms "including," "comprising," "having" and variations thereof are meant to encompass the items listed thereafter, but do not exclude other items from also being present. The term "consisting of" is meant to exclude any item not specified, but "consisting essentially of" permits the inclusion of additional items provided that the additional items do not materially alter the basic characteristics of the application.
[0058] In one embodiment, as shown in FIG. 1, the method comprises: Figure 1
[0059] S11: In response to a first operation of a user, acquiring a first registration image under at least two exposure conditions.
[0060] The first registration image includes an image area of a qualified product, and the at least two exposure conditions include an optimal exposure condition and at least one candidate exposure condition, the candidate exposure condition is determined according to the optimal exposure condition, and the parameters of each candidate exposure condition are different.
[0061] In one possible implementation, step S11 comprises:
[0062] S111: In response to the first operation of the user, capturing an initial image of the qualified product.
[0063] In an application, the user places the qualified product in the shooting area of the camera device, clicks on the registration, and instructs the camera device to perform the shooting operation. The electronic device controls the camera device to capture the initial image of the qualified product in response to the first operation of the user.
[0064] The product is a workpiece, a component, a part, etc.
[0065] S112: Extracting an image area of the qualified product in the initial image, adjusting the brightness of the image area of the qualified product to a target brightness, and obtaining a first registration image under the optimal exposure condition.
[0066] In the application, when the initial image is not clear enough, the subsequent feature extraction is affected, but the brightness of the overall image is adjusted, which cannot distinguish the product from the background, and thus the product cannot be highlighted, resulting in poor product image area extraction effect. Therefore, the brightness of the product and the background is not used as a feedback value to adjust the image brightness, and the brightness of the background is not introduced as interference information, the position of the product in the initial image is recognized, and then the brightness of the image area of the qualified product is used as a feedback to adjust the exposure condition, so that the brightness of the image area of the qualified product is adjusted to the target brightness. When adjusted to the target brightness, the exposure condition at this time obtains the best exposure condition and the first registration map of the best exposure condition. The exposure condition can be exposure time.
[0067] In a possible implementation, the method for positioning the product is a gradient method, the gradient amplitude of each pixel point of the image is obtained by gradient calculation, and then some gradients with large product edge are filtered out in an adaptive manner, and then the gradients enclosing the edge can determine the image area of the workpiece.
[0068] The target brightness is determined according to a brightness that can better display the details of the product. For example, the target brightness is 128.
[0069] As shown in the figure, Figure 2 The initial image contains a qualified product, the qualified product of the initial image is not clear enough, and the details are not obvious enough. The initial image is adjusted. Figure 3 The first registration map is the first registration map, the brightness of the qualified product of the first registration map is the target brightness, the details are obvious, and the image area of the qualified product is distinguished from the background.
[0070] S113: determining at least one candidate exposure condition according to the best exposure condition.
[0071] In practice, although the best brightness that highlights the product details is obtained, the best brightness may be affected by external light. By calibrating the images of multiple exposure conditions, the exposure condition that is least affected by the external environment is selected, and the exposure condition that can resist external interference and maintain stable detection is obtained. Selecting the exposure condition near the best exposure condition, at least one candidate exposure condition is obtained.
[0072] The best exposure condition can be the best exposure time. Selecting a preset number of exposure times lower than the best exposure time and selecting a preset number of exposure conditions higher than the best exposure time, the candidate exposure times from dark to light are obtained.
[0073] For example, the preset number is four. The formula for calculating the maximum value and the minimum value is , n is the nth exposure time, a = 2.8561, b = 0.3, Tmin is the minimum exposure time, Tmax is the maximum exposure time, Tbest is the best exposure time, a, b are determined according to actual experience. The candidate exposure time calculation formula: (Tbest / 2.8561) / 0.3+(n-1)(Tbest / 2.8561), the first candidate exposure time: (Tbest / 2.8561), the second candidate exposure time: (Tbest / 2.8561) / 0.3+(Tbest / 2.8561), and so on, to obtain the required exposure time. The best exposure time obtained is 864us, then according to the formula, the exposure time is obtained in turn (1) 302us, (2) 393us, (3) 511us, (4) 664us, (5) 864us, (6) 1123us, (7) 1459us, (8) 1896us, (9) 1896us. Because the minimum exposure time and the maximum exposure time are set, the exposure time (9) is limited to 1896us.
[0074] S114: For each candidate exposure condition, an image of the qualified product is collected to obtain a first registration image of the candidate exposure condition.
[0075] In application, after obtaining the candidate exposure condition, the shooting device performs a shooting operation to collect the first registration image of each candidate exposure condition.
[0076] S12: In response to a second operation of the user, a second registration image under at least two exposure conditions is obtained.
[0077] The second registration image is a background image not including the product.
[0078] In application, the user removes the qualified product in the shooting area of the camera device, and clicks on the registration to instruct the camera device to perform a shooting operation. In response to the second operation of the user, the electronic device controls the camera device to collect images not including the product under each exposure condition to obtain the second registration image under each exposure condition.
[0079] In a possible implementation, the user can adjust the shooting area of the camera device, which can reduce the possibility of adjusting the position of the camera device due to changes in product types.
[0080] S13: Calculate the first similarity between the first registration image and the second registration image under each exposure condition.
[0081] In a possible implementation, step S13 includes:
[0082] S131: For each exposure condition, extract the first features of the first registration image and the second registration image.
[0083] In application, the first registration image and the second registration image are differentially processed for each exposure condition, the background information of the first registration image is removed, the position of the qualified product is located by using the gradient algorithm, the image area of the qualified product is extracted, and then the features of the qualified product in the first registration image are extracted to obtain the first features of the first registration image. The image features of the second registration image are extracted to obtain the first features of the second registration image.
[0084] Among them, the first features include features of different dimensions, including contour features, brightness features, edge point features, etc., so as to stably and accurately detect the product.
[0085] S132: For each first feature, the first feature similarity between the first features of the first registration image and the first features of the second registration image is calculated, and the weight of the first feature is determined according to the first feature similarity.
[0086] In application, the feature dimensions of each first feature are the same or different, and if the weights of all first features are the same or a high-similarity first feature is incorrectly assigned a high weight, the overall similarity between the first registration image and the second registration image is inaccurate. Therefore, the weight of the low-similarity second feature is increased, the weight of the high-similarity second feature is decreased, the feature weight is intelligently assigned, the defects and differences are amplified, the defects and rotation changes can be detected, and the stable and accurate classification of the qualified product is realized.
[0087] For example, the first features are feature 1 and feature 2. The weight of feature 1 is (preset maximum similarity-feature 1 first feature similarity) / (preset maximum similarity-feature 1 first feature similarity)+(preset maximum similarity-feature 2 first feature similarity).
[0088] S133: Determine the first similarity according to the weight of each first feature and the first feature similarity.
[0089] In application, the first similarities of each first feature are weighted and summed to obtain the first similarity.
[0090] S14: Determine the first threshold value according to the first similarity of each exposure condition.
[0091] In application, the average fluctuation similarity of each exposure condition is determined according to the first similarity of each exposure condition. The target exposure condition with the smallest first similarity and the smallest average fluctuation similarity is selected from the exposure conditions. The first threshold value is determined according to the first similarity of the target exposure condition.
[0092] Specifically, the exposure conditions are sorted according to the parameters of the exposure conditions to obtain a sorted exposure condition sequence; in the sorted exposure condition sequence, for each exposure condition, a similarity difference between the first similarity of the exposure condition and the first similarity of the adjacent exposure condition is calculated, and an average fluctuation similarity is determined according to the similarity differences; the target exposure condition is determined according to the first similarity of each exposure condition and the average fluctuation similarity, the target exposure condition is that the first similarity is less than a fifth threshold value and the average fluctuation similarity is less than a sixth threshold value, the fifth threshold value is determined according to the first similarity of the first third number of small values, and the sixth threshold value is determined according to the average fluctuation similarity of the first fourth number of small values; and the second threshold value is determined according to the first similarity of the target exposure condition.
[0093] In a possible implementation, a formula for calculating the first threshold value is: the first threshold value = (the first similarity of the target exposure condition + a preset highest similarity) / 2.
[0094] S15: Obtain the first to-be-detected image.
[0095] In an application, the detection evaluation is entered, the camera device performs a shooting operation, an image of a shooting area is collected, the first to-be-detected image is obtained, and the detection of the product on the production line is realized.
[0096] S16: Calculate the second similarity between the first to-be-detected image and the first registered image.
[0097] In an application, the features of the first to-be-detected image and the first registered image are extracted. For each feature, the similarity between the feature of the first to-be-detected image and the feature of the first registered image is calculated. The second similarity is determined according to the similarity and the weight of each feature.
[0098] In a possible implementation, the whole image is taken as the scoring area by using the whole method, and then the features of the first to-be-detected image are extracted. An example diagram is provided to illustrate, Figure 4 a first registered image of a noodle type, Figure 5 a first to-be-detected image of a noodle type. In actual production, the placement position of the noodles in the production line is prone to change, so that the gap of the noodles is greatly different from the gap of the noodles in the first registered image, and the shapes are different, so that the positioning is inaccurate, and the whole image is taken as the scoring area by using the whole method.
[0099] S17: Determine the detection type to which the first to-be-detected image belongs according to the first threshold value and the second similarity.
[0100] In an application, when the second similarity is greater than or equal to the first threshold value, it is determined that the to-be-detected product in the first to-be-detected image is a qualified product.
[0101] When the second similarity is less than the first threshold, the first to-be-detected image is determined as a background image.
[0102] It should be noted that the threshold is calculated according to the first registration image and the second registration image, and the threshold is used to determine whether the product in the first to-be-detected image is a qualified product or whether the first to-be-detected image does not contain a product and is a background image. The detection mode is a two-point tuning mode. The two-point tuning mode registers two images, and because the images are sampled in a plane, the position of the product is different each time the image is captured, which does not affect the detection. In the case of a clean and stable background, a product shape that may change greatly, a product posture that is easy to rotate or a product posture that is not easy to rotate, etc., the product can be detected by the brightness feature to determine whether the product exists. Because the product is detected, the product is not detected whether it is rotated, and the rotated product is directly detected, so that the direction of the product can be known at the same time.
[0103] In the embodiment, the first registration image under at least two exposure conditions is acquired in response to a first operation of a user, and the first registration image includes an image area of a qualified product. The second registration image under at least two exposure conditions is acquired in response to a second operation of the user, and the second registration image is a background image that does not include a product. The first similarity between the first registration image and the second registration image under each exposure condition is calculated. The first threshold is determined according to the first similarity of each exposure condition. The appropriate threshold can be determined according to the actual situation of the product on the production line, which provides a basis for accurately determining the type of the product. The first to-be-detected image is acquired. The second similarity between the first to-be-detected image and the first registration image is calculated. The detection type to which the first to-be-detected image belongs is determined according to the first threshold and the second similarity, and the situation of the product is accurately determined.
[0104] In one embodiment, as shown in FIG. 1, the method further includes: Figure 6
[0105] S21: In response to a third operation of a user, a third registration image under at least two exposure conditions is acquired.
[0106] The third registration image includes an image area of an unqualified product.
[0107] In an application, the user places an unqualified product in the shooting area of the camera device, and the user clicks to register and instructs the camera device to perform a shooting operation. The electronic device acquires the image of the unqualified product under each exposure condition in response to the third operation of the user, and obtains the third registration image under each exposure condition.
[0108] The unqualified product is a product of the same type as the qualified product but is unqualified, or a product that is not of the same type as the qualified product, so that the to-be-detected product is detected as an unqualified product or a product of another type in subsequent detection.
[0109] S22: Calculate the third similarity between the first registration map and the third registration map under each exposure condition.
[0110] In one possible way, step S22 comprises:
[0111] S221: Extract the second features of the qualified products in the first registration map and the second features of the unqualified products in the third registration map for each exposure condition.
[0112] In application, the third registration map is differentially processed with the second registration map for each exposure condition, the background information of the third registration map is removed, the position of the unqualified products is located by using gradient algorithm, the image area of the unqualified products is extracted, and then the second features of the unqualified products in the third registration map are extracted. The second features of the qualified products in the first registration map are extracted in the same way.
[0113] Among them, the second features include different dimensional features, including contour features, brightness features, edge point features, etc., so as to stably and accurately detect the products.
[0114] S222: Calculate the second feature similarity between the second features of the qualified products and the second features of the unqualified products for each second feature, and determine the weight of the second feature according to the second feature similarity.
[0115] In application, the similarity of each second feature between the qualified products and the unqualified products is calculated to obtain the second feature similarity.
[0116] The feature dimensions of each second feature are different or the same, and if the weights of all second features are the same or the high-similarity second features are wrongly assigned with high weights, the overall similarity between the first registration map and the third registration map will be inaccurate. For example, when there is a small defect, the high-similarity second feature will make it difficult to distinguish the unqualified products from the qualified products, resulting in a high overall similarity between the unqualified products and the qualified products, and making it difficult to stably distinguish between the two. Therefore, the low-similarity second feature is upgraded in weight, the high-similarity second feature is downgraded in weight, the feature weight is intelligently assigned, the defects and differences are amplified, the defects, rotation changes, etc. can be detected, and the qualified products and the unqualified products can be stably and accurately classified.
[0117] For example, the second features are feature 1, feature 2, feature 3, feature 4, and feature 5. The second feature similarity of feature 1 is 400, the second feature similarity of feature 2 is 1000, the second feature similarity of feature 3 is 200, the second feature similarity of feature 3 is 900, and the second feature similarity of feature 4 is 600. Among them, 1000 is the preset highest similarity.
[0118] The weight of feature 1 is (1000-400) / ((1000-400)+(1000-1000)+(1000-200)+(1000-900)+(1000-600)=0.32%, and the weights of feature 2, feature 3, feature 4 and feature 5 are 0%, 0.42%, 0.05% and 0.21% respectively. Since feature 2 is similar to the qualified product and the unqualified product, feature 2 is deleted by assigning a weight of 0% to improve the stability of detection.
[0119] S223: Determine the third similarity according to the weight of each second feature and the second feature similarity.
[0120] In an application, the third similarity is obtained by weighted sum of each second feature similarity.
[0121] For example, the third similarity=(weight of feature 1 x second feature similarity of feature 1)+(weight of feature 2 x second feature similarity of feature 2)+(weight of feature 3 x second feature similarity of feature 3)+(weight of feature 4 x second feature similarity of feature 4)+(weight of feature 5 x second feature similarity of feature 5).
[0122] S23: Determine the second threshold according to the third similarity of each exposure condition.
[0123] In a possible implementation, step S23 includes:
[0124] S231: Sort each exposure condition according to the parameters of each exposure condition to obtain a sorted exposure condition sequence.
[0125] For example, the sorted exposure condition sequence is obtained by sorting from dark to light: (1) 302us, (2) 393us, (3) 511us, (4) 664us, (5) 864us, (6) 1123us, (7) 1459us, (8) 1896us, (9) 1896us.
[0126] S232: Calculate the similarity difference between the third similarity of each exposure condition and the third similarity of the adjacent exposure condition in the sorted exposure condition sequence, and determine the average fluctuation similarity according to each similarity difference.
[0127] In an application, the similarity difference between each exposure condition and the adjacent two exposure conditions is calculated. The average fluctuation similarity of the exposure condition is determined according to the two similarity differences.
[0128] For example, the third similarity of the exposure condition 1 is 550, the third similarity of the exposure condition 2 is 500, the third similarity of the exposure condition 3 is 450, the third similarity of the exposure condition 4 is 500, the third similarity of the exposure condition 5 is 550, the third similarity of the exposure condition 6 is 650, the third similarity of the exposure condition 7 is 300, the third similarity of the exposure condition 8 is 400, and the third similarity of the exposure condition 9 is 700. The third similarity of the exposure condition 7 is 300, and the average fluctuation similarity of the exposure conditions 6 and 8 is 225. The third similarity of the exposure condition 8 is 400, and the average fluctuation similarity of the exposure conditions 7 and 9 is 200.
[0129] S233: determining the target exposure condition according to the third similarity and the average fluctuation similarity of each exposure condition.
[0130] In the formula, the target exposure condition is the third similarity less than a third threshold value and the average fluctuation similarity less than a fourth threshold value, the third threshold value is determined according to the first quantity of small third similarities, and the fourth threshold value is determined according to the second quantity of small average fluctuation similarities.
[0131] The first quantity and the second quantity are determined according to specific conditions to obtain the target exposure condition with the third similarity as small as possible and the average fluctuation similarity as small as possible.
[0132] In application, the smaller the third similarity is, the more the qualified products and unqualified products can be distinguished, and the smaller the average fluctuation similarity is, the less the brightness change caused by external illumination affects the subsequent detection results. The target exposure condition with the third similarity as small as possible and the average fluctuation similarity as small as possible is selected from the exposure conditions to find the exposure condition in which the details of the product under external illumination are obvious.
[0133] For example, the third similarity of the exposure condition 7 is 300, and the average fluctuation similarity of the exposure conditions 6 and 8 is 225. The third similarity of the exposure condition 8 is 400, and the average fluctuation similarity of the exposure conditions 7 and 9 is 200. The third similarity of the exposure condition 8 is the second smallest, and the average fluctuation similarity of the exposure condition 8 is smaller than the average fluctuation similarity of the exposure condition 7, so the exposure condition 8 is determined as the target exposure condition.
[0134] S234: determining the second threshold value according to the third similarity of the target exposure condition.
[0135] In a possible implementation, the formula for calculating the second threshold value is: the second threshold value=(the third similarity of the target exposure condition+the preset highest similarity) / 2.
[0136] For example, 700=(400+1000) / 2.
[0137] S24: Obtain a second to-be-detected image.
[0138] In application, in the detection evaluation, the camera device performs the shooting operation, collects the image of the shooting area, and obtains the second to-be-detected image.
[0139] S25: Calculate a fourth similarity between the second to-be-detected image and the first registered image.
[0140] In a possible implementation, the step S25 comprises:
[0141] S251: Perform product positioning on the second to-be-detected image.
[0142] In a possible implementation, the product positioning is performed by using a search method to narrow down the scoring area. The search method uses a cross-correlation algorithm and a contour algorithm for positioning. The contour algorithm uses gradient to calculate the edge point position information of the product, to obtain a series of point sets, which represent the contour information of the product. In the search, the series of point sets are used to search for the position corresponding to the most edge points as the positioning point of the product in the point search manner. The contour algorithm is simple and efficient, and has high positioning accuracy and short positioning time. For example, the contour algorithm takes 200 us to position the product on a 480 Mhz MCU.
[0143] In use, the positioning algorithm can be selected according to the response time required by the user. For example, when the user requires a lower response time, the electronic device selects an algorithm that takes less time, or replaces the cross-correlation algorithm for positioning with the contour positioning algorithm, which can adapt to high-frame-rate camera devices for high-speed detection.
[0144] S252: If the product is detected in the second to-be-detected image, extract the to-be-detected product and extract a third feature of the to-be-detected product.
[0145] In application, the to-be-detected product is compared with the qualified product to detect the rotation direction of the product. When the rotation direction of the product is detected, the electronic device calculates the images of multiple rotation directions by affine transformation, and extracts the third feature of the to-be-detected product in the images of the rotation directions.
[0146] When the product direction defect is detected, the electronic device directly obtains the third feature of the to-be-detected product in the second to-be-detected image.
[0147] By extracting the to-be-detected product, the background information is excluded, and the background interference is eliminated, thereby providing a basis for subsequent accurate similarity calculation and detection type determination.
[0148] S253: Compare the third feature of the to-be-detected product with the third feature of the qualified product to obtain the fourth similarity.
[0149] In application, the third feature of the qualified product of the first registration image is extracted.
[0150] When detecting the rotation direction of the product, for the product to be detected in each rotation direction, the electronic device compares the third feature of the product to be detected with the third feature of the qualified product, calculates the third feature similarity of each third feature, determines the weight of the third feature according to the third feature similarity, and performs weighted summation according to the weight of each third feature and the third feature similarity to obtain a fourth similarity.
[0151] When detecting the product direction defect, the electronic device directly compares the third feature of the product to be detected in the second to-be-detected image with the third feature of the qualified product, and determines the fourth similarity in the same way.
[0152] Or, S254: If no product is detected in the second to-be-detected image, the fourth feature of the second to-be-detected image is extracted.
[0153] In application, when the product is not located, the electronic device directly extracts the image feature of the second to-be-detected image to obtain the fourth feature, and extracts the fourth feature of the qualified product of the first registration image.
[0154] S255: Compare the fourth feature of the second to-be-detected image with the fourth feature of the qualified product to obtain a fourth similarity.
[0155] In application, for each fourth feature, the electronic device compares the fourth feature of the second to-be-detected image with the fourth feature of the qualified product, calculates the fourth feature similarity of each fourth feature, determines the weight of the fourth feature according to the fourth feature similarity, and performs weighted summation according to the weight of each fourth feature and the fourth feature similarity to obtain a fourth similarity.
[0156] It can be understood that during detection and evaluation, through product positioning and feature similarity between the product to be detected and the qualified product, the difference is recorded in detection during weight distribution, so as to accurately detect the detection type of the product to be detected.
[0157] S26: Determine the detection type to which the second to-be-detected image belongs according to the second threshold value and the fourth similarity.
[0158] In application, when the fourth similarity is greater than or equal to the second threshold value, it is determined that the product to be detected in the second to-be-detected image is a qualified product.
[0159] When the product is detected and the fourth similarity is less than the second threshold value, it is determined that the product to be detected in the second to-be-detected image is an unqualified product or a certain type of product.
[0160] When no product is detected and the fourth similarity is less than the second threshold value, it is determined that the second to-be-detected image is a background image.
[0161] When detecting the rotation direction of the product, the image with the largest similarity is selected from the fourth similarities of the images in each rotation direction. The type of the second image to be detected is determined according to the largest similarity, so that the qualified product or unqualified product can be detected after the product is rotated, and the rotation angle can also be obtained.
[0162] When detecting the direction defect of the product, the type of the second image to be detected is determined according to the fourth similarity. Whether there is a direction defect is determined according to the similarity of the contour feature and the like. The low similarity of the contour feature indicates that there is a direction defect, and the high similarity of the contour feature indicates that there is no direction defect.
[0163] For better understanding, each example diagram is described. Figure 7 is a first registration image of a certain type, Figure 8 is a second registration image of a certain type, Figure 9 is a third registration image of a certain type. Figure 10 is a qualified product in a second image to be detected of a certain type, wherein 966 is a fourth similarity, and 837 is a second threshold value. Figure 11 is an unqualified product in a second image to be detected of a certain type, wherein 568 is a fourth similarity, and 837 is a second threshold value.
[0164] Figure 12 is a first registration image of another type, Figure 13 is a second registration image of another type, Figure 14 is a third registration image of another type. Figure 15 is a qualified product in a second image to be detected of a certain type, wherein 903 is a fourth similarity, and 692 is a second threshold value. Figure 16 is an unqualified product in a second image to be detected of a certain type, wherein 349 is a fourth similarity, and 692 is a second threshold value.
[0165] When detecting the rotation direction of the product, the product can also be detected after the product is rotated. Figure 17 is a first registration image of another type, Figure 18 is a second registration image of another type, Figure 19 is a third registration image of another type. Figure 20 is a qualified product in a second image to be detected of a certain type, wherein 878 is a fourth similarity, and 509 is a second threshold value. Figure 21 is a qualified product in a second image to be detected of a certain type, wherein 830 is a fourth similarity, and 509 is a second threshold value.
[0166] It should be noted that the threshold is calculated according to the first registration map and the third registration map, the threshold is used to determine whether the product in the second to-be-detected image is a qualified product or an unqualified product, or to determine whether the second to-be-detected image is a background image, and the detection mode is a three-point tuning mode. The three-point tuning mode registers three images, and can detect product defects, types, and rotation directions through shape, brightness, and other characteristics in the case of background interference and single product shape. Since the product defects are detected, it can be detected whether the product is rotated, and the product rotation angle can also be obtained at the same time.
[0167] The third registration map including the image area of the unqualified product is obtained under at least two exposure conditions in response to a third operation of the user, the third similarity between the first registration map and the third registration map under each exposure condition is calculated, the second threshold is determined according to the third similarity of each exposure condition, the appropriate threshold can be determined according to the actual situation of the product on the production line, which provides a basis for accurately determining the type of the product, and the second to-be-detected image is obtained, the fourth similarity between the second to-be-detected image and the first registration map is calculated, the detection type to which the second to-be-detected image belongs is determined according to the second threshold and the fourth similarity, and the condition of the product is accurately determined.
[0168] It can be understood that the user indicates the device to collect the registration image through two or three operations, the device automatically selects the appropriate detection condition according to the plurality of registration images, and then calculates the appropriate threshold, and then detects the detection type of the to-be-detected image based on the appropriate threshold, so that the product is simply, accurately and efficiently detected in terms of presence, rotation direction, product defect, and the like, the requirement for the operator (user) is reduced, the operator can operate the device for detection without adjusting or training any parameter, the detection operation is simple, and a large amount of product data is collected and calibrated before detection, so that the detection is simple and efficient.
[0169] In one embodiment, the method further comprises:
[0170] Data in the detection process is stored, and the data includes registration image data, feature data of the image, weight data of the feature, and threshold data.
[0171] The data in the detection process is stored, power failure protection is realized, the user can directly select or switch the data after the device is powered on, the parameters can be quickly set for product detection, and the time for detection deployment is reduced.
[0172] In one embodiment, the method further comprises:
[0173] The first target value in the detection process, the first target image corresponding to the first target value and the second target value, and the second target image corresponding to the second target value are displayed. The first target value is an extreme value in the plurality of second similarities. The second target value is an extreme value in the plurality of fourth similarities.
[0174] The guidance animation, the similarity statistical value, the image corresponding to the similarity statistical value, and each registered image are displayed.
[0175] In the application, the image with the maximum similarity in the detection process is displayed, so that the user knows whether there is an abnormal workpiece in the production line operation process. Or the maximum similarity and its image are output when the detection is a non-conforming product, and the minimum similarity and its image are output when the detection is a conforming product, so that the user knows the maximum similarity and its image in the process from detecting a conforming product to detecting a non-conforming product, and the minimum similarity and its image in the process from detecting a non-conforming product to detecting a conforming product.
[0176] In the detection evaluation, Figure 22 The image with the maximum similarity in the detection process is MAX, and the image with the minimum similarity in the detection process is MIN.
[0177] Figure 23 The image with the minimum similarity when the current detection is a non-conforming product is BTM. PEAK represents the maximum similarity when the detection is a conforming product. Pmin represents the minimum similarity and its image in the history process of PEAK, so that the user knows the maximum setting amount of the threshold in the process of detecting a conforming product. Bmax represents the maximum similarity and its image in the history process of BTM, so that the user knows the minimum threshold setting amount to prevent false detection in the process of detecting a non-conforming product.
[0178] The first target image corresponding to the first target value in the detection process and the second target image corresponding to the second target value are displayed, so that the user can observe the state of the production line operation process, thereby providing a basis for the user to adjust and optimize the detection method, and guiding the user to operate through a series of demonstration animations to enable the user to quickly deploy, further reduce the requirements for the operator, and improve the detection speed.
[0179] It should be understood that the size of the serial number of each step in the above embodiments does not mean the order of execution. The execution order of each process should be determined according to its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. In addition, the data collection in the above embodiments is in compliance with the law, and its use or implementation does not involve any harm to the public interest.
[0180] Corresponding to the method described in the above embodiment, only the part related to the embodiment of the present application is shown for the convenience of illustration.
[0181] In one embodiment, Figure 24 is a structural schematic diagram of a detection device provided by an embodiment of the present application. The device comprises:
[0182] The processing module 10 is configured to, in response to a first operation of a user, acquire a first registration image under at least two exposure conditions, the first registration image comprising an image region of a qualified product, the at least two exposure conditions comprising an optimal exposure condition and at least one candidate exposure condition, the candidate exposure condition being determined according to the optimal exposure condition, and the parameters of each candidate exposure condition being different.
[0183] The processing module 10 is also configured to, in response to a second operation of the user, acquire a second registration image under the at least two exposure conditions, the second registration image being a background image not comprising a product.
[0184] The detection calculation module 11 is configured to calculate a first similarity between the first registration image and the second registration image under each exposure condition.
[0185] The detection calculation module 11 is also configured to determine a first threshold value according to the first similarity of each exposure condition.
[0186] The detection evaluation module 12 is configured to acquire a first to-be-detected image.
[0187] The detection evaluation module 12 is also configured to calculate a second similarity between the first to-be-detected image and the first registration image.
[0188] The detection evaluation module 12 is also configured to determine a detection type to which the first to-be-detected image belongs according to the first threshold value and the second similarity.
[0189] In one embodiment, the processing module is also configured to, in response to a third operation of the user, acquire a third registration image under the at least two exposure conditions, the third registration image comprising an image region of an unqualified product.
[0190] The detection calculation module is also configured to calculate a third similarity between the first registration image and the third registration image under each exposure condition, and determine a second threshold value according to the third similarity of each exposure condition.
[0191] The detection evaluation module is also configured to acquire a second to-be-detected image, calculate a fourth similarity between the second to-be-detected image and the first registration image, and determine a detection type to which the second to-be-detected image belongs according to the second threshold value and the fourth similarity.
[0192] In one embodiment, the processing module is specifically configured to, in response to a first operation of a user, capture an initial image of the qualified product, the initial image comprising an image region of the qualified product; extract the image region of the qualified product in the initial image and adjust brightness of the image region of the qualified product to a target brightness to obtain a first registration image under optimal exposure conditions; determine at least one candidate exposure condition according to the optimal exposure condition; and capture images of the qualified product for each candidate exposure condition to obtain a first registration image under the candidate exposure condition.
[0193] In one embodiment, the detection calculation module is specifically configured to, for each exposure condition, extract a first feature of the first registration image and a first feature of the second registration image; calculate, for each first feature, a first feature similarity between the first feature of the first registration image and the first feature of the second registration image, and determine a weight of the first feature according to the first feature similarity; and determine a first similarity according to the weight and the first feature similarity of each first feature.
[0194] In one embodiment, the detection calculation module is specifically configured to, for each exposure condition, extract a second feature of the qualified product in the first registration image and a second feature of the unqualified product in the third registration image; calculate, for each second feature, a second feature similarity between the second feature of the qualified product and the second feature of the unqualified product, and determine a weight of the second feature according to the second feature similarity; and determine a third similarity according to the weight and the second feature similarity of each second feature.
[0195] In one embodiment, the detection calculation module is specifically configured to sort the exposure conditions according to parameters of the exposure conditions to obtain a sorted exposure condition sequence; and in the sorted exposure condition sequence, for each exposure condition, calculate a similarity difference between the third similarity of the exposure condition and the third similarity of an adjacent exposure condition, and determine an average fluctuation similarity according to each similarity difference; determine a target exposure condition according to the third similarity of each exposure condition and the average fluctuation similarity, the target exposure condition being a third similarity less than a third threshold value and an average fluctuation similarity less than a fourth threshold value, the third threshold value being determined according to a first number of small third similarities, and the fourth threshold value being determined according to a second number of small average fluctuation similarities; and determine a second threshold value according to the third similarity of the target exposure condition.
[0196] In one embodiment, the detection evaluation module is specifically configured to perform object positioning on the second to-be-detected image; if an object is detected in the second to-be-detected image, extract the to-be-detected object and extract a third feature of the to-be-detected object; compare the third feature of the to-be-detected object with the third feature of the qualified product to obtain a fourth similarity; or, if no object is detected in the second to-be-detected image, extract a fourth feature of the second to-be-detected image; and compare the fourth feature of the second to-be-detected image with the fourth feature of the qualified product to obtain the fourth similarity.
[0197] In one embodiment, the apparatus further comprises a storage module.
[0198] The storage module is configured to store data in the detection process, the data comprising registered image data, feature data of the image, weight data of the feature, threshold data.
[0199] In one embodiment, the apparatus further comprises a display module.
[0200] The display module is configured to display the first target value, the first target image corresponding to the first target value and the second target value, and the second target image corresponding to the second target value in the detection process, the first target value being an extreme value in the plurality of second similarities, and the second target value being an extreme value in the plurality of fourth similarities.
[0201] The display module is further configured to display a guide animation, a similarity statistical value, an image corresponding to the similarity statistical value, and each registered image.
[0202] In one embodiment, the apparatus further comprises a setting module.
[0203] The setting module is configured to provide setting options, wherein the setting options comprise a response time setting option, a threshold adjustment setting option, a detection range setting option, and a tuning algorithm setting option.
[0204] Figure 25 A structural schematic diagram of an electronic device according to an embodiment of the present application is shown in FIG. 2. As shown in FIG. 2, the electronic device 2 according to the embodiment comprises at least one processor 20 (only one processor is shown in the figure), a memory 21, and a computer program 22 stored in the memory 21 and executable on the at least one processor 20, wherein the processor 20 implements the steps in any of the method embodiments described above when executing the computer program 22. Figure 25 Figure 25 The electronic device 2 can include, but is not limited to, the processor 20 and the memory 21. Those skilled in the art can understand that the electronic device 2 shown in the figure is only an example and does not constitute a limitation on the electronic device 2, and the electronic device 2 can include more or fewer components than those shown in the figure, or combine certain components, or different components, for example, the electronic device 2 can also include an input / output device, a network access device, etc.
[0205] The electronic device 2 can include, but is not limited to, the processor 20 and the memory 21. Those skilled in the art can understand that the electronic device 2 shown in the figure is only an example and does not constitute a limitation on the electronic device 2, and the electronic device 2 can include more or fewer components than those shown in the figure, or combine certain components, or different components, for example, the electronic device 2 can also include an input / output device, a network access device, etc. Figure 25
[0206] The processor 20 can be a central processing unit (CPU), and can also be other general-purpose processors, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.
[0207] The memory 21 can be an internal storage unit of the electronic device 2 in some embodiments, for example, a hard disk or a memory of the electronic device 2. The memory 21 can also be an external storage device of the electronic device 2 in other embodiments, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. Further, the memory 21 can include both the internal storage unit and the external storage device of the electronic device 2. The memory 21 is used to store an operating system, an application program, a boot loader, data and other programs, for example, program codes of the computer program, etc. The memory 21 can also be used to temporarily store data that has been output or is to be output.
[0208] It should be noted that the information interaction, execution process, etc. between the above apparatuses / units, since based on the same concept as the method embodiments of the present application, the specific functions and the brought technical effects can be referred to the method embodiments part, and will not be described here in detail.
[0209] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of each functional unit and module is exemplified, and in actual application, the above-mentioned functions can be completed by different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or software function unit. In addition, the specific name of each functional unit and module is only for easy distinction, and does not limit the protection scope of the present application. The specific working process of the unit and module in the above system can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
[0210] The embodiment of the present application further provides a computer readable storage medium, the computer readable storage medium stores a computer program, and the computer program is executed by a processor to realize the steps in each method embodiment.
[0211] The embodiment of the present application provides a computer program product, when the computer program product runs on an electronic device, so that the electronic device executes the steps in each method embodiment.
[0212] The integrated unit, if realized in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on this understanding, the present application realizes all or part of the processes in the above-mentioned embodiment methods, which can be completed by a computer program instructing related hardware. The computer program can be stored in a computer readable storage medium, and the computer program can realize the steps in each method embodiment when executed by a processor. The computer program includes computer program code, which can be in the form of source code, object code, executable file or some intermediate form, etc. The computer readable medium at least includes any entity or device capable of carrying the computer program code to the photographing device / terminal equipment, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium. For example, U disk, mobile hard disk, magnetic disk or optical disk, etc. In some cases, the computer readable medium can not be an electrical carrier signal and a telecommunication signal.
[0213] In the above embodiments, the description of each embodiment focuses on different aspects, and the parts not described in detail or recorded in a certain embodiment can be referred to the relevant description of other embodiments.
[0214] Those skilled in the art can understand that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0215] In the embodiments provided in the present application, it should be understood that the disclosed apparatus / network device and method can be implemented in other ways. For example, the apparatus / network device embodiments described above are merely schematic, for example, the division of the modules or units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be omitted or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed units can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.
[0216] The units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, that is, they can be located in one place, or can be distributed on a plurality of network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.
[0217] The above described embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.
Claims
1. A method of detection, characterized in that, The method comprises: in response to a first operation of a user, obtaining a first registration image under at least two exposure conditions, the first registration image comprising an image area of a qualified product, the at least two exposure conditions comprising an optimal exposure condition and at least one candidate exposure condition, the candidate exposure condition being determined according to the optimal exposure condition, and parameters of each of the candidate exposure conditions being different; in response to a second operation of the user, obtaining a second registration image under at least two exposure conditions, the second registration image being a background image not comprising a product; calculating a first similarity between the first registration image and the second registration image under each exposure condition; determining a first threshold value according to the first similarity of each exposure condition; obtaining a first to-be-detected image; calculating a second similarity between the first to-be-detected image and the first registration image; determining a detection type to which the first to-be-detected image belongs according to the first threshold value and the second similarity; wherein determining the first threshold value according to the first similarity of each exposure condition comprises: sorting each exposure condition according to the parameters of each exposure condition from dark to light to obtain a sorted exposure condition sequence; for each exposure condition in the sorted exposure condition sequence, calculating a first similarity difference between the first similarity of the exposure condition and the first similarity of an adjacent exposure condition; and determining a first average fluctuation similarity according to each first similarity difference; determining a first target exposure condition according to the first similarity of each exposure condition and the first average fluctuation similarity, the first target exposure condition being a first similarity less than a fifth threshold value and an average fluctuation similarity less than a sixth threshold value, the fifth threshold value being determined according to the first similarity of the first third number of small values, and the sixth threshold value being determined according to the first average fluctuation similarity of the first fourth number of small values; determining the first threshold value according to the first similarity of the first target exposure condition and a preset highest similarity.
2. The method of claim 1, wherein, The method further comprises: in response to a third operation of the user, obtaining a third registration image under at least two exposure conditions, the third registration image comprising an image area of an unqualified product; calculating a third similarity between the first registration image and the third registration image under each exposure condition; determining a second threshold value according to the third similarity of each exposure condition; obtaining a second to-be-detected image; calculating a fourth similarity between the second to-be-detected image and the first registration image; determining a detection type to which the second to-be-detected image belongs according to the second threshold value and the fourth similarity.
3. The method of claim 1, wherein, The method of obtaining the first registration image under at least two exposure conditions in response to the first operation of the user comprises: in response to the first operation of the user, collecting an initial image of the qualified product, the initial image comprising an image area of the qualified product; extracting the image area of the qualified product in the initial image and adjusting the brightness of the image area of the qualified product to a target brightness to obtain the first registration image under the optimal exposure condition; determining at least one candidate exposure condition according to the optimal exposure condition; for each of the candidate exposure conditions, collecting an image of the qualified product to obtain the first registration image under the candidate exposure condition.
4. The method according to any one of claims 1 to 3, characterized in that, The calculating the first similarity between the first registration image and the second registration image under each exposure condition comprises: extracting first features of the first registration image and the second registration image for each exposure condition; calculating a first feature similarity between the first feature of the first registration image and the first feature of the second registration image for each first feature, and determining a weight of the first feature according to the first feature similarity; determining the first similarity according to the weight and the first feature similarity of each first feature.
5. The method of claim 2, wherein, The calculating the third similarity between the first registration image and the third registration image under each exposure condition comprises: extracting second features of the qualified product in the first registration image and second features of the unqualified product in the third registration image for each exposure condition; calculating a second feature similarity between the second feature of the qualified product and the second feature of the unqualified product for each second feature, and determining a weight of the second feature according to the second feature similarity; determining the third similarity according to the weight and the second feature similarity of each second feature.
6. The method of claim 2, wherein, The determining the second threshold according to the third similarity of each exposure condition comprises: sorting each exposure condition according to parameters of each exposure condition to obtain a sorted exposure condition sequence; calculating a second similarity difference between the third similarity of each exposure condition and the third similarity of an adjacent exposure condition in the sorted exposure condition sequence, and determining a second average fluctuation similarity according to each second similarity difference; determining a second target exposure condition according to the third similarity and the second average fluctuation similarity of each exposure condition, the second target exposure condition being that the third similarity is less than a third threshold and the average fluctuation similarity is less than a fourth threshold, the third threshold being determined according to a first number of small third similarities, and the fourth threshold being determined according to a second number of small second average fluctuation similarities; determining the second threshold according to the third similarity of the second target exposure condition.
7. The method according to claim 5 or 6, characterized in that, The calculating the fourth similarity between the second to-be-detected image and the first registration image comprises: performing object positioning on the second to-be-detected image; if an object is detected in the second to-be-detected image, extracting a to-be-detected object and extracting third features of the to-be-detected object; comparing the third features of the to-be-detected object with the third features of the qualified product to obtain the fourth similarity; or, if no object is detected in the second to-be-detected image, extracting fourth features of the second to-be-detected image; comparing the fourth features of the second to-be-detected image with the fourth features of the qualified product to obtain the fourth similarity.
8. A detection device, characterized in that comprises: The processing module is configured to, in response to a first operation of a user, acquire a first registration image under at least two exposure conditions, the first registration image comprising an image region of a qualified product, the at least two exposure conditions comprising an optimal exposure condition and at least one candidate exposure condition, the candidate exposure condition being determined according to the optimal exposure condition, and parameters of the candidate exposure conditions being different from each other; The processing module is further configured to, in response to a second operation of the user, acquire a second registration image under at least two exposure conditions, the second registration image being a background image not comprising a product; The detection calculation module is configured to calculate a first similarity between the first registration image and the second registration image under each exposure condition; The detection calculation module is further configured to determine a first threshold according to the first similarity of each exposure condition; The detection evaluation module is configured to acquire a first to-be-detected image; The detection evaluation module is further configured to calculate a second similarity between the first to-be-detected image and the first registration image; The detection evaluation module is further configured to determine a detection type to which the first to-be-detected image belongs according to the first threshold and the second similarity. The detection calculation module is specifically configured to sort each exposure condition from dark to light to obtain a sorted exposure condition sequence, calculate, for each exposure condition in the sorted exposure condition sequence, a first similarity difference between the first similarity of the exposure condition and the first similarity of an adjacent exposure condition, determine a first average fluctuation similarity according to each first similarity difference, determine a first target exposure condition according to the first similarity of each exposure condition and the first average fluctuation similarity, the first target exposure condition being a first similarity smaller than a fifth threshold and an average fluctuation similarity smaller than a sixth threshold, the fifth threshold being determined according to a first quantity of small first similarities, the sixth threshold being determined according to a second quantity of small first average fluctuation similarities, and determine the first threshold according to the first similarity of the first target exposure condition and a preset highest similarity.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The computer program is executed by the processor to implement the method of any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, the computer program comprising instructions that, when executed by a computer, cause the computer to perform the method of any one of claims 1-9. The computer program is executed by the processor to implement the method of any one of claims 1 to 7.
Citation Information
Patent Citations
Label classification method and device, electronic equipment and storage medium
CN113435499A