An abnormal management place checking detection method and system based on image recognition
By using image recognition technology to automatically analyze advertising slogans in business premises, the problem of time-consuming and labor-intensive traditional manual verification has been solved, achieving efficient and accurate compliance detection of advertising slogans and improving the efficiency and accuracy of market supervision.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING GREEN APPLE TECH CO LTD
- Filing Date
- 2026-03-06
- Publication Date
- 2026-06-05
AI Technical Summary
Traditional advertising slogan review methods rely on manual verification, which is time-consuming and labor-intensive, and is prone to errors due to human factors. They cannot effectively cope with the rapid changes in a large amount of information and the massive amount of advertising content from merchants, resulting in the lag in market supervision.
An image recognition-based method for detecting abnormal business premises is adopted. By collecting images of the storefronts of business premises, performing grayscale processing and uniform grid division, identifying effective seed points and gradient directions, forming text candidate regions, and comparing them with a historical advertising slogan database, the compliance of the advertising slogans is identified.
It improves the accuracy and efficiency of advertising slogan identification, promptly detects potential violations, reduces the burden of manual review, ensures the legality and compliance of advertising content, and enhances the rigor of market supervision and public trust.
Smart Images

Figure CN122157291A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image recognition, and in particular to a method and system for verifying and detecting abnormal business premises based on image recognition. Background Technology
[0002] In recent years, with the accelerating pace of urbanization and the diversification and complexity of commercial activities, market supervision faces new challenges. Against this backdrop, monitoring abnormal business premises and their advertising information has become particularly important. The advertising slogans used by businesses in their premises not only directly influence consumer choices but also relate to public order and the healthy development of the business environment. Therefore, ensuring the legality and compliance of advertising content and maintaining market order have become increasingly important focuses for regulatory authorities and all sectors of society.
[0003] Traditional advertising review methods rely heavily on manual verification, which is time-consuming, labor-intensive, and prone to errors due to human factors. They are also ill-suited to handling the rapid changes in information and the sheer volume of advertising content from numerous businesses. Furthermore, manual review struggles to quickly respond to newly emerging potentially illegal advertisements, leading to delays in market regulation. Therefore, there is an urgent need for an efficient, accurate, and automated technological approach to monitor and analyze advertising content in real time.
[0004] The rapid development of image recognition technology in recent years has provided new solutions to the aforementioned problems. With advancements in deep learning and computer vision technologies, image recognition applications in areas such as text detection and image understanding have gradually matured. Through automatic analysis of commercial advertising images, textual information can be quickly identified and compared with existing databases of compliant advertising slogans to determine the compliance of the advertising content. This technology not only improves detection accuracy but also significantly enhances regulatory efficiency, enabling the timely detection and handling of abnormal content, and providing strong support for the standardization of business activities.
[0005] Furthermore, many regions and industries have specific legal and regulatory requirements regarding advertising content, such as prohibiting the publication of false information and vulgar content. Therefore, establishing a comprehensive database of text advertising slogans and combining it with advanced image processing technology to conduct real-time verification of advertising slogans can effectively improve the rigor of market supervision and truly safeguard consumer rights and a fair competitive market environment. Summary of the Invention
[0006] The purpose of this invention is to provide a method and system for verifying and detecting abnormal business premises based on image recognition, which solves the above-mentioned technical problems pointed out in the prior art.
[0007] This invention provides a method for detecting and verifying abnormal business premises based on image recognition, comprising the following steps:
[0008] Collect images of the storefront of the target business location, obtain image data of the advertising slogan, preprocess the image data of the advertising slogan, and obtain the image to be detected;
[0009] The image to be detected is divided into grayscale and uniform grids to form sub-image regions. Effective seed points are identified in each sub-image region based on pixel grayscale values and gradients. These effective seed points are then grown to form preliminary text candidate regions. Gradient directions are identified in the preliminary text candidate regions to obtain text paths. Clear edge pixels are identified in the text paths to form text.
[0010] Obtain a historical text advertising slogan database; compare the text with the historical text advertising slogan database to identify whether there are any anomalies in the text of the target business location.
[0011] Accordingly, this invention also proposes an image recognition-based system for detecting and verifying abnormal business premises, comprising: a data acquisition module; an analysis module; and a recognition module;
[0012] The acquisition module is used to acquire images of the storefront of the target business location, obtain image data of the advertising slogan, preprocess the image data of the advertising slogan, and obtain the image to be detected.
[0013] The analysis module is used to divide the image to be detected into a uniform grid to form sub-image regions, identify effective seed points by pixel grayscale values and gradients in the sub-image regions, grow the effective seed points to form preliminary text candidate regions, identify the gradient direction of the preliminary text candidate regions to obtain text paths, and identify clear edge pixels in the text paths to form text.
[0014] The identification module is used to acquire a historical text advertising slogan database; compare the text with the historical text advertising slogan database, and identify whether there are any anomalies in the text of the target business location.
[0015] Compared with the prior art, the embodiments of the present invention have at least the following technical advantages:
[0016] Analysis of the above-mentioned image recognition-based method and system for detecting abnormal business premises provided by the present invention shows that, in specific applications, the image preprocessing and grayscale conversion steps effectively reduce the complexity of data processing; color images may confuse the text recognition process in many cases, while grayscale conversion focuses on shape features, making subsequent text recognition more accurate; this solution divides the image into uniform sub-image regions, which can perform fine processing on each smaller region, improving the detection accuracy of text candidate regions, while effectively reducing interference from non-text regions;
[0017] Furthermore, identifying effective seed points within sub-regions and utilizing these seed points for text region growth helps construct more complete text candidate regions. This process, by identifying pixel grayscale values and gradient directions, allows us to more accurately grasp the boundaries of text, thus laying the foundation for text structure; the resulting text paths are clear and coherent, providing excellent conditions for subsequent text recognition and significantly improving the overall recognition effect.
[0018] Furthermore, this solution demonstrates excellent anomaly detection by comparing text with a historical advertising slogan database. The inclusion of a historical database makes the compliance detection of advertising slogans more comprehensive and scientific, especially in identifying potentially non-compliant or newly emerging abnormal advertising slogans, where its accuracy is significantly improved. Through such comparison, advertisements that do not comply with relevant regulations and industry standards can be identified in a timely manner, reducing the burden of manual review and improving work efficiency.
[0019] Finally, integrating image recognition technology with database comparison not only improves the accuracy of advertising slogan recognition but also provides regulatory authorities with a powerful tool to help build a compliant business environment. The implementation of this method helps enhance public trust in commercial activities, ensures the authenticity and legality of advertising, and reduces social risks. Attached Figure Description
[0020] Figure 1 This is a flowchart of the main steps of an image recognition-based method for detecting abnormal business premises, as described in Example 1.
[0021] Figure 2 This is a text path flowchart of an abnormal business premises verification and detection method based on image recognition, as described in Example 1.
[0022] Figure 3 This is a schematic diagram of the cross-grid points of an abnormal business premises verification and detection method based on image recognition, as described in Example 1.
[0023] Figure 4 This is a noise diagram illustrating an image recognition-based method for detecting abnormal business premises, as described in Example 1.
[0024] Figure 5 The flowchart shows an enhanced image of an abnormal business premises verification and detection method based on image recognition, as described in Example 1.
[0025] Figure 6 This is a schematic diagram of the closed contour of an image recognition-based method for detecting abnormal business premises, as described in Example 1.
[0026] Figure 7 This is a flowchart of the character strokes in an image recognition-based method for detecting abnormal business premises, as described in Example 1.
[0027] Figure 8 This is a schematic diagram illustrating potential breakpoints in an image recognition-based method for detecting abnormal business premises, as described in Example 1.
[0028] Figure 9 This is a schematic diagram of the actual breakpoint of an abnormal business premises verification and detection method based on image recognition, as described in Example 1.
[0029] Figure 10 This is a schematic diagram of pixel breaks in the strokes of characters in an abnormal business premises verification and detection method based on image recognition, as described in Embodiment 1.
[0030] Figure 11 This is a flowchart of an image recognition-based abnormal business premises verification and detection system according to Embodiment 2;
[0031] Labels: Acquisition module 10; Analysis module 20; Identification module 30. Detailed Implementation
[0032] The technical solution of the present invention will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0033] The present invention will now be described in further detail with reference to specific embodiments and accompanying drawings.
[0034] Example 1
[0035] like Figure 1 As shown, this embodiment of the invention provides a method for detecting and verifying abnormal business premises based on image recognition, including the following steps:
[0036] S10: Collect the storefront image of the target business location, obtain the image data of the advertising slogan, preprocess the image data of the advertising slogan, and obtain the image to be detected;
[0037] S20: The image to be detected is divided into a uniform grid to form a sub-image region by grayscale conversion; effective seed points are identified by pixel grayscale values and gradients in the sub-image region; the effective seed points are grown to form a preliminary text candidate region; the gradient direction of the preliminary text candidate region is identified to obtain the text path; clear edge pixels are identified in the text path to form the text.
[0038] It should be noted that converting a color image to a grayscale image helps reduce computational complexity and emphasizes shape features. In subsequent text recognition, color information is limited and may even interfere with text recognition, making grayscale conversion more suitable. Dividing the grayscale image into multiple sub-regions allows for localized processing, thereby improving the detection accuracy of text candidate regions. Uniform grid division helps eliminate interference from non-text regions and ensures that each small region can effectively detect potential text information. A series of important pixels are identified as the basis for further analysis. Effective seed points based on grayscale values and gradients are used to more accurately determine the possible boundaries of text, improving recognition performance. Based on preliminary detection, potential text regions are formed, facilitating the subsequent capture of complete text regions through seed point growth, improving the accuracy of subsequent recognition. Identifying possible text paths provides clear and continuous lines for text recognition. Since text is usually composed of continuous strokes, identifying gradient directions helps establish the structure of the text, improving overall recognition performance.
[0039] Identifying well-defined text pixels helps in forming the final text image; edge information is crucial for high-precision text recognition, and clear edges can effectively improve the text recognition rate.
[0040] S30: Obtain the historical text advertising slogan database; compare the text with the historical text advertising slogan database to identify whether there are any abnormalities in the text of the target business location;
[0041] It should be noted that the above steps, through comparison, are used to determine whether there are any abnormalities in the advertising slogans of the target business premises, ensuring the validity and compliance of the information; comparing with historical databases helps to identify newly emerging, abnormal, or potentially non-compliant advertising slogans, ensuring that they comply with relevant laws and industry standards;
[0042] Specifically, such as Figure 2 As shown, in step S20, the image to be detected is divided into a uniform grid to form sub-image regions by grayscale conversion. Effective seed points are identified based on the grayscale values and gradients of pixels within the sub-image regions. These effective seed points are then grown to form preliminary text candidate regions. Gradient directions are identified within the preliminary text candidate regions to obtain text paths. Finally, clear edge pixels are identified within the text paths to form text. The specific operation steps are as follows:
[0043] S21: Convert the image to be detected to grayscale to obtain a grayscale image to be detected;
[0044] The grayscale image to be detected is divided into a uniform grid, and a neighborhood window is preset;
[0045] A neighboring window is extracted centered at the intersection point of adjacent grid lines, serving as a sub-image region. (If the window extends beyond the image boundaries, it is filled (e.g., mirror fill) or the window size is adjusted.) Figure 3 (as shown)
[0046] For each sub-image region, calculate the local grayscale standard deviation of all pixels (i.e., the standard deviation measures the dispersion of grayscale values within a window; text regions typically contain strokes with abrupt black-to-white transitions, resulting in drastic grayscale changes and thus a higher standard deviation; while backgrounds (such as solid-color walls) have a lower standard deviation). First, calculate the standard deviation of the grayscale values for each sub-image region. The average grayscale value of all pixels within Then calculate the grayscale value and mean of each pixel. The formula is: square the difference, then calculate the average, and finally take the square root. );
[0047] For each sub-image region, calculate the mean local gradient magnitude of the pixels (i.e., use gradient operators (such as Sobel, Prewitt) to calculate the sub-image region). For each pixel, calculate the gradient Gx and Gy along the x and y axes, and then calculate the gradient magnitude of each pixel based on the gradients Gx and Gy. Then based on the gradient magnitude Calculate the gradient magnitude of all pixels within the sub-image region. The average value of the gradient magnitude is obtained by averaging the values. Gradient magnitude reflects the intensity of image edges. The boundaries of text strokes are strong edges, therefore the text region... (Higher)
[0048] It's important to note that converting a color image to grayscale reduces information complexity. Grayscale images retain brightness information while discarding color information, simplifying subsequent processing. In text detection, color information is often not the primary factor; grayscale values effectively represent text intensity variations. Histograms reveal the distribution of different grayscale values within the image, and peaks and troughs in the histogram determine the global threshold. Peaks correspond to high-frequency grayscale values (usually text or background), while troughs represent classification thresholds. Extracting the global threshold effectively distinguishes text from background. The grayscale image is divided into multiple small regions, each analyzed independently in subsequent processing. Dividing the grayscale image into a grid allows for localized analysis, adapting to variations in grayscale features within regions, rather than the entire grayscale image to be detected. This is particularly suitable for processing images containing regions of varying brightness.
[0049] The dispersion of gray values within each sub-image region is evaluated. A high standard deviation usually indicates that there are obvious gray-level variations within the region (such as strokes in text), while a low standard deviation indicates that the region is relatively uniform (such as the background), which helps to distinguish between text and non-text regions. The average level of edge intensity within each region is also evaluated. Text usually contains obvious edges, while the background is generally smoother. The above steps calculate gradient magnitudes to effectively identify lines and edges, thereby helping to detect text regions.
[0050] S22: Calculate the standard deviation of the global grayscale value and the mean of the global gradient magnitude of all pixels in the grayscale image to be detected;
[0051] If the standard deviation of the local gray value in the local features of the sub-image region is greater than the standard deviation of the global gray value, and the mean of the local gradient magnitude is greater than the mean of the global gradient magnitude, then the intersection grid point corresponding to the sub-image region is determined as a valid seed point (that is, using the prior knowledge that the text region has higher local contrast and edge density than the whole image, the suspected occurrence point of the text can be quickly located from the grid).
[0052] For each valid seed point, calculate the absolute value of the grayscale difference between it and its neighboring pixels;
[0053] A preset dynamic threshold is established; it is then determined whether the absolute value of the grayscale difference is less than the dynamic threshold.
[0054] If so, the effective seed point is determined to grow the pixels in the neighborhood to obtain a connected region;
[0055] For each connected region, determine the minimum and maximum values of the pixels along the x and y axes, and construct an axially aligned rectangle (i.e., [...]). , , , In the above steps, the sub-image region in S21 is a fixed window used to discover text seed points (i.e., effective seed points), while the axial alignment rectangle in S22 is the final positioning box of the text region formed after these seed points grow.
[0056] Calculate the number of pixels within the axially aligned rectangle, which is used as the area of the rectangle; and simultaneously calculate the width and height (i.e., width) of the axially aligned rectangle. = - +1, Height = - + 1);
[0057] The aspect ratio (i.e., AspectRatio = ...) is calculated using the width and height of the axially aligned rectangle. / );
[0058] The density (i.e., Density = |) is calculated by using the number of pixels in the axially aligned rectangle and the area of the rectangle. | / ( * ));
[0059] Set area threshold, aspect ratio normal threshold, and density threshold;
[0060] Determine whether the area of the rectangle is greater than the area threshold (i.e., if it is less than or equal to the area threshold, it is a noise point).
[0061] If so, then continue to determine whether the aspect ratio is equal to the normal aspect ratio threshold (i.e., if it is not equal, it means that the font may be too tall or too thin, or too wide and flat, which does not conform to the shape of common characters or text lines).
[0062] If so, then continue to determine whether the density is greater than the density threshold (i.e., if it is less than or equal to, it means that there are too many holes inside the region, which is more like texture or scattered noise than solid text strokes, such as...). Figure 4 (as shown)
[0063] If so, then the axially aligned rectangle (i.e., the connected region) is determined to be a preliminary candidate text region;
[0064] It should be noted that the global grayscale standard deviation reflects the grayscale distribution of the entire image, while the global gradient magnitude mean reflects the edge strength of the entire image. Understanding the basic attributes of the entire image helps to distinguish local areas with high overall contrast (such as text). The above steps, by comparing the local grayscale standard deviation with the global standard deviation, and the local gradient magnitude mean with the global mean, can locate regions with significant local features. Speech or text often has high contrast and edge density in local areas, and regions that meet these two characteristics are more likely to be text regions. Calculating the grayscale difference between neighboring pixels and effective seed points helps to identify the similarity with effective seed points. This step determines which pixels can be considered part of the effective seed point by finding similar grayscale values, thereby helping region growth. The above uses dynamic thresholding (i.e., adaptively determined based on the local grayscale characteristics of the sub-image region where the current seed point is located; the specific calculation method is as follows). ;in, This is the standard deviation of the local grayscale values in the sub-image region where the current valid seed point is located (this value has been calculated in step S21). This is an empirical coefficient, and its value range is... Preferably, take The dynamic threshold determines whether to continue region growing on valid seed points. It considers the characteristics of different images and can flexibly handle different contrast conditions to avoid overgrowing or undergrowing. Specifically, for each valid seed point, its coordinates are pushed onto an empty stack (or queue), and a binary marker map of the same size as the grayscale image to be detected is created to mark the seed point's location as grown. When the stack is not empty, the stack vertex is popped as the current growth point. ; Traversal 8 neighboring pixels ;if If it has already been marked in the binary labeled image, skip it and proceed with the calculation. and The absolute value of the grayscale difference And preset dynamic thresholds (For example, take half of the global grayscale standard deviation); determine Is it true? If it is true, then... Push onto the stack and in the binary labeled graph Mark as grown; repeat the above process until the stack is empty; finally, all pixels marked as grown in the binary label map form a connected region.
[0065] The minimum and maximum extent of each region are determined to construct an axially aligned rectangle. This rectangle represents each connected region in a standardized way, facilitating subsequent area and proportion calculations. This information can be used for further region feature analysis, such as calculating the occupied space. Aspect ratio and density are calculated, which measure the normality of the region's shape and its internal filling, respectively. Typically, the aspect ratio of text should be within a specific range, while density reflects the solidity within the region, helping to filter out textured or noisy regions. Thresholds for area, aspect ratio, and density are set for judgment. By judging these thresholds, regions that do not meet the conditions can be efficiently filtered out, and regions that do not conform to the normal shape or texture characteristics can be excluded, ensuring that the finally extracted text regions are relatively reliable. The finally determined regions can be regarded as preliminary text candidate regions, ensuring that the extracted regions have high accuracy and reliability and reducing false detections.
[0066] S23: Calculate the square root of the area of the preliminary text candidate region based on the area of the rectangle (i.e., the area of the rectangle is the area of the preliminary text candidate region, and the square root of the area is the side length of the region).
[0067] A preset search step size is set; starting from the upper left corner inside the axially aligned rectangle, sub-grid points are generated in the x-axis and z-axis directions at intervals of the search step size (i.e., the generation of sub-grid points is the same as the intersection grid points in S21, and the search step size is used to continuously search and form a grid, with adjacent grids constituting grid points).
[0068] For each sub-grid point, a sliding window is applied. The gradient direction of the internal pixels of each sliding window is calculated, and the average gradient direction of all pixel gradient directions is calculated as the dominant direction.
[0069] A preset angle tolerance threshold is used; the dominant direction and the angle tolerance threshold are used to form a direction angle range (i.e., - , + ; Indicates the dominant direction; (represented as the angle tolerance threshold).
[0070] The number of pixels whose gradient direction is within the specified angle range is selected (that is, whether the gradient direction of these pixels is within the specified angle range is selected, and the number of pixels within the specified angle range is calculated; pixels within the specified angle range indicate that the direction of these pixels is consistent).
[0071] The orientation consistency ratio is calculated by comparing the number of pixels with the total number of pixels in the sliding window (i.e., the number of pixels with the same orientation divided by the total number of pixels; the orientation consistency ratio is between 0 and 1, and the higher the value, the more uniform and consistent the edge orientation around the point; that is, by using the characteristic of consistent stroke orientation of text, points that may be located on the center line of the strokes are selected).
[0072] It should be noted that calculating the side length of the initial text candidate region allows for grid generation in subsequent steps. The aforementioned method, by obtaining the side length of the rectangle (i.e., the square root of the area), ensures that these sub-grid points are evenly distributed within the candidate region, facilitating better gradient direction analysis. Multiple sub-grid points are evenly distributed within the rectangle for subsequent gradient calculations. The method involves setting a preset search step size to generate grid points in a specified direction, ensuring effective sampling in each candidate region and avoiding redundant calculations across the entire region. A sliding window is executed at each sub-grid point to calculate the gradient direction of the internal pixels. This sliding window technique allows for analysis of the environment around each point, extraction of local features, and gradient direction calculation, which helps in understanding edge information in the image. The dominant gradient direction within each sliding window is determined; this dominant direction helps in understanding the main features of the local region and comparing which direction has more pixels.
[0073] By defining a tolerance threshold, an allowable range of variation can be created, ensuring that pixels in a certain direction can be considered directionally consistent, which helps focus on the main edge directions. The number of pixels within the previously defined directional range is calculated. Through the above filtering, it is possible to evaluate which pixels in a specific direction are meaningful and likely to form part or whole of the character's structure. The directional consistency ratio is obtained, which determines the edge regularity within the region. The higher the directional consistency ratio, the more regular the edge direction within the region, and the more likely it is to be at the center of a stroke when writing a character, helping to filter out the real text region or character, rather than noise or random structures.
[0074] S24: Sort all sub-grid points in descending order according to the direction consistency ratio, select the top k sub-grid points as dynamic path planning nodes (that is, indicate how many independent path explorations are to be initiated, ensuring that the path exploration starts from the point with the clearest texture direction and most like the strokes of a character, which improves the efficiency and success rate of exploration), and use the dynamic path planning node with the largest direction consistency ratio as the path starting node.
[0075] The preset cost function (i.e., the cost function is obtained by adding the actual cost and the heuristic cost) is f(n) = actual cost g(n) + heuristic cost h(n); where the actual cost g(n) is the sum of the reciprocals of the gradient magnitudes of each pixel on the path from the starting node to the current node n; the heuristic cost h(n) is defined as the estimated cost from the current node n to the preset target region; the preset target region is the other boundary of the axially aligned rectangle R generated in step S22 that is opposite to the side where the starting node of the path is located (for example, if the starting node is close to the left boundary of the rectangle, then the target region is the right boundary x = h(n) uses Euclidean distance to calculate the shortest distance from the current node n to the target boundary.
[0076] The dynamic path planning node with the smallest cost function is selected (that is, the dynamic path planning node with the smallest cost function is selected), and the Euclidean distance between the smallest dynamic path planning node and the axially aligned rectangle is calculated.
[0077] A preset distance target threshold (i.e., set based on historical experience) is established; it is then determined whether the Euclidean distance is greater than or equal to the target threshold.
[0078] If so, the exploration of the smallest dynamic path planning node is considered successful (i.e., the route of the stroke is found; if the target condition is met, it means that the path exploration of the smallest dynamic path planning node starting from the starting node is successfully completed).
[0079] If not, then the smallest dynamic path planning node is discarded (meaning no path for the strokes was found).
[0080] The neighboring dynamic path planning nodes of the smallest dynamic path planning node are selected as candidate nodes.
[0081] If the candidate node is a discard node or the Euclidean distance between the candidate node and the axially aligned rectangle is less than the distance target threshold, then the candidate node is skipped.
[0082] Calculate the actual cost of the path formed by the starting node of the path reaching the candidate node through the smallest dynamic path planning node (i.e., the cost is the sum of the inverses of the gradient magnitudes of all pixels on the path, which is intended to encourage the path to extend along regions with high edge intensity in the image).
[0083] If the actual cost of the path is less than the actual cost of the candidate node, then the candidate node of the path is determined as a new path node. The above steps are repeated until all dynamic path planning nodes have been filtered out, and the path terminal node is obtained. The path starting node and the path terminal node are connected to form a text path.
[0084] It should be noted that the above sorting prioritizes points with higher directional consistency, which may be components of text strokes or edges. Points with a high proportion of directional consistency usually represent obvious edges or strokes, and following this order improves the effectiveness of subsequent path exploration. Selecting the k most representative nodes as the starting point of the exploration path helps improve the success rate and efficiency of the exploration. It reduces the amount of computation while ensuring the correctness of the exploration process. Selecting multiple starting nodes can provide diversity and increase the chance of finding stroke paths. By selecting the node with the highest directional consistency as the starting point, the path exploration is ensured to start from the point with the highest probability of success. This selection increases the probability of finding effective edges and can find stroke paths faster. The cost function combines actual cost and heuristic cost, so that path planning considers both real-world costs and has a certain degree of predictability. Actual cost encourages the path to land along the edge, while heuristic cost guides the search to the target area. Combining the two helps to find paths more accurately. The above filtering can find the most effective nodes to continue path exploration. A smaller cost function usually means a higher quality path, that is, the path travels better on the edge and is closer to the target area.
[0085] Determining whether a stroke path has been successfully found reduces unnecessary exploration to some extent. If the distance is less than a threshold, it means that the current path is close enough to the text stroke; otherwise, it means that the exploration has failed, and the node is marked as no longer participating in the subsequent exploration. This avoids unnecessary calculations, effectively improves the execution efficiency of the algorithm, and reduces repeated exploration of known unsuccessful paths.
[0086] The above-mentioned approach, by exploring neighboring nodes and continuously searching for possible candidate path points, increases the likelihood of finding an effective path. Exploring paths in different directions can increase the probability of finding strokes and avoid being confined to a specific area. If a lower-cost path is found, the path nodes are updated; this dynamic adjustment can find the optimal solution. By comparing costs, the path selection can be adjusted in a timely manner to ensure the quality of the final path. Through iteration, the path formed by the starting point and the ending point is finally obtained, ensuring the effectiveness and optimization of the path. (The specific operation process involves initializing two lists: an open list to store nodes to be explored and a closed list to store explored nodes; adding the path's starting node 'start' to the open list and setting its value...) start start start ;
[0087] While the open list is not empty, execute the loop to select from the open list. The node with the smallest value is designated as the current node; the current node is removed from the open list and added to the closed list; if the Euclidean distance between the current node and the target region (e.g., the center of the axially aligned rectangle) is less than the target threshold. If the path search is successful, backtrack to obtain the final text path and exit the loop; otherwise, examine each neighbor (candidate node) of the current node's dynamic path planning.
[0088] If the dynamic path planning node is in the closed list or has been marked as an abandoned node, skip it; calculate the actual cost of the path from the starting node to the dynamic path planning node via the current node. current current, neighbor cost current, neighbor This is the sum of the reciprocals of the gradient magnitudes of the pixels between the two points; if the dynamic path planning node is not in the open list, then add the dynamic path planning node to the open list and record its value. neighbor neighbor neighbor And set the current node as its parent node; if the dynamic path planning node is already in the open list, and neighbor Then update neighbor neighbor neighbor And update its parent node to the current node (current).
[0089] S25: Identify text pixel regions based on the gradient of pixels in the text path; identify sharp edge pixels based on the gradient values of pixels in the text pixel regions; connect the sharp edge pixels to form an edge chain, calculate the length of the edge chain, identify short chain edge segments as breaks, and set the sharp edge pixels of the short chain edge segments as initial breakpoints; with each initial breakpoint as the center point, form a square region enhancement according to a preset diameter to form a global edge image; connect all sharp edge pixels in the global edge image to obtain a closed text outline; identify text from the closed text outline.
[0090] It should be noted that the above steps analyze the gradient of pixels to effectively identify text regions. Typically, there is a significant intensity difference between text and the background; gradient analysis can highlight these changes, thus locating the text. Identifying text regions is the foundation for subsequent processing, ensuring that only text is processed, thereby reducing noise interference and improving recognition efficiency. Binarizing the text pixel regions identifies clear edge pixels, highlighting the text outline and clearly identifying sharp edge pixels. The formation of edge chains systematizes the text outline information; connecting edge pixels helps construct a complete outline, thus providing complete shape information for subsequent recognition. The above steps, by calculating the edge chain length, identify shorter edge chains, which may represent broken sections.
[0091] In some cases, text edges may be broken due to blurring. Identifying these short chains can help correct potential errors and improve recognition accuracy. The edge segments of the short chains are selected as breakpoints and used as the starting points for reconstruction. Broken parts need to be repaired, so these breakpoints are found for repair and connection in subsequent steps. A square region is formed with each initial breakpoint as the center point and a preset diameter for enhancement. The constructed square region enhances the pixels around the initial breakpoint. The enhanced pixels within the region can better restore the connection of characters, achieving the effect of smoothing and integrating text boundaries, improving the overall recognition accuracy, and forming a global edge image. Connecting all clear edge pixels in the global edge image can generate a more complete and continuous text outline, strengthening overall connectivity.
[0092] Specifically, such as Figure 5As shown, in step S25, the text pixel region is identified based on the gradient of the pixels in the text path; clear edge pixels are identified based on the gradient values of the pixels in the text pixel region; the clear edge pixels are connected to form an edge chain, the length of the edge chain is calculated, short chain edge segments are identified as breaks, and the clear edge pixels of the short chain edge segments are set as initial breakpoints; a square region is formed with each initial breakpoint as the center point and a preset diameter is used to enhance it, forming a global edge image; the clear edge pixels in all global edge images are connected to obtain a closed text outline; the closed text outline is used to identify the text, and the specific operation steps are as follows:
[0093] S251: Calculate the distance between the terminal nodes of all text paths (i.e., the distance between the terminal nodes represents the Euclidean distance between the terminal nodes of all text paths (i.e., the last node of the character stroke). The distance between the terminal nodes of all text paths reflects whether these text paths are close to each other, and thus indirectly reflects whether these close text paths are strokes of the same character).
[0094] Cluster all path terminal nodes whose distance is less than the preset clustering threshold to obtain terminal node clusters (i.e., each cluster may correspond to a corner or boundary of the text region).
[0095] Calculate the geometric centroid of each terminal node cluster;
[0096] Calculate the average gradient magnitude of the pixels along each text path;
[0097] Preset gradient magnitude average threshold and cluster distance threshold;
[0098] Determine whether the average gradient magnitude of the path is greater than the average gradient magnitude threshold.
[0099] If so, calculate the centroid distance between the starting node of the path and the geometric centroid; determine whether the centroid distance is less than the cluster distance threshold;
[0100] If so, then determine that the text path corresponding to the path terminal node of the terminal node cluster is a high-quality path.
[0101] Cluster all pixels on high-quality paths and create a binary mask to obtain the text pixel region (i.e., the text pixel region of the mask; the mask represents a high-probability text pixel region that is pointed to by multiple high-quality stroke paths, indicating the approximate location range of the advertising slogan).
[0102] It should be noted that the above method calculates the distance between the terminal nodes of each text path to understand the spatial distribution of these paths, identify which terminal nodes are close together and may form the same text region, and that the stroke endpoints of different characters should be clustered together for subsequent clustering analysis; terminal nodes with a distance less than a preset clustering threshold are clustered to form several terminal node clusters, which helps to identify the clustering characteristics of different text regions; clustering can classify similar paths, making subsequent text region localization more efficient; each terminal node cluster has a geometric centroid, which can be regarded as the "center" of the cluster, effectively representing the overall position of the cluster and providing a reference for subsequent path judgment; the average gradient magnitude of pixels on each text path is obtained to intuitively reflect the detail, intensity, and other characteristics of the path, and the gradient magnitude of the path can better distinguish strokes of different quality, helping to judge the quality of the path;
[0103] The above steps filter out high-quality text paths by setting an average threshold for gradient magnitude, eliminating low-quality paths that clearly do not meet the criteria. High-quality paths typically have strong gradients, which are related to clear strokes and clarity; therefore, this step helps to eliminate low-quality invalid paths. The next step calculates the distance from the path's starting node to its geometric centroid to determine if the path effectively points to the clustered text region. If the distance between the starting node and the centroid is small, it indicates that the path can well represent the features of the text region; otherwise, it may be invalid. If a path meets multiple conditions, it is marked as a high-quality path, providing a basis for high signal-to-noise ratio processing and suggesting it is more likely to contain clear text information, making it suitable for further image processing and content extraction. All pixels in the high-quality paths are clustered, and a binary mask is generated to make the text region more clearly displayed. The clustered mask effectively represents the shape and layout of the text region for subsequent image analysis and extraction.
[0104] S252: Calculate the gradient value of each pixel in the text pixel region of the binary mask, and use the gradient value to calculate the gradient magnitude and gradient direction of the pixel to construct a gradient magnitude map and a gradient direction map (i.e., the gradient magnitude map reflects the edge strength of the rough position range of the advertising text in the text pixel region of the binary mask, that is, the sharpness of the pixel; while the gradient direction map reflects the orientation of the advertising text in the text pixel region of the binary mask, that is, the orientation of the strokes).
[0105] Each pixel in the gradient magnitude map is quantized in four directions (0°, 45°, 90°, 135°) according to the gradient direction. The gradient magnitude of the pixel is compared with the gradient magnitude of the diagonal neighboring pixels in the same gradient direction (i.e., if the gradient direction angle of pixel p is in the horizontal direction (e.g., -22.5° to 22.5°), then its corresponding edge direction is the vertical direction. The gradient magnitudes of the pixels to the left and right of p are compared, thus filtering out pixels with stronger edges, eliminating edge blurring, and enhancing image edges). The pixel with the largest gradient magnitude is retained, and the edge response map is finally obtained.
[0106] Preset sharpness and blur thresholds (i.e., thresholds for gradient magnitude judgment) are used to further analyze edge pixels of the image and enhance edge strength. In this embodiment, the gradient magnitude map is normalized, and the gradient magnitude values of all pixels range from [value missing]. Based on extensive experimental statistics, the gradient magnitude of sharp edge points is usually higher, followed by blurry edge points; therefore, a sharpness threshold is set. fuzzy threshold );
[0107] The gradient magnitude of the pixels in the edge response map is compared with the sharpness threshold and the blur threshold.
[0108] If the gradient magnitude of a pixel in the edge response map is greater than or equal to the sharpness threshold, then the pixel is determined to be a sharp edge pixel (i.e., if the gradient magnitude is greater than or equal to the sharpness threshold, it is directly regarded as an edge point, which is a sharp edge point).
[0109] If the gradient magnitude of a pixel in the edge response map is greater than or equal to the blur threshold and less than the sharp threshold (i.e., blur threshold ≤ gradient magnitude < sharp threshold), then the pixel is determined to be a blurry edge pixel (i.e., these points may be edges or noise, and further judgment is required).
[0110] If the gradient magnitude of a pixel in the edge response map is less than the blur threshold, then the pixel is determined to be a non-edge point (i.e., non-edge points are not utilized).
[0111] If there are blurred edge pixels in the neighborhood of each clear edge pixel, then the blurred edge pixel is taken as a clear edge pixel (that is, the weak edges adjacent to the clear edge pixel are connected by connectivity to obtain a more complete and cleaner initial edge map).
[0112] It's important to note that calculating the gradient value of each pixel helps capture areas of greatest change in the image, often marking edges or feature boundaries. The gradient represents the rate of change of an image at a point, signifying a sudden change in brightness and typically indicating the region where an edge is located. The gradient magnitude indicates the edge's strength, while the gradient direction provides information about the edge's orientation, which can be used for subsequent edge detection and feature extraction, such as identifying the stroke direction of a font. Quantizing the gradient direction into four directions (0°, 45°, 90°, 135°) simplifies subsequent comparisons and processing. Limiting the direction to four main directions makes it easier to compare gradient magnitudes between neighboring pixels, optimizing edge detection. Retaining the pixel with the largest gradient magnitude enhances edge sharpness and suppresses blur. By focusing only on the pixel with the largest gradient magnitude in the neighborhood, pixels that may be affected by noise can be effectively excluded, thus improving the accuracy of edge response.
[0113] Setting thresholds helps classify edges of varying intensities. A sharp threshold is used to identify strong edges, while a blurry threshold is used to identify potential edges (which may be noise). Pixels in the edge response map are evaluated to determine which are sharp edges, blurry edges, or non-edges. This classification helps filter out irrelevant and unreliable pixels. Pixels close to sharp edges that contain blurry edges are converted into sharp edges, forming a more complete edge map. By utilizing connectivity, adjacent weak edges are included, enhancing the integrity and usability of the edges, especially in applications such as character recognition.
[0114] S253: Connect adjacent sharp edge pixels to form an edge chain (that is, connect sharp edge pixels with 0 intervals to form multiple edge chains).
[0115] Calculate the number of clear edge pixels for each edge chain. If the number of clear edge pixels for the edge chain is less than a preset length threshold, then the edge chain is determined to be a short edge segment (that is, it means that this is a very short edge segment, which is likely a fragment left after a break).
[0116] Obtain the starting and ending sharp edge pixels of the short chain edge segment, and calculate the gradient direction; calculate the absolute difference (i.e., absolute difference) of the gradient direction between the starting and ending sharp edge pixels. );
[0117] Set an absolute threshold; determine whether the absolute difference is greater than the absolute threshold;
[0118] If so, it is determined that the edge segment of the short chain is broken (that is, the edge direction at both ends of this short chain has changed drastically; on the edge of a normal continuous stroke, the direction should change gently; drastic changes usually occur at the break point, because the edges at both ends of the break may belong to the boundaries of different objects or be affected by different backgrounds), and all clear edge pixels in the edge segment of the short chain are taken as the initial break point.
[0119] It should be noted that connecting adjacent clear edge pixels in an image forms a continuous edge chain. Edges are usually important features in an image, and extracting edge chains helps to understand the shape and contour of an object. The length (number of pixels) of each edge chain is determined; if it is less than a preset threshold, the edge chain is considered a short edge segment. Short edge segments may be fragments caused by object breakage or interference, which are usually meaningless in shape analysis and therefore need to be removed. Identifying the start and end points of short edge segments and analyzing their gradient directions helps to further evaluate edge consistency. The gradient direction of an edge reflects its direction, and evaluating the consistency of the direction helps to determine the continuity of the edge and whether there are any problems. The difference in gradient direction between the start and end points is quantified to obtain the absolute difference Δθ.
[0120] If the gradient direction difference is extremely large, it usually indicates that there is a significant break or shape change at the edge, thus confirming the quality problem of the edge segment. The above steps compare the absolute difference Δθ with the preset absolute threshold to determine whether the short chain is likely to be broken, and retain those edge segments that are indeed broken. All clear pixels of the short chain edge segments that are determined to be broken are marked as initial breakpoints for subsequent processing.
[0121] S254: Using each initial breakpoint as the center point, form a square area according to the preset diameter (that is, form a square area with the diameter as the horizontal and vertical side lengths, instead of forming a circular area).
[0122] Calculate the grayscale variance of all pixels in the square region; preset a background variance threshold; determine whether the grayscale variance is less than the background variance threshold;
[0123] If so, the square area is determined to be a low-contrast uniform background blend (that is, to enhance the contrast between the text and the background, enhance the image, indicating that the gray-scale distribution in the area is very uniform, the contrast is extremely low, and the text and the background are almost blended into one); the square area is divided into several sub-squares and adaptive histogram equalization is applied to finally obtain the enhanced square area.
[0124] If not, the square area is determined to be a complex background or unevenly lit area (meaning that the grayscale changes within the area are large, possibly containing complex textures or uneven lighting, resulting in blurred edges); the reflection component R (the object's original color / texture) and the illumination component L of the square area are collected, and the square area is enhanced to obtain an enhanced square area (which is equivalent to "subtracting" the uneven illumination component from the original image; the result is that areas that were originally darkened by shadows are brightened, while areas that were overexposed by strong light are darkened, thus making the reflection properties of the entire area (i.e., the intrinsic contrast between the text ink and the background material) more uniform and prominent, and the text edges become clearer).
[0125] Repeat steps S252-S253 above for the enhanced square region to obtain a global edge image (i.e., edge points of higher quality and more continuous). Connect the clear edge pixels in the global edge image to obtain a closed text outline (i.e., text strokes; the arrangement of points is the result of traversing clockwise or counterclockwise along the outline boundary, forming a closed loop, such as...). Figure 6 (as shown)
[0126] It should be noted that breakpoints are selected (which could be the start or end of text or a feature point), and then square regions are formed around these points. Setting a fixed square region ensures consistent analysis of the local area and avoids the complexity introduced by improper boundary handling in circular regions. Gray-scale variance reflects the degree of brightness variation within the region. If the variance is small, it indicates that the brightness variation in the region is very uniform, effectively identifying low-contrast areas and complex background areas. A background variance threshold is set to distinguish between low-contrast and complex background areas. If the gray-scale variance is less than the threshold, it indicates that the region has a uniform background and is suitable for further processing; otherwise, it indicates that the region contains complex textures or lighting variations, requiring different processing methods.
[0127] The above steps enhance the contrast between text and background by strengthening low-contrast areas; adaptive histogram equalization improves the contrast of background areas, making the text clearer and more legible, thus enhancing the overall image readability (adaptive histogram equalization is common knowledge and will not be elaborated further); for complex backgrounds or unevenly lit areas, the reflection properties and lighting information of objects are separated. The above steps enhance the parts of the image that are occluded by shadows by extracting and adjusting the reflection components, while reducing the overexposure of areas with strong light. As a result, the edges of the text are clearer, and the details of the background are appropriately preserved; repeated processing obtains a global edge image, and multiple iterations of steps S252-S253 continuously optimize the image to obtain more stable edge information, making the text outline more obvious;
[0128] S255: Set a local window for each closed text outline and identify potential break points in the local window; identify real break points based on the direction vector of each potential break point; extract candidate paths in the closed text outline based on adjacent real break points and binarize them to obtain the text.
[0129] It should be noted that the above steps, by setting multiple local windows within the closed text outline, enhance the analysis and processing capabilities of local areas. The introduction of local windows helps to focus on specific regions, enabling the algorithm to more accurately identify and locate potential breakpoints. Local analysis reduces background noise interference, improving recognition accuracy. Identifying potential breakpoints within each local window provides candidate locations for subsequent identification of actual breakpoints. Since text often has many connected strokes or subtle breaks, predicting potential breakpoints improves the efficiency of subsequent judgments, avoiding excessive computational resources and time spent on the entire outline. Determining the actual breakpoint based on the direction vector of the potential breakpoint provides a more accurate break location; the direction vector provides the direction of the breakpoint. Information, by analyzing these directions, is used to more accurately determine which points are actual text breaks, rather than burrs or noise, ensuring that the final extracted path is meaningful. Candidate paths are extracted based on adjacent real break points, forming path contours that conform to the text's shape. The connection of adjacent real break points forms a structured representation of the text. Extracting candidate paths ensures that the final result can be further binarized in subsequent processing, improving readability. Binarizing the extracted candidate paths ultimately generates clear, easily recognizable text images. Binarization transforms the image into a black-and-white format, which is crucial for Optical Character Recognition (OCR) and subsequent computer processing, reducing computational complexity, improving recognition accuracy, and making the text stand out more.
[0130] Specifically, such as Figure 7 As shown, in step S255, a local window is set for each closed text contour, and potential break points in the local window are identified; the actual break points are identified based on the direction vector of each potential break point; candidate paths in the closed text contour are extracted based on adjacent actual break points and binarized to obtain the text. The specific operation steps are as follows:
[0131] S2551: Set a local window for each closed text outline (that is, form a window with 5 points before and after the current clear edge pixel, the first 5 points...). arrive ); the last 5 points ( arrive Curve fitting is performed using the sharp edge pixels at the current center of the local window as the local point set, and the curvature of the sharp edge pixels at the current center is calculated (curvature represents the degree of bending of the current point of the contour).
[0132] Take t clear edge pixels before and after the current center clear edge pixel (i.e. and ), calculate the chord length (i.e. between (straight-line distance) and arc length (i.e. from) Walk along the outline The total length of the polyline traversed is the sum of the number of sharp edge pixels along the contour, which is the arc length.
[0133] If the arc length is greater than the chord length, then the closed text outline at the current center's clear edge pixel position is determined to be broken (i.e., curvature represents the degree of bending; curvature). With chord length / arc length Related; Greater than This indicates that the outline is in The greater the curvature in the vicinity, the larger the absolute value of curvature; fractures or sharp corners typically have higher absolute values of curvature; the calculation method is as follows: ≈ ( - ) / );
[0134] It should be noted that the above steps obtain local information about the region by selecting neighborhood points of the current sharp edge pixel. The local window helps reduce the impact of noise and focus on shape changes within the region when processing specific edge features. The above steps obtain a curve equation representing the region by fitting the local point set. The fitted curve helps quantify the geometric properties of the current point, such as the degree of curvature. Fitting local points is to accurately calculate curvature, which can reflect the curvature characteristics of the contour at that point. The curvature of the current center sharp edge pixel is determined. The curvature value is used to effectively reflect the shape characteristics of the edge, especially where there are sharp corners or bends. The degree of curvature is closely related to the smoothness and breakage of the contour. High curvature usually indicates potential breakage or sharp corners.
[0135] Collect edge information before and after the current center point for distance calculation. By setting the points before and after the center point, a more comprehensive analysis of the local structure can be performed. Calculate the chord length and arc length. Comparing these two quantities can better understand the curve characteristics of the edge contour. If the arc length is greater than the chord length, it means that there is a significant curvature in the contour in this area, which may indicate a discontinuity in the contour. The above steps determine whether there is a break by calculating the relationship between curvature and chord and arc length. This can determine whether the position of clear edge pixels is normal and detect potential shape anomalies. An arc length greater than the chord length indicates that the edge is not smoothly connected, but has a relatively obvious change. The change usually means a break in the contour or a region close to a cusp.
[0136] S2552: Preset continuous point threshold, curvature threshold, gradient magnitude threshold;
[0137] Calculate the average curvature of the sharp edge pixels within the local window, and use it as the average curvature of the window.
[0138] Calculate the average gradient magnitude of the sharp edge pixels within the local window, and use it as the window average gradient magnitude (i.e., the curvature and gradient magnitude of the pixels have already been obtained in the previous steps, so we can directly calculate it for the pixels in the local window).
[0139] Determine whether the average curvature of the window is greater than the curvature threshold;
[0140] If so, it is determined that the closed text outline is curved at the local window position (i.e., the local window is a sequence consisting of the current point and 5 points before and after it, and the outline at the position of the sequence is likely to be sharply curved or turned); and it is further determined whether the average gradient magnitude of the window is less than the gradient magnitude threshold.
[0141] If so, then the sharp edge pixels at the center of the local window are determined to be potential breakpoints (i.e., indicating that although the contour geometry is curved, the edge strength at this point is weak, likely due to breakage or blurring causing incomplete edge detection; when the above conditions are met simultaneously, it indicates that the central region of the window may be a potential breakpoint, such as...). Figure 8 (as shown)
[0142] It should be noted that the above steps use these thresholds to effectively filter out noise and unnecessary details, focusing only on possible edge features. The continuous point threshold ensures that the detected contour is a continuous edge, while the curvature and gradient magnitude thresholds determine the prominence and curvature of the edge. These thresholds help define what constitutes a sharp edge, thus more accurately locating potential breakage areas. The average curvature of sharp edge pixels within the local window is calculated as the window average curvature, reflecting the curvature characteristics of the edge within that window. The greater the curvature, the more pronounced the edge transition. By calculating the average curvature, the changes in contour shape within the local window can be more comprehensively evaluated, identifying possible sharp angles or curved sections. The average gradient magnitude of sharp edge pixels within the local window is calculated as the window average gradient magnitude, providing a quantification of edge strength and indicating whether the edge strength within the window is sufficiently sharp. The gradient magnitude reflects the salience of the edge; a larger gradient magnitude usually indicates a sharp edge. Used in conjunction with curvature, it allows us to better understand the salience of edge features within a specific region.
[0143] The process involves determining whether the average curvature of the window is greater than the curvature threshold to confirm whether the curvature features within the current window are sufficiently significant. If so, it indicates that the window contains possible sharp angles or bending features, identifying areas with drastic contour changes that may indicate the presence of important structural features (e.g., sharp turns). If so, it determines that the closed text contour has a bend at the local window location, confirming the geometric features at that location and providing more information to help identify breakpoints. Bending points are often key parts of structural changes in the contour, and focusing on these areas can improve the accuracy of potential breakpoint identification. The process continues by determining whether the average gradient magnitude of the window is less than the gradient magnitude threshold. If the average gradient magnitude is less than the set threshold, it means that the edge strength of the area is weak, possibly due to blurring or other reasons. Even if the contour is curved, insufficient edge strength may lead to incomplete edge detection, reflecting that the point may be broken or missing. If so, the clear edge pixel at the center of the local window is identified as a potential breakpoint, determining a specific location as a possible area where image gaps or discontinuities may exist, effectively filtering out potential breakpoints.
[0144] S2553: Preset neighborhood range threshold; find each potential break point in the closed text outline;
[0145] The forward and backward directional vectors of the potential breakpoints are calculated based on the neighborhood range threshold; that is, potential breakpoints are found in the contour sequence. Calculate the forward direction vector based on the corresponding index idx. ,from Begin by moving along the outline sequence. The endpoint after each point (where s represents the distance between points), calculate the vector. = (Subtract coordinates); Calculate the backward direction vector. ,starting point From potential breakpoints Begin by moving in the opposite direction of the outline sequence. The endpoint after each point Calculate vector = [idx] - [idx-s];
[0146] The angle between the forward and backward directional vectors of the potential break point is calculated using the formula: ;
[0147] A preset angle jump threshold is set; it is then determined whether the included angle is greater than the angle jump threshold.
[0148] If so, then the potential break point is determined to be a real break point (i.e., the contours on both sides of a real break point usually undergo discontinuous and abrupt directional changes, meaning their included angle is within a specified range (within the neighborhood threshold), such as... Figure 9 As shown, that is Figure 10 The image shown is a fractured text formed by a real fracture point.
[0149] If not, then the angle change corresponding to the potential break point is determined to be a normal curvature of the closed character outline (such as a stroke corner).
[0150] It should be noted that a range threshold is set to determine the number of neighboring points to consider when searching for breakpoints. Analysis is performed within a certain local area to ensure that only relatively close contour points are considered during the analysis, avoiding the introduction of irrelevant points due to excessive distance and maintaining the focus of the analysis. Each potential breakpoint is found within the closed text contour, identifying all possible breakpoints, which may be points of inflection or interruption on the contour. The forward and backward directions around the potential breakpoints are calculated to analyze the contour's directional characteristics at that point. Breakpoints are often accompanied by abrupt changes in direction, so it is necessary to compare the contour directions around the breakpoint to capture this change. The forward direction vector (vforward) is calculated to determine the target point after moving s points along the contour from the potential breakpoint, and the vector difference between them is calculated. The forward direction vector provides directional information at that point, reflecting the trend of the contour in this direction. Similarly, the vector difference is calculated s points backward from the potential breakpoint to obtain the backward direction vector. The backward direction vector effectively captures the directional changes of the contour before the potential breakpoint and can be compared with the forward direction.
[0151] By calculating the angle between two vectors, it is determined whether there are significant differences in the trends on both sides; if the angle is large, it indicates that there is an obvious trend change at this point, which is usually a characteristic of a break point; a preset angle jump threshold is set, and only when the angle change exceeds a certain threshold can it be considered that there may be a break, which can reduce misjudgments; it is determined whether this potential break point can be recognized as a real break point, and significant direction changes (possibly break points) are distinguished from normal contour changes (such as corners); it is determined that this potential break point is a real break point / normal bend, and only real break points are extracted to reduce errors, and clear judgment criteria are defined, thereby improving the accuracy of applications such as character recognition or image processing;
[0152] S2554: Sort all real break points according to their coordinate positions, and extract candidate paths in the closed text contour based on adjacent real break points (that is, for example, adjacent in the sorting of real break points are ( , ), but in the closed text contour, there are many clear edge pixel points between adjacent real break points ( , }), and extract the adjacent real break points and the sequence of clear edge pixel points in the middle as candidate paths);
[0153] Calculate the Euclidean distance between adjacent clear edge pixel points in each candidate path and connect them to obtain the total length as the arc length (that is, it reflects the length of the broken line, which is the same as the calculation of the arc length in the above steps);
[0154] Perform binary masking on the candidate path, and calculate the shortest distance from each foreground pixel point in the mask to the background pixel point (that is, all points of the candidate path);
[0155] Skeletonize the candidate path of the binary mask to obtain the central path line (that is, the candidate path);
[0156] Take the shortest distance of the central path line as half of the stroke width (that is, 1 / 2), and average the half of the stroke width on all central path lines and multiply by 2 to obtain the average stroke width;
[0157] Calculate the diameter distance of the central path line (that is, the straight-line distance between the two endpoints); use the arc length and the diameter distance for calculation to obtain the straightness (that is, The closer it is to 1, the straighter the path (such as the character '一'); The smaller it is, the more curved the path (such as the stroke of the character '弯'));
[0158] Preset the minimum stroke length, reasonable stroke width range, and minimum straightness;
[0159] If the diameter distance is greater than the minimum stroke length, the average stroke width is within the reasonable stroke width range, and the straightness is greater than the minimum straightness, then the candidate path is determined to be a text stroke.
[0160] It should be noted that the above steps sort the coordinates of the real break points to form an ordered sequence, providing a foundation for subsequent path extraction. The sorted break points help to understand the structure and direction of the text outline, ensuring a smooth transition from one point to the next when processing the path, avoiding path recognition errors caused by disordered point order. The above steps generate possible text paths by extracting adjacent real break points and the clear edge pixels between them, connecting the break points with clear edges to ensure the path is visually coherent. To ensure the continuity and integrity of the path, visual information for filling is sought between the real break points. The total length of the path is obtained by summing the Euclidean distances between adjacent clear edge pixels, which helps to evaluate the shape and complexity of the path. Calculating the arc length can reflect the actual length of the stroke, which is crucial for the subsequent calculation of the stroke width to diameter ratio.
[0161] A binary mask is created to analyze pixels within the path and calculate the shortest distance from foreground to background pixels. The binary mask highlights potential path features and helps determine stroke width and density, thus affecting the final character recognition. The skeletonization process obtains the path's centerline, extracting the main structure while ignoring details. The centerline simplifies and summarizes stroke shapes, aiding in more accurate calculation of stroke width and path characteristics. The shortest distance of the centerline is taken as half the stroke width to calculate the average stroke width across all paths. Stroke width is a crucial indicator for determining character features, recognition ability, and clarity. The diameter of the stroke is obtained by calculating the straight-line distance between the endpoints of the centerline, allowing comparison with arc length to evaluate the overall shape. The ratio of arc length to diameter distance yields a straightness index, Sk, reflecting the path's straightness. By comparing this with preset minimum stroke length, reasonable stroke width range, and straightness, the effectiveness of the path is confirmed, ensuring the extracted path meets standardized requirements for writing features, facilitating more accurate character recognition and analysis.
[0162] S2555: Calculate the Euclidean distance between the endpoints of each character stroke;
[0163] Preset the maximum allowed connection distance; determine whether the Euclidean distance between the endpoints of the character strokes is less than the maximum allowed connection distance (i.e., determine whether they can be connected to form characters);
[0164] If so, calculate the direction vectors of the two endpoints of the character stroke (i.e., organic acids in the above steps, which will not be repeated here), and continue to calculate the included angle;
[0165] If the included angle is less than the preset included angle threshold, then the adjacent character strokes are connected (that is, the directions are consistent) to form characters;
[0166] It should be noted that the purpose of this step is to quantify the physical distance between two stroke endpoints. By using Euclidean distance, the geometric relationship between the two stroke endpoints is accurately determined, especially their proximity. In the fields of character recognition and image processing, understanding the spatial relationships between different elements is crucial, especially in scenarios involving automatic splicing or recognizing drawn characters. Setting a threshold limits the maximum acceptable distance between strokes, thereby determining whether a connection is allowed. Different fonts and characters have different structures and features. Setting a reasonable connection distance can prevent unrelated strokes from being mistakenly connected, ensuring that the generated characters are reasonable and accurate. Determining whether the Euclidean distance between the stroke endpoints is less than the maximum allowed connection distance applies to the previous two steps, determining whether the two stroke endpoints meet the connection conditions. Only when the corresponding conditions are met can the next step be calculated, ensuring that the subsequent connection process is based on a solid distance judgment.
[0167] Calculating the direction vectors of the two endpoints of a character's strokes—that is, determining the direction vectors through the two endpoints—helps understand the direction of stroke extension. This directional information is crucial for subsequently judging the relative positions of strokes and the rationality of merging, ensuring that the connected strokes present a natural appearance that conforms to structural rules. Calculating the angle between the direction vectors of two adjacent strokes is used to determine whether their connection is reasonable. This step effectively assesses the compatibility between strokes after considering direction, preventing misaligned stroke connections. The above steps compare the angle vectors with a preset threshold to determine whether two strokes can form a unified whole in the direction, helping to ensure smooth stroke connections. Adjusting the threshold controls the flexibility of connections, optimizes the overall character structure, and ensures character recognition and visual effects. Finally, if all previous conditions are met, the connection operation is performed to form a complete character structure. Connecting reasonable strokes not only improves recognition accuracy but also enhances the aesthetics and logic of manually or automatically generated characters.
[0168] Example 2
[0169] like Figure 11 As shown, the present invention also provides an image recognition-based system for verifying and detecting abnormal business premises, comprising: a data acquisition module 10; an analysis module 20; and an identification module 30.
[0170] The acquisition module 10 is used to acquire the storefront image of the target business location, obtain the image data of the advertising slogan, and preprocess the image data of the advertising slogan to obtain the image to be detected;
[0171] The analysis module 20 is used to divide the image to be detected into a grayscale uniform grid to form a sub-image region, identify effective seed points of pixel grayscale values and gradients in the sub-image region, grow the effective seed points to form a preliminary text candidate region, identify the gradient direction of the preliminary text candidate region to obtain the text path, and identify clear edge pixels of the text path to form text.
[0172] The identification module 30 is used to acquire a historical text advertising slogan database; compare the text with the historical text advertising slogan database, and identify whether there are any abnormalities in the text of the target business location.
[0173] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; those skilled in the art can modify the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for detecting and verifying abnormal business premises based on image recognition, characterized in that, The following steps are included: Collect images of the storefront of the target business location, obtain image data of the advertising slogan, preprocess the image data of the advertising slogan, and obtain the image to be detected; The image to be detected is divided into grayscale and uniform grids to form sub-image regions. Effective seed points are identified in each sub-image region based on pixel grayscale values and gradients. These effective seed points are then grown to form preliminary text candidate regions. Gradient directions are identified in the preliminary text candidate regions to obtain text paths. Clear edge pixels are identified in the text paths to form text. Obtain a historical text advertising slogan database; compare the text with the historical text advertising slogan database to identify whether there are any anomalies in the text of the target business location.
2. The method for detecting and verifying abnormal business premises based on image recognition according to claim 1, characterized in that, The initial text candidate region is subjected to gradient direction recognition to obtain the text path; the text path is then used to identify clear edge pixels to form the text. The specific operation steps are as follows: The image to be detected is converted to grayscale to obtain a grayscale image to be detected; the grayscale image to be detected is divided into a uniform grid, and a neighborhood window is preset; the neighborhood window is cropped with the intersection point between adjacent grids as the center, as a sub-image region; the local grayscale value standard deviation of all pixels in each sub-image region is calculated; the local gradient magnitude mean of pixels in each sub-image region is calculated; the global grayscale value standard deviation and the global gradient magnitude mean of all pixels in the grayscale image to be detected are calculated. If the standard deviation of the local gray value in the local features of the sub-image region is greater than the standard deviation of the global gray value and the mean of the local gradient magnitude is greater than the mean of the global gradient magnitude, then the intersection grid point corresponding to the sub-image region is determined as a valid seed point. For each valid seed point, calculate the absolute value of the grayscale difference between it and its neighboring pixels; Preset dynamic threshold; Determine whether the absolute value of the grayscale difference is less than a dynamic threshold; If so, the effective seed point is determined to grow the pixels in the neighborhood to obtain a connected region; the minimum and maximum values of the x-axis and y-axis are determined for the pixels in each connected region to construct an axially aligned rectangle; the number of pixels in the axially aligned rectangle is calculated as the area of the rectangle. Simultaneously calculate the width and height of the axially aligned rectangle; calculate the aspect ratio using the width and height of the axially aligned rectangle; calculate the density using the number of pixels in the axially aligned rectangle and the area of the rectangle; set an area threshold, a normal aspect ratio threshold, and a density threshold; determine whether the area of the rectangle is greater than the area threshold. If so, then continue to determine whether the aspect ratio is equal to the normal aspect ratio threshold; If so, then continue to determine whether the density is greater than the density threshold; If so, the axially aligned rectangle is determined to be a preliminary text candidate area.
3. The method for detecting and verifying abnormal business premises based on image recognition according to claim 2, characterized in that, Gradient direction recognition is performed on the preliminary text candidate regions to obtain the text path. The specific operation steps are as follows: Calculate the square root of the area of the preliminary text candidate region based on the area of the rectangle; preset the search step size; starting from the upper left corner inside the axially aligned rectangle, generate sub-grid points in the x-axis and z-axis directions at intervals of the search step size; A sliding window is applied to each sub-grid point. The gradient direction of the internal pixels of each sliding window is calculated, and the average gradient direction of all pixel gradient directions is calculated as the dominant direction. A preset angle tolerance threshold is used to form a direction angle range using the dominant direction and the angle tolerance threshold. The number of pixels whose gradient direction falls within the direction angle range is then selected. The directional consistency ratio is calculated by comparing the number of pixels with all pixels within the sliding window. All subgrid points are sorted in descending order according to the directional consistency ratio. The top k subgrid points are selected as dynamic path planning nodes, and the dynamic path planning node with the largest directional consistency ratio is selected as the path starting node. A preset cost function is used; the dynamic path planning node with the smallest cost function is selected, and the Euclidean distance between the smallest dynamic path planning node and the axially aligned rectangle is calculated. Preset distance to target threshold; Determine whether the Euclidean distance is greater than or equal to the target threshold; If so, then the exploration of the smallest dynamic path planning node is considered successful; If not, then the smallest dynamic path planning node will be discarded. The neighboring dynamic path planning nodes of the smallest dynamic path planning node are selected as candidate nodes; if the candidate node is an abandoned node or the Euclidean distance between the candidate node and the axially aligned rectangle is less than the distance target threshold, then the candidate node is skipped. Calculate the actual cost of the path formed by the starting node of the path reaching the candidate node through the smallest dynamic path planning node; If the actual cost of the path is less than the actual cost of the candidate node, then the candidate node of the path is determined as a new path node. The above steps are repeated until all dynamic path planning nodes have been screened and the path terminal node is obtained. The path starting node and the path terminal node are connected to form a text path.
4. The method for verifying and detecting abnormal business premises based on image recognition according to claim 3, characterized in that, The initial text candidate region is subjected to gradient direction recognition to obtain the text path; the text path is then used to identify clear edge pixels to form the text. The specific operation steps are as follows: The text pixel region is identified based on the gradient of the pixels in the text path; clear edge pixels are identified based on the gradient values of the pixels in the text pixel region; the clear edge pixels are connected to form an edge chain, the length of the edge chain is calculated, short chain edge segments are identified as breaks, and the clear edge pixels of the short chain edge segments are set as initial breakpoints; a square region is formed with each initial breakpoint as the center point and a preset diameter is used to enhance it, forming a global edge image; the clear edge pixels in all global edge images are connected to obtain a closed text outline; the closed text outline is then used to identify the text.
5. The method for verifying and detecting abnormal business premises based on image recognition according to claim 4, characterized in that, The text pixel region is identified based on the gradient of pixels in the text path. The specific operation steps are as follows: Calculate the distance between the terminal nodes of all text paths; cluster all path terminal nodes whose distance is less than a preset clustering threshold to obtain terminal node clusters. Calculate the geometric centroid of each terminal node cluster; Calculate the average gradient magnitude of the pixels along each text path; Preset gradient magnitude average threshold and cluster distance threshold; Determine whether the average gradient magnitude of the path is greater than the average gradient magnitude threshold. If so, calculate the centroid distance between the starting node of the path and the geometric centroid; determine whether the centroid distance is less than the cluster distance threshold; If so, determine the high-quality text path corresponding to the path terminal node of the terminal node cluster; cluster all pixels on the high-quality paths and perform a binary mask to obtain the text pixel region.
6. The method for detecting and verifying abnormal business premises based on image recognition according to claim 5, characterized in that, The gradient values of pixels in the text pixel region are used to identify pixels with clear edges. The specific operation steps are as follows: Calculate the gradient value of each pixel in the text pixel region of the binary mask, and use the gradient value to calculate the gradient magnitude and gradient direction of the pixel to construct a gradient magnitude map and a gradient direction map; Each pixel in the gradient magnitude map is quantized in four directions according to the gradient direction; the gradient magnitude of the pixel is compared with the gradient magnitude of the diagonal neighboring pixels in the gradient direction of the neighboring pixels, and the pixel with the largest gradient magnitude is retained to finally obtain the edge response map; Preset sharpness threshold and blur threshold; determine the gradient magnitude of the pixels in the edge response map with the sharpness threshold and blur threshold; If the gradient magnitude of a pixel in the edge response map is greater than or equal to the sharpness threshold, then the pixel is determined to be a sharp edge pixel. If the gradient magnitude of a pixel in the edge response map is greater than or equal to the blur threshold and less than the sharp threshold, then the pixel is determined to be a blurry edge pixel. If the gradient magnitude of a pixel in the edge response map is less than the blur threshold, then the pixel is determined to be a non-edge point. If a blurred edge pixel exists in the neighborhood of each sharp edge pixel, then the blurred edge pixel is taken as a sharp edge pixel.
7. The method for detecting and verifying abnormal business premises based on image recognition according to claim 6, characterized in that, The sharp edge pixels are connected to form an edge chain. The length of the edge chain is calculated, and short chain edge segments are identified as breaks. The sharp edge pixels of the short chain edge segments are set as initial breakpoints. With each initial breakpoint as the center point, a square region is formed according to a preset diameter for enhancement to form a global edge image. The sharp edge pixels in all global edge images are connected to obtain a closed text outline. The specific operation steps are as follows: Connect adjacent sharp edge pixels to form an edge chain; calculate the number of sharp edge pixels in each edge chain; if the number of sharp edge pixels in the edge chain is less than a preset length threshold, the edge chain is determined to be a short chain edge segment; obtain the starting and ending sharp edge pixels of the short chain edge segment and calculate the gradient direction; calculate the absolute difference of the gradient direction between the starting and ending sharp edge pixels; preset an absolute threshold; determine whether the absolute difference is greater than the absolute threshold; If so, it is determined that the edge segment of the short chain is broken, and all clear edge pixels in the edge segment of the short chain are used as the initial breakpoints; Using each initial breakpoint as the center point, form a square region with a preset diameter; calculate the grayscale variance of all pixels in the square region; A preset background variance threshold is established; it is then determined whether the grayscale variance is less than the background variance threshold. If so, the square area is determined to be a low-contrast uniform background blend; the square area is divided into several sub-squares and adaptive histogram equalization is applied to finally obtain the enhanced square area. If not, the square area is determined to be a complex background or unevenly lit area; the reflection component R and illumination component L of the square area are collected and the square area is enhanced to obtain an enhanced square area; the above steps are repeated for the enhanced square area to obtain a global edge image; the clear edge pixels in the global edge image are connected to obtain a closed text outline.
8. The method for detecting and verifying abnormal business premises based on image recognition according to claim 7, characterized in that, The specific steps for recognizing characters from the closed character outline are as follows: For each closed text outline, a local window is set, and potential break points in the local window are identified; the actual break points are identified based on the direction vector of each potential break point; candidate paths in the closed text outline are extracted based on adjacent actual break points and binarized to obtain the text.
9. The method for verifying and detecting abnormal business premises based on image recognition according to claim 8, characterized in that, For each closed text outline, a local window is set, and potential breakpoints within the local window are identified. The specific steps are as follows: Set a local window for each closed text outline; use the sharp edge pixel at the current center of the local window as the local point set to perform curve fitting and calculate the curvature of the sharp edge pixel at the current center. Take t clear edge pixels before and after the current center clear edge pixel, and calculate the chord length and arc length; If the arc length is greater than the chord length, it is determined that the closed text outline at the current center clear edge pixel position is broken; Preset thresholds for consecutive points, curvature, and gradient magnitude; Calculate the average curvature of the sharp edge pixels within the local window, and use it as the average curvature of the window. Calculate the average gradient magnitude of the clear edge pixels within the local window as the average gradient magnitude of the window; determine whether the average curvature of the window is greater than the curvature threshold; if so, determine that the closed text outline is curved at the local window position; and continue to determine whether the average gradient magnitude of the window is less than the gradient magnitude threshold. If so, then the clear edge pixel at the center of the local window is determined to be a potential break point.
10. The method for detecting and verifying abnormal business premises based on image recognition according to claim 9, characterized in that, The actual break points are identified based on the direction vector of each potential break point; candidate paths in the closed text contour are extracted from adjacent actual break points and binarized to obtain the text. The specific operation steps are as follows: A preset neighborhood range threshold is set; each potential break point is found in the closed text outline; the forward and backward directional vectors of the potential break points are calculated based on the neighborhood range threshold; the included angle is calculated using the forward and backward directional vectors of the potential break points. A preset angle jump threshold is set; it is determined whether the included angle is greater than the angle jump threshold; if not, it is determined that the angle change corresponding to the potential break point is a normal curvature of the closed text outline. If so, the potential break point is determined to be a real break point; all real break points are sorted according to their coordinate positions, and candidate paths in the closed text outline are extracted based on adjacent real break points; the Euclidean distance between adjacent clear edge pixels in each candidate path is calculated and connected to obtain the total length, which is taken as the arc length; the candidate paths are subjected to a binary mask, and the shortest distance from each foreground pixel to the background pixel within the mask is calculated; the candidate paths in the binary mask are skeletonized to obtain the center path line; the shortest distance of the center path line is taken as half the stroke width, and the average of the half the stroke widths on all center path lines is multiplied by 2 to obtain the average stroke width. Calculate the diameter distance of the center path line; calculate the straightness using the arc length and diameter distance; preset the minimum stroke length, reasonable stroke width range, and minimum straightness; If the diameter distance is greater than the minimum stroke length, the average stroke width is within the reasonable stroke width range, and the straightness is greater than the minimum straightness, then the candidate path is determined to be a character stroke; calculate the Euclidean distance between the endpoints of each character stroke; Preset the maximum allowed connection distance; determine if the Euclidean distance between the endpoints of character strokes is less than the maximum allowed connection distance; If so, the direction vectors of the two endpoints of the character strokes are calculated, and the included angle is calculated. If the included angle is less than a preset included angle threshold, the adjacent character strokes are connected to form a character.