A webpage element testing method and device
By automatically testing the outlines of web page elements using grayscale processing and Gaussian filtering techniques, the problem of low testing efficiency in existing technologies is solved, achieving efficient and accurate testing of web page elements.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUNAN HAPPLY SUNSHINE INTERACTIVE ENTERTAINMENT MEDIA CO LTD
- Filing Date
- 2023-06-09
- Publication Date
- 2026-05-29
AI Technical Summary
Existing technologies for testing web page elements are inefficient, mainly relying on manual methods, which leads to low testing efficiency.
The images of the web page elements to be tested and the template web page elements are processed using grayscale processing and Gaussian filtering techniques. Edge detection is performed using Gaussian parameters and gradient values, and similarity is calculated to automatically test the contours of the web page elements.
It enables automated testing of web page elements, improving testing efficiency, enhancing contrast, reducing noise, improving the accuracy and robustness of edge detection, and ensuring the accuracy of similarity and testing.
Smart Images

Figure CN116703868B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method and apparatus for testing web page elements. Background Technology
[0002] Testing web pages is essential in the software development process.
[0003] Currently, the outlines of elements on web pages are typically tested manually. However, this manual method suffers from low testing efficiency. Summary of the Invention
[0004] This application provides the following technical solution:
[0005] This application provides a method for testing web page elements, including:
[0006] The images corresponding to the elements of the webpage to be tested and the images corresponding to the elements of the template webpage are processed into grayscale to obtain the first grayscale image and the second grayscale image.
[0007] Obtain the first Gaussian parameter corresponding to the first grayscale image and the second Gaussian parameter corresponding to the second grayscale image;
[0008] The first grayscale image is subjected to Gaussian filtering based on the first Gaussian parameter to obtain the third grayscale image, and the second grayscale image is subjected to Gaussian filtering based on the second Gaussian parameter to obtain the fourth grayscale image.
[0009] Obtain the first gradient value corresponding to the third grayscale image and the second gradient value corresponding to the fourth grayscale image;
[0010] Based on the first gradient value, edge detection is performed on the third grayscale image to obtain a first edge image; based on the second gradient value, edge detection is performed on the fourth grayscale image to obtain a second edge image.
[0011] Based on the first edge map and the second edge map, the similarity between the web page element to be tested and the template web page element is determined;
[0012] If the similarity meets the similarity threshold, the webpage element to be tested is determined to have passed the contour test.
[0013] Optionally, obtaining the first Gaussian parameters corresponding to the first grayscale image includes:
[0014] Obtain the total number of pixels in the first grayscale image;
[0015] Divide the square root of the total number of pixels in the first grayscale image by 100 to obtain the usable Gaussian kernel size for the first grayscale image.
[0016] If the usable Gaussian kernel size corresponding to the first grayscale image is an odd number, the usable Gaussian kernel size corresponding to the first grayscale image is determined to be the first Gaussian parameter corresponding to the first grayscale image.
[0017] If the usable Gaussian kernel size corresponding to the first grayscale image is an even number, the usable Gaussian kernel size corresponding to the first grayscale image is added to a set odd number to obtain the first Gaussian parameter corresponding to the first grayscale image.
[0018] Optionally, obtaining the first Gaussian parameter corresponding to the first grayscale image and the second Gaussian parameter corresponding to the second grayscale image includes:
[0019] Obtain the total number of pixels in the second grayscale image;
[0020] Divide the total number of pixels in the second grayscale image by 100 to obtain the usable Gaussian kernel size for the second grayscale image;
[0021] If the usable Gaussian kernel size corresponding to the second grayscale image is an odd number, then the usable Gaussian kernel size corresponding to the second grayscale image is determined to be the second Gaussian parameter corresponding to the second grayscale image.
[0022] If the usable Gaussian kernel size corresponding to the second grayscale image is an even number, the usable Gaussian kernel size is added to the set odd number to obtain the second Gaussian parameter corresponding to the second grayscale image.
[0023] Optionally, obtaining the first Gaussian parameters corresponding to the first grayscale image includes:
[0024] By searching within a set Gaussian kernel size range with a set step size, multiple first candidate Gaussian kernel sizes are obtained;
[0025] The first grayscale image is processed by Gaussian filtering based on the size of each first candidate Gaussian kernel to obtain the fifth grayscale image;
[0026] Obtain the mean square error between each of the fifth grayscale images and the first grayscale image;
[0027] The minimum mean square error between each of the fifth grayscale images and the first grayscale image is determined;
[0028] Based on the image noise level corresponding to the first grayscale image, the size of the first candidate Gaussian kernel corresponding to the minimum value is scaled to obtain the first Gaussian parameter corresponding to the first grayscale image. The image noise level corresponding to the first grayscale image is determined based on the minimum value of the mean square error between each fifth grayscale image and the first grayscale image.
[0029] Optionally, scaling the size of the first candidate Gaussian kernel corresponding to the minimum value based on the image noise level corresponding to the first grayscale image to obtain the first Gaussian parameter corresponding to the first grayscale image includes:
[0030] Divide the size of the first candidate Gaussian kernel corresponding to the minimum value by the image noise level corresponding to the first grayscale image to obtain the size of the first Gaussian kernel to be used.
[0031] If the size of the first Gaussian kernel to be used is odd, the size of the first Gaussian kernel to be used is determined to be the first Gaussian parameter corresponding to the first grayscale image;
[0032] If the first usable Gaussian kernel size is even, add the first usable Gaussian kernel size to a set odd number to obtain the first Gaussian parameter corresponding to the first grayscale image.
[0033] Optionally, obtaining the second Gaussian parameters corresponding to the second grayscale image includes:
[0034] By searching within a set Gaussian kernel size range with a set step size, multiple second candidate Gaussian kernel sizes are obtained;
[0035] The second grayscale image is processed based on the size of each second candidate Gaussian kernel to obtain the sixth grayscale image;
[0036] Obtain the mean square error between each of the sixth grayscale images and the second grayscale image;
[0037] The minimum mean square error between each of the sixth grayscale images and the second grayscale image is determined;
[0038] Based on the image noise level corresponding to the second grayscale image, the size of the second candidate Gaussian kernel corresponding to the minimum value is scaled to obtain the second Gaussian parameter corresponding to the second grayscale image. The image noise level corresponding to the second grayscale image is determined based on the minimum value of the mean square error between each sixth grayscale image and the second grayscale image.
[0039] Optionally, scaling the size of the second candidate Gaussian kernel corresponding to the minimum value based on the image noise level corresponding to the second grayscale image to obtain the second Gaussian parameter corresponding to the second grayscale image includes:
[0040] Divide the second candidate Gaussian kernel size corresponding to the minimum value by the image noise level corresponding to the second grayscale image to obtain the second Gaussian kernel size to be used.
[0041] If the size of the second Gaussian kernel to be used is odd, the size of the second Gaussian kernel to be used is determined to be the second Gaussian parameter corresponding to the second grayscale image;
[0042] If the second usable Gaussian kernel size is even, add the second usable Gaussian kernel size to the set odd number to obtain the second Gaussian parameter corresponding to the second grayscale image.
[0043] This application also provides a webpage element testing apparatus, comprising:
[0044] The grayscale processing module is used to perform grayscale processing on the images corresponding to the web page elements to be tested and the images corresponding to the template web page elements respectively, to obtain the first grayscale image and the second grayscale image.
[0045] The first obtaining module is used to obtain the first Gaussian parameter corresponding to the first grayscale image and the second Gaussian parameter corresponding to the second grayscale image;
[0046] The Gaussian filtering module is used to perform Gaussian filtering on the first grayscale image based on the first Gaussian parameter to obtain a third grayscale image, and to perform Gaussian filtering on the second grayscale image based on the second Gaussian parameter to obtain a fourth grayscale image.
[0047] The second obtaining module is used to obtain the first gradient value corresponding to the third grayscale image and the second gradient value corresponding to the fourth grayscale image;
[0048] An edge detection module is used to perform edge detection on the third grayscale image based on the first gradient value to obtain a first edge image, and to perform edge detection on the fourth grayscale image based on the second gradient value to obtain a second edge image;
[0049] The first determining module is used to determine the similarity between the webpage element to be tested and the template webpage element based on the first edge map and the second edge map;
[0050] The second determining module is used to determine that the webpage element to be tested passes the contour test if the similarity meets the similarity threshold.
[0051] Optionally, the process by which the first obtaining module obtains the first Gaussian parameter corresponding to the first grayscale image specifically includes:
[0052] Obtain the total number of pixels in the first grayscale image;
[0053] Divide the square root of the total number of pixels in the first grayscale image by 100 to obtain the usable Gaussian kernel size for the first grayscale image.
[0054] If the usable Gaussian kernel size corresponding to the first grayscale image is an odd number, the usable Gaussian kernel size corresponding to the first grayscale image is determined to be the first Gaussian parameter corresponding to the first grayscale image.
[0055] If the usable Gaussian kernel size corresponding to the first grayscale image is an even number, the usable Gaussian kernel size corresponding to the first grayscale image is added to a set odd number to obtain the first Gaussian parameter corresponding to the first grayscale image.
[0056] Optionally, the process by which the first obtaining module obtains the second Gaussian parameters corresponding to the second grayscale image specifically includes:
[0057] Obtain the total number of pixels in the second grayscale image;
[0058] Divide the total number of pixels in the second grayscale image by 100 to obtain the usable Gaussian kernel size for the second grayscale image;
[0059] If the usable Gaussian kernel size corresponding to the second grayscale image is an odd number, then the usable Gaussian kernel size corresponding to the second grayscale image is determined to be the second Gaussian parameter corresponding to the second grayscale image.
[0060] If the usable Gaussian kernel size corresponding to the second grayscale image is an even number, the usable Gaussian kernel size is added to the set odd number to obtain the second Gaussian parameter corresponding to the second grayscale image.
[0061] In this application, the web page element testing method can automatically test the outline of the web page element to be tested, thereby improving testing efficiency.
[0062] Furthermore, grayscale processing is performed on the images corresponding to the elements of the webpage under test and the images corresponding to the elements of the template webpage, respectively, to obtain a first grayscale image and a second grayscale image. This can improve contrast and reduce noise. Based on this, a first Gaussian parameter corresponding to the first grayscale image and a second Gaussian parameter corresponding to the second grayscale image are obtained. Gaussian filtering is then performed on the first grayscale image based on the first Gaussian parameter to obtain a third grayscale image. Gaussian filtering is then performed on the second grayscale image based on the second Gaussian parameter to obtain a fourth grayscale image. This allows for more precise smoothing and noise removal of the first and second grayscale images. The method obtains the first gradient value corresponding to the third grayscale image and the second gradient value corresponding to the fourth grayscale image. Based on the first gradient value, edge detection is performed on the third grayscale image to obtain the first edge image. Based on the second gradient value, edge detection is performed on the fourth grayscale image to obtain the second edge image. This can improve the accuracy and robustness of edge detection. Based on the first edge image and the second edge image, the similarity between the webpage element to be tested and the template webpage element is determined, which can ensure the accuracy of the similarity. If the similarity meets the similarity threshold, the webpage element to be tested is determined to have passed the contour test, thereby ensuring the accuracy of the test on the webpage element to be tested. Attached Figure Description
[0063] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0064] Figure 1 This is a flowchart illustrating a webpage element testing method provided in Embodiment 1 of this application;
[0065] Figure 2 This is a schematic diagram of a process for obtaining the first Gaussian parameter corresponding to the first grayscale image, provided in Embodiment 2 of this application;
[0066] Figure 3 This is a schematic diagram of a process for obtaining the second Gaussian parameter corresponding to the second grayscale image, provided in Embodiment 3 of this application;
[0067] Figure 4 This is a schematic diagram of a process for obtaining the first Gaussian parameter corresponding to the first grayscale image, provided in Embodiment 4 of this application;
[0068] Figure 5 This is a schematic diagram of a process for obtaining the second Gaussian parameter corresponding to the second grayscale image, provided in Embodiment 5 of this application;
[0069] Figure 6 This is a schematic diagram of the structure of a web page element testing device provided in this application. Detailed Implementation
[0070] The technical solutions of 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.
[0071] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0072] Reference Figure 1 This is a flowchart illustrating a webpage element testing method provided in Embodiment 1 of this application. Figure 1 As shown, the method may include, but is not limited to, the following steps:
[0073] Step S101: Perform grayscale processing on the images corresponding to the elements of the webpage to be tested and the images corresponding to the elements of the template webpage to obtain the first grayscale image and the second grayscale image.
[0074] In this embodiment, the elements to be tested on the webpage can be located, and screenshots can be taken of the located elements to obtain images corresponding to them. Specifically, methods such as find_element_by_id and XPath from the Selenium library can be used, but are not limited to, to locate the elements to be tested on the webpage, and then screenshots can be taken of the located elements using the screenshot method.
[0075] After obtaining the image corresponding to the element of the webpage to be tested, the image corresponding to the template element of the element of the webpage to be tested can be obtained.
[0076] After obtaining the images corresponding to the elements of the webpage under test and the elements of the template webpage, the images corresponding to the elements of the webpage under test can be processed into grayscale to obtain the first grayscale image, and the images corresponding to the elements of the template webpage can be processed into grayscale to obtain the second grayscale image.
[0077] Step S102: Obtain the first Gaussian parameter corresponding to the first grayscale image and the second Gaussian parameter corresponding to the second grayscale image.
[0078] The first Gaussian parameter corresponding to the first grayscale image can be used to perform Gaussian filtering on the first grayscale image.
[0079] The second Gaussian parameter corresponding to the second grayscale image can be used to perform Gaussian filtering on the second grayscale image.
[0080] Step S103: Perform Gaussian filtering on the first grayscale image based on the first Gaussian parameter to obtain a third grayscale image; perform Gaussian filtering on the second grayscale image based on the second Gaussian parameter to obtain a fourth grayscale image.
[0081] Step S104: Obtain the first gradient value corresponding to the third grayscale image and the second gradient value corresponding to the fourth grayscale image.
[0082] In this embodiment, the gradient of the third grayscale image in the horizontal and vertical directions can be determined based on, but is not limited to, the Sobel algorithm, to obtain the first gradient value corresponding to the third grayscale image.
[0083] In this embodiment, the gradient of the fourth grayscale image in the horizontal and vertical directions can be determined based on, but is not limited to, the Sobel algorithm, to obtain the second gradient value corresponding to the fourth grayscale image.
[0084] Step S105: Based on the first gradient value, perform edge detection on the third grayscale image to obtain a first edge image; based on the second gradient value, perform edge detection on the fourth grayscale image to obtain a second edge image.
[0085] In this embodiment, the first gradient value and the third grayscale image can be fed into the Canny edge detection algorithm for edge detection to obtain the first edge image, but are not limited to this method.
[0086] In this embodiment, the second gradient value and the fourth grayscale image can be, but are not limited to, being fed into the Canny edge detection algorithm for edge detection to obtain the second edge image.
[0087] Step S106: Based on the first edge map and the second edge map, determine the similarity between the webpage element to be tested and the template webpage element.
[0088] This step may include, but is not limited to:
[0089] S1061. Determine the coordinates of each edge pixel in the first edge map, and obtain a first contour point set containing the coordinates of each edge pixel in the first edge map.
[0090] The coordinates of the edge pixels in the first edge map represent the positions of the edge pixels in the first edge map.
[0091] S1062. Determine the coordinates of each edge pixel in the second edge map, and obtain a second contour point set containing the coordinates of each edge pixel in the second edge map.
[0092] The first and second contour point sets are arrays of the same size.
[0093] S1063. Determine the mean square error between the first contour point set and the second contour point set.
[0094] The smaller the mean square error, the higher the similarity between the first edge map and the second edge map.
[0095] Step S1063 may include, but is not limited to:
[0096] S10631. Calculate the square of the element difference between corresponding positions in the first contour point set and the second contour point set.
[0097] S10632. Sum the squares of each coordinate difference to get the sum of squares.
[0098] S10633. Divide the sum of squares by the total number of elements in the first contour point set or the second contour point set to obtain the mean square error between the first contour point set and the second contour point set.
[0099] Step S107: If the similarity meets the similarity threshold, determine that the webpage element to be tested passes the contour test.
[0100] Corresponding to steps S10631-S10633, this step may include, but is not limited to:
[0101] If the mean square error is less than the mean square error threshold, the webpage element under test is determined to have passed the contour test.
[0102] In this embodiment, the web page element testing method can automatically test the outline of the web page element to be tested, thereby improving testing efficiency.
[0103] Furthermore, grayscale processing is performed on the images corresponding to the elements of the webpage under test and the images corresponding to the elements of the template webpage, respectively, to obtain a first grayscale image and a second grayscale image. This can improve contrast and reduce noise. Based on this, the first Gaussian parameter corresponding to the first grayscale image and the second Gaussian parameter corresponding to the second grayscale image are obtained. The first grayscale image is processed based on the first Gaussian parameter to obtain a third grayscale image, and the second grayscale image is processed based on the second Gaussian parameter to obtain a fourth grayscale image. This allows for more precise smoothing and noise removal of the first and second grayscale images. Based on this, a third grayscale image is obtained. The first gradient value corresponding to the third grayscale image and the second gradient value corresponding to the fourth grayscale image are used to perform edge detection on the third grayscale image to obtain a first edge image. Based on the first gradient value, edge detection is performed on the fourth grayscale image to obtain a second edge image. This can improve the accuracy and robustness of edge detection. Based on the first and second edge images, the similarity between the webpage element to be tested and the template webpage element is determined, which can ensure the accuracy of the similarity. If the similarity meets the similarity threshold, the webpage element to be tested is determined to have passed the contour test, thereby ensuring the accuracy of the test on the webpage element to be tested.
[0104] As another optional embodiment of this application, refer to Figure 2 This is a flowchart illustrating a process for obtaining the first Gaussian parameter corresponding to a first grayscale image, as provided in Embodiment 2 of this application. This embodiment is primarily a refinement of step S102 in Embodiment 1 above, which involves obtaining the first Gaussian parameter corresponding to the first grayscale image. Figure 2 As shown, obtaining the first Gaussian parameter corresponding to the first grayscale image in step S102 may include, but is not limited to, the following steps:
[0105] Step S11: Obtain the total number of pixels in the first grayscale image.
[0106] Step S12: Divide the square root of the total number of pixels in the first grayscale image by 100 to obtain the usable Gaussian kernel size corresponding to the first grayscale image.
[0107] In this embodiment, the following empirical formula can be obtained through testing. Substituting the square root of the total number of pixels in the first grayscale image into the empirical formula, the usable Gaussian kernel size corresponding to the first grayscale image can be obtained:
[0108]
[0109] Where G1 represents the size of the Gaussian kernel that can be used for the first grayscale image, p t1 This represents the total number of pixels in the first grayscale image.
[0110] Step S13: If the usable Gaussian kernel size corresponding to the first grayscale image is odd, determine the usable Gaussian kernel size corresponding to the first grayscale image as the first Gaussian parameter corresponding to the first grayscale image.
[0111] Step S14: If the usable Gaussian kernel size corresponding to the first grayscale image is an even number, add the usable Gaussian kernel size to a set odd number to obtain the first Gaussian parameter corresponding to the first grayscale image.
[0112] The setting of odd numbers can be set as needed and is not limited in this application. For example, the setting of odd numbers can be, but is not limited to, 1.
[0113] In this embodiment, steps S13 and S14 can ensure that the first Gaussian parameter corresponding to the first grayscale image is a Gaussian kernel with an odd size, so as to meet the requirement that the Gaussian kernel has symmetry, thereby ensuring the smoothness and continuity of the image and obtaining a better filtering effect.
[0114] In this embodiment, by obtaining the total number of pixels in the first grayscale image, dividing the square root of the total number of pixels in the first grayscale image by 100, the usable Gaussian kernel size corresponding to the first grayscale image is obtained. If the usable Gaussian kernel size corresponding to the first grayscale image is an odd number, the usable Gaussian kernel size corresponding to the first grayscale image is determined to be the first Gaussian parameter corresponding to the first grayscale image. If the usable Gaussian kernel size corresponding to the first grayscale image is an even number, the usable Gaussian kernel size corresponding to the first grayscale image is added to the set odd number to obtain the first Gaussian parameter corresponding to the first grayscale image. Based on the first Gaussian parameter, Gaussian filtering is performed on the first grayscale image to obtain the third grayscale image, which can achieve more accurate smoothing and noise removal of the first grayscale image.
[0115] As another optional embodiment of this application, refer to Figure 3 This is a flowchart illustrating a process for obtaining the second Gaussian parameter corresponding to a second grayscale image, as provided in Embodiment 3 of this application. This embodiment is primarily a refinement of step S102 in Embodiment 1 above, which involves obtaining the second Gaussian parameter corresponding to the second grayscale image. Figure 3 As shown, obtaining the second Gaussian parameter corresponding to the second grayscale image in step S102 may include, but is not limited to, the following steps:
[0116] Step S21: Obtain the total number of pixels in the second grayscale image.
[0117] Step S22: Divide the total number of pixels in the second grayscale image by 100 to obtain the usable Gaussian kernel size corresponding to the second grayscale image.
[0118] In this embodiment, the following empirical formula can be obtained through testing. Substituting the square root of the total number of pixels in the second grayscale image into the empirical formula, the usable Gaussian kernel size corresponding to the second grayscale image can be obtained:
[0119]
[0120] Where G2 represents the Gaussian kernel size that can be used for the second grayscale image, p t2 This represents the total number of pixels in the second grayscale image.
[0121] Step S23: If the usable Gaussian kernel size corresponding to the second grayscale image is odd, determine the usable Gaussian kernel size corresponding to the second grayscale image as the second Gaussian parameter corresponding to the second grayscale image.
[0122] Step S24: If the usable Gaussian kernel size corresponding to the second grayscale image is an even number, add the usable Gaussian kernel size to the set odd number to obtain the second Gaussian parameter corresponding to the second grayscale image.
[0123] The setting of odd numbers can be set as needed and is not limited in this application. For example, the setting of odd numbers can be, but is not limited to, 1.
[0124] In this embodiment, steps S23 and S24 can ensure that the second Gaussian parameter corresponding to the second grayscale image is a Gaussian kernel with an odd size, so as to meet the requirement that the Gaussian kernel has symmetry, thereby ensuring the smoothness and continuity of the image and obtaining a better filtering effect.
[0125] In this embodiment, by obtaining the total number of pixels in the second grayscale image, dividing the total number of pixels in the second grayscale image by 100, the usable Gaussian kernel size corresponding to the second grayscale image is obtained. If the usable Gaussian kernel size corresponding to the second grayscale image is an odd number, the usable Gaussian kernel size corresponding to the second grayscale image is determined to be the second Gaussian parameter corresponding to the second grayscale image. If the usable Gaussian kernel size corresponding to the second grayscale image is an even number, the usable Gaussian kernel size is added to the set odd number to obtain the second Gaussian parameter corresponding to the second grayscale image. Based on the second Gaussian parameter, Gaussian filtering is performed on the second grayscale image to obtain the fourth grayscale image, which can achieve more accurate smoothing and noise removal of the second grayscale image.
[0126] As another optional embodiment of this application, refer to Figure 4This is a flowchart illustrating a process for obtaining the first Gaussian parameter corresponding to a first grayscale image, as provided in Embodiment 4 of this application. This embodiment is primarily a refinement of step S102 in Embodiment 1 above, which involves obtaining the first Gaussian parameter corresponding to the first grayscale image. Figure 4 As shown, obtaining the first Gaussian parameter corresponding to the first grayscale image in step S102 may include, but is not limited to, the following steps:
[0127] Step S31: Search within the set Gaussian kernel size range with a set step size to obtain multiple first candidate Gaussian kernel sizes.
[0128] In this embodiment, the step size and the range of Gaussian kernel size can be set as needed, and are not limited in this application.
[0129] In order to find the optimal Gaussian kernel size and cover possible Gaussian kernel sizes while ensuring computational efficiency, the step size should be small enough to ensure search accuracy. The step size can be set to, but is not limited to, 2, and the range of Gaussian kernel size can be set to, but is not limited to, 1 to 31.
[0130] Step S32: Perform Gaussian filtering on the first grayscale image based on the size of each first candidate Gaussian kernel to obtain the fifth grayscale image.
[0131] Step S33: Obtain the mean square error between each of the fifth grayscale images and the first grayscale image.
[0132] The mean square error between the fifth grayscale image and the first grayscale image can characterize the difference between them. The smaller the mean square error between the fifth grayscale image and the first grayscale image, the smaller the difference between them, and thus the better the smoothing effect of Gaussian filtering on the first grayscale image using the first candidate Gaussian kernel size.
[0133] Step S34: Determine the minimum mean square error between each of the fifth grayscale images and the first grayscale image.
[0134] Step S35: Based on the image noise level corresponding to the first grayscale image, scale the size of the first candidate Gaussian kernel corresponding to the minimum value to obtain the first Gaussian parameter corresponding to the first grayscale image.
[0135] The image noise level corresponding to the first grayscale image is determined based on the minimum mean square error between each of the fifth grayscale images and the first grayscale image.
[0136] Specifically, the minimum mean square error between each of the fifth grayscale images and the first grayscale image can be determined as the image noise level corresponding to the first grayscale image, but is not limited to this.
[0137] The size of the first candidate Gaussian kernel corresponding to the minimum value is scaled based on the image noise level corresponding to the first grayscale image, so as to limit the scaled first candidate Gaussian kernel size to between 1 and 31, and avoid the Gaussian kernel size being too large or too small.
[0138] Step S35 may include, but is not limited to:
[0139] Step S351: Divide the size of the first candidate Gaussian kernel corresponding to the minimum value by the image noise level corresponding to the first grayscale image to obtain the size of the first Gaussian kernel to be used.
[0140] Step S352: If the size of the first Gaussian kernel to be used is odd, determine that the size of the first Gaussian kernel to be used is the first Gaussian parameter corresponding to the first grayscale image.
[0141] Step S353: If the first usable Gaussian kernel size is even, add the first usable Gaussian kernel size to a set odd number to obtain the first Gaussian parameter corresponding to the first grayscale image.
[0142] The setting of odd numbers can be set as needed and is not limited in this application. For example, the setting of odd numbers can be, but is not limited to, 1.
[0143] In this embodiment, a search is performed within a set Gaussian kernel size range with a set step size to obtain multiple first candidate Gaussian kernel sizes. Gaussian filtering is then applied to the first grayscale image based on each first candidate Gaussian kernel size to obtain a fifth grayscale image. The mean square error between each fifth grayscale image and the first grayscale image is obtained. The minimum mean square error between each fifth grayscale image and the first grayscale image is determined. The first candidate Gaussian kernel size corresponding to the minimum value is scaled based on the image noise level corresponding to the first grayscale image to obtain a first Gaussian parameter corresponding to the first grayscale image. Gaussian filtering is then applied to the first grayscale image based on the first Gaussian parameter to obtain a third grayscale image. This allows for more precise smoothing and noise removal of the first grayscale image.
[0144] As another optional embodiment of this application, refer to Figure 5 This is a flowchart illustrating a process for obtaining the second Gaussian parameter corresponding to a second grayscale image, provided in Embodiment 5 of this application. This embodiment is primarily a refinement of step S102 in Embodiment 1 above, which involves obtaining the second Gaussian parameter corresponding to the second grayscale image. Figure 5 As shown, obtaining the second Gaussian parameter corresponding to the second grayscale image in step S102 may include, but is not limited to, the following steps:
[0145] Step S41: Search within the set Gaussian kernel size range with a set step size to obtain multiple second candidate Gaussian kernel sizes.
[0146] In this embodiment, the step size and the range of Gaussian kernel size can be set as needed, and are not limited in this application.
[0147] In order to find the optimal Gaussian kernel size and cover possible Gaussian kernel sizes while ensuring computational efficiency, the step size should be small enough to ensure search accuracy. The step size can be set to, but is not limited to, 2, and the range of Gaussian kernel size can be set to, but is not limited to, 1 to 31.
[0148] Step S42: Process the second grayscale image based on the size of each second candidate Gaussian kernel to obtain the sixth grayscale image.
[0149] Step S43: Obtain the mean square error between each of the sixth grayscale images and the second grayscale image.
[0150] The mean square error between the sixth grayscale image and the first grayscale image can characterize the difference between them. The smaller the mean square error between the sixth grayscale image and the first grayscale image, the smaller the difference between them, and thus the better the smoothing effect of Gaussian filtering on the second grayscale image using the second candidate Gaussian kernel size.
[0151] Step S44: Determine the minimum mean square error between each of the sixth grayscale images and the second grayscale image.
[0152] Step S45: Based on the image noise level corresponding to the second grayscale image, scale the size of the second candidate Gaussian kernel corresponding to the minimum value to obtain the second Gaussian parameter corresponding to the second grayscale image.
[0153] The image noise level corresponding to the second grayscale image is determined based on the minimum mean square error between each of the sixth grayscale images and the second grayscale image.
[0154] Specifically, the minimum mean square error between each of the sixth grayscale images and the first grayscale image can be determined as the image noise level corresponding to the second grayscale image, but is not limited to this.
[0155] The size of the second candidate Gaussian kernel corresponding to the minimum value is scaled based on the image noise level corresponding to the second grayscale image, so as to limit the scaled second candidate Gaussian kernel size to between 1 and 31, and avoid the Gaussian kernel size being too large or too small.
[0156] Step S45 may include, but is not limited to:
[0157] Step S451: Divide the second candidate Gaussian kernel size corresponding to the minimum value by the image noise level corresponding to the second grayscale image to obtain the second Gaussian kernel size to be used.
[0158] Step S452: If the size of the second Gaussian kernel to be used is odd, determine that the size of the second Gaussian kernel to be used is the second Gaussian parameter corresponding to the second grayscale image.
[0159] Step S453: If the second usable Gaussian kernel size is even, add the second usable Gaussian kernel size to the set odd number to obtain the second Gaussian parameter corresponding to the second grayscale image.
[0160] In this embodiment, a search is performed within a set Gaussian kernel size range with a set step size to obtain multiple second candidate Gaussian kernel sizes. The second grayscale image is then processed based on each second candidate Gaussian kernel size to obtain a sixth grayscale image. The mean square error between each sixth grayscale image and the second grayscale image is obtained. The minimum value of the mean square error between each sixth grayscale image and the second grayscale image is determined. The second candidate Gaussian kernel size corresponding to the minimum value is scaled based on the image noise level corresponding to the second grayscale image to obtain the second Gaussian parameter corresponding to the second grayscale image. The second grayscale image is then subjected to Gaussian filtering based on the second Gaussian parameter to obtain a fourth grayscale image. This allows for more accurate smoothing and noise removal of the second grayscale image.
[0161] The following section introduces a webpage element testing device provided in this application. The webpage element testing device described below can be referred to in correspondence with the webpage element testing method described above.
[0162] Please see Figure 6 The web page element testing device includes: a grayscale processing module 100, a first acquisition module 200, a Gaussian filtering module 300, a second acquisition module 400, an edge detection module 500, a first determination module 600, and a second determination module 700.
[0163] The grayscale processing module 100 is used to perform grayscale processing on the images corresponding to the web page elements to be tested and the images corresponding to the template web page elements respectively, to obtain a first grayscale image and a second grayscale image.
[0164] The first obtaining module 200 is used to obtain the first Gaussian parameter corresponding to the first grayscale image and the second Gaussian parameter corresponding to the second grayscale image;
[0165] The Gaussian filtering module 300 is used to perform Gaussian filtering on the first grayscale image based on the first Gaussian parameter to obtain a third grayscale image, and to perform Gaussian filtering on the second grayscale image based on the second Gaussian parameter to obtain a fourth grayscale image.
[0166] The second obtaining module 400 is used to obtain the first gradient value corresponding to the third grayscale image and the second gradient value corresponding to the fourth grayscale image;
[0167] The edge detection module 500 is used to perform edge detection on the third grayscale image based on the first gradient value to obtain a first edge image, and to perform edge detection on the fourth grayscale image based on the second gradient value to obtain a second edge image.
[0168] The first determining module 600 is used to determine the similarity between the webpage element to be tested and the template webpage element based on the first edge map and the second edge map;
[0169] The second determining module 700 is used to determine that the webpage element to be tested passes the contour test if the similarity meets the similarity threshold.
[0170] The process by which the first obtaining module 200 obtains the first Gaussian parameter corresponding to the first grayscale image may specifically include:
[0171] Obtain the total number of pixels in the first grayscale image;
[0172] Divide the square root of the total number of pixels in the first grayscale image by 100 to obtain the usable Gaussian kernel size for the first grayscale image.
[0173] If the usable Gaussian kernel size corresponding to the first grayscale image is an odd number, the usable Gaussian kernel size corresponding to the first grayscale image is determined to be the first Gaussian parameter corresponding to the first grayscale image.
[0174] If the usable Gaussian kernel size corresponding to the first grayscale image is an even number, the usable Gaussian kernel size corresponding to the first grayscale image is added to a set odd number to obtain the first Gaussian parameter corresponding to the first grayscale image.
[0175] The process by which the first obtaining module 200 obtains the second Gaussian parameter corresponding to the second grayscale image may specifically include:
[0176] Obtain the total number of pixels in the second grayscale image;
[0177] Divide the total number of pixels in the second grayscale image by 100 to obtain the usable Gaussian kernel size for the second grayscale image;
[0178] If the usable Gaussian kernel size corresponding to the second grayscale image is an odd number, then the usable Gaussian kernel size corresponding to the second grayscale image is determined to be the second Gaussian parameter corresponding to the second grayscale image.
[0179] If the usable Gaussian kernel size corresponding to the second grayscale image is an even number, the usable Gaussian kernel size is added to the set odd number to obtain the second Gaussian parameter corresponding to the second grayscale image.
[0180] The process by which the first obtaining module 200 obtains the first Gaussian parameter corresponding to the first grayscale image may specifically include:
[0181] By searching within a set Gaussian kernel size range with a set step size, multiple first candidate Gaussian kernel sizes are obtained;
[0182] The first grayscale image is processed by Gaussian filtering based on the size of each first candidate Gaussian kernel to obtain the fifth grayscale image;
[0183] Obtain the mean square error between each of the fifth grayscale images and the first grayscale image;
[0184] The minimum mean square error between each of the fifth grayscale images and the first grayscale image is determined;
[0185] Based on the image noise level corresponding to the first grayscale image, the size of the first candidate Gaussian kernel corresponding to the minimum value is scaled to obtain the first Gaussian parameter corresponding to the first grayscale image. The image noise level corresponding to the first grayscale image is determined based on the minimum value of the mean square error between each fifth grayscale image and the first grayscale image.
[0186] The process by which the first obtaining module 200 scales the size of the first candidate Gaussian kernel corresponding to the minimum value based on the image noise level corresponding to the first grayscale image to obtain the first Gaussian parameter corresponding to the first grayscale image may specifically include:
[0187] Divide the size of the first candidate Gaussian kernel corresponding to the minimum value by the image noise level corresponding to the first grayscale image to obtain the size of the first Gaussian kernel to be used.
[0188] If the size of the first Gaussian kernel to be used is odd, the size of the first Gaussian kernel to be used is determined to be the first Gaussian parameter corresponding to the first grayscale image;
[0189] If the first usable Gaussian kernel size is even, add the first usable Gaussian kernel size to a set odd number to obtain the first Gaussian parameter corresponding to the first grayscale image.
[0190] The process by which the first obtaining module 200 obtains the second Gaussian parameter corresponding to the second grayscale image may specifically include:
[0191] By searching within a set Gaussian kernel size range with a set step size, multiple second candidate Gaussian kernel sizes are obtained;
[0192] The second grayscale image is processed based on the size of each second candidate Gaussian kernel to obtain the sixth grayscale image;
[0193] Obtain the mean square error between each of the sixth grayscale images and the second grayscale image;
[0194] The minimum mean square error between each of the sixth grayscale images and the second grayscale image is determined;
[0195] Based on the image noise level corresponding to the second grayscale image, the size of the second candidate Gaussian kernel corresponding to the minimum value is scaled to obtain the second Gaussian parameter corresponding to the second grayscale image. The image noise level corresponding to the second grayscale image is determined based on the minimum value of the mean square error between each sixth grayscale image and the second grayscale image.
[0196] The process by which the first obtaining module 200 scales the size of the second candidate Gaussian kernel corresponding to the minimum value based on the image noise level corresponding to the second grayscale image to obtain the second Gaussian parameter corresponding to the second grayscale image may specifically include:
[0197] Divide the second candidate Gaussian kernel size corresponding to the minimum value by the image noise level corresponding to the second grayscale image to obtain the second Gaussian kernel size to be used.
[0198] If the size of the second Gaussian kernel to be used is odd, the size of the second Gaussian kernel to be used is determined to be the second Gaussian parameter corresponding to the second grayscale image;
[0199] If the second usable Gaussian kernel size is even, add the second usable Gaussian kernel size to the set odd number to obtain the second Gaussian parameter corresponding to the second grayscale image.
[0200] It should be noted that each embodiment focuses on describing the differences from other embodiments, and the same or similar parts between the embodiments can be referred to accordingly. For the device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments.
[0201] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0202] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, in implementing this application, the functions of each module can be implemented in one or more software and / or hardware.
[0203] As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in various embodiments or some parts of the embodiments of this application.
[0204] The above provides a detailed description of a webpage element testing method and apparatus provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for testing web page elements, characterized in that, include: The images corresponding to the elements of the webpage to be tested and the images corresponding to the elements of the template webpage are processed into grayscale to obtain the first grayscale image and the second grayscale image. Obtain the first Gaussian parameter corresponding to the first grayscale image and the second Gaussian parameter corresponding to the second grayscale image; The first grayscale image is subjected to Gaussian filtering based on the first Gaussian parameter to obtain the third grayscale image, and the second grayscale image is subjected to Gaussian filtering based on the second Gaussian parameter to obtain the fourth grayscale image. Obtain the first gradient value corresponding to the third grayscale image and the second gradient value corresponding to the fourth grayscale image; Based on the first gradient value, edge detection is performed on the third grayscale image to obtain a first edge image; based on the second gradient value, edge detection is performed on the fourth grayscale image to obtain a second edge image. Based on the first edge map and the second edge map, the similarity between the web page element to be tested and the template web page element is determined; If the similarity meets the similarity threshold, the webpage element to be tested is determined to have passed the contour test; Obtaining the first Gaussian parameter corresponding to the first grayscale image includes: Obtain the total number of pixels in the first grayscale image; Divide the square root of the total number of pixels in the first grayscale image by 100 to obtain the usable Gaussian kernel size for the first grayscale image. If the usable Gaussian kernel size corresponding to the first grayscale image is an odd number, the usable Gaussian kernel size corresponding to the first grayscale image is determined to be the first Gaussian parameter corresponding to the first grayscale image. If the usable Gaussian kernel size corresponding to the first grayscale image is an even number, the usable Gaussian kernel size corresponding to the first grayscale image is added to a set odd number to obtain the first Gaussian parameter corresponding to the first grayscale image.
2. The method according to claim 1, characterized in that, Obtaining the first Gaussian parameter corresponding to the first grayscale image and the second Gaussian parameter corresponding to the second grayscale image includes: Obtain the total number of pixels in the second grayscale image; Divide the total number of pixels in the second grayscale image by 100 to obtain the usable Gaussian kernel size for the second grayscale image; If the usable Gaussian kernel size corresponding to the second grayscale image is an odd number, then the usable Gaussian kernel size corresponding to the second grayscale image is determined to be the second Gaussian parameter corresponding to the second grayscale image. If the usable Gaussian kernel size corresponding to the second grayscale image is an even number, the usable Gaussian kernel size is added to a set odd number to obtain the second Gaussian parameter corresponding to the second grayscale image.
3. The method according to claim 1, characterized in that, Obtaining the first Gaussian parameters corresponding to the first grayscale image includes: By searching within a set Gaussian kernel size range with a set step size, multiple first candidate Gaussian kernel sizes are obtained; The first grayscale image is processed by Gaussian filtering based on the size of each first candidate Gaussian kernel to obtain the fifth grayscale image; Obtain the mean square error between each of the fifth grayscale images and the first grayscale image; The minimum mean square error between each of the fifth grayscale images and the first grayscale image is determined; Based on the image noise level corresponding to the first grayscale image, the size of the first candidate Gaussian kernel corresponding to the minimum value is scaled to obtain the first Gaussian parameter corresponding to the first grayscale image. The image noise level corresponding to the first grayscale image is determined based on the minimum value of the mean square error between each fifth grayscale image and the first grayscale image.
4. The method according to claim 3, characterized in that, The step of scaling the size of the first candidate Gaussian kernel corresponding to the minimum value based on the image noise level corresponding to the first grayscale image to obtain the first Gaussian parameter corresponding to the first grayscale image includes: Divide the size of the first candidate Gaussian kernel corresponding to the minimum value by the image noise level corresponding to the first grayscale image to obtain the size of the first Gaussian kernel to be used. If the size of the first Gaussian kernel to be used is odd, the size of the first Gaussian kernel to be used is determined to be the first Gaussian parameter corresponding to the first grayscale image; If the size of the first Gaussian kernel to be used is even, the size of the first Gaussian kernel to be used is added to a set odd number to obtain the first Gaussian parameter corresponding to the first grayscale image.
5. The method according to claim 1, characterized in that, Obtaining the second Gaussian parameters corresponding to the second grayscale image includes: By searching within a set Gaussian kernel size range with a set step size, multiple second candidate Gaussian kernel sizes are obtained; The second grayscale image is processed based on the size of each second candidate Gaussian kernel to obtain the sixth grayscale image; Obtain the mean square error between each of the sixth grayscale images and the second grayscale image; The minimum mean square error between each of the sixth grayscale images and the second grayscale image is determined; Based on the image noise level corresponding to the second grayscale image, the size of the second candidate Gaussian kernel corresponding to the minimum value is scaled to obtain the second Gaussian parameter corresponding to the second grayscale image. The image noise level corresponding to the second grayscale image is determined based on the minimum value of the mean square error between each sixth grayscale image and the second grayscale image.
6. The method according to claim 5, characterized in that, The step of scaling the size of the second candidate Gaussian kernel corresponding to the minimum value based on the image noise level corresponding to the second grayscale image to obtain the second Gaussian parameters corresponding to the second grayscale image includes: Divide the second candidate Gaussian kernel size corresponding to the minimum value by the image noise level corresponding to the second grayscale image to obtain the second Gaussian kernel size to be used. If the size of the second Gaussian kernel to be used is odd, the size of the second Gaussian kernel to be used is determined to be the second Gaussian parameter corresponding to the second grayscale image; If the size of the second Gaussian kernel to be used is even, the size of the second Gaussian kernel to be used is added to the set odd number to obtain the second Gaussian parameter corresponding to the second grayscale image.
7. A webpage element testing device, characterized in that, include: The grayscale processing module is used to perform grayscale processing on the images corresponding to the web page elements to be tested and the images corresponding to the template web page elements respectively, to obtain the first grayscale image and the second grayscale image. The first obtaining module is used to obtain the first Gaussian parameter corresponding to the first grayscale image and the second Gaussian parameter corresponding to the second grayscale image; The Gaussian filtering module is used to perform Gaussian filtering on the first grayscale image based on the first Gaussian parameter to obtain a third grayscale image, and to perform Gaussian filtering on the second grayscale image based on the second Gaussian parameter to obtain a fourth grayscale image. The second obtaining module is used to obtain the first gradient value corresponding to the third grayscale image and the second gradient value corresponding to the fourth grayscale image; An edge detection module is used to perform edge detection on the third grayscale image based on the first gradient value to obtain a first edge image, and to perform edge detection on the fourth grayscale image based on the second gradient value to obtain a second edge image; The first determining module is used to determine the similarity between the webpage element to be tested and the template webpage element based on the first edge map and the second edge map; The second determining module is used to determine that the webpage element to be tested passes the contour test if the similarity meets the similarity threshold. The process by which the first obtaining module obtains the first Gaussian parameter corresponding to the first grayscale image specifically includes: Obtain the total number of pixels in the first grayscale image; Divide the square root of the total number of pixels in the first grayscale image by 100 to obtain the usable Gaussian kernel size for the first grayscale image. If the usable Gaussian kernel size corresponding to the first grayscale image is an odd number, the usable Gaussian kernel size corresponding to the first grayscale image is determined to be the first Gaussian parameter corresponding to the first grayscale image. If the usable Gaussian kernel size corresponding to the first grayscale image is an even number, the usable Gaussian kernel size corresponding to the first grayscale image is added to a set odd number to obtain the first Gaussian parameter corresponding to the first grayscale image.
8. The apparatus according to claim 7, characterized in that, The process by which the first obtaining module obtains the second Gaussian parameter corresponding to the second grayscale image specifically includes: Obtain the total number of pixels in the second grayscale image; Divide the total number of pixels in the second grayscale image by 100 to obtain the usable Gaussian kernel size for the second grayscale image; If the usable Gaussian kernel size corresponding to the second grayscale image is an odd number, then the usable Gaussian kernel size corresponding to the second grayscale image is determined to be the second Gaussian parameter corresponding to the second grayscale image. If the usable Gaussian kernel size corresponding to the second grayscale image is an even number, the usable Gaussian kernel size is added to a set odd number to obtain the second Gaussian parameter corresponding to the second grayscale image.