Method, apparatus, device, medium, and program product for obtaining text contrast
By determining the text controls in the terminal device page and calculating the pixel value of the center point of the black and white image, the problem of low efficiency and insufficient accuracy of manual measurement of text contrast on the terminal device page is solved, and efficient and accurate text contrast acquisition is achieved to adapt to the reading needs of people with weak color blindness and color.
Patent Information
- Application Number
- CN202210778445.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-30
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2042-06-30
AI Technical Summary
In the prior art, the acquisition of text contrast of the terminal equipment page depends on manual measurement, resulting in low efficiency and difficult to guarantee accuracy, high labor costs, and measurement errors caused by operational errors.
By determining the text control from the initial control node of the page to be tested, performing screenshot processing, obtaining the center point of the black and white image, calculating text contrast using the pixel value of the center point, and optimizing control recognition with the control learning model.
It improves the efficiency and accuracy of text contrast measurement, reduces manpower consumption, reduces errors caused by operational errors, and meets the reading needs of color blind and weak color groups.
Smart Images

Figure CN115019318B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method, device, equipment, medium and program product for obtaining text contrast. Background Art
[0002] With the continuous development of information technology, terminal devices play an increasingly important role in our lives, and mobile applications are becoming increasingly important in basic functions such as navigation, transaction processing, payment, life and entertainment.
[0003] To ensure that terminal devices can adapt to the needs of color-blind and color-weak people, it is necessary to test the text contrast on the terminal device page. Currently, this is mainly done by developers manually obtaining the text and background colors, and then confirming the text contrast through third-party website tools.
[0004] However, the above method for obtaining text contrast has high labor costs, and the accuracy of manual measurement is difficult to guarantee. Summary of the Invention
[0005] Based on this, it is necessary to provide a method, device, equipment, medium and program product for obtaining text contrast to address the above technical issues.
[0006] In a first aspect, the present application provides a method for obtaining text contrast. The method comprises:
[0007] Determine a text control from at least one control corresponding to the initial control node of the page to be tested, wherein the text attribute of the text control is not empty;
[0008] Based on the position information of the text control, taking a screenshot of the text control on the page to be tested to obtain an initial image;
[0009] Determining a first center point of a black area and a second center point of a white area in a black and white image corresponding to the initial image;
[0010] The text contrast of the page to be tested is determined according to the pixels of the first center point and the pixels of the second center point.
[0011] In one embodiment, determining a first center point of a black area and a second center point of a white area in a black and white image corresponding to the initial image includes:
[0012] Scanning the black-and-white image based on an arrangement format of pixels in the black-and-white image to obtain a plurality of row scanning areas, wherein each row scanning area includes at least one black area and at least one white area;
[0013] According to the position of each pixel point, a first center point of each black area and a second center point of each white area are determined.
[0014] In one embodiment, it further includes:
[0015] Performing grayscale processing on the initial image to obtain a grayscale image;
[0016] The grayscale image is binarized to obtain the black and white image.
[0017] In one embodiment, determining a text control from at least one control corresponding to an initial control node of the page to be tested includes:
[0018] Acquire control tree information of the page to be tested, and determine the initial control node based on the control tree information;
[0019] Determine at least one control corresponding to the initial control node according to the control tree information;
[0020] A control whose text attribute is not empty among the at least one control is determined as the text control.
[0021] In one embodiment, determining the text contrast of the page to be tested based on the pixels of the first center point and the pixels of the second center point includes:
[0022] Obtaining coordinate information of the first center point and coordinate information of the second center point;
[0023] Determining a pixel of the first center point based on the coordinate information of the first center point;
[0024] determining a pixel of the second center point based on the coordinate information of the second center point;
[0025] The text contrast of the page to be tested is determined according to the pixels of the first center point and the pixels of the second center point.
[0026] In one embodiment, it further includes:
[0027] Obtaining control tree information of the page to be tested, and inputting the control tree information into a pre-generated control learning model;
[0028] If the control learning model outputs the information of the initial control node based on the control tree information, the step of determining a text control from at least one control corresponding to the initial control node of the page to be tested is performed.
[0029] In one embodiment, it further includes:
[0030] If the control learning model does not output the information of the initial control node based on the control tree information, the control learning model is trained using the control tree information as training data until a new control learning model outputs the information of the initial control node.
[0031] In a second aspect, the present application further provides a device for obtaining text contrast. The device comprises:
[0032] A screening module, configured to determine a text control from at least one control corresponding to an initial control node of the page to be tested, wherein a text attribute of the text control is not empty;
[0033] A screenshot module, configured to take a screenshot of the text control on the page to be tested based on the position information of the text control to obtain an initial image;
[0034] a processing module, configured to determine a first center point of a black area and a second center point of a white area in a black and white image corresponding to the initial image;
[0035] The determination module is configured to determine the text contrast of the page to be tested according to the pixels of the first center point and the pixels of the second center point.
[0036] In a third aspect, the present application further provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method for obtaining text contrast as described in any embodiment of the first aspect is implemented.
[0037] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for obtaining text contrast as described in any embodiment of the first aspect.
[0038] In a fifth aspect, the present application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the method for obtaining text contrast as described in any embodiment of the first aspect.
[0039] According to the technical solution of the present application, by confirming the text control and taking a screenshot of the text control, it is ensured that the first center point and the second center point can be successfully obtained subsequently, providing a basic guarantee for obtaining the contrast of the text in the text control; through the first center point and the second center point, the contrast of the text in the text control is obtained, which increases the work efficiency of measuring the text contrast, reduces the manpower consumption of measuring the text contrast, and prevents the occurrence of measurement errors due to operational errors when manually measuring the text contrast, thereby increasing the accuracy of measuring the text contrast. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 A flowchart of a method for obtaining text contrast provided in an embodiment of the present application;
[0041] Figure 2 A flowchart of another method for obtaining text contrast provided in an embodiment of the present application;
[0042] Figure 3 A flowchart of another method for obtaining text contrast provided in an embodiment of the present application;
[0043] Figure 4 A flowchart of another method for obtaining text contrast provided in an embodiment of the present application;
[0044] Figure 5 A flowchart of another method for obtaining text contrast provided in an embodiment of the present application;
[0045] Figure 6 A flowchart of another method for obtaining text contrast provided in an embodiment of the present application;
[0046] Figure 7 A flowchart of another method for obtaining text contrast provided in an embodiment of the present application;
[0047] Figure 8 A structural block diagram of a device for obtaining text contrast provided in an embodiment of the present application;
[0048] Figure 9 A structural block diagram of a device for obtaining text contrast provided in an embodiment of the present application;
[0049] Figure 10 A structural block diagram of a device for obtaining text contrast provided in an embodiment of the present application;
[0050] Figure 11 A structural block diagram of a device for obtaining text contrast provided in an embodiment of the present application;
[0051] Figure 12 A structural block diagram of a device for obtaining text contrast provided in an embodiment of the present application;
[0052] Figure 13 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0054] In the description of this application, the reference terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" mean that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine different embodiments or examples described in this specification and features of different embodiments or examples without contradiction.
[0055] With the continuous advancement of information technology, mobile devices are playing an increasingly important role in our lives. Mobile device applications are becoming increasingly important in basic functions such as navigation, business transactions, payment, and entertainment. The development and maintenance of mobile device applications has become a top priority for businesses. Consequently, the speed of updates and product quality requirements for mobile device applications are becoming increasingly stringent. Mobile applications are required to maintain a contrast ratio of at least 4.5:1 between text / image presentation, icons, and other elements to accommodate color blindness and color deficiency. Therefore, after iterative development, mobile device applications must undergo contrast testing before going live. Currently, businesses can only rely on developers to manually determine text and background colors and then verify the contrast ratio using third-party website tools, which is time-consuming and labor-intensive. To address labor cost issues, many businesses are introducing automated mobile device testing to replace some traditional testing tasks, freeing up manpower and improving efficiency.
[0056] To further explain, during the contrast test of terminal device application pages, the following problems are usually encountered:
[0057] 1. Since there is currently no automated method for obtaining the contrast ratio of terminal device application pages, the text contrast ratio of mobile application pages is currently calculated by developers manually obtaining the text and background colors, which results in low testing efficiency.
[0058] 2. Currently, the speed of iterative launch of terminal device applications is very fast. The functions of terminal device applications are becoming more and more complex, and the functional interfaces involved are becoming more and more complicated. Before each launch, more developers are required to perform contrast verification tests, which results in high labor costs.
[0059] 3. Manually obtaining text contrast relies on the developer's judgment and recording results, which may contain omissions or errors, and the accuracy of the text contrast results cannot be guaranteed.
[0060] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 1 As shown. The computer device includes a processor, memory, and a network interface connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store data obtained for text contrast. The network interface of the computer device is used to communicate with an external terminal via a network connection. When executed by the processor, the computer program implements a method for obtaining text contrast.
[0061] The present application discloses a method, apparatus, device, medium, and program product for obtaining text contrast. A developer's computer device obtains an initial control node in a terminal device's page to be tested and stores the initial control node in a database. When the text contrast in the terminal device page needs to be obtained, the developer's computer device obtains the initial control node from the database and determines a text control from at least one control corresponding to the initial control node. The developer obtains a black and white image corresponding to the text control, determines a first center point of a black area and a second center point of a white area in the black and white image, and determines the text contrast of the page to be tested based on the first center point and the second center point. Specifically, the developer will describe the method for obtaining text contrast according to an embodiment of the present application with reference to the accompanying drawings.
[0062] Figure 2 A flowchart of another method for obtaining text contrast provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, the method for obtaining the text contrast includes the following steps:
[0063] Step 201: Determine a text control from at least one control corresponding to an initial control node of the page to be tested, wherein the text attribute of the text control is not empty.
[0064] The initial control node refers to the root node in the page to be tested, and the at least one control corresponding to the initial control node refers to a child node or a leaf node corresponding to the root node.
[0065] It should be noted that the text attribute is not empty means that text information is displayed on the text control. For example: if "Start" is displayed on control A, it proves that the text attribute of control A is not empty. If an image but no text information is displayed on control B, it proves that the text attribute of control B is empty.
[0066] In one embodiment of the present application, when it is necessary to obtain the text contrast in the page to be tested of the terminal device, the initial control node A (root node A) in the page to be tested of the terminal device is determined, and the three controls corresponding to the initial control node A (root node A) are confirmed. The three controls are control B (child node B), control C (child node C) and control D (child node D). The controls whose text attributes are not empty among the three controls corresponding to the initial control node A (root node A) are judged. Among them, the text attributes of control C (child node C) and control D (child node D) are not empty, then the text controls corresponding to the initial control node are control C (child node C) and control D (child node D).
[0067] Step 202 : Based on the position information of the text control, a screenshot is taken of the text control on the page to be tested to obtain an initial image.
[0068] It should be noted that the position information includes the control position, size attributes and diagonal coordinates corresponding to the text control. It can be understood that: the position information is a kind of information that can determine the position of the text control, that is, the position of the text control can be determined based on the position information.
[0069] It should be noted that the initial image includes all text properties of the text control; for example, if the text property of the text control is "Insert", the initial image obtained by taking a screenshot of the text control must fully display the text property "Insert" of the text control.
[0070] In one embodiment of the present application, if the position information is the diagonal coordinates of the text control, the diagonal coordinates of the text control are obtained as: (x, y) and (m, n), and the four corner coordinates of the text control are determined based on the diagonal coordinates as: (x, y), (m, y), (m, n) and (x, n). The text control is screenshoted based on the four corner coordinates of the text control to obtain the initial image.
[0071] In one embodiment of the present application, if the position information is the control position and size attributes of a text control, the control position (x, y) and size attributes (height, width) of the text control are obtained, the boundary range of the text control is determined according to the control position (x, y) and size attributes (height, width), and the text control is screenshoted based on the boundary range of the text control to obtain an initial image.
[0072] Step 203: Determine a first center point of a black area and a second center point of a white area in the black-and-white image corresponding to the initial image.
[0073] It should be noted that a black and white image refers to the image obtained by binarizing and grayscale processing the original image. By grayscale and binarizing the original image, the amount of data in the original image is reduced, the processing efficiency of the original image is increased, and the outlines of the elements in the original image are highlighted.
[0074] The black area refers to the area where the pixel value in each row of pixels is 0 (black) after the original image is divided into rows. The white area refers to the area where the pixel value in each row of pixels is 255 (white) after the original image is divided into rows.
[0075] It should be noted that the "first center point" of a black area refers to the geometric center of the black area, or a point in the black area that is equidistant from each corner. This means that the distances from the first center point to each corner of the black area are equidistant. By determining the first center point in the black area, the text contrast calculated based on this point accurately reflects the actual conditions of the page being tested. Calculating text contrast based on an arbitrary point on the edge of the black area will result in a certain degree of error.
[0076] It should be noted that the second center point of the white area refers to the geometric center of the white area, or a point in the white area that is equidistant from each corner. This means that the second center point of the white area is equidistant from each corner. By determining the second center point of the white area, the text contrast calculated based on this second center point accurately reflects the actual conditions of the page being tested. Calculating text contrast based on an arbitrary point on the edge of the white area will result in a certain degree of error.
[0077] Step 204 : determining the text contrast of the page to be tested based on the pixels at the first center point and the pixels at the second center point.
[0078] It should be noted that the factors that affect the user's reading of the text on the page to be tested in the terminal device include hue, saturation and brightness. Among them, the hue and saturation of the text on the page to be tested in the terminal device have little or no effect on the color blindness and color weakness group, while the brightness of the text on the page to be tested in the terminal device has a greater impact on the color blindness and color weakness group. That is, for the color blindness and color weakness group, the brightness of the text is the main factor that affects whether the text reading is affected.
[0079] In one embodiment of the present application, the brightness value of the first center point can be determined based on the pixels of the first center point, the brightness value of the second center point can be determined based on the pixels of the second center point, and the text contrast of the page to be tested can be calculated based on the brightness value of the first center point and the brightness value of the second center point.
[0080] In one embodiment of the present application, the pixel value of the first center point can be determined based on the pixels of the first center point, the pixel value of the second center point can be determined based on the pixels of the second center point, and the text contrast of the page to be tested can be calculated based on the pixel value of the first center point and the pixel value of the second center point. It should be noted that text contrast can be divided into three levels, namely: A level, AA level and AAA level. As the text contrast level increases, the greater the visual pressure presented, the easier it is to be read by color blind and color weak groups. In order to ensure that color blind and color weak groups can read normally, the text contrast of the page to be tested needs to be greater than or equal to AA level, where AA level refers to the case where the text contrast is 4.5:1.
[0081] According to the method for obtaining text contrast of the present application, by confirming the text control and taking a screenshot of the text control, it is ensured that the first center point and the second center point can be successfully obtained subsequently, providing a basic guarantee for obtaining the contrast of the text in the text control; through the first center point and the second center point, the text contrast in the text control is obtained, which increases the work efficiency of measuring text contrast, reduces the manpower consumption of measuring text contrast, and prevents the occurrence of measurement errors due to operational errors when manually measuring text contrast, thereby increasing the accuracy of measuring text contrast.
[0082] It should be noted that at least one black area and at least one white area can be obtained by performing line scanning on a black and white image. Optionally, Figure 3 As shown, Figure 3 A flowchart of another method for obtaining text contrast provided in an embodiment of the present application, the method comprising the following steps:
[0083] Step 301 : performing line scanning on the black and white image based on the arrangement format of pixels in the black and white image to obtain a plurality of line scanning areas, wherein each line scanning area includes at least one black area and at least one white area.
[0084] It should be noted that “performing line scanning on the black and white image based on the arrangement format of pixels in the black and white image” means performing line scanning on the pixels in the black and white image based on the shape feature pairs of the black and white image.
[0085] As an example, if the black and white image is a rectangular structure, and the four sides of the black and white image are parallel to the X-axis and Y-axis of the page to be tested, based on the arrangement format of the pixels in the black and white image, a plurality of row scanning areas are obtained after row scanning of the black and white image, and the pixel arrangement directions of the plurality of row scanning areas are all parallel to the X-axis of the page to be tested or are all parallel to the Y-axis of the page to be tested.
[0086] As another example, if the black and white image has a diamond structure and the four sides of the black and white image are not parallel to the X-axis and Y-axis of the page to be tested, then based on the arrangement format of the pixels in the black and white image, the black and white image is scanned row by row to obtain multiple row scanning areas, and the pixel arrangement directions of the multiple row scanning areas are parallel to one of the sides of the black and white image.
[0087] Step 302: Determine the first center point of each black area and the second center point of each white area according to the position of each pixel point.
[0088] It should be noted that due to color variations at the edges of the black area, to ensure that the first center point of the black area can accurately calculate the text contrast of the tested page, the first center point must be located at the center of the black area to ensure that there are no color variations at the first center point. As an example, based on the positions of each pixel in the black area, a point with the same distance from each corner of the black area is determined; this point is the first center point.
[0089] It should be noted that due to the color differences at the edges of the white area, to ensure that the second center point of the white area can accurately calculate the text contrast of the tested page, the second center point must be located at the center of the white area to ensure that there are no color differences at the second center point. As an example, based on the positions of each pixel in the white area, a point in the white area with the same distance from each corner is determined, and this point is the second center point.
[0090] According to the method for obtaining text contrast of the present application, by performing line scanning on a black and white image, the black area and the white area of each line scanning area are determined, providing a data basis for the subsequent calculation of the text contrast of the page to be tested; by determining the first center point of the area and the second center point of the white area, the accuracy of the text contrast calculation is guaranteed, the work efficiency of measuring text contrast is increased, and the manpower consumption of measuring text contrast is reduced.
[0091] It should be noted that, in order to ensure that the text contrast of the page to be tested can be calculated based on the initial image, the initial image needs to be grayscale processed and binarized. Optionally, Figure 4 As shown, Figure 4 A flowchart of another method for obtaining text contrast provided in an embodiment of the present application, the method comprising the following steps:
[0092] Step 401: grayscale processing is performed on the initial image to obtain a grayscale image.
[0093] It should be noted that there are many methods for grayscale processing of the initial image, including: component method, maximum method, average method and weighted average method; among them, the component method refers to taking the brightness of the three components in the initial image as the grayscale values of the three grayscale images, and selecting a grayscale value as the grayscale value of the black and white image according to actual needs; the maximum method refers to taking the maximum value of the three-component brightness in the initial image as the grayscale value of the black and white image; the average method refers to performing an average operation on the three-component brightness in the initial image, and the result is used as the grayscale value of the black and white image; the weighted average method refers to determining the importance of the three components according to actual conditions, and performing weighted averaging on the three components with different weights, and the final result is used as the grayscale value of the black and white image.
[0094] Step 402: binarize the grayscale image to obtain a black and white image.
[0095] It should be noted that there are many methods for binarizing grayscale images. As an example, the pixel value of each pixel in the grayscale image is scanned. If the pixel value is less than 127, the pixel value of the pixel is set to 0; if the pixel value is greater than or equal to 127, the pixel value of the pixel is set to 255. As another example, the pixel value of each pixel in the grayscale image is scanned, the average of the pixel values in the grayscale image is calculated, and the relationship between the pixel value of each pixel and the average pixel value is determined. If the pixel value of the pixel is greater than the average pixel value, the pixel value of the pixel is set to 255; if the pixel value of the pixel is less than or equal to the average pixel value, the pixel value of the pixel is set to 0. As another example, the pixel value of each pixel in the grayscale image is scanned, a processing threshold is pre-set according to actual conditions, and the relationship between the pixel value of each pixel and the processing threshold is determined. If the pixel value of the pixel is greater than the processing threshold, the pixel value of the pixel is set to 255; if the pixel value of the pixel is less than or equal to the processing threshold, the pixel value of the pixel is set to 0.
[0096] According to the text contrast acquisition method of the present application, by grayscale processing and binarization processing of the initial image, a basis is provided for the subsequent calculation of the text contrast of the page to be tested, thereby reducing the amount of data in the initial image, increasing the efficiency of processing the initial image, and highlighting the outline of each element in the initial image.
[0097] It should be noted that the text control can be determined by obtaining the control tree information. Optionally, Figure 5 As shown, Figure 5 A flowchart of another method for obtaining text contrast provided in an embodiment of the present application, the method comprising the following steps:
[0098] Step 501: Obtain control tree information of the page to be tested, and determine an initial control node based on the control tree information.
[0099] It should be noted that the control tree information of the page to be tested is obtained and input into a pre-generated control learning model. If the control learning model outputs information about the initial control node based on the control tree information, the step of determining a text control from at least one control corresponding to the initial control node of the page to be tested is performed. If the control learning model does not output information about the initial control node based on the control tree information, the control learning model is trained using the control tree information as training data until a new control learning model outputs information about the initial control node.
[0100] The control learning model can determine the initial control node corresponding to the control tree information based on the control tree information. Training samples for the control learning model may include positive samples and negative samples. Positive samples refer to the control tree information and the initial control node corresponding to the control tree information, while negative samples refer to the control tree information and the initial control node that does not correspond to the control tree information.
[0101] For example, when it is necessary to obtain the initial control node, the control tree information of the page to be tested is input into the control learning model to obtain a calculation result. If the calculation result is the initial control node corresponding to the control tree information, the initial control node is determined; if the calculation result is not the initial control node corresponding to the control tree information, the control tree information and the calculation result are used as negative samples to retrain the control learning model to obtain a new control learning model, and the control tree information is input as training data into the new control learning model until the new control learning model outputs the information of the initial control node.
[0102] Step 502: Determine at least one control corresponding to the initial control node according to the control tree information.
[0103] It should be noted that, based on the control tree information, the correspondence between the root node and the child nodes is determined, and based on the correspondence between the root node and the child nodes, at least one control corresponding to the initial control node is determined. For example, the initial control node A (root node A) in the page to be tested is determined, and the three controls corresponding to the initial control node A (root node A) are confirmed. The three controls are control B (child node B), control C (child node C) and control D (child node D).
[0104] Step 503: Determine the control whose text attribute is not empty among the at least one control as a text control.
[0105] It should be noted that a control with a non-empty text attribute means that: the control's display content contains text attributes; for example: if control A displays "input", it can be determined that control A is a control with a non-empty text attribute; if control B displays an image, it can be determined that control B is not a control with a non-empty text attribute.
[0106] In one embodiment of the present application, when determining a text control, the text control is input into a text judgment model, and at least one control whose text attribute is not empty is determined according to the text judgment model; wherein the text judgment model can determine whether the input control is a control whose text attribute is not empty.
[0107] According to the method for obtaining text contrast of the present application, an initial control node is determined based on control tree information, and at least one control corresponding to the initial control node is determined based on the control tree information; this ensures that the text contrast of the page to be tested can be successfully calculated subsequently; and by setting a control learning model to achieve the determination of text controls, the operational difficulty of calculating text contrast is reduced, the work efficiency of calculating text contrast is increased, and the labor cost is reduced.
[0108] It should be noted that the text contrast of the page to be tested can be calculated by determining the pixels of the first center point and the pixels of the second center point. Optionally, Figure 6 As shown, Figure 6 A flowchart of another method for obtaining text contrast provided in an embodiment of the present application, the method comprising the following steps:
[0109] Step 601: Obtain coordinate information of a first center point and coordinate information of a second center point.
[0110] It should be noted that the first coordinate information is determined based on the position of the first center point in the black area. Since the first center point is the center of the black area, the coordinates of the center of the black area are the first center point coordinates. The second coordinate information is determined based on the position of the second center point in the white area. Since the second center point is the center of the white area, the coordinates of the center of the white area are the second center point coordinates.
[0111] For example, if the coordinates of the four corners of the black area are (2,2), (2,1), (4,2), and (4,1), the coordinates of the first center point can be determined to be (3,1.5). If the coordinates of the four corners of the white area are (4,2), (6,2), (4,1), and (6,1), the coordinates of the first center point can be determined to be (5,1.5).
[0112] Step 602: Determine the pixel of the first center point based on the coordinate information of the first center point.
[0113] It should be noted that, in the black and white image, based on the coordinate information of the first center point, the corresponding pixel is determined, and the pixel is the pixel of the first center point.
[0114] Step 603: Determine the pixel of the second center point based on the coordinate information of the second center point.
[0115] It should be noted that, in the black and white image, based on the coordinate information of the second center point, the corresponding pixel is determined, and the pixel is the pixel of the second center point.
[0116] Step 604 : Determine the text contrast of the page to be tested based on the pixels at the first center point and the pixels at the second center point.
[0117] In one embodiment of the present application, the brightness value of the first center point is determined based on the pixels of the first center point, the brightness value of the second center point is determined based on the pixels of the second center point, and the text contrast of the page to be tested is calculated based on the brightness value of the first center point and the brightness value of the second center point.
[0118] According to the method for obtaining text contrast of the present application, by determining the coordinate information of the first center point and the coordinate information of the second center point, the pixels of the first center point and the second center point are obtained, and then the text contrast of the page to be measured is calculated through the pixels of the first center point and the second center point, thereby increasing the work efficiency of measuring text contrast and reducing the manpower consumption of measuring text contrast.
[0119] In one embodiment of the present application, Figure 7 As shown, when you need to obtain the text contrast of the page to be tested:
[0120] Step 71: Obtain the control tree information of the page to be tested.
[0121] Step 72: Input the control tree information into the control learning model to obtain the initial control node; if the acquisition is successful, go to step 74; if the acquisition fails, go to step 73.
[0122] Step 73: Add the control tree information that failed to be obtained to the training library, and retrain the control learning model.
[0123] Step 74: Determine a control whose text attribute is not empty among at least one control corresponding to the initial control node as a text control, and take a screenshot of the text control according to the control position and size attributes of the text control to obtain an initial image.
[0124] Step 75: Perform grayscale processing and binarization processing on the initial image to obtain a black and white image.
[0125] Step 76: Perform line scanning on the black and white image to obtain multiple line scanning areas, and determine the first center point of the black area in the line scanning area and the second center point of the white area in the line scanning area.
[0126] Step 77: Determine the text contrast of the page to be tested based on the pixels of the first center point and the pixels of the second center point.
[0127] According to the method for obtaining text contrast of the present application, by confirming the text control and taking a screenshot of the text control, it is ensured that the first center point and the second center point can be successfully obtained subsequently, providing a basic guarantee for obtaining the contrast of the text in the text control; through the first center point and the second center point, the text contrast in the text control is obtained, which increases the work efficiency of measuring text contrast, reduces the manpower consumption of measuring text contrast, and prevents the occurrence of measurement errors due to operational errors when manually measuring text contrast, thereby increasing the accuracy of measuring text contrast.
[0128] It should be understood that, although the steps in the flowcharts of the above embodiments are shown in sequence as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the flowcharts of the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily to be performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0129] Based on the same inventive concept, embodiments of the present application also provide a device for obtaining text contrast for implementing the aforementioned method for obtaining text contrast. The solution provided by this device is similar to the solution described in the aforementioned method. Therefore, the specific limitations of one or more embodiments of the device for obtaining text contrast provided below can be found in the aforementioned method for obtaining text contrast, and will not be further elaborated here.
[0130] In one embodiment, Figure 8 As shown, Figure 8 This is a structural block diagram of a device for obtaining text contrast provided in an embodiment of the present application. The device includes: a screening module 810, a screenshot module 820, a processing module 830, and a determination module 840, wherein:
[0131] The screening module 810 is configured to determine a text control from at least one control corresponding to the initial control node of the page to be tested, wherein the text attribute of the text control is not empty.
[0132] The screenshot module 820 is used to take a screenshot of the text control on the page to be tested based on the position information of the text control to obtain an initial image.
[0133] The processing module 830 is configured to determine a first center point of a black area and a second center point of a white area in a black and white image corresponding to the initial image.
[0134] The determination module 840 is configured to determine the text contrast of the page to be tested based on the pixels of the first center point and the pixels of the second center point.
[0135] According to the device for obtaining text contrast of the present application, by confirming the text control and taking a screenshot of the text control, it is ensured that the first center point and the second center point can be successfully obtained subsequently, providing a basic guarantee for obtaining the contrast of the text in the text control; through the first center point and the second center point, the text contrast in the text control is obtained, which increases the work efficiency of measuring text contrast, reduces the manpower consumption of measuring text contrast, and prevents the occurrence of measurement errors due to operational errors when manually measuring text contrast, thereby increasing the accuracy of measuring text contrast.
[0136] In one embodiment, Figure 9 As shown, Figure 9 This is a structural block diagram of a device for obtaining text contrast provided in an embodiment of the present application. A device for obtaining text contrast is provided. In the device for obtaining text contrast, a processing module 930 includes: a scanning unit 931 and a first determining unit 932 .
[0137] The scanning unit 931 is used to perform line scanning on the black and white image based on the arrangement format of the pixels in the black and white image to obtain multiple line scanning areas, wherein each line scanning area includes at least one black area and at least one white area.
[0138] The first determining unit 932 is configured to determine a first center point of each black area and a second center point of each white area according to the position of each pixel point.
[0139] in, Figure 9 910, 920 and 940 and Figure 8 810, 820 and 840 have the same function and structure.
[0140] According to the text contrast acquisition device of the present application, by performing line scanning on a black and white image, the black area and the white area of each line scanning area are determined, providing a data basis for the subsequent calculation of the text contrast of the page to be measured; by determining the first center point of the area and the second center point of the white area, the accuracy of the text contrast calculation is guaranteed, the work efficiency of measuring the text contrast is increased, and the manpower consumption of measuring the text contrast is reduced.
[0141] In one embodiment, Figure 10 As shown, Figure 10 This is a structural block diagram of a device for obtaining text contrast provided in an embodiment of the present application. A device for obtaining text contrast is provided. The device for obtaining text contrast further includes: a first processing module 1050 and a second processing module 1060 .
[0142] The first processing module 1050 is used to perform grayscale processing on the initial image to obtain a grayscale image.
[0143] The second processing module 1060 is used to perform binarization processing on the grayscale image to obtain a black and white image.
[0144] in, Figure 10 1010-1040 and Figure 9 910-940 have the same function and structure.
[0145] According to the text contrast acquisition method of the present application, by grayscale processing and binarization processing of the initial image, a basis is provided for the subsequent calculation of the text contrast of the page to be tested, thereby reducing the amount of data in the initial image, increasing the efficiency of processing the initial image, and highlighting the outline of each element in the initial image.
[0146] In one embodiment, Figure 11 As shown, Figure 11 This is a structural block diagram of a device for obtaining text contrast provided in an embodiment of the present application. A device for obtaining text contrast is provided. In the device for obtaining text contrast, a screening module 1110 includes: an obtaining unit 1111, a second determining unit 1112, and a third determining unit 1113.
[0147] The first acquiring unit 1111 is configured to acquire control tree information of the page to be tested, and determine an initial control node based on the control tree information.
[0148] It should be noted that the control tree information of the page to be tested is obtained and input into a pre-generated control learning model. If the control learning model outputs information about the initial control node based on the control tree information, the step of determining a text control from at least one control corresponding to the initial control node of the page to be tested is performed. If the control learning model does not output information about the initial control node based on the control tree information, the control learning model is trained using the control tree information as training data until a new control learning model outputs information about the initial control node.
[0149] The second determining unit 1112 is configured to determine at least one control corresponding to the initial control node according to the control tree information.
[0150] The third determining unit 1113 is configured to determine a control whose text attribute is not empty among the at least one control as a text control.
[0151] in, Figure 11 Medium 1120-1060 and Figure 10 1020-1060 have the same function and structure.
[0152] According to the text contrast acquisition device of the present application, an initial control node is determined based on control tree information, and at least one control corresponding to the initial control node is determined based on the control tree information; thereby ensuring that the text contrast of the page to be tested can be successfully calculated subsequently; by setting a control learning model to achieve the determination of the text control, the operational difficulty of calculating the text contrast is reduced, the work efficiency of calculating the text contrast is increased, and the labor cost is reduced.
[0153] In one embodiment, Figure 12 As shown, Figure 12 This is a structural block diagram of a device for obtaining text contrast provided in an embodiment of the present application. A device for obtaining text contrast is provided. In the device for obtaining text contrast, a determination module 1240 includes: a second acquisition unit 1241, a fourth determination unit 1242, a fifth determination unit 1243, and a sixth determination unit 1244.
[0154] The second acquiring unit 1241 is configured to acquire coordinate information of the first center point and coordinate information of the second center point.
[0155] The fourth determining unit 1242 is configured to determine the pixel of the first center point based on the coordinate information of the first center point.
[0156] The fifth determining unit 1243 is configured to determine the pixel of the second center point based on the coordinate information of the second center point.
[0157] The sixth determining unit 1244 is configured to determine the text contrast of the page to be tested according to the pixels of the first center point and the pixels of the second center point.
[0158] in, Figure 12 1210-1230, 1250 and 1260 and Figure 11 1110-1130, 1150 and 1160 have the same function and structure.
[0159] According to the method for obtaining text contrast of the present application, by determining the coordinate information of the first center point and the coordinate information of the second center point, the pixels of the first center point and the second center point are obtained, and then the text contrast of the page to be measured is calculated through the pixels of the first center point and the second center point, thereby increasing the work efficiency of measuring text contrast and reducing the manpower consumption of measuring text contrast.
[0160] Each module in the above-mentioned text contrast acquisition device can be implemented in whole or in part through software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in hardware form, or can be stored in a computer device memory in software form, so that the processor can call and execute the corresponding operations of each module.
[0161] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 13 As shown. The computer device includes a processor, memory, a communication interface, a display screen, and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal via wired or wireless communication. The wireless communication can be achieved via Wi-Fi, a mobile cellular network, NFC (near-field communication), or other technologies. When executed by the processor, the computer program implements a method for obtaining text contrast. The display screen of the computer device can be a liquid crystal display or an electronic ink display. The input device of the computer device can be a touch layer covering the display screen, or keys, a trackball, or a touchpad provided on the computer device housing, or an external keyboard, touchpad, or mouse.
[0162] Those skilled in the art will understand that Figure 13The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0163] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0164] Determine a text control from at least one control corresponding to the initial control node of the page to be tested, wherein the text attribute of the text control is not empty;
[0165] Based on the position information of the text control, a screenshot of the text control is taken on the page to be tested to obtain an initial image;
[0166] Determine a first center point of a black area and a second center point of a white area in a black and white image corresponding to the initial image;
[0167] The text contrast of the page to be tested is determined according to the pixels of the first center point and the pixels of the second center point.
[0168] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0169] Based on the arrangement format of pixels in the black and white image, line scanning is performed on the black and white image to obtain a plurality of line scanning areas, wherein each line scanning area includes at least one black area and at least one white area;
[0170] According to the position of each pixel point, a first center point of each black area and a second center point of each white area are determined.
[0171] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0172] Perform grayscale processing on the initial image to obtain a grayscale image;
[0173] Binarize the grayscale image to obtain a black and white image.
[0174] In one embodiment, the control tree information of the page to be tested is obtained, and the initial control node is determined based on the control tree information;
[0175] Determine at least one control corresponding to the initial control node according to the control tree information;
[0176] Determine at least one control whose text property is not empty as a text control.
[0177] In one embodiment, obtaining coordinate information of the first center point and coordinate information of the second center point;
[0178] Determining a pixel of the first center point based on the coordinate information of the first center point;
[0179] Determining a pixel of the second center point based on the coordinate information of the second center point;
[0180] The text contrast of the page to be tested is determined according to the pixels of the first center point and the pixels of the second center point.
[0181] In one embodiment, the control tree information of the page to be tested is obtained, and the control tree information is input into a pre-generated control learning model;
[0182] If the control learning model outputs information of the initial control node based on the control tree information, a step of determining a text control from at least one control corresponding to the initial control node of the page to be tested is performed.
[0183] In one embodiment, if the control learning model does not output information of the initial control node based on the control tree information, the control learning model is trained using the control tree information as training data until the new control learning model outputs information of the initial control node.
[0184] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0185] Determine a text control from at least one control corresponding to the initial control node of the page to be tested, wherein the text attribute of the text control is not empty;
[0186] Based on the position information of the text control, a screenshot of the text control is taken on the page to be tested to obtain an initial image;
[0187] Determine a first center point of a black area and a second center point of a white area in a black and white image corresponding to the initial image;
[0188] The text contrast of the page to be tested is determined according to the pixels of the first center point and the pixels of the second center point.
[0189] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0190] Based on the arrangement format of pixels in the black and white image, line scanning is performed on the black and white image to obtain a plurality of line scanning areas, wherein each line scanning area includes at least one black area and at least one white area;
[0191] According to the position of each pixel point, a first center point of each black area and a second center point of each white area are determined.
[0192] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0193] Perform grayscale processing on the initial image to obtain a grayscale image;
[0194] Binarize the grayscale image to obtain a black and white image.
[0195] In one embodiment, the control tree information of the page to be tested is obtained, and the initial control node is determined based on the control tree information;
[0196] Determine at least one control corresponding to the initial control node according to the control tree information;
[0197] Determine at least one control whose text property is not empty as a text control.
[0198] In one embodiment, obtaining coordinate information of the first center point and coordinate information of the second center point;
[0199] Determining a pixel of the first center point based on the coordinate information of the first center point;
[0200] Determining a pixel of the second center point based on the coordinate information of the second center point;
[0201] The text contrast of the page to be tested is determined according to the pixels of the first center point and the pixels of the second center point.
[0202] In one embodiment, the control tree information of the page to be tested is obtained, and the control tree information is input into a pre-generated control learning model;
[0203] If the control learning model outputs information of the initial control node based on the control tree information, a step of determining a text control from at least one control corresponding to the initial control node of the page to be tested is performed.
[0204] In one embodiment, if the control learning model does not output information of the initial control node based on the control tree information, the control learning model is trained using the control tree information as training data until the new control learning model outputs information of the initial control node.
[0205] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0206] Determine a text control from at least one control corresponding to the initial control node of the page to be tested, wherein the text attribute of the text control is not empty;
[0207] Based on the position information of the text control, a screenshot of the text control is taken on the page to be tested to obtain an initial image;
[0208] Determine a first center point of a black area and a second center point of a white area in a black and white image corresponding to the initial image;
[0209] The text contrast of the page to be tested is determined according to the pixels of the first center point and the pixels of the second center point.
[0210] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0211] Based on the arrangement format of pixels in the black and white image, line scanning is performed on the black and white image to obtain a plurality of line scanning areas, wherein each line scanning area includes at least one black area and at least one white area;
[0212] According to the position of each pixel point, a first center point of each black area and a second center point of each white area are determined.
[0213] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0214] Perform grayscale processing on the initial image to obtain a grayscale image;
[0215] Binarize the grayscale image to obtain a black and white image.
[0216] In one embodiment, the control tree information of the page to be tested is obtained, and the initial control node is determined based on the control tree information;
[0217] Determine at least one control corresponding to the initial control node according to the control tree information;
[0218] Determine at least one control whose text property is not empty as a text control.
[0219] In one embodiment, obtaining coordinate information of the first center point and coordinate information of the second center point;
[0220] Determining a pixel of the first center point based on the coordinate information of the first center point;
[0221] Determining a pixel of the second center point based on the coordinate information of the second center point;
[0222] The text contrast of the page to be tested is determined according to the pixels of the first center point and the pixels of the second center point.
[0223] In one embodiment, the control tree information of the page to be tested is obtained, and the control tree information is input into a pre-generated control learning model;
[0224] If the control learning model outputs information of the initial control node based on the control tree information, a step of determining a text control from at least one control corresponding to the initial control node of the page to be tested is performed.
[0225] In one embodiment, if the control learning model does not output information of the initial control node based on the control tree information, the control learning model is trained using the control tree information as training data until the new control learning model outputs information of the initial control node.
[0226] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0227] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiments. In particular, any reference to memory, database, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The databases involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processors involved in the various embodiments provided herein may be, but are not limited to, general-purpose processors, central processing units (CPUs), graphics processing units (GPUs), digital signal processors (DSPs), programmable logic devices (PLDs), data processing logic devices based on quantum computing, and the like.
[0228] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0229] The above embodiments merely illustrate several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art may make various modifications and improvements without departing from the spirit of the present invention, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.
Claims
1. A method for obtaining text contrast, characterized in that: The method comprises: Determine a text control from at least one control corresponding to the initial control node of the page to be tested, wherein the text attribute of the text control is not empty; Based on the position information of the text control, taking a screenshot of the text control on the page to be tested to obtain an initial image; Determining a first center point of a black area and a second center point of a white area in a black and white image corresponding to the initial image includes: Based on the arrangement format of pixels in the black and white image, line scanning is performed on the black and white image to obtain a plurality of line scanning areas, wherein each of the line scanning areas includes at least one black area and at least one white area; Determining a first center point of each black area and a second center point of each white area according to the position of each pixel point; The brightness value of the first center point is determined based on the pixels of the first center point; the brightness value of the second center point is determined based on the pixels of the second center point; and the text contrast of the page to be tested is calculated based on the brightness value of the first center point and the brightness value of the second center point.
2. The method according to claim 1, characterized in that The method further comprises: Performing grayscale processing on the initial image to obtain a grayscale image; The grayscale image is binarized to obtain the black and white image.
3. The method according to claim 1, characterized in that The step of determining a text control from at least one control corresponding to an initial control node of the page to be tested includes: Acquire control tree information of the page to be tested, and determine the initial control node based on the control tree information; Determine at least one control corresponding to the initial control node according to the control tree information; A control whose text attribute is not empty among the at least one control is determined as the text control.
4. The method according to claim 1, wherein Determining the pixel of the first center point and the pixel of the second center point includes: Obtaining coordinate information of the first center point and coordinate information of the second center point; Determining a pixel of the first center point based on the coordinate information of the first center point; Based on the coordinate information of the second center point, a pixel of the second center point is determined.
5. The method according to claim 1, wherein The method further comprises: Obtaining control tree information of the page to be tested, and inputting the control tree information into a pre-generated control learning model; If the control learning model outputs the information of the initial control node based on the control tree information, the step of determining a text control from at least one control corresponding to the initial control node of the page to be tested is performed.
6. The method according to claim 5, characterized in that The method further comprises: If the control learning model does not output the information of the initial control node based on the control tree information, the control learning model is trained using the control tree information as training data until a new control learning model outputs the information of the initial control node.
7. A device for obtaining text contrast, characterized in that: The device comprises: A screening module, configured to determine a text control from at least one control corresponding to an initial control node of the page to be tested, wherein a text attribute of the text control is not empty; A screenshot module, configured to take a screenshot of the text control on the page to be tested based on the position information of the text control to obtain an initial image; a processing module, configured to determine a first center point of a black area and a second center point of a white area in a black and white image corresponding to the initial image; a determination module, configured to determine a brightness value of the first center point based on the pixels of the first center point; determine a brightness value of the second center point based on the pixels of the second center point; and calculate the text contrast of the page to be tested based on the brightness value of the first center point and the brightness value of the second center point; The processing module in the device for obtaining text contrast includes: a scanning unit and a first determining unit; The scanning unit is configured to perform line scanning on the black and white image based on an arrangement format of pixels in the black and white image to obtain a plurality of line scanning areas, wherein each of the line scanning areas includes at least one black area and at least one white area; The first determining unit is configured to determine a first center point of each of the black areas and a second center point of each of the white areas according to positions of the pixels.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Control tree generation method and terminal equipment
CN109656827A
Control identification method and device
CN109871316A
Barrier-free character intelligent detection method based on computer vision
CN113780260A