CN114782433B - Keycap detection method and device and electronic equipment - Google Patents
Keycap detection method and device and electronic equipment Download PDFInfo
- Publication number
- CN114782433B CN114782433B CN202210694627.6A CN202210694627A CN114782433B CN 114782433 B CN114782433 B CN 114782433B CN 202210694627 A CN202210694627 A CN 202210694627A CN 114782433 B CN114782433 B CN 114782433B
- Authority
- CN
- China
- Prior art keywords
- keycap
- detected
- circumscribed rectangle
- minimum circumscribed
- template
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000001514 detection method Methods 0.000 title claims abstract description 64
- 238000000034 method Methods 0.000 claims abstract description 27
- 230000015654 memory Effects 0.000 claims description 10
- 238000012360 testing method Methods 0.000 claims description 4
- 239000011159 matrix material Substances 0.000 claims description 3
- 238000012545 processing Methods 0.000 description 25
- 238000010586 diagram Methods 0.000 description 21
- 238000004590 computer program Methods 0.000 description 11
- 230000008569 process Effects 0.000 description 9
- 238000004891 communication Methods 0.000 description 6
- 238000012937 correction Methods 0.000 description 6
- 230000006870 function Effects 0.000 description 6
- 230000000694 effects Effects 0.000 description 4
- 238000004519 manufacturing process Methods 0.000 description 4
- 238000005516 engineering process Methods 0.000 description 3
- 238000013473 artificial intelligence Methods 0.000 description 2
- 238000004364 calculation method Methods 0.000 description 2
- 238000001914 filtration Methods 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000003044 adaptive effect Effects 0.000 description 1
- 238000004458 analytical method Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000004422 calculation algorithm Methods 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000009499 grossing Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 239000000463 material Substances 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000005192 partition Methods 0.000 description 1
- 238000013515 script Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/0002—Inspection of images, e.g. flaw detection
- G06T7/0004—Industrial image inspection
- G06T7/001—Industrial image inspection using an image reference approach
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/23—Clustering techniques
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/60—Analysis of geometric attributes
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/70—Determining position or orientation of objects or cameras
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/30—Subject of image; Context of image processing
- G06T2207/30108—Industrial image inspection
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Computer Vision & Pattern Recognition (AREA)
- General Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Evolutionary Biology (AREA)
- Evolutionary Computation (AREA)
- Bioinformatics & Computational Biology (AREA)
- General Engineering & Computer Science (AREA)
- Artificial Intelligence (AREA)
- Life Sciences & Earth Sciences (AREA)
- Geometry (AREA)
- Quality & Reliability (AREA)
- Image Analysis (AREA)
Abstract
The application provides a keycap detection method, a keycap detection device and electronic equipment; the method comprises the following steps: determining the minimum circumscribed rectangle of the keycap to be detected based on the gray image of the keycap to be detected; comparing the minimum circumscribed rectangle of the keycap to be detected with the minimum circumscribed rectangle of the keycap of the template in the template image corresponding to the keycap to be detected to obtain an intermediate comparison result; and detecting whether the to-be-detected worn cap is correctly assembled or not based on the intermediate comparison result. The keycap detection method can reduce consumption of labor cost and improve efficiency and accuracy of keycap detection.
Description
Technical Field
The application relates to the technical field of image processing, in particular to a keycap detection method and device and electronic equipment.
Background
At present, keyboard key cap is various, and in most current schemes, only detect to the length and width size of key cap, to having the detection of the key cap that the same length and width size is different in edge, not only the rate of accuracy is not high, needs a large amount of human cost input moreover. Therefore, the key for ensuring the product quality and the cost is to improve the detection efficiency and the accuracy of the keycap.
Disclosure of Invention
The embodiment of the application provides a keycap detection method and device and electronic equipment, consumption of labor cost can be reduced, and keycap detection efficiency and accuracy are improved.
The technical scheme of the embodiment of the application is realized as follows:
in a first aspect, an embodiment of the present application provides a keycap detection method, including:
determining the minimum circumscribed rectangle of the keycap to be detected based on the gray image of the keycap to be detected;
comparing the minimum circumscribed rectangle of the keycap to be detected with the minimum circumscribed rectangle of the keycap of the template in the template image corresponding to the keycap to be detected to obtain an intermediate comparison result;
and detecting whether the keycap to be detected is assembled correctly or not based on the intermediate comparison result.
In the above-mentioned scheme, based on the grey scale image of the key cap that awaits measuring, confirm minimum circumscribed rectangle, include:
determining the maximum connected domain of the keycap to be detected based on the gray image of the keycap to be detected;
constructing a convex polygon based on the maximum connected domain;
and determining the minimum circumscribed rectangle corresponding to the convex polygon as the minimum circumscribed rectangle of the keycap to be detected.
In the above scheme, after determining the minimum circumscribed rectangle of the keycap to be detected based on the grayscale image of the keycap to be detected, the method further includes:
judging whether the minimum circumscribed rectangle is inclined or not;
and if the minimum external matrix is inclined, correcting the gray image of the keycap to be detected and the binary image of the keycap to be detected.
In the above scheme, will await measuring the minimum circumscribed rectangle of key cap with the minimum circumscribed rectangle of template key cap in the template image that the key cap that awaits measuring corresponds compares, obtains middle comparison result, includes:
calculating a first difference value between the length of the minimum circumscribed rectangle of the keycap to be detected and the length of the minimum circumscribed rectangle of the template keycap in the template image;
calculating a second difference value between the width of the minimum circumscribed rectangle of the keycap to be detected and the width of the minimum circumscribed rectangle of the template keycap in the template image;
comparing the absolute value of the first difference value with a preset first threshold value and the absolute value of the second difference value with a preset second threshold value to obtain an intermediate comparison result;
and detecting whether the keycap to be detected is assembled correctly or not based on the intermediate comparison result.
In the above scheme, whether the key cap that awaits measuring is assembled correctly based on the middle result of comparison detects includes:
and if the absolute value of the first difference is larger than the first threshold value and/or the absolute value of the second difference is larger than the second threshold value, determining that the keycap to be tested is assembled wrongly.
In the foregoing solution, if the absolute value of the first difference is smaller than or equal to the first threshold and the absolute value of the second difference is smaller than or equal to the second threshold, detecting whether the keycap to be tested is correctly assembled includes:
and detecting whether the keycap to be detected is assembled correctly or not based on the upper left corner area and the upper right corner area of the keycap to be detected and the upper left corner area and the upper right corner area of the keycap template in the template image.
In the above scheme, based on the upper left corner region and the upper right corner region of the keycap to be tested, and the upper left corner region and the upper right corner region of the template keycap in the template image, whether the keycap to be tested is correctly assembled or not is detected by:
determining a first rectangular area of the upper left corner of the keycap to be tested and a second rectangular area of the upper left corner of the template keycap;
determining a third rectangular area of the top right corner of the keycap to be tested and a fourth rectangular area of the top right corner of the template keycap;
and respectively clustering each rectangular area in the first rectangular area, the second rectangular area, the third rectangular area and the fourth rectangular area, and detecting whether the keycap to be detected is correctly assembled or not based on a clustering result.
In the foregoing solution, the clustering each rectangular region of the first rectangular region, the second rectangular region, the third rectangular region, and the fourth rectangular region, and detecting whether the keycap to be tested is correctly assembled based on a clustering result includes:
clustering each rectangular area, and dividing pixel points in each rectangular area into two categories, namely, a key cap circular arc area and a key cap circular arc area;
determining a third difference between the ratio of the number of the pixel points in the circular arc area of the key cap in the first rectangular area to the number of the pixel points outside the circular arc area of the key cap and the ratio of the number of the pixel points in the circular arc area of the key cap in the second rectangular area to the number of the pixel points outside the circular arc area of the key cap; determining a first absolute value corresponding to the third difference value;
determining a fourth difference value between the ratio of the number of the pixel points in the circular arc area of the key cap in the third rectangular area to the number of the pixel points outside the circular arc area of the key cap and the ratio of the number of the pixel points in the circular arc area of the key cap in the fourth rectangular area to the number of the pixel points outside the circular arc area of the key cap; determining a second absolute value corresponding to the fourth difference value;
and if the first absolute value is larger than a preset third threshold value and/or the second absolute value is larger than a preset fourth threshold value, determining that the keycap to be tested is assembled wrongly.
In a second aspect, an embodiment of the present application provides a key cap detection apparatus, including:
the minimum circumscribed rectangle determining module is used for determining the minimum circumscribed rectangle of the keycap to be detected based on the gray image of the keycap to be detected;
the minimum circumscribed rectangle comparison module is used for comparing the minimum circumscribed rectangle of the keycap to be detected with the minimum circumscribed rectangle of the template keycap in the template image corresponding to the keycap to be detected to obtain an intermediate comparison result;
and the detection module for the upper left corner region and the upper right corner region detects whether the keycap to be detected is assembled correctly or not based on the middle comparison result.
In a third aspect, an embodiment of the present application provides an electronic device, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the key cap detection method provided by the embodiment of the application.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium, where the storage medium includes a set of computer-executable instructions, and when the instructions are executed, the method for detecting a keycap provided by embodiments of the present application is performed.
The keycap detection method provided by the embodiment of the application determines the minimum circumscribed rectangle of the keycap to be detected based on the gray image of the keycap to be detected; comparing the minimum circumscribed rectangle of the keycap to be detected with the minimum circumscribed rectangle of the keycap of the template in the template image corresponding to the keycap to be detected to obtain an intermediate comparison result; and detecting whether the keycap to be detected is assembled correctly or not based on the intermediate comparison result. According to the key cap detection method, automatic detection of the key caps by production detection equipment can be achieved instead of manual work, so that the consumption of labor cost is reduced, and the key cap detection efficiency is improved; meanwhile, the keycap detection method provided by the application can realize automatic detection of keycaps with the same size but different edge shapes, so that the accuracy of keycap detection is improved.
Drawings
The drawings are included to provide a better understanding of the present solution and are not intended to limit the present application. Wherein:
FIG. 1 is a schematic view of an alternative processing flow of a key cap detection method provided by an embodiment of the present application;
FIG. 2 is a schematic diagram of image rectification provided by an embodiment of the present application;
FIG. 3 is a schematic diagram of a keyboard image provided by an embodiment of the application;
FIG. 4 is a diagram illustrating image processing results provided by an embodiment of the present application;
fig. 5 is an effect diagram of an upper left corner arc and an upper right corner arc in a binary image of an acquired target according to the embodiment of the present application;
FIG. 6 is a schematic diagram illustrating a processing flow of a key cap detection method according to an embodiment of the present application;
FIG. 7 is a schematic diagram of an alternative key cap detection apparatus according to an embodiment of the present application;
FIG. 8 is a schematic block diagram of an electronic device implementing a key cap detection method provided by an embodiment of the application.
Detailed Description
In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be described in further detail with reference to the attached drawings, the described embodiments should not be considered as limiting the present application, and all other embodiments obtained by a person of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
In the following description, reference is made to "some embodiments" which describe a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict.
In the following description, references to the terms "first," "second," and the like, are intended only to distinguish similar objects and not to imply a particular order to the objects, it being understood that "first," "second," and the like may be interchanged under appropriate circumstances or a sequential order, such that the embodiments of the application described herein may be practiced in other than those illustrated or described herein.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of the present application only and is not intended to be limiting of the application.
A key cap detection method provided by an embodiment of the present application will be described below, referring to fig. 1, where fig. 1 is a schematic processing flow diagram of an alternative key cap detection method provided by an embodiment of the present application, and the following description will be made with reference to steps S101 to S103 shown in fig. 1 and with reference to fig. 2 to fig. 5.
And S101, determining the minimum circumscribed rectangle of the keycap to be detected based on the gray-scale image of the keycap to be detected.
In some application scenarios, keycaps on a notebook keyboard are typically assembled by hand. Because the key cap has manufacturing cost higher, and specification variety is various, and the key cap size and the shape of same specification characteristics such as very similar, the assembly work of key cap can be more loaded down with trivial details and make mistakes easily usually. Therefore, after the key cap is assembled, the key cap needs to be detected and found in time whether the key cap is mistakenly assembled or not, and the like.
In some embodiments, the grayscale image of a single keycap to be detected can be subjected to gaussian filtering smoothing processing to obtain a smoothed grayscale image of the keycap to be detected; and performing self-adaptive binarization processing on the smoothed gray level image of the keycap to be detected to obtain a binary image of the keycap to be detected. The binary image of the keycap to be tested shows the visual effect that the foreground area is white and the background area is black. The keycap region to be detected is the largest connected domain in the binary image of the keycap to be detected, so that the keycap region to be detected can be determined by obtaining the largest connected domain in the binary image of the keycap to be detected.
In some embodiments, after acquiring the maximum connected component in the binary image of the keycap to be detected, the minimum bounding rectangle of the maximum connected component may be calculated. The edge position of the maximum connected domain can be simplified into a convex polygon, and the rectangle with the smallest area in the circumscribed rectangles of the convex polygon is calculated.
In some embodiments, after determining the minimum circumscribed rectangle of the key cap to be detected, it is determined whether the determined circumscribed rectangle of the key cap to be detected is tilted, and if the circumscribed rectangle of the key cap to be detected is tilted, the rotation correction processing needs to be performed on the gray-scale image of the key cap to be detected. As shown in fig. 2, fig. 2 is a schematic diagram of image rectification provided by an embodiment of the present application. The left image is a gray scale image of the keycap to be detected before correction, and because the minimum circumscribed rectangle of the keycap to be detected in the left image is inclined relative to the background image, the gray scale image of the keycap to be detected needs to be subjected to rotation correction processing based on the inclination angle of the minimum circumscribed rectangle of the keycap to be detected, and then the keycap to be detected after correction is subjected to self-adaptive binarization processing. The right image of FIG. 2 is a binary image of the keycap under test after correction.
After the minimum circumscribed rectangle of the keycap to be detected is determined, the image area corresponding to the keycap to be detected can be obtained.
And S102, comparing the minimum circumscribed rectangle of the keycap to be detected with the minimum circumscribed rectangle of the template keycap in the template image corresponding to the keycap to be detected to obtain an intermediate comparison result.
In some embodiments, the template image may be a material Document in pdf Format (Portable Document Format); if the image to be detected is the notebook keyboard, the template image can be understood as a design drawing which is one-to-one with the notebook keyboard image. As shown in fig. 3, fig. 3 is a schematic diagram of a keyboard image provided in the embodiment of the present application.
In some implementations, after the minimum circumscribed rectangle of the keycap to be detected is obtained, the minimum circumscribed rectangle of the keycap to be detected and the minimum circumscribed rectangle of the template keycap are compared, and a first difference value between the length of the minimum circumscribed rectangle of the keycap to be detected and the length of the minimum circumscribed rectangle of the template keycap in the template image is calculated; and calculating a second difference value between the width of the minimum circumscribed rectangle of the keycap to be detected and the width of the minimum circumscribed rectangle of the template keycap in the template image. And comparing the absolute value of the first difference value with a preset first threshold value, and comparing the absolute value of the second difference value with a preset second threshold value to obtain an intermediate comparison result.
And S103, detecting whether the keycap to be detected is assembled correctly or not based on the intermediate comparison result.
In some embodiments, in the intermediate comparison result between the minimum circumscribed rectangle of the keycap to be tested and the minimum circumscribed rectangle of the template keycap, if the absolute value of a first difference between the length of the minimum circumscribed rectangle of the keycap to be tested and the length of the minimum circumscribed rectangle of the template keycap in the template image is greater than the first threshold value, determining that the keycap to be tested is assembled incorrectly; if the absolute value of a second difference value between the width of the minimum circumscribed rectangle of the keycap to be tested and the width of the minimum circumscribed rectangle of the template keycap in the template image is larger than the second threshold value, determining that the keycap to be tested is assembled wrongly; and if the absolute value of a first difference value between the length of the minimum external rectangle of the keycap to be tested and the length of the minimum external rectangle of the template keycap in the template image is greater than the first threshold value, and the absolute value of a second difference value between the width of the minimum external rectangle of the keycap to be tested and the width of the minimum external rectangle of the template keycap in the template image is greater than the second threshold value, determining that the keycap to be tested is assembled wrongly.
As an example, after determining the minimum circumscribed rectangle of the keycap to be tested, obtaining the length numerical information and the width numerical information of the minimum circumscribed rectangle of the keycap to be tested, and obtaining the length numerical information and the width numerical information of the minimum circumscribed rectangle of the template keycap in the template image corresponding to the keycap to be tested, wherein the length numerical information of the minimum circumscribed rectangle of the keycap to be tested is represented by L, and the width numerical information is represented by W; numerical information of the length of the smallest circumscribed rectangle of the template keycap is represented by ML, numerical information of the width is represented by MW, a first threshold value is represented by Thresh _1, and a second threshold value is represented by Thresh _ 2. If abs (L-ML) > Thresh _1, determining that the keycap to be tested is assembled wrongly; if abs (L-ML) > Thresh _2, determining that the keycap to be tested is assembled wrongly; if abs (L-ML) > Thresh _1 and abs (L-ML) > Thresh _2, a key cap assembly error is determined. Wherein the value of the first threshold and the value of the second threshold may be obtained from a working experience of key cap assembly.
In some implementations, some of the key caps are the same size, but the shapes of the edges of the two ends of the key caps are different, such as the shape of the edge of the two ends of some key caps is a circular arc angle and the shape of the edge of the two ends of some key caps is a right angle. And if the result of comparison between the minimum external rectangle of the keycap to be detected and the minimum external rectangle of the template keycap does not satisfy the condition of the assembling error of the keycap to be detected, namely the absolute value of a first difference value between the length of the minimum external rectangle of the keycap to be detected and the length of the minimum external rectangle of the template keycap in the template image is less than or equal to the first threshold value, and the absolute value of a second difference value between the width of the minimum external rectangle of the keycap to be detected and the width of the minimum external rectangle of the template keycap in the template image is less than or equal to the second threshold value, the keycap to be detected is continuously detected. And aiming at the scene, whether the keycap to be tested is assembled correctly or not can be detected based on the upper left corner area and the upper right corner area of the keycap to be tested and the upper left corner area and the upper right corner area of the keycap template in the template image. As shown in fig. 4, fig. 4 is a diagram illustrating an image processing result according to an embodiment of the present application. The left side picture is a display effect picture of an upper left corner region and an upper right corner region for acquiring a gray scale image of the keycap to be detected, and the right side picture is a display effect picture of an upper left corner region and an upper right corner region for acquiring a binary image of the keycap of the template.
In some embodiments, when the upper left corner region and the upper right corner region of the keycap are cut, the upper left corner square region and the upper right corner square region can be optionally cut, for example, the length of the cut square is 1/10 of the width of the keycap to be measured; or, the rectangle area at the upper left corner and the rectangle area at the upper right corner can be selectively cut out, the size of the rectangle area is determined according to the keycap binary image, for example, the area at the upper left corner and the area at the upper right corner of the keycap binary image of the right-side template in fig. 4, the area at the upper left corner can be obtained through the vanishing point of the black part at the upper left corner in the keycap binary image, and the area at the upper right corner can be obtained through the vanishing point of the black part at the upper right corner in the keycap binary image.
In some embodiments, after determining a first rectangular region at the top left corner of the keycap to be tested, a second rectangular region at the top left corner of the template keycap, a third rectangular region at the top right corner of the keycap to be tested, and a fourth rectangular region at the top right corner of the template keycap, clustering each rectangular region, wherein the clustering method can divide pixel points in each rectangular region into two categories, namely, within a keycap circular arc region and outside the keycap circular arc region; whether the keycaps to be detected are assembled correctly is detected based on the clustering result. As an example, a KMeans clustering method may be selected to implement the partition of the outer pixel points in the circular arc region in the rectangular region. As shown in fig. 5, fig. 5 is an effect diagram of an upper left circular arc and an upper right circular arc in a binary image of an acquisition target provided by the embodiment of the present application.
Wherein, whether the key cap that awaits measuring whether assembles the correct process based on the clustering result detects does: determining a third difference between the ratio of the number of the pixel points in the circular arc area of the key cap in the first rectangular area to the number of the pixel points outside the circular arc area of the key cap and the ratio of the number of the pixel points in the circular arc area of the key cap in the second rectangular area to the number of the pixel points outside the circular arc area of the key cap; determining a first absolute value corresponding to the third difference value; determining a fourth difference value between the ratio of the number of the pixel points in the circular arc area of the key cap in the third rectangular area to the number of the pixel points outside the circular arc area of the key cap and the ratio of the number of the pixel points in the circular arc area of the key cap in the fourth rectangular area to the number of the pixel points outside the circular arc area of the key cap; determining a second absolute value corresponding to the fourth difference value; if the first absolute value is larger than a preset third threshold value, determining that the keycap to be tested is assembled wrongly; if the second absolute value is larger than a preset fourth threshold value, determining that the keycap to be tested is assembled wrongly; and if the first absolute value is greater than a preset third threshold value and the second absolute value is greater than a preset fourth threshold value, determining that the keycap to be tested is assembled incorrectly.
As an example, if the ratio of the number of pixels in the circular arc region in the first rectangular region at the top left corner of the key cap to be tested to the number of pixels outside the circular arc region in the first rectangular region at the top left corner of the key cap to be tested is r 1 The ratio of the number of the pixel points in the circular arc region in the second rectangular region at the upper left corner of the template keycap to the number of the pixel points outside the circular arc region in the second rectangular region at the upper left corner of the template keycap is r 2 The ratio of the number of the pixel points in the circular arc region in the third rectangular region at the upper right corner of the keycap to be detected to the number of the pixel points outside the circular arc region in the third rectangular region at the upper right corner of the keycap to be detected is r 3 The ratio of the number of the pixel points in the circular arc region in the fourth rectangular region at the right upper corner of the template keycap to the number of the pixel points outside the circular arc region in the fourth rectangular region at the right upper corner of the template keycap is r 4 . The third threshold is denoted by Thresh _3 and the fourth threshold is denoted by Thresh _ 4.
If abs (r) 1 -r 2 )>T 3 Determining that the keycap to be tested is assembled wrongly; if abs (r) 3 -r 4 )>T 4 Determining that the keycap to be tested is assembled wrongly; if abs (r) 1 -r 2 )>T 3 And abs (r) 3 -r 4 )>T 4 And determining that the keycap is assembled incorrectly.
Accordingly, ifabs(r 1 -r 2 )<T 3 And abs (r) 3 -r 4 )<T 4 Then the key cap is determined to be properly assembled.
Wherein the values of the third threshold and the fourth threshold may be obtained from working experience of actual key cap assembly.
In some working scenes, the keycap detection provided by the method can be automatically executed through production detection equipment, so that the labor cost can be reduced, the detection efficiency can be improved, and the problems of low detection efficiency and false detection caused by fatigue in the detection process by manpower can be avoided; the key cap detection method not only detects the size of the key cap, but also detects the key cap based on the shapes of the two ends of the upper edge of the key cap, so that false detection caused by the fact that the sizes are the same and the shapes of the two ends of the edge are different is avoided, and the accuracy rate of key cap detection can be improved.
The following describes a processing flow of the key cap detection method provided by the embodiment of the present application. Fig. 6 is a schematic view of a processing flow of a key cap detection method according to an embodiment of the present application, as shown in fig. 6.
In some embodiments, the obtained grayscale image of the single keycap to be detected is subjected to adaptive binarization processing to obtain a binary image of the single keycap to be detected.
In some embodiments, the minimum bounding rectangle of the maximum connected domain is calculated based on the maximum connected domain in the binary image of the keycap to be tested.
In some embodiments, after determining the minimum circumscribed rectangle of the key cap to be detected, it is necessary to determine whether the determined circumscribed rectangle is inclined, if the circumscribed rectangle is inclined, it is necessary to perform rotation correction processing on the grayscale image of the key cap to be detected, and then perform binarization processing based on the corrected grayscale image to obtain a corrected binary image of the key cap to be detected.
In some embodiments, the specific process of obtaining the intermediate comparison result between the minimum circumscribed rectangle of the keycap to be tested and the minimum circumscribed rectangle of the template keycap is as follows: calculating a first difference value between the length of the minimum circumscribed rectangle of the keycap to be detected and the length of the minimum circumscribed rectangle of the template keycap in the template image; and calculating a second difference value between the width of the minimum circumscribed rectangle of the keycap to be detected and the width of the minimum circumscribed rectangle of the template keycap in the template image.
In some embodiments, the specific process of determining whether the intermediate comparison result is within the preset threshold value is as follows: if the absolute value of the first difference is smaller than or equal to the first threshold and the absolute value of the second difference is smaller than or equal to the second threshold, determining that the intermediate comparison result is within a preset threshold, and continuing to execute step 606; if the absolute value of the first difference is greater than the first threshold; or the absolute value of the second difference is greater than the second threshold; or the absolute value of the first difference is larger than the first threshold value and the absolute value of the second difference is larger than the second threshold value, determining that the intermediate comparison result is not within a preset threshold value, determining that the keycap to be tested is assembled wrongly, and not continuing to execute the operation.
In some embodiments, a first rectangular region of the top left corner of the keycap to be tested, a second rectangular region of the top left corner of the template keycap, a third rectangular region of the top right corner of the keycap to be tested, and a fourth rectangular region of the top right corner of the template keycap are obtained, respectively.
And 607, clustering each rectangular area to obtain a clustering analysis result.
In some embodiments, each of the rectangular regions is clustered, and the pixel points in each rectangular region are divided into two categories, namely, inside the circular arc region of the key cap and outside the circular arc region of the key cap.
Determining a first absolute value corresponding to a third difference value between the ratio of the number of pixel points in the circular arc area at the upper left corner of the keycap to be detected to the number of pixel points outside the circular arc area and the ratio of the number of pixel points in the circular arc area in the upper left corner area of the template keycap to the number of pixel points outside the circular arc area; and determining a second absolute value corresponding to a fourth difference value between the ratio of the number of the pixel points in the circular arc area at the upper right corner of the keycap to be detected to the number of the pixel points outside the circular arc area and the ratio of the number of the pixel points in the circular arc area in the upper right corner area of the template keycap to the number of the pixel points outside the circular arc area.
In some embodiments, the specific process of determining whether the clustering result is within the preset threshold value is as follows: if the first absolute value is smaller than or equal to a preset third threshold value and the second absolute value is smaller than or equal to a preset fourth threshold value, determining that the clustering result is within the preset threshold value, and determining that the keycap to be tested is correctly assembled; otherwise, determining that the clustering result is not within the preset threshold value, and determining that the keycap to be tested is assembled wrongly.
Fig. 7 is a schematic structural diagram of an alternative key cap detection apparatus provided in an embodiment of the present application, where the key cap detection apparatus 700 includes a minimum circumscribed rectangle determination module 701, a minimum circumscribed rectangle comparison module 702, and a detection module 703 for an upper left corner region and an upper right corner region. Wherein,
the minimum circumscribed rectangle determining module 701 is used for determining the minimum circumscribed rectangle of the keycap to be detected based on the gray level image of the keycap to be detected;
a minimum circumscribed rectangle comparing module 702, configured to compare the minimum circumscribed rectangle of the keycap to be detected with the minimum circumscribed rectangle of the template keycap in the template image corresponding to the keycap to be detected, so as to obtain an intermediate comparison result;
and the detection module 703 for the upper left corner area and the upper right corner area detects whether the keycap to be detected is correctly assembled based on the middle comparison result.
In some embodiments, the minimum bounding rectangle determination module 701 is specifically configured to: determining the maximum connected domain of the keycap to be detected based on the gray image of the keycap to be detected; constructing a convex polygon based on the maximum connected domain; determining the minimum circumscribed rectangle corresponding to the convex polygon as the minimum circumscribed rectangle of the keycap to be detected;
the minimum circumscribed rectangle determining module 701 is specifically configured to: performing Gaussian filtering processing on the gray level image of the keycap to be detected to obtain a processed gray level image of the keycap to be detected; performing binarization processing on the processed keycap gray level image to be detected to obtain a binary image of the keycap to be detected; based on the binary image, determining a maximum connected component in the binary image.
The minimum circumscribed rectangle determining module 701 is further configured to determine whether the minimum circumscribed rectangle of the key cap to be detected is inclined or not after determining the minimum circumscribed rectangle of the key cap to be detected based on the grayscale image of the key cap to be detected; and if the minimum external matrix is inclined, correcting the gray image of the keycap to be detected and the binary image of the keycap to be detected.
In some embodiments, the minimum bounding rectangle comparison module 702 is specifically configured to: calculating a first difference value between the length of the minimum circumscribed rectangle of the keycap to be detected and the length of the minimum circumscribed rectangle of the template keycap in the template image; calculating a second difference value between the width of the minimum circumscribed rectangle of the keycap to be detected and the width of the minimum circumscribed rectangle of the template keycap in the template image; comparing the absolute value of the first difference value with a preset first threshold value and the absolute value of the second difference value with a preset second threshold value to obtain an intermediate comparison result; and detecting whether the keycap to be detected is assembled correctly or not based on the intermediate comparison result.
The minimum external rectangle comparison module 702 is specifically configured to: and if the absolute value of the first difference is larger than the first threshold value and/or the absolute value of the second difference is larger than the second threshold value, determining that the keycap to be tested is assembled wrongly.
The minimum circumscribed rectangle comparison module 702 is specifically configured to: and detecting whether the keycap to be detected is assembled correctly or not based on the upper left corner area and the upper right corner area of the keycap to be detected and the upper left corner area and the upper right corner area of the keycap template in the template image.
In some embodiments, the top left corner region and top right corner region detection module 703 is specifically configured to: determining a first rectangular area of the upper left corner of the keycap to be tested and a second rectangular area of the upper left corner of the template keycap; determining a third rectangular area of the top right corner of the keycap to be tested and a fourth rectangular area of the top right corner of the template keycap; and respectively clustering each rectangular area in the first rectangular area, the second rectangular area, the third rectangular area and the fourth rectangular area, and detecting whether the keycap to be detected is correctly assembled based on a clustering result.
The detection module 703 for the upper left corner area and the upper right corner area is specifically configured to: clustering each rectangular area, and dividing pixel points in each rectangular area into two categories, namely a keycap circular arc area and a keycap circular arc area; determining a third difference value between the ratio of the number of the pixel points in the circular arc area of the key cap in the first rectangular area to the number of the pixel points outside the circular arc area of the key cap and the ratio of the number of the pixel points in the circular arc area of the key cap in the second rectangular area to the number of the pixel points outside the circular arc area of the key cap; determining a first absolute value corresponding to the third difference value; determining a fourth difference value between the ratio of the number of the pixel points in the circular arc area of the key cap in the third rectangular area to the number of the pixel points outside the circular arc area of the key cap and the ratio of the number of the pixel points in the circular arc area of the key cap in the fourth rectangular area to the number of the pixel points outside the circular arc area of the key cap; determining a second absolute value corresponding to the fourth difference value; and if the first absolute value is larger than a preset third threshold value and/or the second absolute value is larger than a preset fourth threshold value, determining that the keycap to be tested is assembled wrongly.
It should be noted that the key cap detection apparatus in the embodiment of the present application is similar to the key cap detection method in the above description, and has similar beneficial effects to the method in the embodiment, and therefore, the detailed description is omitted. The inexhaustible technical details in the key cap detection device provided in the embodiment of the present application can be understood from the description of any one of fig. 1 to 6.
FIG. 8 shows a schematic block diagram of an example electronic device 800 that may be used to implement embodiments of the present application. The electronic device 800 is used for implementing the keycap detection method of the disclosed embodiments. In some alternative embodiments, the electronic device 800 may implement the key cap detection method provided by the embodiments of the present application by running a computer program, for example, the computer program may be a software module in an operating system; may be a local (Native) Application (APP), i.e. a program that needs to be installed in the operating system to run; or may be an applet, i.e. a program that can be run only by downloading it to the browser environment; but also an applet that can be embedded into any APP. In general, the computer programs described above may be any form of application, module or plug-in.
In practical applications, the electronic device 800 may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a Cloud server providing basic Cloud computing services such as a Cloud service, a Cloud database, Cloud computing, a Cloud function, Cloud storage, a network service, Cloud communication, a middleware service, a domain name service, a security service, a CDN, and a big data and artificial intelligence platform, where Cloud Technology (Cloud Technology) refers to a hosting Technology for unifying series resources such as hardware, software, and a network in a wide area network or a local area network to implement computing, storage, processing, and sharing of data. The electronic device 800 may be, but is not limited to, a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart television, a smart watch, and the like.
Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, in-vehicle terminals, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the present application that are described and/or claimed herein.
As shown in fig. 8, the electronic device 800 includes a computing unit 801 that can perform various appropriate actions and processes according to a computer program stored in a Read Only Memory (ROM) 802 or a computer program loaded from a storage unit 808 into a Random Access Memory (RAM) 803. In the RAM803, various programs and data required for the operation of the electronic apparatus 800 can also be stored. The calculation unit 801, the ROM 802, and the RAM803 are connected to each other by a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
A number of components in the electronic device 800 are connected to the I/O interface 805, including: an input unit 806, such as a keyboard, a mouse, or the like; an output unit 807 such as various types of displays, speakers, and the like; a storage unit 808, such as a magnetic disk, optical disk, or the like; and a communication unit 809 such as a network card, modem, wireless communication transceiver, etc. The communication unit 809 allows the electronic device 800 to exchange information/data with other devices through a computer network such as the internet and/or various telecommunication networks.
Embodiments of the present application provide a computer-readable storage medium storing executable instructions, which when executed by a processor, will cause the processor to execute the key cap detection method provided by embodiments of the present application.
In some embodiments, the computer-readable storage medium may be memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories.
In some embodiments, executable instructions may be written in any form of programming language (including compiled or interpreted languages), in the form of programs, software modules, scripts or code, and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
By way of example, executable instructions may be deployed to be executed on one computing device or on multiple computing devices at one site or distributed across multiple sites and interconnected by a communication network.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable key cap detection apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable key cap detection apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable key cap detection apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
It should be understood that, in the various embodiments of the present application, the size of the serial number of each implementation process does not mean the execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
The above description is only an example of the present application, and is not intended to limit the scope of the present application. Any modification, equivalent replacement, and improvement made within the spirit and scope of the present application are included in the protection scope of the present application.
Claims (9)
1. A method of key cap detection, the method comprising:
determining the minimum circumscribed rectangle of the keycap to be detected based on the gray image of the keycap to be detected;
comparing the minimum circumscribed rectangle of the keycap to be detected with the minimum circumscribed rectangle of the keycap of the template in the template image corresponding to the keycap to be detected to obtain an intermediate comparison result;
detecting whether the keycap to be detected is assembled correctly or not based on the intermediate comparison result;
wherein, whether the key cap that awaits measuring is assembled correctly based on the middle result of comparison detects includes:
if the absolute value of a first difference value between the length of the minimum circumscribed rectangle of the keycap to be tested and the length of the minimum circumscribed rectangle of the template keycap in the template image is smaller than or equal to a first threshold value, and the absolute value of a second difference value between the width of the minimum circumscribed rectangle of the keycap to be tested and the width of the minimum circumscribed rectangle of the template keycap in the template image is smaller than or equal to a second threshold value, determining a first rectangular region at the upper left corner of the keycap to be tested and a second rectangular region at the upper left corner of the template keycap, and determining a third rectangular region at the upper right corner of the keycap to be tested and a fourth rectangular region at the upper right corner of the template keycap; and respectively clustering each rectangular area in the first rectangular area, the second rectangular area, the third rectangular area and the fourth rectangular area, and detecting whether the keycap to be detected is correctly assembled based on a clustering result.
2. The method of claim 1, wherein determining the minimum circumscribed rectangle of the keycap to be tested based on the grayscale image of the keycap to be tested comprises:
determining the maximum connected domain of the keycap to be detected based on the gray image of the keycap to be detected;
constructing a convex polygon based on the maximum connected domain;
and determining the minimum circumscribed rectangle corresponding to the convex polygon as the minimum circumscribed rectangle of the keycap to be detected.
3. The method of claim 1, wherein after determining the minimum bounding rectangle for the keycap under test based on the grayscale image of the keycap under test, the method further comprises:
judging whether the minimum circumscribed rectangle is inclined or not;
and if the minimum external matrix is inclined, correcting the gray image of the keycap to be detected.
4. The method of claim 1, wherein comparing the minimum bounding rectangle of the keycap to be tested with the minimum bounding rectangle of the template keycap in the template image corresponding to the keycap to be tested to obtain an intermediate comparison result comprises:
calculating a first difference value between the length of the minimum circumscribed rectangle of the keycap to be detected and the length of the minimum circumscribed rectangle of the template keycap in the template image;
calculating a second difference value between the width of the minimum circumscribed rectangle of the keycap to be detected and the width of the minimum circumscribed rectangle of the template keycap in the template image;
comparing the absolute value of the first difference value with a preset first threshold value and the absolute value of the second difference value with a preset second threshold value to obtain an intermediate comparison result;
and detecting whether the keycap to be detected is assembled correctly or not based on the intermediate comparison result.
5. The method of claim 4, wherein the detecting whether the keycap under test is correctly assembled based on the intermediate comparison result comprises:
and if the absolute value of the first difference is larger than the first threshold value and/or the absolute value of the second difference is larger than the second threshold value, determining that the keycap to be tested is assembled wrongly.
6. The method according to claim 1, wherein the clustering each of the first rectangular area, the second rectangular area, the third rectangular area and the fourth rectangular area, and detecting whether the keycap to be tested is correctly assembled based on the clustering result comprises:
clustering each rectangular area, and dividing pixel points in each rectangular area into two categories, namely, a key cap circular arc area and a key cap circular arc area;
determining a third difference value between the ratio of the number of the pixel points in the circular arc area of the key cap in the first rectangular area to the number of the pixel points outside the circular arc area of the key cap and the ratio of the number of the pixel points in the circular arc area of the key cap in the second rectangular area to the number of the pixel points outside the circular arc area of the key cap; determining a first absolute value corresponding to the third difference value;
determining a fourth difference value between the ratio of the number of the pixel points in the circular arc area of the key cap in the third rectangular area to the number of the pixel points outside the circular arc area of the key cap and the ratio of the number of the pixel points in the circular arc area of the key cap in the fourth rectangular area to the number of the pixel points outside the circular arc area of the key cap; determining a second absolute value corresponding to the fourth difference value;
and if the first absolute value is larger than a preset third threshold value and/or the second absolute value is larger than a preset fourth threshold value, determining that the keycap to be tested is assembled wrongly.
7. A key cap detection apparatus, the apparatus comprising:
the minimum circumscribed rectangle determining module is used for determining the minimum circumscribed rectangle of the keycap to be detected based on the gray level image of the keycap to be detected;
the minimum circumscribed rectangle comparison module is used for comparing the minimum circumscribed rectangle of the keycap to be detected with the minimum circumscribed rectangle of the keycap of the template in the template image corresponding to the keycap to be detected to obtain a middle comparison result;
the detection module for the upper left corner area and the upper right corner area is used for detecting whether the keycap to be detected is assembled correctly or not based on the middle comparison result;
wherein, upper left corner region and upper right corner region detection module specifically are used for: if the absolute value of a first difference between the length of the minimum circumscribed rectangle of the keycap to be tested and the length of the minimum circumscribed rectangle of the template keycap in the template image is smaller than or equal to a first threshold value, and the absolute value of a second difference between the width of the minimum circumscribed rectangle of the keycap to be tested and the width of the minimum circumscribed rectangle of the template keycap in the template image is smaller than or equal to a second threshold value, determining a first rectangular region of the upper left corner of the keycap to be tested and a second rectangular region of the upper left corner of the template keycap, and determining a third rectangular region of the upper right corner of the keycap to be tested and a fourth rectangular region of the upper right corner of the template keycap; and respectively clustering each rectangular area in the first rectangular area, the second rectangular area, the third rectangular area and the fourth rectangular area, and detecting whether the keycap to be detected is correctly assembled based on a clustering result.
8. An electronic device, characterized in that the electronic device comprises:
at least one processor; and a memory communicatively coupled to the at least one processor;
wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.
9. A computer-readable storage medium comprising a set of computer-executable instructions that, when executed, perform the key cap detection method of any of claims 1-6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210694627.6A CN114782433B (en) | 2022-06-20 | 2022-06-20 | Keycap detection method and device and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210694627.6A CN114782433B (en) | 2022-06-20 | 2022-06-20 | Keycap detection method and device and electronic equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN114782433A CN114782433A (en) | 2022-07-22 |
CN114782433B true CN114782433B (en) | 2022-09-20 |
Family
ID=82420405
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210694627.6A Active CN114782433B (en) | 2022-06-20 | 2022-06-20 | Keycap detection method and device and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114782433B (en) |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105548208B (en) * | 2016-02-05 | 2018-10-19 | 湖北工业大学 | A kind of ceramic cartridge detection method of surface flaw based on machine vision |
CN110223301B (en) * | 2019-03-01 | 2021-08-03 | 华为技术有限公司 | Image clipping method and electronic equipment |
CN111914874A (en) * | 2020-06-09 | 2020-11-10 | 上海欣巴自动化科技股份有限公司 | Target detection method and system |
CN112634259A (en) * | 2020-12-30 | 2021-04-09 | 凌云光技术股份有限公司 | Automatic modeling and positioning method for keyboard keycaps |
-
2022
- 2022-06-20 CN CN202210694627.6A patent/CN114782433B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN114782433A (en) | 2022-07-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US20240078646A1 (en) | Image processing method, image processing apparatus, and non-transitory storage medium | |
CN108304775B (en) | Remote sensing image recognition method and device, storage medium and electronic equipment | |
US10929648B2 (en) | Apparatus and method for data processing | |
KR20210110823A (en) | Image recognition method, training method of recognition model, and related devices and devices | |
US10885660B2 (en) | Object detection method, device, system and storage medium | |
KR102435365B1 (en) | Certificate recognition method and apparatus, electronic device, computer readable storage medium | |
CN105046254A (en) | Character recognition method and apparatus | |
CN111507958A (en) | Target detection method, training method of detection model and electronic equipment | |
CN110942004A (en) | Handwriting recognition method and device based on neural network model and electronic equipment | |
CN108021863B (en) | Electronic device, age classification method based on image and storage medium | |
CN110135421A (en) | Licence plate recognition method, device, computer equipment and computer readable storage medium | |
CN113436080A (en) | Seal image processing method, device, equipment and storage medium | |
KR20220093187A (en) | Positioning method and apparatus, electronic device, computer readable storage medium | |
CN111382687A (en) | Face detection method and system | |
CN110232381A (en) | License Plate Segmentation method, apparatus, computer equipment and computer readable storage medium | |
CN114782433B (en) | Keycap detection method and device and electronic equipment | |
CN113902899A (en) | Training method, target detection method, device, electronic device and storage medium | |
CN112749769A (en) | Graphic code detection method and device, computer equipment and storage medium | |
CN115311237A (en) | Image detection method and device and electronic equipment | |
CN114511862B (en) | Form identification method and device and electronic equipment | |
CN115063614A (en) | Image matching method and device and electronic equipment | |
CN112766256B (en) | Grating phase diagram processing method and device, electronic equipment and storage medium | |
CN114663418A (en) | Image processing method and device, storage medium and electronic equipment | |
CN114419370A (en) | Target image processing method and device, storage medium and electronic equipment | |
CN114049646A (en) | Bank card identification method and device, computer equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |