An image detection method and device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202211633656.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-19
- Publication Date
- 2026-09-15
- Estimated Expiration
- 2042-12-19
AI Technical Summary
[0026] The method of this application embodiment obtains a template image corresponding to a keyboard; performs connected component segmentation on the template image to determine a first connected component for each key image included in the template image; and determines whether the template image has defects based on the first connected component. In this way, it can intelligently detect whether there are defects in the image, improving the detection accuracy and efficiency of defects in the image.
Smart Images

Figure CN115841480B_ABST
Abstract
Description
Technical Field
[0001] This application relates to image detection technology, and more particularly to an image detection method, apparatus, electronic device, and storage medium. Background Technology
[0002] With the rapid development and widespread use of image detection technology, keyboard defect detection has gradually become the mainstream application of image detection technology. However, in the process of keyboard defect detection, the existing methods involve manually inspecting the template image corresponding to the keyboard and then determining the keyboard defects based on the inspected template image. There is a greater desire to automatically inspect the template image corresponding to the keyboard to determine whether defects exist in the template image, thereby reducing image inspection time and improving the detection accuracy of defects in the image.
[0003] Therefore, how to intelligently detect whether there are defects in images in order to improve the detection accuracy and efficiency of defects in images has always been a goal. Summary of the Invention
[0004] This application provides an image detection method, apparatus, electronic device, and storage medium.
[0005] According to a first aspect of this application, an image detection method is provided, the method comprising: acquiring a template image corresponding to a keyboard; performing connected component segmentation on the template image to determine a first connected component of each key image included in the template image; and determining whether the template image has defects based on the first connected component.
[0006] According to one embodiment of this application, before determining the first connected component of each key image included in the template image, the method further includes: performing binarization thresholding on the template image to obtain a binarized template image; performing vertical and horizontal projection on the binarized template image to obtain adjacent non-projected regions corresponding to the binarized template image; determining the ordinate difference between the adjacent non-projected regions; in response to the ordinate difference being less than a preset distance threshold, determining the adjacent non-projected region corresponding to the ordinate difference as an invalid character region; deleting the invalid character region in the binarized template image to obtain a region to be detected; and filling holes in the region to be detected to obtain a first keyboard image; the first keyboard image is a part of the template image corresponding to the keyboard.
[0007] According to one embodiment of this application, after determining the first connected component of each button image included in the template image, the method further includes: determining at least one of the pixel height, pixel width, horizontal coordinate of the first center point, and vertical coordinate of the top left corner point corresponding to the first connected component of each button image.
[0008] According to one embodiment of this application, determining whether the template image has a defect based on the first connected component includes: determining the horizontal coordinate of the second center point of the first keyboard image; determining a first difference between the horizontal coordinate of the second center point and the horizontal coordinate of the first center point; and determining that the template image has a first defect in response to the pixel height being greater than a preset height threshold, the pixel width being greater than a preset width threshold, and the first difference being less than a preset pixel threshold.
[0009] According to one embodiment of this application, determining whether the template image has a defect based on the first connected component includes: determining a first number of first connected components of the first button image; the first button image is a button image whose horizontal coordinate of the upper left corner point is within a preset horizontal coordinate range; and determining that the template image has a second defect in response to the first number being less than a preset first number threshold.
[0010] According to one embodiment of this application, determining whether the template image has a defect based on the first connected component includes: determining the maximum value of the ordinate of the pixels in the first connected component of the first button image; determining the vertical height of the area to be detected; and determining that the template image has a third defect in response to the difference between the vertical height and the maximum value of the ordinate of the pixels being greater than a preset difference threshold.
[0011] According to one embodiment of this application, determining whether the template image has a defect based on the first connected component includes: determining a second number of the first connected components included in the first keyboard image; determining that the template image has a fourth defect in response to the second number being greater than a preset second number threshold; performing connected component segmentation on the region to be detected to determine a second connected component included in the region to be detected; determining a third number of the second connected components included in the region to be detected; and determining that the template image has a fifth defect in response to the third number being less than a preset third number threshold.
[0012] According to one embodiment of this application, determining whether the template image has a defect based on the first connected component includes: determining the first connected component of the button image corresponding to the preset coordinate position based on the preset coordinate position; determining the character region with the largest horizontal coordinate within the first connected component; determining the roundness and area corresponding to the character region with the largest horizontal coordinate; and determining that the template image has a sixth defect if the roundness is greater than a preset roundness threshold and the area is greater than a preset area threshold.
[0013] According to a second aspect of this application, an image detection apparatus is provided, comprising: an acquisition module for acquiring a template image corresponding to a keyboard; a determination module for performing connected component segmentation on the template image to determine a first connected component of each key image included in the template image; and a detection module for determining whether the template image has defects based on the first connected component.
[0014] According to one embodiment of this application, the image detection device further includes a projection module, which is configured to: perform binarization thresholding on the template image to obtain a binarized template image; perform vertical and horizontal projection on the binarized template image to obtain adjacent non-projected regions corresponding to the binarized template image; determine the ordinate difference between the adjacent non-projected regions; in response to the ordinate difference being less than a preset distance threshold, determine the adjacent non-projected region corresponding to the ordinate difference as an invalid character region; delete the invalid character region in the binarized template image to obtain a region to be detected; and fill holes in the region to be detected to obtain a first keyboard image; the first keyboard image is a part of the template image corresponding to the keyboard.
[0015] According to one embodiment of this application, the image detection device further includes a calculation module, which is used to: determine at least one of the pixel height, pixel width, horizontal coordinate of the first center point, and vertical coordinate of the upper left corner point corresponding to the first connected region of each button image.
[0016] According to one embodiment of this application, the detection module is configured to: determine the horizontal coordinate of the second center point of the first keyboard image; determine a first difference between the horizontal coordinate of the second center point and the horizontal coordinate of the first center point; and determine that the template image has a first defect in response to the pixel height being greater than a preset height threshold, the pixel width being greater than a preset width threshold, and the first difference being less than a preset pixel threshold.
[0017] According to one embodiment of this application, the detection module is used to: determine a first number of first connected components of a first button image; the first button image is a button image whose horizontal coordinate of the upper left corner point is within a preset horizontal coordinate range; and in response to the first number being less than a preset first number threshold, determine that the template image has a second defect.
[0018] According to one embodiment of this application, the detection module is used to: determine the maximum value of the ordinate of the pixels in the first connected region of the first button image; determine the vertical height of the region to be detected; and determine that the template image has a third defect in response to the difference between the vertical height and the maximum value of the ordinate of the pixels being greater than a preset difference threshold.
[0019] According to one embodiment of this application, the detection module is configured to: determine a second number of the first connected components included in the first keyboard image; determine that the template image has a fourth defect in response to the second number being greater than a preset second number threshold; perform connected component segmentation on the region to be detected to determine a second connected component included in the region to be detected; determine a third number of the second connected components included in the region to be detected; and determine that the template image has a fifth defect in response to the third number being less than a preset third number threshold.
[0020] According to one embodiment of this application, the detection module is used to: determine a first connected component of the key image corresponding to a preset coordinate position based on a preset coordinate position; determine the character region with the largest horizontal coordinate within the first connected component; determine the roundness and area corresponding to the character region with the largest horizontal coordinate; and determine that the template image has a sixth defect if the roundness is greater than a preset roundness threshold and the area is greater than a preset area threshold.
[0021] According to a third aspect of this application, an electronic device is provided, comprising:
[0022] At least one processor; and
[0023] A memory communicatively connected to the at least one processor; wherein,
[0024] The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method described in this application.
[0025] According to a fourth aspect of this application, a non-transitory computer-readable storage medium is provided storing computer instructions for causing the computer to perform the methods described in this application.
[0026] The method of this application embodiment obtains a template image corresponding to a keyboard; performs connected component segmentation on the template image to determine a first connected component for each key image included in the template image; and determines whether the template image has defects based on the first connected component. In this way, it can intelligently detect whether there are defects in the image, improving the detection accuracy and efficiency of defects in the image.
[0027] It should be understood that the teachings of this application are not required to achieve all the beneficial effects described above, but rather that a specific technical solution can achieve a specific technical effect, and other embodiments of this application can also achieve beneficial effects not mentioned above. Attached Figure Description
[0028] The above and other objects, features, and advantages of exemplary embodiments of this application will become readily apparent from the following detailed description taken in conjunction with the accompanying drawings. Several embodiments of this application are illustrated in the drawings by way of example and not limitation, in which:
[0029] In the accompanying drawings, the same or corresponding reference numerals indicate the same or corresponding parts.
[0030] Figure 1 This paper illustrates the processing flow of the image detection method provided in an embodiment of the present application. Figure 1 ;
[0031] Figure 2 This paper illustrates the processing flow of the image detection method provided in an embodiment of the present application. Figure 2 ;
[0032] Figure 3 This paper illustrates the processing flow of the image detection method provided in an embodiment of the present application. Figure 3 ;
[0033] Figure 4 This paper illustrates the processing flow of the image detection method provided in an embodiment of the present application. Figure 4 ;
[0034] Figure 5 This paper illustrates the processing flow of the image detection method provided in an embodiment of the present application. Figure 5 ;
[0035] Figure 6 This paper illustrates the processing flow of the image detection method provided in an embodiment of the present application. Figure 6 ;
[0036] Figure 7 This application illustrates an application scenario of the image detection method provided in the embodiments of this application. Figure 1 ;
[0037] Figure 8 This application illustrates an application scenario of the image detection method provided in the embodiments of this application. Figure 2 ;
[0038] Figure 9 This application illustrates an application scenario of the image detection method provided in the embodiments of this application. Figure 3 ;
[0039] Figure 10 This application illustrates an application scenario of the image detection method provided in the embodiments of this application. Figure 4 ;
[0040] Figure 11 This illustration shows an optional schematic diagram of the image detection apparatus provided in an embodiment of this application;
[0041] Figure 12 A schematic diagram of the composition structure of the electronic device provided in the embodiments of this application is shown. Detailed Implementation
[0042] To make the objectives, features, and advantages of this application more apparent and understandable, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0043] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, 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.
[0044] In the following description, the terms "first" and "second" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first" and "second" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0045] Unless otherwise defined, 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 this application only and is not intended to limit this application.
[0046] In related technologies, current known image detection solutions rely on manual inspection of a template image corresponding to the keyboard, followed by determination of keyboard defects based on the inspected template image. Existing image detection processes are very time-consuming and have low accuracy in detecting defects in the image. The long processing time and low accuracy of related technologies in image detection result in low efficiency in defect detection.
[0047] The image detection methods provided by related technologies suffer from long processing times and low detection accuracy, resulting in low efficiency. This application's embodiment addresses this issue by acquiring a template image corresponding to a keyboard; performing connected component segmentation on the template image to determine a first connected component for each key image included in the template image; and determining whether the template image contains defects based on the first connected component. This intelligently detects defects in the image, reducing processing time and improving both detection accuracy and efficiency. Therefore, compared to the long processing times and low detection accuracy of related technologies, this application's image detection method significantly reduces processing time and improves defect detection efficiency.
[0048] The processing flow of the image detection method provided in the embodiments of this application will be described. See [link to relevant documentation]. Figure 1 , Figure 1 This is a schematic diagram of the processing flow of the image detection method provided in the embodiments of this application. Figure 1 , will combine Figure 1 Steps S101-S103 shown will be explained.
[0049] Step S101: Obtain the template image corresponding to the keyboard.
[0050] In some embodiments, the template image may include: a template image obtained by converting a keyboard-based design document.
[0051] Step S102: Perform connected component segmentation on the template image to determine the first connected component of each button image included in the template image.
[0052] In some embodiments, the button image may include: an image of each button included in the template image. The first connected component may include: the connected component corresponding to the image of each button.
[0053] In some embodiments, before step S102, the image detection method may further include: performing binarization thresholding on the template image to obtain a binarized template image; performing vertical and horizontal projection on the binarized template image to obtain adjacent non-projected regions corresponding to the binarized template image; determining the ordinate difference between adjacent non-projected regions; in response to the ordinate difference being less than a preset distance threshold, determining the adjacent non-projected regions corresponding to the ordinate difference as invalid character regions; deleting invalid character regions from the binarized template image to obtain a region to be detected; and filling holes in the region to be detected to obtain a first keyboard image; the first keyboard image is a part of the template image corresponding to the keyboard.
[0054] In practice, the template image is first binarized and thresholded to obtain a binarized template image. Then, a two-dimensional array with the same dimensions as the binarized template image is defined.
[0055] _ProjArr[_rows][_cols]. Here, _cols represents the x-coordinate and _rows represents the y-coordinate. The pixels in the binarized template image are traversed one by one. In response to a pixel with a non-zero grayscale value in the binarized template image, the x-coordinate of that pixel in the two-dimensional array is incremented by 1, maintaining consistency with the current x-coordinate of that pixel. After traversal, the region corresponding to the x-coordinate of 0 in the two-dimensional array is determined and designated as the adjacent non-projected region. The difference in y-coordinates between adjacent non-projected regions is calculated. In response to a y-coordinate difference less than a preset distance threshold, the adjacent non-projected region corresponding to the y-coordinate difference is identified as an invalid character region. The invalid character regions in the binarized template image are deleted, and the minimum bounding rectangle of the remaining region in the binarized template image is subtracted to obtain the region to be detected. Holes are filled in the region to be detected to obtain the first keyboard image. The first keyboard image is the image of the keyboard key area in the template image. The preset distance threshold is preferably 70 pixels. Invalid character regions may include redundant invalid character regions in the template image corresponding to the keyboard.
[0056] In practical implementation, the difference in ordinates between adjacent non-projected regions, _MAXDISTENCE, can be expressed by the following formula (1):
[0057] _MAXDISTENCE = _rowsStart-_rowsEnd (1)
[0058] Where _rowsStart represents the ordinate value of the starting pixel of the adjacent non-projected region, and _rowsEnd represents the ordinate value of the ending pixel of the adjacent non-projected region.
[0059] In some embodiments, after step S102, the image detection method may further include: determining at least one of the following: pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top-left corner point corresponding to the first connected region of each button image. The first center point may include the center point of the first connected region of the button image.
[0060] Step S103: Based on the first connected component, determine whether there are defects in the template image.
[0061] In Embodiment 1, step S103 may include: determining the abscissa of a second center point of the first keyboard image; determining a first difference between the abscissa of the second center point and the abscissa of the first center point; and determining that the template image has a first defect in response to a pixel height greater than a preset height threshold, a pixel width greater than a preset width threshold, and the first difference less than a preset pixel threshold. The second center point may include the center point of the first keyboard image. The preset height threshold is preferably 1.5 times the average key height. The preset width threshold is preferably 1.2 times the average key width. The preset pixel threshold is preferably 850 pixels. The first defect in the template image may include a defect where the keys are connected.
[0062] In Embodiment 2, step S103 may include: determining a first number of first connected components of the first button image; the first button image is a button image whose upper left corner point's x-coordinate is within a preset x-coordinate range; in response to the first number being less than a preset first number threshold, determining that the template image has a second defect. The preset x-coordinate range is preferably a range where the x-coordinate is greater than 0 and less than 10. The preset first number threshold is preferably 10. The second defect in the template image may include: the template image having a thick outline.
[0063] In Embodiment 3, step S103 may include: determining the maximum ordinate value of the pixels in the first connected region of the first button image; determining the vertical height of the area to be detected; and determining that the template image has a third defect in response to the difference between the vertical height and the maximum ordinate value of the pixels being greater than a preset difference threshold. The presence of a third defect in the template image may include: the template image having a defect of having redundant touchpad areas.
[0064] In practical implementation, the difference between the vertical height and the maximum value of the pixel's ordinate, _diffRows, can be expressed by the following formula (2):
[0065] _diffRows = _imgRows - _rowMax (2)
[0066] Where _imgRows represents the vertical height of the region to be detected, and _rowMax represents the maximum vertical coordinate of the pixels in the first connected region.
[0067] In Embodiment 4, step S103 may include: determining a second number of first connected components included in the first keyboard image; determining a fourth defect in the template image in response to the second number being greater than a preset second number threshold; performing connected component segmentation on the region to be detected to determine the second connected components included in the region to be detected; determining a third number of the second connected components included in the region to be detected; and determining a fifth defect in the template image in response to the third number being less than a preset third number threshold. The preset second number threshold is preferably 110. A fourth defect in the template image may include: a watermark defect. A fourth defect in the template image may also include: a missing outline region of the keys in the template image. The preset third number threshold is preferably twice the second number minus 1. A fifth defect in the template image may include: a missing key character defect in the template image.
[0068] In Embodiment 5, step S103 may include: determining a first connected component of the key image corresponding to a preset coordinate position; determining the character region with the largest horizontal coordinate within the first connected component; determining the roundness and area corresponding to the character region with the largest horizontal coordinate; and determining that the template image has a sixth defect if the roundness is greater than a preset roundness threshold and the area is greater than a preset area threshold. The preset coordinate position may include the coordinate position of the key image containing an indicator light in the template image. The preset roundness threshold is preferably 0.7. The preset area threshold is preferably 100 pixels. The sixth defect in the template image may include a defect where the key indicator light is blocked.
[0069] In practical implementation, the roundness _CIRCULARITY corresponding to the character area with the largest horizontal coordinate can be expressed by the following formulas (3), (4), (5) and (6):
[0070]
[0071]
[0072]
[0073]
[0074] Where _avaDistence represents the average distance from the outline points of the character region to the center point, n represents the number of outline points, _ptX represents the x-coordinate of the outline points of the character region, _ptY represents the y-coordinate of the outline points of the character region, _centerX represents the x-coordinate of the center point of the character region, _centerY represents the y-coordinate of the center point of the character region, _sumSpreadVal represents the deviation index, and _sigemaDistence represents the deviation coefficient.
[0075] In some embodiments, one or more of the defect detection methods in the template image provided in Embodiments 1 to 5 above for step S103 can be used to determine the defects present in the template image based on the first connected component.
[0076] In some embodiments, the processing flow of the image detection method is illustrated. Figure 2 ,like Figure 2 As shown, it includes:
[0077] Step S201: Perform binarization thresholding on the template image to obtain a binarized template image.
[0078] Step S202: Perform vertical and horizontal projection on the binarized template image to obtain the adjacent non-projected regions corresponding to the binarized template image.
[0079] Step S203: Determine the difference in ordinates between adjacent non-projected regions.
[0080] Step S204: In response to the vertical coordinate difference being less than a preset distance threshold, the adjacent non-projected regions corresponding to the vertical coordinate difference are determined as invalid character regions.
[0081] As an example, for steps S203 and S204, the preset distance threshold is 70 pixels. The difference in ordinates between adjacent non-projected regions is determined to be 50 pixels. If the difference in ordinates between adjacent non-projected regions is 50 pixels, which is less than the preset distance threshold of 70 pixels, the adjacent non-projected region corresponding to the difference in ordinates of 50 pixels is determined to be an invalid character region.
[0082] Step S205: Delete invalid character regions in the binarized template image to obtain the region to be detected.
[0083] Step S206: Fill the holes in the area to be detected to obtain the first keyboard image.
[0084] The specific explanations for each step in steps S201 and S206 are the same as those for step S103 above, and will not be repeated here.
[0085] In some embodiments, the processing flow of the image detection method is illustrated. Figure 3 ,like Figure 3 As shown, it includes:
[0086] Step S301a: Determine the horizontal coordinate of the second center point of the first keyboard image.
[0087] Step S301b: Determine the first difference between the x-coordinate of the second center point and the x-coordinate of the first center point.
[0088] In step S301c, in response to the pixel height being greater than a preset height threshold, the pixel width being greater than a preset width threshold, and the first difference being less than a preset pixel threshold, it is determined that the template image has a first defect.
[0089] As an example, for step S301c, the pixel height being greater than a preset height threshold, the pixel width being greater than a preset width threshold, and the first difference being less than a preset pixel threshold can be expressed by the following formulas (7), (8), and (9):
[0090] _HEIGHT > 1.5 * _avaHeight (7)
[0091] _WIDTH > 1.2 * _avaWidth (8)
[0092] abs|_CENTERX - _curCenterX| < 850 pixel (9)
[0093] Where _HEIGHT represents the pixel height, 1.5*_avaHeight represents the preset height threshold of 1.5 times the average button height, _WIDTH represents the pixel width, 1.2*_avaWidth represents the preset width threshold of 1.2 times the average button width, _CENTERX represents the x-coordinate of the second center point, _curCenterX represents the x-coordinate of the second center point, and 850pixel represents the preset pixel threshold of 850 pixels.
[0094] The specific descriptions of each step S301a-S301c are the same as those for step S103 above, and will not be repeated here.
[0095] In some embodiments, the processing flow of the image detection method is illustrated. Figure 4 ,like Figure 4 As shown, it includes:
[0096] Step S302a: Determine the first number of first connected components of the first button image.
[0097] In step S302b, in response to the first quantity being less than a preset first quantity threshold, it is determined that the template image has a second defect.
[0098] Step S302c: Determine the maximum value of the ordinate of the pixels in the first connected region of the first button image.
[0099] Step S302d: Determine the vertical height of the area to be detected.
[0100] In step S302e, in response to the difference between the vertical height and the maximum value of the ordinate of the pixel being greater than a preset difference threshold, it is determined that the template image has a third defect.
[0101] The specific descriptions of each step S302a-S302e are the same as those for step S103 above, and will not be repeated here.
[0102] In some embodiments, the processing flow of the image detection method is illustrated. Figure 5 ,like Figure 5 As shown, it includes:
[0103] Step S303a: Determine the second number of first connected components included in the first keyboard image.
[0104] In step S303b, in response to the second quantity being greater than a preset second quantity threshold, it is determined that the template image has a fourth defect.
[0105] Step S303c: Perform connected component segmentation on the region to be detected to determine the second connected component included in the region to be detected.
[0106] Step S303d: Determine the third number of the second connected components included in the region to be detected.
[0107] In step S303e, in response to the third quantity being less than a preset third quantity threshold, it is determined that the template image has a fifth defect.
[0108] The specific descriptions of each step S303a-S303e are the same as those for step S103 above, and will not be repeated here.
[0109] In some embodiments, the processing flow of the image detection method is illustrated. Figure 6 ,like Figure 6 As shown, it includes:
[0110] Step S304a: Based on the preset coordinate position, determine the first connected component of the button image corresponding to the preset coordinate position.
[0111] Step S304b: Determine the character region with the largest x-coordinate within the first connected component.
[0112] Step S304c: Determine the roundness and area corresponding to the character region with the largest horizontal coordinate.
[0113] In step S304d, in response to the roundness being greater than a preset roundness threshold and the area being greater than a preset area threshold, it is determined that the template image has a sixth defect.
[0114] The specific descriptions of each step S304a-S304d are the same as those for step S103 above, and will not be repeated here.
[0115] Figure 7 This application illustrates an application scenario of the image detection method provided in the embodiments of this application. Figure 1 ;
[0116] refer to Figure 7 Application scenarios of the image detection method provided in this application embodiment Figure 1 This method is applied to detect template images using image detection techniques, identifying defects such as invalid character regions. It also identifies defects such as missing key outlines in the template images.
[0117] Understandable. Figure 7 The application scenarios of the image detection method described in this application are only some exemplary implementations. The application scenarios of the image detection method in this application include, but are not limited to, those mentioned above. Figure 7 The image detection method shown is applicable to various scenarios.
[0118] Figure 8 This application illustrates an application scenario of the image detection method provided in the embodiments of this application. Figure 2 ;
[0119] refer to Figure 8 Application scenarios of the image detection method provided in this application embodiment Figure 2 This method is applied to detect template images using image detection techniques, identifying defects such as watermarks. Specifically, it identifies template images with defects such as thick outlines.
[0120] Understandable. Figure 8 The application scenarios of the image detection method described in this application are only some exemplary implementations. The application scenarios of the image detection method in this application include, but are not limited to, those mentioned above. Figure 8 The image detection method shown is applicable to various scenarios.
[0121] Figure 9 This application illustrates an application scenario of the image detection method provided in the embodiments of this application. Figure 3 ;
[0122] refer to Figure 9 This application provides an example of an image detection method that, in one scenario, is used to detect a template image based on the image detection method and determine if the template image has a defect of missing key characters. It also describes a scenario where the template image has a defect of connected keys.
[0123] Understandable. Figure 9The application scenarios of the image detection method described in this application are only some exemplary implementations. The application scenarios of the image detection method in this application include, but are not limited to, those mentioned above. Figure 9 The image detection method shown is applicable to various scenarios.
[0124] Figure 10 This application illustrates an application scenario of the image detection method provided in the embodiments of this application. Figure 4 ;
[0125] refer to Figure 10 Application scenarios of the image detection method provided in this application embodiment Figure 4 This method is applied to detect template images using image detection techniques, identifying defects such as redundant touchpad areas and blocked button indicator lights.
[0126] Understandable. Figure 10 The application scenarios of the image detection method described in this application are only some exemplary implementations. The application scenarios of the image detection method in this application include, but are not limited to, those mentioned above. Figure 10 The image detection method shown is applicable to various scenarios.
[0127] The method in this embodiment performs binarization thresholding on a template image to obtain a binarized template image; performs vertical and horizontal projection on the binarized template image to obtain adjacent non-projected regions corresponding to the binarized template image; determines the difference in ordinates between adjacent non-projected regions; in response to the difference in ordinates being less than a preset distance threshold, determines the adjacent non-projected regions corresponding to the difference in ordinates as invalid character regions; deletes the invalid character regions in the binarized template image to obtain the region to be detected; and fills holes in the region to be detected to obtain a first keyboard image; the first keyboard image is a part of the template image corresponding to the keyboard. Thus, the template image corresponding to the keyboard can be automatically detected to determine whether there are defects in the template image, eliminating the need for manual detection, improving the detection accuracy of defects in the image, reducing the image detection time, and thus improving the detection efficiency of defects in the image. The method in this embodiment also determines the abscissa of the second center point of the first keyboard image; determines the first difference between the abscissa of the second center point and the abscissa of the first center point; and in response to a pixel height greater than a preset height threshold, a pixel width greater than a preset width threshold, and the first difference less than a preset pixel threshold, determines that the template image has a first defect. Thus, the template image corresponding to the keyboard can be automatically detected, and defects in the template image can be identified, improving the detection accuracy of defects in the image, reducing the image detection time, and thus improving the detection efficiency of defects in the image. The method of this application embodiment determines a first number of first connected components in the first key image; the first key image is a key image whose upper left corner point's x-coordinate is within a preset x-coordinate range; in response to the first number being less than a preset first number threshold, it is determined that the template image has a second defect. Thus, the template image corresponding to the keyboard can be automatically detected, and defects in the template image can be identified, improving the detection accuracy of defects in the image, reducing the image detection time, and thus improving the detection efficiency of defects in the image. The method of this application embodiment determines the maximum ordinate value of the pixels in the first connected component of the first key image; determines the vertical height of the area to be detected; in response to the difference between the vertical height and the maximum ordinate value of the pixels being greater than a preset difference threshold, it is determined that the template image has a third defect. Thus, the template image corresponding to the keyboard can be automatically detected, and defects in the template image can be identified, improving the detection accuracy of defects in the image, reducing the image detection time, and thus improving the detection efficiency of defects in the image. The method of this application embodiment determines a second number of first connected components included in a first keyboard image; in response to the second number being greater than a preset second number threshold, determines that a fourth defect exists in the template image; performs connected component segmentation on the region to be detected to determine a second connected component included in the region to be detected; determines a third number of second connected components included in the region to be detected; in response to the third number being less than a preset third number threshold, determines that a fifth defect exists in the template image.In this way, the template image corresponding to the keyboard can be automatically detected, and defects in the template image can be identified, improving the detection accuracy of defects in the image, reducing the image detection time, and thus improving the detection efficiency of defects in the image. The method of this embodiment determines a first connected component of the key image corresponding to a preset coordinate position; determines the character region with the largest horizontal coordinate within the first connected component; determines the roundness and area corresponding to the character region with the largest horizontal coordinate; and determines that the template image has a sixth defect if the roundness is greater than a preset roundness threshold and the area is greater than a preset area threshold. Thus, the template image corresponding to the keyboard can be automatically detected, and defects in the template image can be identified, improving the detection accuracy of defects in the image, reducing the image detection time, and thus improving the detection efficiency of defects in the image.
[0128] Therefore, compared with the related technologies that are time-consuming in the image detection process and have low detection accuracy of defects in the image, the image detection method of this application can reduce the image detection time, improve the detection accuracy of defects in the image, and thus improve the detection efficiency of defects in the image.
[0129] The following description continues to illustrate the exemplary structure of the image detection device 90 provided in the embodiments of this application as a software module. In some embodiments, such as... Figure 11 As shown, the software modules in the image detection device 90 may include: an acquisition module 901, used to acquire a template image corresponding to the keyboard; a determination module 902, used to perform connected component segmentation on the template image and determine the first connected component of each key image included in the template image; and a detection module 903, used to determine whether there are defects in the template image based on the first connected component.
[0130] In some embodiments, the image detection device 90 may further include a projection module 904, wherein the projection module 904 in Figure 11 Not shown in the text, the projection module 904 can be used to: perform binarization thresholding on the template image to obtain a binarized template image; perform vertical and horizontal projection on the binarized template image to obtain adjacent non-projected regions corresponding to the binarized template image; determine the difference in ordinates between adjacent non-projected regions; in response to the difference in ordinates being less than a preset distance threshold, determine the adjacent non-projected regions corresponding to the difference in ordinates as invalid character regions; delete the invalid character regions in the binarized template image to obtain the region to be detected; fill holes in the region to be detected to obtain a first keyboard image; the first keyboard image is a part of the template image corresponding to the keyboard.
[0131] In some embodiments, the image detection device 90 may further include a calculation module 905, wherein the calculation module 905 performs... Figure 11Not shown in the text, the calculation module 905 can be used to: determine at least one of the following: pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top left corner point corresponding to the first connected component of each button image.
[0132] In some embodiments, the detection module 903 may be used to: determine the abscissa of the second center point of the first keyboard image; determine the first difference between the abscissa of the second center point and the abscissa of the first center point; and determine that the template image has a first defect in response to the pixel height being greater than a preset height threshold, the pixel width being greater than a preset width threshold, and the first difference being less than a preset pixel threshold.
[0133] In some embodiments, the detection module 903 may be used to: determine a first number of first connected components of a first button image; the first button image is a button image whose upper left corner point has an abscissa within a preset abscissa range; and in response to the first number being less than a preset first number threshold, determine that the template image has a second defect.
[0134] In some embodiments, the detection module 903 may be used to: determine the maximum value of the ordinate of the pixels in the first connected region of the first button image; determine the vertical height of the region to be detected; and determine that the template image has a third defect in response to the difference between the vertical height and the maximum value of the ordinate of the pixels being greater than a preset difference threshold.
[0135] In some embodiments, the detection module 903 may be used to: determine a second number of first connected components included in the first keyboard image; determine that a fourth defect exists in the template image in response to the second number being greater than a preset second number threshold; perform connected component segmentation on the region to be detected to determine a second connected component included in the region to be detected; determine a third number of second connected components included in the region to be detected; and determine that a fifth defect exists in the template image in response to the third number being less than a preset third number threshold.
[0136] In some embodiments, the detection module 903 can be used to: determine a first connected region of the key image corresponding to a preset coordinate position based on a preset coordinate position; determine the character region with the largest horizontal coordinate within the first connected region; determine the roundness and area corresponding to the character region with the largest horizontal coordinate; and determine that the template image has a sixth defect if the roundness is greater than a preset roundness threshold and the area is greater than a preset area threshold.
[0137] It should be noted that the description of the apparatus in this application embodiment is similar to the description of the method embodiment above, and has similar beneficial effects as the method embodiment, therefore it will not be repeated. For any technical details not covered in the image detection apparatus provided in this application embodiment, please refer to... Figures 1 to 11 The meaning is understood in accordance with the description of any of the accompanying drawings.
[0138] According to embodiments of this application, this application also provides an electronic device and a non-transitory computer-readable storage medium.
[0139] Figure 12 A schematic block diagram of an example electronic device 800 that can be used to implement embodiments of this application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the application described and / or claimed herein.
[0140] like Figure 12 As shown, the electronic device 800 includes a computing unit 801, which 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. The RAM 803 may also store various programs and data required for the operation of the electronic device 800. The computing unit 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0141] Multiple components in electronic device 800 are connected to I / O interface 805, including: input unit 806, such as keyboard, mouse, etc.; output unit 807, such as various types of displays, speakers, etc.; storage unit 808, such as disk, optical disk, etc.; and communication unit 809, such as network card, modem, wireless transceiver, etc. Communication unit 809 allows electronic device 800 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0142] The computing unit 801 can be a variety of general-purpose 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 special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 801 performs the various methods and processes described above, such as image detection methods. For example, in some embodiments, the image detection method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of the image detection method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform the image detection method by any other suitable means (e.g., by means of firmware).
[0143] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0144] The program code used to implement the methods of this application may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0145] In the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0146] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0147] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0148] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.
[0149] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this application can be achieved, and this is not limited herein.
[0150] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "a plurality of" means two or more, unless otherwise explicitly specified.
[0151] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. An image detection method, characterized in that, The method includes: Get the template image corresponding to the keyboard; Perform connected component segmentation on the template image to determine the first connected component of each button image included in the template image; Determine at least one of the following: pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top-left corner point, corresponding to the first connected component of each button image; Based on at least one of the pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top-left corner point corresponding to the first connected component, determine whether the template image has defects; Determining whether the template image has a defect based on at least one of the pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top-left corner point corresponding to the first connected component includes: determining the x-coordinate of the second center point of the first keyboard image; the first keyboard image is a part of the template image corresponding to the keyboard; the second center point is the center point of the first keyboard image; the first center point is the center point of the first connected component of the key image; determining a first difference between the x-coordinate of the second center point and the x-coordinate of the first center point; and determining that the template image has a first defect in response to the pixel height being greater than a preset height threshold, the pixel width being greater than a preset width threshold, and the first difference being less than a preset pixel threshold; the first defect includes the template image having a defect of connected keys.
2. The method according to claim 1, characterized in that, Before determining the first connected component of each button image included in the template image, the method further includes: The template image is subjected to binarization thresholding to obtain a binarized template image; The binarized template image is subjected to vertical and horizontal projection to obtain the adjacent non-projected regions corresponding to the binarized template image; Determine the difference in ordinates between the adjacent non-projected regions; In response to the ordinate difference being less than a preset distance threshold, the adjacent non-projected region corresponding to the ordinate difference is determined as an invalid character region; The invalid character region in the binarized template image is deleted to obtain the region to be detected; The area to be detected is filled with holes to obtain a first keyboard image.
3. The method according to claim 2, characterized in that, Determining whether the template image has defects based on at least one of the pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top-left corner point corresponding to the first connected component includes: Determine the first number of first connected components of the first button image; the first button image is a button image whose x-coordinate of the upper left corner point is within a preset x-coordinate range; In response to the first quantity being less than a preset first quantity threshold, it is determined that the template image has a second defect; The second defect includes the template image having thick outlines.
4. The method according to claim 3, characterized in that, Determining whether the template image has defects based on at least one of the pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top-left corner point corresponding to the first connected component includes: Determine the maximum value of the ordinate of the pixels in the first connected region of the first button image; Determine the vertical height of the area to be detected; In response to the fact that the difference between the vertical height and the maximum value of the ordinate of the pixel is greater than a preset difference threshold, it is determined that the template image has a third defect; The third defect includes the presence of redundant touchpad areas in the template image.
5. The method according to claim 2, characterized in that, Determining whether the template image has defects based on at least one of the pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top-left corner point corresponding to the first connected component includes: Determine a second number of the first connected components included in the first keyboard image; In response to the second quantity being greater than a preset second quantity threshold, it is determined that the template image has a fourth defect; Perform connected component segmentation on the region to be detected to determine the second connected component included in the region to be detected; Determine the third number of the second connected components included in the region to be detected; In response to the third quantity being less than a preset third quantity threshold, it is determined that the template image has a fifth defect; The fourth defect includes the defect that the template image has a watermark or the defect that the outline area of the key is missing in the template image. The fifth defect includes the defect of missing key characters in the template image.
6. The method according to claim 2, characterized in that, Determining whether the template image has defects based on at least one of the pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top-left corner point corresponding to the first connected component includes: Based on the preset coordinate position, determine the first connected component of the button image corresponding to the preset coordinate position; Determine the character region with the largest x-coordinate within the first connected component; Determine the roundness and area corresponding to the character region with the largest horizontal coordinate; If the roundness is greater than a preset roundness threshold and the area is greater than a preset area threshold, then it is determined that the template image has a sixth defect. The sixth defect includes the defect that the button indicator lights in the template image are blocked.
7. An image detection device, characterized in that, The image detection device includes: The acquisition module is used to acquire the template image corresponding to the keyboard. A determination module is used to perform connected component segmentation on the template image and determine the first connected component of each button image included in the template image; The calculation module is used to: determine at least one of the following: pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top-left corner point corresponding to the first connected component of each button image; The detection module is used to determine whether the template image has defects based on at least one of the pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top-left corner point corresponding to the first connected component; Determining whether the template image has a defect based on at least one of the pixel height, pixel width, x-coordinate of the first center point, and y-coordinate of the top-left corner point corresponding to the first connected component includes: determining the x-coordinate of the second center point of the first keyboard image; the first keyboard image is a part of the template image corresponding to the keyboard; the second center point is the center point of the first keyboard image; the first center point is the center point of the first connected component of the key image; determining a first difference between the x-coordinate of the second center point and the x-coordinate of the first center point; and determining that the template image has a first defect in response to the pixel height being greater than a preset height threshold, the pixel width being greater than a preset width threshold, and the first difference being less than a preset pixel threshold; the first defect includes the template image having a defect of connected keys.
8. The apparatus according to claim 7, characterized in that, The image detection device further includes a projection module, which is used for: The template image is subjected to binarization thresholding to obtain a binarized template image; The binarized template image is subjected to vertical and horizontal projection to obtain the adjacent non-projected regions corresponding to the binarized template image; Determine the difference in ordinates between the adjacent non-projected regions; In response to the ordinate difference being less than a preset distance threshold, the adjacent non-projected region corresponding to the ordinate difference is determined as an invalid character region; The invalid character region in the binarized template image is deleted to obtain the region to be detected; The area to be detected is filled with holes to obtain a first keyboard image.
9. The apparatus according to claim 8, characterized in that, The detection module is used for: Determine the first number of first connected components of the first button image; the first button image is a button image whose x-coordinate of the upper left corner point is within a preset x-coordinate range; In response to the first quantity being less than a preset first quantity threshold, it is determined that the template image has a second defect; The second defect includes the template image having thick outlines.
10. The apparatus according to claim 9, characterized in that, The detection module is used for: Determine the maximum value of the ordinate of the pixels in the first connected region of the first button image; Determine the vertical height of the area to be detected; In response to the fact that the difference between the vertical height and the maximum value of the ordinate of the pixel is greater than a preset difference threshold, it is determined that the template image has a third defect; The third defect includes the presence of redundant touchpad areas in the template image.
11. The apparatus according to claim 8, characterized in that, The detection module is used for: Determine a second number of the first connected components included in the first keyboard image; In response to the second quantity being greater than a preset second quantity threshold, it is determined that the template image has a fourth defect; Perform connected component segmentation on the region to be detected to determine the second connected component included in the region to be detected; Determine the third number of the second connected components included in the region to be detected; In response to the third quantity being less than a preset third quantity threshold, it is determined that the template image has a fifth defect; The fourth defect includes the defect that the template image has a watermark or the defect that the outline area of the key is missing in the template image. The fifth defect includes the defect of missing key characters in the template image.
12. The apparatus according to claim 8, characterized in that, The detection module is used for: Based on the preset coordinate position, determine the first connected component of the button image corresponding to the preset coordinate position; Determine the character region with the largest x-coordinate within the first connected component; Determine the roundness and area corresponding to the character region with the largest horizontal coordinate; If the roundness is greater than a preset roundness threshold and the area is greater than a preset area threshold, then it is determined that the template image has a sixth defect. The sixth defect includes the defect that the button indicator lights in the template image are blocked.
13. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.
14. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-6.
Citation Information
Patent Citations
Defect detection method and device, electronic equipment and storage medium
CN114445318A
Detection method and device, detection equipment and storage medium
CN115375608A