CN114782433A - Keycap detection method and device and electronic equipment - Google Patents

Keycap detection method and device and electronic equipment Download PDF

Info

Publication number
CN114782433A
CN114782433A CN202210694627.6A CN202210694627A CN114782433A CN 114782433 A CN114782433 A CN 114782433A CN 202210694627 A CN202210694627 A CN 202210694627A CN 114782433 A CN114782433 A CN 114782433A
Authority
CN
China
Prior art keywords
keycap
detected
key cap
circumscribed rectangle
determining
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.)
Granted
Application number
CN202210694627.6A
Other languages
Chinese (zh)
Other versions
CN114782433B (en
Inventor
赵玲玲
王敏
张培远
张伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
LCFC Hefei Electronics Technology Co Ltd
Original Assignee
LCFC Hefei Electronics Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by LCFC Hefei Electronics Technology Co Ltd filed Critical LCFC Hefei Electronics Technology Co Ltd
Priority to CN202210694627.6A priority Critical patent/CN114782433B/en
Publication of CN114782433A publication Critical patent/CN114782433A/en
Application granted granted Critical
Publication of CN114782433B publication Critical patent/CN114782433B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/0002Inspection of images, e.g. flaw detection
    • G06T7/0004Industrial image inspection
    • G06T7/001Industrial image inspection using an image reference approach
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/23Clustering techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/60Analysis of geometric attributes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/70Determining position or orientation of objects or cameras
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/30Subject of image; Context of image processing
    • G06T2207/30108Industrial 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 external 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 template keycap in the template image corresponding to the keycap to be detected to obtain a middle comparison result; and detecting whether the to-be-detected worn cap is correctly assembled or not based on the intermediate comparison result. The key cap detection method provided by the application can reduce the consumption of labor cost and improve the efficiency and accuracy of key cap detection.

Description

Keycap detection method and device and electronic equipment
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 of a great variety, and in most of current schemes, the length and width size that only detects to the key cap is to having the detection of the different key caps in the same length and width size but edge, and 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 external 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 scheme, based on the grey scale image of the key cap that awaits measuring, confirm minimum external rectangle, include:
determining the maximum connected domain of the keycap to be detected based on the gray-scale 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 circumscribed matrix is inclined, correcting the gray-scale 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 correctly assembled 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 correctly assembled 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 template keycap 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 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 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 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.
According to the key cap detection method provided by the embodiment of the application, the minimum circumscribed rectangle of the key cap to be detected is determined based on the gray image of the key cap 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; simultaneously, the keycap detection method provided by the application can realize automatic detection of keycaps with the same size and 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 diagram of an alternative processing flow of a key cap detection method according to 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 present application;
FIG. 4 is a diagram showing image processing results provided by an embodiment of the present application;
fig. 5 is an effect diagram of an upper left arc and an upper right 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 device structure of a key cap detection device provided by the 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 purpose, technical solutions and advantages of the present application clearer, the present application will be described in further detail with reference to the accompanying 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 making creative efforts 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 only to distinguish similar objects and do not denote a particular order, but rather the terms "first", "second", and the like may be used interchangeably with the order specified, where permissible, to enable embodiments of the present application described herein to be practiced otherwise than as specifically 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, key caps 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 key cap area to be detected is the largest connected domain in the binary image of the key cap to be detected, so that the key cap area to be detected can be determined by obtaining the largest connected domain in the binary image of the key cap 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 necessary to determine whether the determined circumscribed rectangle of the key cap to be detected is inclined, and if the circumscribed rectangle of the key cap to be detected is inclined, it is necessary to perform rotation correction processing on the grayscale map of the key cap to be detected. As shown in fig. 2, fig. 2 is a schematic diagram of image rectification provided by the 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 graph of FIG. 2 is a binary image of the keycap to be measured 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 image of the notebook keyboard. 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 correctly assembled 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 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 greater than the 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 detected and the width of the minimum circumscribed rectangle of the template keycap in the template image is greater than the second threshold value, determining that the keycap to be detected 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; the numerical information of the length of the smallest circumscribed rectangle of the template key cap is represented by ML, the numerical information of the width is represented by MW, the first threshold is represented by Thresh _1, and the second threshold 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; and if abs (L-ML) > Thresh _1 and abs (L-ML) > Thresh _2, determining that the key cap is assembled incorrectly. 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, the keycaps are the same size, but have different edge shapes, such as circular arc edges and right angle edges. 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, detecting whether the keycap to be detected is correctly assembled 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 template keycap 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 selected to be cut, 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 template at the right side 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 clustering result detection does: 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; 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 detected is assembled wrongly.
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 r1The ratio of the number of pixels in the circular arc region in the second rectangular region at the top left corner of the template keycap to the number of pixels outside the circular arc region in the second rectangular region at the top left corner of the template keycapA value of r2The ratio of the number of the pixel points in the circular arc region in the third rectangular region at the top 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 top right corner of the keycap to be detected is r3The ratio of the number of the pixel points in the circular arc region in the fourth rectangular region at the upper right corner of the template keycap to the number of the pixel points outside the circular arc region in the fourth rectangular region at the upper right corner of the template keycap is r4. The third threshold is denoted by Thresh _3 and the fourth threshold is denoted by Thresh _ 4.
(r) of waas1-r2)>T3Determining that the keycap to be tested is assembled wrongly; (r) of waas3-r4)>T4Determining that the keycap to be tested is assembled wrongly; (r) of waas1-r2)>T3And abs (r)3-r4)>T4And determining that the keycap is assembled incorrectly.
Corresponding, if abs (r)1-r2)<T3And abs (r)3-r4)<T4Then the key cap is determined to be properly assembled.
Wherein the values of the third threshold and the fourth threshold are 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 in 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.
Step 601, performing self-adaptive binarization processing on the keycap to be detected.
In some embodiments, the acquired gray level 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.
Step 602, obtaining the minimum external rectangle of the 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.
Step 603, determining whether the minimum circumscribed rectangle is inclined.
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.
Step 604, obtaining a middle comparison result between the minimum circumscribed rectangle of the keycap to be detected and the minimum circumscribed rectangle of the template keycap in the template image corresponding to the keycap to be detected.
In some embodiments, the specific process of obtaining the intermediate comparison result between the minimum bounding rectangle of the keycap to be measured and the minimum bounding 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.
Step 605, determining whether the intermediate comparison result is within a preset threshold.
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 larger 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.
Step 606, obtaining a first rectangular area and a third rectangular area of the keycap to be detected, and obtaining a second rectangular area and a fourth rectangular area of the template keycap.
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 subjected to clustering processing, 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.
Step 608, determine whether the clustering result is within a preset threshold.
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 first and the second end of the pipe are connected with each other,
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 tested with the minimum circumscribed rectangle of the keycap of the template in the template image corresponding to the keycap to be tested, 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 determining module 701 is specifically configured to: determining the maximum connected domain of the keycap to be detected based on the gray-scale 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 comparing 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 module 703 for detecting the upper left corner region and the upper right corner region 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 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 description of the above embodiments of the key cap detection method, and has similar beneficial effects to the embodiments of the method, and therefore, the description is omitted here. The inexhaustible technical details in the key cap detection device provided by the embodiment of the application can be understood according to the description of any one of the drawings in 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 embodiment 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 an 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.
Computing unit 801 may be a variety of general and/or special purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various dedicated Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, and the like. The computing unit 801 performs the various methods and processes described above, such as the key cap detection method. For example, in some alternative embodiments, the key cap detection method may be implemented as a computer software program tangibly embodied in a machine-readable medium, such as the storage unit 808. In some alternative embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 800 via the ROM 802 and/or the communication unit 809. When the computer program is loaded into the RAM803 and executed by the computing unit 801, one or more steps of the key cap detection method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured as a keycap detection method in any other suitable manner (e.g., by way of firmware).
Embodiments of the present application provide a computer-readable storage medium storing executable instructions, wherein the executable instructions, when executed by a processor, cause the processor to execute the key cap detection method provided by the 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 to 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 (11)

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 template keycap in the template image corresponding to the keycap to be detected to obtain a middle comparison result;
and detecting whether the keycap to be detected is assembled correctly or not based on the intermediate comparison 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 tested.
3. The method of claim 1, wherein after determining the minimum bounding rectangle for the key cap under test based on the grayscale image of the key cap 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 of claim 4, wherein detecting whether the key cap under test is correctly assembled if the absolute value of the first difference is less than or equal to the first threshold and the absolute value of the second difference is less than or equal to the second threshold comprises:
and detecting whether the keycap to be detected is correctly assembled 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 template keycap in the template image.
7. The method of claim 6, wherein the detecting whether the key cap to be tested is correctly assembled based on the top left corner region and the top right corner region of the key cap to be tested and the top left corner region and the top right corner region of the template key cap in the template image comprises:
determining a first rectangular area of the top left corner of the keycap to be detected and a second rectangular area of the top 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.
8. The method according to claim 7, 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 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.
9. 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 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 correctly assembled or not based on the middle comparison result.
10. 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-8.
11. A computer-readable storage medium comprising a set of computer-executable instructions that, when executed, perform the key cap detection method of any one of claims 1-8.
CN202210694627.6A 2022-06-20 2022-06-20 Keycap detection method and device and electronic equipment Active CN114782433B (en)

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 true CN114782433A (en) 2022-07-22
CN114782433B 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)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105548208A (en) * 2016-02-05 2016-05-04 湖北工业大学 Method for detecting surface defects of ceramic valve cores based on machine vision
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
US20220139008A1 (en) * 2019-03-01 2022-05-05 Huawei Technologies Co., Ltd. Image Cropping Method and Electronic Device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105548208A (en) * 2016-02-05 2016-05-04 湖北工业大学 Method for detecting surface defects of ceramic valve cores based on machine vision
US20220139008A1 (en) * 2019-03-01 2022-05-05 Huawei Technologies Co., Ltd. Image Cropping Method and Electronic Device
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

Also Published As

Publication number Publication date
CN114782433B (en) 2022-09-20

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
US10885660B2 (en) Object detection method, device, system and storage medium
KR102435365B1 (en) Certificate recognition method and apparatus, electronic device, computer readable storage medium
KR20210110823A (en) Image recognition method, training method of recognition model, and related devices and devices
CN105046254A (en) Character recognition method and apparatus
CN110942004A (en) Handwriting recognition method and device based on neural network model and electronic equipment
CN115063875B (en) Model training method, image processing method and device and electronic equipment
CN108021863B (en) Electronic device, age classification method based on image and storage medium
CN110414649B (en) DM code positioning method, device, terminal and storage medium
KR20220093187A (en) Positioning method and apparatus, electronic device, computer readable storage medium
CN113436080A (en) Seal image processing method, device, equipment and storage medium
CN111382687A (en) Face detection method and system
CN113902899A (en) Training method, target detection method, device, electronic device and storage medium
CN114782433B (en) Keycap detection method and device and electronic equipment
CN114511862B (en) Form identification method and device and electronic equipment
CN115311237A (en) Image detection method and device and electronic equipment
CN114663418A (en) Image processing method and device, storage medium and electronic equipment
CN114049646A (en) Bank card identification method and device, computer equipment and storage medium
CN114419370A (en) Target image processing method and device, storage medium and electronic equipment
CN114299299A (en) Tree leaf feature extraction method and device, computer equipment and storage medium
WO2023221292A1 (en) Methods and systems for image generation
CN116883544A (en) Character stroke weight adjusting method and device, electronic equipment and storage medium
CN117689621A (en) Measurement method, measurement device, electronic equipment and computer readable 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