Postal code positioning method and device and electronic equipment
By obtaining the first line segment and its normal vector in the postal code image, obtaining the line segment cluster along the normal vector direction, determining the positioning area of the postal code, solving the problem of inaccurate postal code positioning and achieving high-precision postal code positioning.
Patent Information
- Application Number
- CN202411798450.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-03-18
AI Technical Summary
How to accurately locate the position of postal codes in the image and solve the problem of inaccurate positioning in the prior art.
By traversing the postal code image, the first line segment is obtained, and its first normal vector and its second normal vector are determined. The first and second line segment clusters are acquired along the normal direction of the first normal vector and the second normal vector, and the positioning area of the postal code is determined based on these clusters.
It realizes accurate positioning of postal codes, has good positioning accuracy, and can accurately locate postal codes under low precision and complex backgrounds.
Smart Images

Figure CN119647496A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technology, and in particular to a method, device and electronic equipment for locating a postal code. Background Art
[0002] Postal codes are a type of barcode that has been widely used in recent years. They are mostly used in logistics companies or postal companies. They are developed to store information including sender, delivery address and postal number. Postal codes are mostly printed on paper. They can be printed in dark colors on light backgrounds or in light colors on dark backgrounds, as long as there is enough contrast to ensure readability.
[0003] The premise of identifying the postal code is to accurately locate the location of the postal code. Therefore, how to accurately locate the postal code has become a problem that needs to be solved urgently. Summary of the invention
[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a postal code positioning method, device and electronic device.
[0005] In a first aspect, an embodiment of the present disclosure provides a method for locating a postal code, comprising:
[0006] Traverse the postal code image and obtain the first line segment;
[0007] Obtain a first normal vector and a second normal vector of the first line segment, where the first normal vector and the second normal vector are in opposite directions;
[0008] Acquire a first line segment cluster along a first normal direction of the first normal vector;
[0009] Acquire a second line segment cluster along a second normal direction of the second normal vector;
[0010] A location area of a postal code is determined based on the first cluster of line segments and the second cluster of line segments.
[0011] In a second aspect, an embodiment of the present disclosure provides a postal code positioning device, comprising:
[0012] A first acquisition module, used for traversing the postal code image to acquire a first line segment;
[0013] A second acquisition module, used to acquire a first normal vector and a second normal vector of the first line segment, where the first normal vector and the second normal vector are in opposite directions;
[0014] A third acquisition module, configured to acquire a first line segment cluster along a first normal direction of the first normal vector, and acquire a second line segment cluster along a second normal direction of the second normal vector;
[0015] A positioning module, configured to determine a positioning area of a postal code based on the first line segment cluster and the second line segment cluster
[0016] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising: a processor; a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the executable instructions to implement the postal code positioning method as described in the first aspect.
[0017] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is used to implement the postal code positioning method as described in the first aspect.
[0018] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has the following advantages:
[0019] The postal code positioning solution provided by the embodiment of the present disclosure traverses the postal code image, obtains the first line segment, obtains the first normal vector and the second normal vector of the first line segment, the first normal vector and the second normal vector are in opposite directions, obtains the first line segment cluster along the first normal direction of the first normal vector, and obtains the second line segment cluster along the second normal direction of the second normal vector, and then determines the positioning area of the postal code based on the first line segment cluster and the second line segment cluster. The solution of the present disclosure is adopted, by first determining the first line segment, then determining the line segment clusters at both ends of the first line segment, and then determining the positioning area of the postal code based on the line segment cluster, thereby achieving accurate positioning of the postal code with good positioning accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.
[0021] Figure 1 A schematic diagram of a flow chart of a method for locating a postal code provided by an exemplary embodiment of the present disclosure;
[0022] Figure 2 A schematic diagram showing a plurality of starting points selected on a first line segment according to an exemplary embodiment of the present disclosure is shown;
[0023] Figure 3 A schematic diagram showing a method of acquiring a second line segment from a first line segment according to an exemplary embodiment of the present disclosure is shown;
[0024] Figure 4 A schematic diagram showing a combined positioning area of a first line segment cluster and a second line segment cluster according to an exemplary embodiment of the present disclosure is shown;
[0025] Figure 5 A schematic diagram of the structure of a postal code positioning device provided in one embodiment of the present disclosure. DETAILED DESCRIPTION
[0026] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0027] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0028] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0029] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0030] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0031] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0032] The postal code positioning method, device and electronic device provided by the present invention are explained in detail below with reference to the accompanying drawings.
[0033] Figure 1A flowchart of a postal code positioning method provided for an exemplary embodiment of the present disclosure is provided. The method can be performed by a postal code positioning device provided for an embodiment of the present disclosure. The device can be implemented by software and / or hardware and can be integrated in an electronic device. The electronic device can be a device for scanning postal codes.
[0034] like Figure 1 As shown, the postal code positioning method may include the following steps:
[0035] Step 101, traverse the postal code image to obtain the first line segment.
[0036] The postal code image contains one or more postal codes.
[0037] In this embodiment, the acquired postal code image may be traversed to determine the first line segment.
[0038] In an optional implementation of the present disclosure, when determining the first line segment, it is possible to start from the center position of the postal code image and traverse to both ends of the postal code image to determine multiple boundary points. For example, a grayscale scan line can be drawn from the center position to both ends, and several boundary points can be determined by waveforms of black to white or white to black until the entire image is scanned. Then, each of the multiple boundary points can be used as a starting point for boundary tracking to obtain a line segment cluster (referred to as a target line segment cluster for ease of description and distinction); wherein, a currently commonly used boundary tracking algorithm can be used to perform boundary tracking starting from the boundary point to obtain a target line segment cluster. In this embodiment, the target line segment cluster is non-broken, and the line segments in the target line segment cluster can save boundary attributes (black to white or white to black), line segment area and other information for subsequent line segment searches, and the line segment area can reflect the width and length of the line segment. Finally, the first line segment is determined from the target line segment cluster.
[0039] As an example, a line segment may be randomly selected from the target line segment cluster as the first line segment.
[0040] As another example, candidate line segments that meet the conditions can be screened out from the target line segment cluster, and then a line segment can be randomly selected from the candidate line segments as the first line segment. The first line segment satisfies the following conditions at the same time: (1) the straightness meets the preset straightness requirement; (2) the line segment width is less than the first line width threshold; (3) the line segment length is less than the first line length threshold. The first line width threshold and the first line length threshold can be preset according to actual needs and experience.
[0041] It can be understood that straightness can be quantified by different parameters. For example, the straightness of the line segment in the target line segment cluster can be represented by the angle during boundary tracking. Accordingly, the straightness requirement is that the angle of the line segment is less than a preset angle threshold. Thus, when the angle of a line segment is less than the angle threshold, it can be determined that the line segment has a good straight line segment and meets the straightness requirement. For another example, when the line segment is obtained by fitting the points based on tracking, the straightness can be represented by the percentage of the number of points on the line segment to the total number of points tracked. Accordingly, the straightness requirement is that the percentage is greater than a preset ratio threshold. Thus, when the percentage of the number of points on a line segment divided by the total number of points tracked is greater than the ratio threshold, it can be determined that the line segment has a good straight line segment and meets the straightness requirement.
[0042] Step 102 : Obtain a first normal vector and a second normal vector of the first line segment, wherein directions of the first normal vector and the second normal vector are opposite.
[0043] In this embodiment, after determining the first line segment, two normal vectors of the first line segment can be further determined, which are respectively recorded as the first normal vector and the second normal vector, and the directions of the two normal vectors are opposite. That is, the first normal vector and the second normal vector are both perpendicular to the first line segment, and the angle between the first normal vector and the second normal vector is 180 degrees. Among them, the direction corresponding to the first normal vector is called the first normal direction, and the direction corresponding to the second normal vector is called the second normal direction.
[0044] Step 103: Acquire a first line segment cluster along a first normal direction of a first normal vector.
[0045] Step 104: Acquire a second line segment cluster along a second normal direction of a second normal vector.
[0046] In this embodiment, the first line segment cluster and the second line segment cluster are obtained in the same manner, except that the directions are different. The following describes in detail the specific process of obtaining the first line segment cluster along the first normal direction of the first normal vector by taking the first line segment cluster as an example, which specifically includes the following steps:
[0047] S1. Initialize the first search distance.
[0048] Among them, the initial first search distance is related to the maximum resolution of the postal code that needs to be supported. When the first search distance is initialized, the initial value of the first search distance can be determined according to the resolution of the postal code image. The initialized first search distance is positively correlated with the resolution of the postal code image. The larger the resolution, the larger the initial value of the first search distance. For example, the corresponding relationship between different resolutions and the first search distance can be preset, for example, when the resolution is 640*480, the corresponding first search distance is 20 pixels, when the resolution is 960*540, the corresponding first search distance is 30 pixels, and so on. Therefore, when the first search distance is initialized, according to the resolution of the postal code image, by querying the corresponding relationship between different resolutions and the first search distance, the corresponding initial value of the first search distance is determined.
[0049] S2. Determine multiple starting points on the first line segment.
[0050] For example, a plurality of starting points may be determined on the first line segment at preset intervals.
[0051] The determined multiple starting points should include a point close to the center of the first line segment and points close to both ends of the first line segment.
[0052] For example, Figure 2 FIG. 2 shows a schematic diagram of selecting multiple starting points on a first line segment according to an exemplary embodiment of the present disclosure. Figure 2 As shown, the first normal direction and the second normal direction of the first line segment are both perpendicular to the first line segment, and the included angle is 180 degrees. Three starting points are selected from the first line segment, namely the first starting point, the second starting point and the third starting point. The second starting point is located near the midpoint of the first line segment, and the first starting point and the third starting point are located at both ends of the first line segment.
[0053] S3. Starting from each starting point, search for the second line segment within the first search distance according to the first normal direction.
[0054] In this embodiment, for multiple starting points that are determined, a line segment search can be performed within the first search distance according to the first normal direction starting from each starting point, and the second line segment can be tried. For a starting point, if multiple line segments are searched within the first search distance, a line segment closest to the first line segment is selected as the line segment searched based on the starting point. In other words, starting from a starting point, at most only one line segment can be searched, so if there are several starting points, then after traversing all the starting points, the maximum corresponding number of line segments can be found, for example, if there are three starting points, at most three line segments can be found. When multiple line segments are obtained from multiple starting points, a line segment is determined from the multiple line segments as the second line segment searched, and then a line segment is determined from the multiple line segments as the second line segment searched.
[0055] As an example, when multiple line segments are found, one line segment may be randomly selected from the multiple line segments as the second line segment.
[0056] As another example, when multiple line segments are found, a line segment that satisfies at least one of the following conditions may be selected from the multiple line segments as the searched second line segment:
[0057] (1) The second line segment is a line segment having the shortest distance from the first line segment among the multiple line segments;
[0058] (2) The angle between the second line segment and the first line segment is less than the angle threshold, that is, the second line segment is parallel or approximately parallel to the first line segment; in addition, for the parallel judgment condition between the first line segment and the second line segment, it is also possible to consider performing straight line fitting on the point set of the second line segment boundary tracking, and judging the parallelism between the fitted straight line and the starting line (that is, the current first line segment), and the line segment whose angle exceeds the angle threshold will not be determined as the second line segment;
[0059] (3) The difference between the line width of the second line segment (hereinafter referred to as line width) and the line width of the first line segment is less than a preset value, that is, the line widths of the second line segment are equal to or approximately equal to those of the first line segment;
[0060] (4) The line segment length of the second line segment (referred to as line length) is greater than the first length threshold and less than the second length threshold, wherein the second length threshold is greater than the first length threshold.
[0061] The above conditions (1) to (4) satisfied by the second line segment are set based on the characteristics that adjacent bars of the postal code are approximately parallel, the widths of adjacent bars are approximately equal, and the mapping of adjacent bars in the normal direction has overlapping areas.
[0062] Figure 3 FIG. 1 shows a schematic diagram of obtaining a second line segment from a first line segment according to an exemplary embodiment of the present disclosure. Figure 3 As shown, the starting points determined on the first line segment are the first starting point, the second starting point and the third starting point, and the search is performed along the first normal direction. The boundaries of the line segment are searched from the first starting point and the second starting point, wherein boundary one is searched from the first starting point, and boundary two is searched from the second starting point. These two boundaries belong to the same line segment, and no line segment is searched from the third starting point. Therefore, a total of one line segment is searched, which is the second line segment.
[0063] It is understandable that in order to reduce the amount of calculation when searching for the second line segment, the search can be performed in the target line segment cluster determined in the above embodiment. In addition, it should be noted that when there is more than one line segment that meets the same condition among the multiple line segments, the line segment that meets the most conditions can be selected as the searched second line segment.
[0064] S4, if the second line segment is found, calculate the distance between the first line segment and the second line segment as the updated first search distance, use the second line segment as the first line segment, obtain the first normal direction of the first line segment, and jump to S2;
[0065] In this embodiment, if the second line segment is successfully searched, the distance between the first line segment and the second line segment is calculated as the updated first search distance, wherein the initialized first search distance is greater than the updated first search distance, the searched second line segment is used as the new first line segment, and the first normal direction of the first line segment is obtained, and then the process is adjusted to step S2 for a new round of search, multiple starting points are re-determined, and a new second line segment is searched within the updated first search distance according to the newly determined first normal direction, and the above process is repeated. If the search for the second line segment fails, the process is terminated and step S5 is executed.
[0066] S5. If the second line segment is not found, the search for the first line segment cluster is completed.
[0067] In this embodiment, if the search for the second line segment fails, the search is completed and the first line segment cluster is obtained.
[0068] When determining the second line segment cluster, searches are performed respectively from a plurality of starting points according to the second normal direction. The search process is similar to the process of determining the first line segment cluster, and will not be described in detail here.
[0069] It should be noted that, in this embodiment, the execution order of step 103 and step 104 is not particular, and the two can be executed sequentially or simultaneously. Figure 1 The illustrated embodiment only takes step 104 being executed after step 103 as an example to explain the present disclosure, and is not intended to limit the present disclosure.
[0070] In this embodiment, when searching for the second line segment, full use is made of the characteristics of the postal code that adjacent bars are approximately parallel, the line widths of adjacent bars are approximately equal, and the mapping of adjacent bars in the normal direction has overlapping areas, thereby effectively realizing the precise positioning of the postal code, having good positioning accuracy, and having good support for low-precision and complex background code images, having good effects, and being able to accurately locate the position of the postal code in the presence of large interference.
[0071] Step 105: determine the location area of the postal code based on the first line segment cluster and the second line segment cluster.
[0072] In this embodiment, after the corresponding line segment cluster is determined along the first normal direction and the second normal direction of the first line segment, the postal code can be located based on the determined line segment cluster to locate the area where the postal code is located.
[0073] In an optional embodiment of the present disclosure, when locating the postal code based on the line segment cluster obtained by the search, the line segments at the outermost boundary of the first line segment cluster and the second line segment cluster can be determined according to the search direction of the first line segment cluster and the search direction of the second line segment cluster, and then a rectangle is calculated according to the endpoints of the two determined line segments, and the rectangular area is the positioning area of the postal code. For example, if the first normal direction is from the first line segment to the left, and the second normal direction is from the first line segment to the right, then the leftmost line segment in the first line segment cluster is determined, and the rightmost line segment in the second line segment cluster is determined, and then the positioning area of the postal code is determined based on these two line segments. It can be understood that the positioning area of the postal code includes both the line segments in the first line segment cluster and the second line segment cluster, as well as the first line segment.
[0074] In an optional embodiment of the present disclosure, when locating the postal code based on the line segment cluster obtained by the search, the first line segment cluster and the second line segment cluster can be merged to obtain a merged line segment cluster, and then the minimum circumscribed quadrilateral of the merged line segment cluster is calculated as the positioning area of the postal code. The minimum circumscribed quadrilateral is calculated as follows: the edges with the same direction as the postal code diagram use the upper and lower endpoints of the segments in the merged line segment cluster to perform single-line or double-line fitting, and the remaining two edges use the first line segment in the merged line segment cluster and the extension of the last line segment, which intersect with the fitted straight line to form the positioning area of the minimum circumscribed quadrilateral. Whether to use single-line or double-line fitting depends on the type of postal code. If the postal code is aligned up and down, single-line fitting can be used. If the postal code is not aligned up and down, double-line fitting is required.
[0075] Figure 4 A schematic diagram showing a first line segment cluster and a second line segment cluster combined positioning area according to an exemplary embodiment of the present disclosure is shown as follows Figure 4 As shown, after merging the first line segment cluster and the second line segment cluster to obtain a merged line segment cluster, the side in the same direction as the postal code diagram (i.e., the side in the horizontal direction) is obtained by performing double straight line fitting according to the upper and lower endpoints of the line segments in the merged line segment cluster, the top side of the quadrilateral is obtained by fitting the straight line through the upper endpoint, and the bottom side of the quadrilateral is obtained by fitting the straight line through the lower endpoint. The line segment obtained by the intersection of the extended line of the leftmost line segment in the merged line segment cluster (i.e., the starting line of the parallel line cluster) and the two fitted straight lines is the left side of the quadrilateral, and the line segment obtained by the extension line of the rightmost line segment in the merged line segment cluster (i.e., the ending line of the parallel line cluster) and the two fitted straight lines is the right side of the quadrilateral, thereby obtaining the positioning area of the postal code, as shown in FIG. Figure 4 The area enclosed by the dotted line is shown in FIG.
[0076] In an optional implementation of the present disclosure, after the postal code positioning area is determined, the obtained area can be marked as a postal code positioning area, and the line segments overlapping with the area in the non-broken line segment cluster obtained by scanning the entire image (i.e., the target line segment cluster described in the aforementioned embodiment) are removed, and the remaining line segment clusters after removing the area are used to calculate other postal code positioning areas. In other words, the line segments within the determined postal code positioning area do not participate in the calculation of other postal code positioning areas, thereby reducing the amount of calculation for postal code positioning.
[0077] The method for locating a postal code provided by the embodiment of the present disclosure traverses the postal code image, obtains a first line segment, obtains a first normal vector and a second normal vector of the first line segment, the first normal vector and the second normal vector are in opposite directions, obtains a first line segment cluster along the first normal direction of the first normal vector, and obtains a second line segment cluster along the second normal direction of the second normal vector, and then determines the location area of the postal code based on the first line segment cluster and the second line segment cluster. The scheme of the present disclosure is adopted, by first determining the first line segment, then determining the line segment clusters at both ends of the first line segment, and then determining the location area of the postal code based on the line segment cluster, thereby achieving accurate location of the postal code with good location accuracy.
[0078] In order to implement the above embodiment, the present disclosure also provides a postal code positioning device.
[0079] Figure 5 This is a schematic diagram of the structure of a postal code positioning device provided in an embodiment of the present disclosure. The device is implemented in software and / or hardware and can be integrated in an electronic device.
[0080] like Figure 5 As shown, the postal code positioning device 50 may include: a first acquisition module 510 , a second acquisition module 520 , a third acquisition module 530 and a positioning module 540 .
[0081] The first acquisition module 510 is used to traverse the postal code image and acquire the first line segment;
[0082] A second acquisition module 520 is used to acquire a first normal vector and a second normal vector of the first line segment, where the first normal vector and the second normal vector are in opposite directions;
[0083] A third acquisition module 530, configured to acquire a first line segment cluster along a first normal direction of the first normal vector, and acquire a second line segment cluster along a second normal direction of the second normal vector;
[0084] The positioning module 540 is used to determine the positioning area of the postal code based on the first line segment cluster and the second line segment cluster.
[0085] Optionally, the first acquisition module 510 is further configured to:
[0086] Starting from the center position of the postal code image, traverse toward both ends to determine a plurality of boundary points;
[0087] Taking each of the plurality of boundary points as a starting point for boundary tracking, and obtaining a target line segment cluster;
[0088] A first line segment is determined from the target line segment cluster.
[0089] Further optionally, the first line segment satisfies the following conditions:
[0090] The straightness meets the preset straightness requirements;
[0091] The line segment width is less than the first line width threshold;
[0092] The line segment length is less than the first line length threshold.
[0093] Optionally, the second line segment cluster and the first line segment cluster are obtained in the same manner; the third obtaining module 530 is further configured to obtain the first line segment cluster by executing the following steps:
[0094] S1, initializing the first search distance;
[0095] S2. determining a plurality of starting points on the first line segment;
[0096] S3. Starting from each starting point, search for a second line segment within the first search distance according to the first normal direction;
[0097] S4, if the second line segment is found, calculate the distance between the first line segment and the second line segment as the updated first search distance, use the second line segment as the first line segment, obtain the first normal direction of the first line segment, and jump to S2;
[0098] S5. If the second line segment is not found, the search for the first line segment cluster is completed.
[0099] Optionally, the initialized first search distance is greater than the updated first search distance, and the initialized first search distance is positively correlated with the resolution of the postal code image.
[0100] Optionally, the third acquisition module 530 is further used to:
[0101] In S3, when multiple line segments are acquired from multiple starting points, one line segment is determined from the multiple line segments as the searched second line segment;
[0102] The second line segment satisfies at least one of the following conditions:
[0103] The second line segment is a line segment having the shortest distance from the first line segment among the plurality of line segments;
[0104] The angle between the second line segment and the first line segment is less than an angle threshold;
[0105] A difference between a line segment width of the second line segment and a line segment width of the first line segment is smaller than a preset value;
[0106] The line segment length of the second line segment is greater than a first length threshold and less than a second length threshold, wherein the second length threshold is greater than the first length threshold.
[0107] Optionally, the positioning module 540 is further configured to:
[0108] Merging the first line segment cluster and the second line segment cluster to obtain a merged line segment cluster;
[0109] The minimum circumscribed quadrilateral of the merged line segment cluster is calculated as the positioning area of the postal code.
[0110] Optionally, a first pair of sides of the minimum circumscribed quadrilateral is parallel to the line segments at both ends of the merged line segment cluster, and a second pair of sides is obtained by fitting according to the two end points of each line segment in the merged line segment cluster.
[0111] The postal code positioning device for electronic devices provided in the embodiments of the present disclosure can execute the postal code positioning method provided in the embodiments of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method. The contents not described in detail in the embodiments of the present disclosure can refer to the description in any method embodiment of the present disclosure.
[0112] The embodiments of the present disclosure also provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements the postal code positioning method provided by any embodiment of the present disclosure.
[0113] According to one or more embodiments of the present disclosure, the present disclosure provides an electronic device, including:
[0114] processor;
[0115] a memory for storing instructions executable by the processor;
[0116] The processor is used to read the executable instructions from the memory and execute the executable instructions to implement the postal code positioning method provided in any embodiment of the present disclosure.
[0117] According to one or more embodiments of the present disclosure, the present disclosure provides a computer-readable storage medium, wherein the storage medium stores a computer program, wherein the computer program is used to implement the postal code positioning method provided in any embodiment of the present disclosure.
[0118] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0119] The computer-readable medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
[0120] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0121] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit does not, in some cases, limit the unit itself.
[0122] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0123] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0124] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0125] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0126] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A method for locating a postal code, characterized in that: The method comprises: Traverse the postal code image and obtain the first line segment; Obtain a first normal vector and a second normal vector of the first line segment, where the first normal vector and the second normal vector are in opposite directions; Acquire a first line segment cluster along a first normal direction of the first normal vector; Acquire a second line segment cluster along a second normal direction of the second normal vector; A location area of a postal code is determined based on the first cluster of line segments and the second cluster of line segments.
2. The method according to claim 1, characterized in that The traversing the postal code image to obtain the first line segment includes: Starting from the center position of the postal code image, traverse toward both ends to determine a plurality of boundary points; Taking each of the plurality of boundary points as a starting point for boundary tracking, and obtaining a target line segment cluster; A first line segment is determined from the target line segment cluster.
3. The method according to claim 2, characterized in that The first line segment satisfies the following conditions: The straightness meets the preset straightness requirements; The line segment width is less than the first line width threshold; The line segment length is less than the first line length threshold.
4. The method according to claim 1, characterized in that: The second line segment cluster is obtained in the same manner as the first line segment cluster; The acquiring a first line segment cluster along a first normal direction of the first normal vector comprises: S1, initializing the first search distance; S2. determining a plurality of starting points on the first line segment; S3. Starting from each starting point, search for a second line segment within the first search distance according to the first normal direction; S4, if the second line segment is found, calculate the distance between the first line segment and the second line segment as the updated first search distance, use the second line segment as the first line segment, obtain the first normal direction of the first line segment, and jump to S2; S5. If the second line segment is not found, the search for the first line segment cluster is completed.
5. The method according to claim 4, characterized in that The initialized first search distance is greater than the updated first search distance, and the initialized first search distance is positively correlated with the resolution of the postal code image.
6. The method according to claim 4, characterized in that In S3, when multiple line segments are acquired from multiple starting points, one line segment is determined from the multiple line segments as the searched second line segment; The second line segment satisfies at least one of the following conditions: The second line segment is a line segment having the shortest distance from the first line segment among the plurality of line segments; The angle between the second line segment and the first line segment is less than an angle threshold; A difference between a line segment width of the second line segment and a line segment width of the first line segment is smaller than a preset value; The line segment length of the second line segment is greater than a first length threshold and less than a second length threshold, wherein the second length threshold is greater than the first length threshold.
7. The method according to any one of claims 1 to 5, characterized in that: The determining of the location area of the postal code based on the first line segment cluster and the second line segment cluster comprises: Merging the first line segment cluster and the second line segment cluster to obtain a merged line segment cluster; The minimum circumscribed quadrilateral of the merged line segment cluster is calculated as the positioning area of the postal code.
8. The method according to claim 6, characterized in that The first pair of sides of the minimum circumscribed quadrilateral is parallel to the line segments at both ends of the merged line segment cluster, and the second pair of sides is obtained by fitting according to the two end points of each line segment in the merged line segment cluster.
9. A postal code positioning device, characterized in that: include: A first acquisition module, used for traversing the postal code image to acquire a first line segment; A second acquisition module, used to acquire a first normal vector and a second normal vector of the first line segment, where the first normal vector and the second normal vector are in opposite directions; A third acquisition module, configured to acquire a first line segment cluster along a first normal direction of the first normal vector, and acquire a second line segment cluster along a second normal direction of the second normal vector; A positioning module is used to determine a positioning area of a postal code based on the first line segment cluster and the second line segment cluster.
10. An electronic device, characterized in that: The electronic device comprises: processor; a memory for storing instructions executable by the processor; The processor is used to read the executable instructions from the memory and execute the executable instructions to implement the postal code positioning method described in any one of claims 1-8 above.