Image correction method, device, server and storage medium

By preprocessing, cropping and segmenting the initial image, calculating and rotating correction, the problem of inaccurate angles in page sheet recognition is solved, and the recognition accuracy and calculation efficiency are improved.

CN113538449BActive Publication Date: 2024-11-26SF TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010309721.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-04-20
Publication Date
2024-11-26
Estimated Expiration
2040-04-20

AI Technical Summary

Technical Problem

The single correction method in the prior art is difficult to identify due to problems such as random single angles, blur, folding, and occlusion, and the accuracy of correction angles is not high, which in turn affects the accuracy of barcode recognition.

Method used

By preprocessing, cropping, and segmenting the initial image to be identified, the center of gravity and direction of the sub-image are calculated, the target angle that the initial image needs to rotate is determined, and rotation correction is performed to cut off areas with large deformations, reduce errors, and improve Calculation accuracy.

Benefits of technology

It realizes high-precision rotation correction of the opposite order, improves the accuracy of barcode recognition, simplifies the calculation process, and reduces manpower and material investment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113538449B_ABST
    Figure CN113538449B_ABST
Patent Text Reader

Abstract

In the embodiment of the present application, an image correction method, device, server and storage medium are disclosed, and the method includes: preprocessing an initial image to be subjected to barcode recognition to obtain a first image corresponding to the barcode recognition area to be corrected; cropping the first image to obtain a second image; segmenting the second image to divide the second image into a preset number of sub-images; calculating the target angle required for rotation of the first image according to the multiple sub-images; rotating the first image according to the target angle to obtain a corrected third image. In the embodiment of the present application, an image correction method is provided, which crops out the area with larger deformation in the initial image, reduces the error, and uses the center of gravity of the image to obtain the target angle required for rotation of the initial image, which is simple to calculate and has high accuracy, reducing manpower and material resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image recognition, and specifically designs an image correction method, device, server and storage medium. Background Art

[0002] Since barcode technology is accurate, fast, convenient and economical, it can easily penetrate into various fields of automated management, and algorithms for barcode recognition are emerging one after another. However, no matter which recognition algorithm is used to recognize and process the barcode, when the user captures the barcode image with the recognition device, it is often not captured from the best angle, which will lead to recognition failure. In order to improve the recognition accuracy of the barcode, these algorithms need to be corrected at an angle.

[0003] However, the existing method for correcting the waybill is difficult to identify because the angle of the waybill is completely random and has no rules; and the barcode and waybill number areas may have blurred, folded, or blocked areas, which in turn leads to low accuracy in the correction angle. Summary of the invention

[0004] An image correction method, device, server and storage medium are provided in the embodiments of the present application, aiming to solve the problems that the image correction methods in the prior art have difficulty in identifying the face order and calculating the correction angle.

[0005] In a first aspect, the present application provides an image correction method, the image correction method comprising: preprocessing an initial image to be subjected to barcode recognition to obtain a first image corresponding to a barcode recognition area to be corrected;

[0006] Cropping the first image to obtain a second image;

[0007] Segmenting the second image into a preset number of sub-images;

[0008] Calculating a target angle that needs to be rotated for correcting the first image according to the plurality of sub-images;

[0009] The first image is rotated according to the target angle to obtain a corrected third image.

[0010] Furthermore, the step of cropping the first image to obtain the second image includes:

[0011] Performing outer contour extraction processing on the first image to obtain a first outer contour image corresponding to the first image;

[0012] Determine a plurality of corner points of the first outer contour image;

[0013] The first outer contour image is cropped according to the plurality of corner points to obtain a second outer contour image, where the second outer contour image is an outer contour image of the second image.

[0014] Furthermore, the first outer contour image includes a plurality of edge lines, and the first outer contour image is cut according to the plurality of corner points to obtain the second outer contour image, including:

[0015] Determine a first angle between the first outer contour image and a horizontal direction or a vertical direction according to a target edge line in the first outer contour image;

[0016] The first outer contour image is cropped according to the first angle to obtain the second outer contour image.

[0017] Furthermore, the step of cutting the first outer contour image according to the first angle to obtain the second outer contour image includes:

[0018] Comparing the first angle with a preset angle to obtain a comparison result;

[0019] According to the comparison result, taking the first target corner point corresponding to the target edge line as a starting point, an intersection line is drawn to intersect with the first outer contour image;

[0020] and taking a second target corner point opposite to the first target corner point as a starting point, making another intersection line intersecting with the first outer contour image, and dividing the first outer contour image into a plurality of regions;

[0021] A first target region adjacent to the first target corner point and a second target region adjacent to the second target corner point are cut off to obtain the second outer contour image.

[0022] Furthermore, the segmenting of the second image into a preset number of sub-images includes:

[0023] Determine a plurality of equally divided points of the second outer contour image in a horizontal direction or a vertical direction;

[0024] The second outer contour image is equally divided into a preset number of sub-images using the plurality of equally divided points and the two intersection lines.

[0025] Furthermore, the step of calculating a target angle by which the first image needs to be rotated according to the multiple sub-images includes:

[0026] respectively calculating the center of gravity corresponding to each of the plurality of sub-images;

[0027] Connecting a plurality of the centroids to obtain an image direction of the first image;

[0028] A target angle by which the first image needs to be rotated is calculated according to the image direction of the first image.

[0029] Further, according to the image direction of the first image, calculating the target angle that needs to be rotated for correction of the first image includes:

[0030] determining a first angle between the first image and a horizontal or vertical direction according to an image direction of the first image;

[0031] A target angle by which the first image needs to be rotated is calculated according to the first angle.

[0032] In a second aspect, the present application provides an image correction device, the image correction device comprising:

[0033] A preprocessing unit, the preprocessing unit is used to preprocess the initial image to be subjected to barcode recognition to obtain a first image corresponding to the barcode recognition area to be corrected;

[0034] A cropping unit, configured to crop the first image to obtain a second image;

[0035] a segmentation unit, the segmentation unit being used to segment the second image into a preset number of sub-images;

[0036] An angle calculation unit, the angle calculation unit is used to calculate the target angle that needs to be rotated for correction of the first image according to the multiple sub-images;

[0037] A rotation unit is used to rotate the first image according to the target angle to obtain a corrected third image.

[0038] Furthermore, the cutting unit is specifically used for:

[0039] Performing outer contour extraction processing on the first image to obtain a first outer contour image corresponding to the first image;

[0040] Determine a plurality of corner points of the first outer contour image;

[0041] The first outer contour image is cropped according to the plurality of corner points to obtain the second image.

[0042] Furthermore, the cutting unit is specifically used for:

[0043] Determine a plurality of random values ​​corresponding to each of the plurality of corner points, wherein the random values ​​are used to determine a deformation amount of each of the plurality of corner points;

[0044] The first outer contour image is cropped according to the multiple corner points and the multiple random values ​​to obtain the second image.

[0045] Furthermore, the cutting unit is specifically used for:

[0046] Taking any two opposite corner points as starting points, making two intersection lines intersecting with the first outer contour image, and dividing the first outer contour image into a plurality of regions, wherein the intersection lines are two horizontal intersection lines or two vertical intersection lines;

[0047] According to the magnitudes of the plurality of random values, determining a first target corner point having the largest random value in the first outer contour image, and a second target corner point opposite to the first target corner point;

[0048] The first target area corresponding to the first target corner point and the second target area corresponding to the second target corner point are cut off to obtain the second outer contour image.

[0049] Furthermore, the segmentation unit is specifically used to: determine a plurality of equally divided points of the second outer contour image in the horizontal direction or the vertical direction;

[0050] The second outer contour image is divided into a preset number of sub-images by using the multiple equally divided points and the two intersection lines.

[0051] Furthermore, the angle calculation unit is specifically used for:

[0052] respectively calculating the center of gravity corresponding to each of the plurality of sub-images;

[0053] Connecting a plurality of the centroids to obtain an image direction of the first image;

[0054] A target angle at which the first image needs to be rotated for correction is calculated according to the image direction of the first image.

[0055] Furthermore, the angle calculation unit is specifically used for:

[0056] determining a first angle between the first image and a horizontal direction or a vertical direction according to an image direction of the first image;

[0057] A target angle that needs to be rotated for correcting the first image is calculated based on the first angle.

[0058] In a third aspect, the present application further provides a server, the server comprising:

[0059] one or more processors;

[0060] Memory; and

[0061] One or more applications, wherein the one or more applications are stored in the memory and are configured to be executed by the processor to implement the steps in any of the above image correction methods.

[0062] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program is loaded by a processor to execute the steps in the image correction method as described in any one of the above items.

[0063] The embodiment of the present application provides an image correction method, device, server and storage medium, which cuts the initial image to be barcode recognized and cuts off the area with larger deformation; divides the cut image to obtain multiple sub-images; calculates the center of gravity of the multiple sub-images respectively, and obtains the direction of the cut image according to the multiple centers of gravity. According to the direction of the cut image, the target angle that the initial image needs to be rotated can be obtained, and then the initial image is rotated and corrected according to the target angle. In this way, the area with larger deformation in the initial image is cut off, which reduces the error. At the same time, the target angle that the initial image needs to be rotated is obtained by using the center of gravity of the image. The calculation is simple and the accuracy is high, which reduces manpower and material resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0065] Figure 1 A schematic diagram of a scenario of a host monitoring system provided in an embodiment of the present application;

[0066] Figure 2 A schematic diagram of a flow chart of an embodiment of an image correction method provided in an embodiment of the present application;

[0067] Figure 3 A schematic diagram of a process flow of an embodiment of cropping a first image to obtain a second image provided in an embodiment of the present application;

[0068] Figure 4 A schematic flow chart of an embodiment of the present application showing a method of cutting a first outer contour image according to a first angle to obtain a second outer contour image;

[0069] Figure 5 A schematic diagram of an embodiment of cutting a first outer contour image provided in an embodiment of the present application;

[0070] Figure 6A schematic diagram of another embodiment of cutting the first outer contour image provided in an embodiment of the present application;

[0071] Figure 7 A schematic diagram of an embodiment of segmenting a second image provided by the present application;

[0072] Figure 8 A schematic diagram of a flow chart of an embodiment of calculating a target angle to be rotated for a first image according to a plurality of sub-images provided in the present application;

[0073] Fig. 9 A schematic diagram of an embodiment of an image correction device provided by the present application;

[0074] Fig.10 This is a schematic diagram of the structure of the server involved in the embodiment of the present application. Specific embodiments

[0075] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.

[0076] In the description of the present application, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the accompanying drawings, which are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present application. In addition, the terms "first" and "second" are used only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.

[0077] In this application, the word "exemplary" is used to mean "used as an example, illustration, or description." Any embodiment described in this application as "exemplary" is not necessarily to be construed as being preferred or advantageous over other embodiments. The following description is given to enable any technician in the field to implement and use the present application. In the following description, details are listed for the purpose of explanation. It should be understood that a person of ordinary skill in the art can recognize that the present application can be implemented without using these specific details. In other instances, well-known structures and processes will not be elaborated in detail to avoid obscuring the description of the present application with unnecessary details. Therefore, the present application is not intended to be limited to the embodiments shown, but is consistent with the widest scope consistent with the principles and features disclosed in the present application.

[0078] When using computer vision technology to identify the waybill barcode and waybill number and decoding them through optical character recognition (OCR) technology, the waybill must be "straightened", that is, the waybill barcode and waybill number should be in a horizontal state. However, how to straighten the angle of a waybill image with arbitrary angles is a very difficult problem.

[0079] The embodiments of the present application provide an image correction method, device, server and storage medium, which are described below respectively.

[0080] like Figure 1 As shown, it is a schematic diagram of a scenario of a host monitoring system provided in an embodiment of the present application. The host monitoring system may include multiple hosts 100 and servers 200. The hosts 100 and the servers 200 are connected via a network. A host monitoring device is integrated in the server 200. Figure 1 In the server, host 100 can access server 200.

[0081] In the embodiment of the present invention, the server 200 is mainly used to pre-process the initial image to be subjected to barcode recognition to obtain a first image corresponding to the barcode recognition area to be corrected; crop the first image to obtain a second image; segment the second image into a preset number of sub-images; calculate the target angle to be rotated for the first image based on the multiple sub-images; rotate the first image according to the target angle to obtain a corrected third image.

[0082] In the embodiment of the present invention, the server 200 may be an independent server, or a server network or server cluster composed of servers. For example, the server 200 described in the embodiment of the present invention includes but is not limited to a computer, a network host, a single network server, a plurality of network server sets or a cloud server composed of a plurality of servers. Among them, the cloud server is composed of a large number of computers or network servers based on cloud computing. In the embodiment of the present invention, communication between the server and the host can be achieved through any communication method, including but not limited to mobile communications based on the 3rd Generation Partnership Project (3GPP), Long Term Evolution (LTE), Worldwide Interoperability for Microwave Access (WiMAX), or computer network communications based on TCP / IP Protocol Suite (TCP / IP), User Datagram Protocol (UDP), etc.

[0083] It is understandable that the host 100 used in the embodiment of the present invention may be a device including both receiving and transmitting hardware, that is, a device having receiving and transmitting hardware capable of performing two-way communication on a two-way communication link. Such a host may include: a cellular or other communication device having a single-line display or a multi-line display or a cellular or other communication device without a multi-line display. The specific host 100 may be a desktop terminal or a mobile terminal, and the host 100 may also be a mobile phone, a tablet computer, a laptop computer, etc.

[0084] Those skilled in the art will understand that Figure 1 The application environment shown in the figure is only one application scenario of the present application solution and does not constitute a limitation on the application scenario of the present application solution. Other application environments may also include Figure 1 More or fewer servers, or server network connections, as shown in Figure 1 Only one server and two hosts are shown. It can be understood that the host monitoring system can also include one or more other servers, and / or one or more hosts connected to the server network, which is not specifically limited here.

[0085] In addition, if Figure 1 As shown, the host monitoring system may further include a memory 300 for storing data, such as storing host data, for example, host status data when the host is running.

[0086] It should be noted that Figure 1 The scenario diagram of the host monitoring system shown is only an example. The host monitoring system and scenario described in the embodiment of the present invention are intended to more clearly illustrate the technical solution of the embodiment of the present invention, and do not constitute a limitation on the technical solution provided by the embodiment of the present invention. Ordinary technicians in this field can know that with the evolution of the host monitoring system and the emergence of new business scenarios, the technical solution provided by the embodiment of the present invention is also applicable to similar technical problems.

[0087] The embodiment of the present application provides an image correction method, which can well calculate the angle at which the face sheet needs to be rotated and corrected, such as Figure 2 FIG. 1 is a flow chart of an embodiment of an image correction method provided in an embodiment of the present application. The image correction method includes:

[0088] 21. Preprocess the initial image to be subjected to barcode recognition to obtain a first image corresponding to the barcode recognition area to be corrected;

[0089] 22. Crop the first image to obtain a second image;

[0090] 23. Segment the second image into a preset number of sub-images.

[0091] 24. Calculate, based on the multiple sub-images, a target angle that needs to be rotated for correcting the first image.

[0092] 25. Rotate the first image according to the target angle to obtain a corrected third image.

[0093] Different from the prior art, the image correction method provided in the embodiment of the present application cuts the initial image to be barcode recognized and cuts off the area with larger deformation; divides the cut image to obtain multiple sub-images; calculates the center of gravity of the multiple sub-images respectively, and obtains the direction of the cut image according to the multiple centers of gravity. According to the direction of the cut image, the target angle that the initial image needs to be rotated can be obtained, and then the initial image is rotated and corrected according to the target angle. In this way, the area with larger deformation in the initial image is cut off, which reduces the error. At the same time, the target angle that the initial image needs to be rotated is obtained by using the center of gravity of the image. The calculation is simple and the accuracy is high, which reduces manpower and material resources.

[0094] In an embodiment of the present application, for an initial image that needs to be barcode recognized, it is necessary to first perform preprocessing to obtain a first image corresponding to the barcode recognition area to be corrected. Specifically, when any initial image that needs to be barcode recognized and corrected is obtained, it is necessary to segment the barcode recognition area of ​​the initial image to obtain a first image corresponding to the barcode recognition area to be corrected. In some embodiments of the present application, the initial image may be an express delivery bill. In this case, the initial image that needs to be barcode recognized is preprocessed to filter out the barcode area or waybill number area on the express delivery bill from the entire bill, and only perform subsequent processing and recognition on the barcode area or waybill number area on the express delivery bill.

[0095] In some embodiments of the present application, the initial image can be processed using the MaskRCNN technology. Specifically, the processing of the initial image using MaskRCNN can include: performing target detection on the initial image; performing target segmentation on the initial image; and performing pixel-level target segmentation on the initial image.

[0096] In the above embodiment, target detection on the initial image refers to drawing a target frame in the initial image, that is, dividing the initial image into multiple areas to be detected. Then, several areas to be detected belonging to the same target (a person or an object) are taken out. For target segmentation on the initial image, for each target, it is necessary to find the category corresponding to the target and distinguish what the target is, whether it is a person, an object, or another category. In the process of target segmentation on the initial image, it is necessary to use a convolutional neural network to extract the features of each area to be detected, and then classify them through these extracted features to obtain the category corresponding to the target in the area to be detected.

[0097] The pixel-level target segmentation of the initial image means that in the process of extracting features, the size of the area to be detected needs to be continuously adjusted to make the target determination more accurate. That is, in the process of continuously adjusting the size of the area to be detected, the initial image can be segmented at the pixel level, making the recognition of the target in the initial image more accurate.

[0098] By using MaskRCNN to pre-process the initial image to be barcode recognized, the barcode recognition area in the bill can be accurately separated from the bill, and the first image corresponding to the barcode recognition area to be corrected can be obtained. In the subsequent correction process, only the first image needs to be processed, and there is no need to process the entire bill, which greatly reduces the workload and saves manpower and material resources.

[0099] It should be noted that the waybill includes a barcode and a waybill number, and in the same waybill, the barcode and the waybill number are one-to-one corresponding and unique, and the positions of the barcode and the waybill number are parallel. Therefore, if you want to perform image correction, you only need to process one of the barcode or the waybill number to obtain the angle that needs to be corrected. That is, the barcode recognition area to be corrected can be the barcode area in the waybill, or the waybill number area in the waybill.

[0100] In some embodiments of the present application, after obtaining the first image corresponding to the barcode recognition area to be corrected, it is also necessary to crop the first image to obtain the second image. Figure 3 As shown, it is a schematic diagram of a flow chart of an embodiment of cropping a first image to obtain a second image provided by an embodiment of the present application. The cropping of the first image to obtain the second image may include:

[0101] 31. Perform outer contour extraction processing on the first image to obtain a first outer contour image corresponding to the first image.

[0102] 32. Determine multiple corner points of the first outer contour image.

[0103] 33. Crop the first outer contour image according to the multiple corner points to obtain a second outer contour image, where the second outer contour image is the outer contour image of the second image.

[0104] In the above embodiment, in actual situations, multiple waybills are photographed and processed at the same time. At this time, the area occupied by a specific waybill in the photo is not large; at the same time, the area occupied by the barcode area in the panel is also not large, which makes the entire barcode area relatively blurred and irregular. Therefore, the first image obtained is not a completely regular image, and the edges of the first image will still be tortuous, which will affect the accuracy of the correction. Therefore, the first image needs to be processed again and part of the area of ​​the first image needs to be cropped.

[0105] Specifically, it is necessary to perform outer contour extraction processing on the first image, because only the edge of the first image is tortuous, so it is only necessary to extract the first outer contour image corresponding to the first image, and it is only necessary to crop the first image according to the first outer contour image.

[0106] In the above embodiment, OpenCV can be used to extract the first outer contour image corresponding to the first image. OpenCV is an open source, free computer vision library. The goal of OpenCV is to build a simple and easy-to-use computer vision framework, using the functions it contains to help developers quickly and easily implement image processing and video processing.

[0107] Specifically, using OpenCV to extract the first outer contour image corresponding to the first image may include two parts: image extraction and contour extraction. The image extraction may include reading the image path, converting the image format, and displaying the image on the operation interface. The contour extraction may include reading the image on the operation interface; grayscale processing the image to obtain a grayscale image corresponding to the image; binarizing the grayscale image; and marking and extracting the contour using the binarized grayscale image.

[0108] In the above embodiment, before grayscale processing is performed on the image, the image may be enhanced, so that the edge of the image is more obvious, which facilitates the subsequent image contour extraction.

[0109] After obtaining the first outer contour image corresponding to the first image, it is also necessary to determine the multiple corner points of the first outer contour image. In face sheet recognition, since the face sheet is generally a rectangular structure, and the barcode recognition area is generally a rectangular structure, the first image corresponding to the barcode recognition area is generally a rectangular structure, and the first outer contour image corresponding to the first image is also a rectangular structure. Then the multiple corner points of the first outer contour image are the multiple corners of the first outer contour image. In some specific embodiments of the present application, the first outer contour image may have four corner points.

[0110] In some embodiments of the present application, after obtaining the first outer contour image and determining multiple corner points of the first outer contour image, the first outer contour image is cropped according to the multiple corner points to obtain the second outer contour image, which may include: determining a first angle between the first outer contour image and the horizontal direction or the vertical direction according to the target edge line in the first outer contour image. According to the first angle, the first outer contour image is cropped to obtain the second outer contour image. The second outer contour image is the outer contour image of the second image.

[0111] Specifically, as mentioned above, the edge of the first image is tortuous, so the edge of the first outer contour image corresponding to the first image is also tortuous, that is, the edge line of the first outer contour image is tortuous, and this tortuous outer contour image will affect the accuracy of image correction, so the first outer contour image needs to be cropped to improve the accuracy of image correction.

[0112] In a specific embodiment of the present application, the first outer contour image is a rectangular structure and includes four edge lines, and the first outer contour image includes four corner points. Although the edge lines of the first outer contour image are tortuous, the four corner points of the first outer contour image can still be used to determine the first angle between the first outer contour image and the vertical direction or the horizontal direction.

[0113] Specifically, taking the target edge line corresponding to the short side in the first outer contour image as an example, since two points can determine a straight line, the target edge line can be used to determine the first angle between the target edge line and the horizontal direction or the vertical direction. It should be noted that since the edge line of the first outer contour image is tortuous, the first angle is only an estimated value, not an accurate value.

[0114] After determining the first angle between the first outer contour image and the horizontal direction or the vertical direction, the first outer contour image may be cropped according to the first angle to obtain a second outer contour image.

[0115] In some embodiments of the present application, Figure 4 As shown, it is a schematic flow chart of an embodiment of the present application to cut the first outer contour image according to the first angle to obtain the second outer contour image. Among them, cutting the first outer contour image according to the first angle to obtain the second outer contour image may include:

[0116] 41. Compare the first angle and the preset angle to obtain a comparison result.

[0117] 42. According to the comparison result, the first target corner point corresponding to the target edge line is taken as the starting point, and an intersection line is made to intersect with the first outer contour image.

[0118] 43. Taking the second target corner point opposite to the first target corner point as the starting point, another intersection line is made to intersect with the first outer contour image, so as to divide the first outer contour image into a plurality of regions.

[0119] 44. Cut off a first target region adjacent to the first target corner point and a second target region adjacent to the second target corner point to obtain a second outer contour image.

[0120] Specifically, Figure 5 FIG. 1 is a schematic diagram of an embodiment of cutting the first outer contour image provided by the present application. Since the initial image is not in a horizontal state, the first image is not in a horizontal state, and the first outer contour image is not in a horizontal state, so the first outer contour image needs to be rotated and corrected.

[0121] In a specific embodiment of the present application, since the first outer contour image includes four corner points, the first angle of the first outer contour image is determined at this time, and in this embodiment, the first angle can be the angle between the target edge line 410 corresponding to the short side of the first outer contour image and the horizontal direction.

[0122] In the above embodiment, the first angle and the preset angle are compared to obtain a comparison result. Specifically, it is determined whether the first angle is greater than the preset angle. If the first angle is greater than the preset angle, a first vertical intersection line 405 is made with the first target corner point corresponding to the target edge line 410, that is, corner point 401, as the starting point to intersect with the first outer contour image, and a second vertical intersection line 406 is made with the corner point 403 opposite to corner point 401 as the starting point to intersect with the first outer contour image; at this time, the first vertical intersection line 405 and the second vertical intersection line 406 divide the first outer contour image into three areas.

[0123] Since the edge of the first image is tortuous, that is, the first outer contour image is tortuous, it is necessary to cut off part of the first outer contour image to ensure the calculation accuracy of the angle, but at the same time it is necessary to ensure that the area of ​​the cut-off part is as small as possible. Therefore, through mathematical calculation, it can be determined that when the first angle between the target edge line 410 and the horizontal direction is greater than the preset angle, a vertical intersection line is made to divide the first outer contour image into multiple areas, and then cut, so that the cut-off area is minimized.

[0124] In the above embodiment, the first target corner point is corner point 401, the second target corner point is corner point 403, and the partial area of ​​the first outer contour image that needs to be cut off is the first target area adjacent to the first target corner point 401, including corner point 404; and the second target area adjacent to the second target corner point 403, including corner point 402; that is, Figure 5 The area on the left side of the first vertical intersection line 405 and the area on the right side of the second vertical intersection line 406 are included in the image. By cutting off the first target area and the second target area, a second outer contour image can be obtained.

[0125] like Figure 6 As shown, it is a schematic diagram of another embodiment of cutting the first outer contour image provided by the embodiment of the present application. At this time, the first angle is smaller than the preset angle. Through mathematical calculation, it can be obtained that when the first angle between the target edge line 410 and the horizontal direction is smaller than the preset angle, a horizontal intersection line is made to divide the first outer contour image into multiple areas, and then cutting is performed, so that the cut area is minimized.

[0126] Specifically, the corner point 404 can be taken as the third target corner point, and the first horizontal intersection line 408 can be made with the corner point 404 as the starting point to intersect with the first outer contour image. At the same time, the corner point 402 can be taken as the fourth target corner point, and the second horizontal intersection line 407 can be made with the corner point 404 as the starting point to intersect with the first outer contour image. At this time, the first horizontal intersection line 408 and the second horizontal intersection line 407 divide the first outer contour image into three areas.

[0127] At this time, the third target area adjacent to the third target corner point 404 may be an area above the first horizontal intersection line, and the fourth target area adjacent to the fourth target corner point 402 may be an area below the second horizontal intersection line. At this time, the third target area and the fourth target area may be cut off to obtain a second outer contour image.

[0128] In the embodiment of the present application, the value of the preset angle can be set manually. Specifically, the preset angle can be 45°. And in the embodiment of the present application, since the value of the first angle is an estimated value, not an accurate value, in fact, by comparing the size between the first angle and the preset angle, it is possible to determine whether the first angle is within the preset range. The preset range is based on 45° and allows a certain error value; that is, in a specific embodiment of the present application, the preset range can be (42°, 47°). That is, if the first angle is greater than 47° or less than 42°, it is determined whether to make a horizontal intersection line or a vertical intersection line to intersect with the first outer contour image; if the first angle is within the range of (42°, 47°), it is possible to make a horizontal intersection line or a vertical intersection line to intersect with the first outer contour image.

[0129] It should be noted that in the embodiments of the present application, when the long side or the short side of the first outer contour image is used as the target edge line, the first angle will be different, and thus the area to be cropped for the first outer contour image will also be different. For details, reference can be made to the above example of cropping the first outer contour image using the short side of the first outer contour image as the target edge line, which will not be described in detail here.

[0130] In an embodiment of the present application, after obtaining the second outer contour image, it is necessary to segment the second outer contour image into a preset number of sub-images to determine the image direction of the first image. Specifically, segmenting the second outer contour image into a preset number of sub-images may include:

[0131] Determine a plurality of equally divided points of the second outer contour image in the horizontal direction or the vertical direction; and divide the second outer contour image into a plurality of sub-images of a preset number by using the plurality of equally divided points and the horizontal intersection lines or the vertical intersection lines.

[0132] Specifically, Figure 7 FIG. 1 is a schematic diagram of an embodiment of segmenting the second outer contour image provided by the present application. Figure 7 In the figure, a first vertical intersection line 405 is made from the corner point 401 to intersect with the second outer contour image, and a second vertical intersection line 406 is made from the corner point 403 to intersect with the second outer contour image. After the second outer contour image is obtained and cropped, the second outer contour image lacks two corner points and the target areas corresponding to the corner points compared to the second outer contour image.

[0133] At this time, multiple equal division points of the second outer contour image in the vertical direction can be determined. After the multiple equal division points are determined, vertical intersection lines can be made with the multiple equal division points as starting points to intersect with the second outer contour image. At this time, the equal division points and the original first vertical intersection line 405 and second vertical intersection line 406 are used to divide the second outer contour image into a preset number of sub-images.

[0134] Please refer to Figure 7 In a specific embodiment of the present application, the edge line of the second outer contour image in the vertical direction can be divided into multiple line segments of equal length, that is, the edge of the second outer contour image in the vertical direction is divided into multiple equal parts, and multiple equal-division points are used as starting points to make multiple vertical intersection lines that intersect with the second outer contour image at multiple equal-division points. The equal-division points can be bisection points, that is, the equal-division points are midpoints. At this time, the midpoint 701 and the midpoint 702 of the second outer contour image in the horizontal direction are connected, and the two midpoints form a straight line, and the straight line and the first vertical intersection line 405 and the second vertical intersection line 406 divide the second outer contour image into two sub-images.

[0135] In some other embodiments of the present application, multiple equally divided points of the second outer contour image in the horizontal direction may also be determined, and a horizontal intersection line is made with the multiple equally divided points as starting points to intersect the second outer contour image, so as to divide the second outer contour image into multiple sub-images. The specific process can be referred to the above content, and will not be described here.

[0136] In other embodiments of the present application, the equal division points may also be three equal division points, four equal division points, etc., which are not limited here. The number of sub-images is related to the number of equal division points, which is not limited here either.

[0137] After the second outer contour image is divided into multiple sub-images, the target angle to be rotated for the first image needs to be calculated based on the multiple sub-images. Figure 8 As shown, it is a schematic flow chart of an embodiment of the present application to calculate the target angle that the first image needs to be rotated according to multiple sub-images. Specifically, in some embodiments of the present application, calculating the target angle that the first image needs to be rotated according to multiple sub-images may include:

[0138] 81. Calculate the centroids corresponding to the multiple sub-images respectively.

[0139] 82. Connect multiple centroids to obtain the image direction of the first image.

[0140] 83. According to the image direction of the first image, a target angle that needs to be rotated for correcting the first image is calculated.

[0141] On the basis of the above embodiment, calculating the target angle to which the first image needs to be rotated according to the image direction of the first image may include: determining a first angle between the first image and a horizontal direction or a vertical direction according to the image direction of the first image. Calculating the target angle to which the first image needs to be rotated according to the first angle.

[0142] Specifically, after obtaining multiple sub-images, the corresponding centers of gravity of the multiple sub-images can be calculated respectively, and after obtaining multiple centers of gravity, the image direction of the first image can be obtained by connecting the multiple centers of gravity. When there are multiple sub-images, there are also multiple corresponding image centers of gravity. At this time, fitting and other methods can be used to connect multiple centers of gravity as much as possible. Since two points can determine a straight line, after obtaining multiple centers of gravity, the direction of the straight line formed by the multiple centers of gravity can be determined, and then the image direction of the first image can be determined. The image direction of the first image determined at this time is a more accurate value different from the first angle.

[0143] In the embodiment of the present application, the first outer contour image is divided into two sub-images, and the centroids of the two sub-images are calculated respectively, and then the image direction of the first image is determined, so that the calculation accuracy is the highest. This division minimizes the number of sub-images, and the area of ​​each sub-image is the largest, and each sub-image includes the most pixels, so that the calculation accuracy is higher.

[0144] After the image direction of the first image is determined, the first angle between the first image and the horizontal direction or the vertical direction can be determined according to the image direction of the first image. According to the first angle, the target angle that the first image needs to be rotated can be calculated.

[0145] In a specific embodiment of the present application, please refer to Figure 7 ,exist Figure 7 The direction of the dotted line in is the image direction of the first image. After determining the image direction of the first image, it can be detected that the first angle between the image direction of the first image and the vertical direction is 30°. At this time, it can be calculated that the target angle to be rotated for the first image is: 90°-30°=60°.

[0146] In the above embodiment, the first image is rotated horizontally, and the target angle is 60°; if the first image is rotated vertically, the target angle is 30°. That is, the target angle to which the first image needs to be rotated is related to the rotation direction of the first image.

[0147] In the embodiments of the present application, the specific process of calculating the centroids of multiple sub-images may refer to the prior art and is not limited here.

[0148] On the basis of the above embodiments, in other embodiments of the present application, the image correction method provided by the present application may further include: outputting the third image so as to identify the third image.

[0149] The present application also provides an image correction device, such as Fig. 9 FIG. 1 is a schematic diagram of an embodiment of an image correction device provided by the present application, and the image correction device includes:

[0150] The preprocessing unit 901 is used to preprocess the initial image to be subjected to barcode recognition, and obtain a first image corresponding to the barcode recognition area to be corrected.

[0151] The cropping unit 902 is used to crop the first image to obtain a second image.

[0152] The segmentation unit 903 is used to segment the second image into a preset number of sub-images.

[0153] Angle calculation unit 904, the angle calculation unit 904 is used to calculate the target angle required for rotation of the first image correction according to the multiple sub-images.

[0154] The rotation unit 905 is used to rotate the first image according to the target angle to obtain a corrected third image.

[0155] The image correction device provided in the embodiment of the present application cuts the initial image to be barcode recognized and cuts off the area with larger deformation; divides the cut image to obtain multiple sub-images; calculates the center of gravity of the multiple sub-images respectively, and obtains the direction of the cut image according to the multiple centers of gravity. According to the direction of the cut image, the target angle that the initial image needs to be rotated can be obtained, and then the initial image is rotationally corrected according to the target angle. In this way, the area with larger deformation in the initial image is cut off, which reduces the error. At the same time, the target angle that the initial image needs to be rotated is obtained by using the center of gravity of the image. The calculation is simple and the accuracy is high, which reduces manpower and material resources.

[0156] Specifically, in some embodiments of the present application, the cropping unit 902 can be specifically used to: perform outer contour extraction processing on the first image to obtain a first outer contour image corresponding to the first image; determine multiple corner points of the first outer contour image; and crop the first outer contour image according to the multiple corner points to obtain a second outer contour image, which is the outer contour image of the second image.

[0157] The cropping unit 902 crops the first outer contour image according to the multiple corner points to obtain the second outer contour image, which may include: determining a first angle between the first outer contour image and the horizontal direction or the vertical direction according to the target edge line in the first outer contour image. The first outer contour image is cropped according to the first angle to obtain the second outer contour image. The second outer contour image is the outer contour image of the second image.

[0158] In some embodiments of the present application, the cropping unit 902 can also be specifically used to: compare the first angle and the preset angle to obtain a comparison result; based on the comparison result, take the first target corner point corresponding to the target edge line as the starting point, make an intersection line to intersect with the first outer contour image; and take the second target corner point opposite to the first target corner point as the starting point, make another intersection line to intersect with the first outer contour image, and divide the first outer contour image into multiple areas; crop the first target area opposite to the first target corner point, and the second target area opposite to the second target corner point, to obtain a second outer contour image.

[0159] In some other embodiments of the present application, the segmentation unit 903 can be specifically used to: determine multiple equally divided points of the second outer contour image in the horizontal direction or the vertical direction; and divide the second outer contour image into a preset number of sub-images using the multiple equally divided points and two intersection lines.

[0160] In other embodiments of the present application, the angle calculation unit 904 can be specifically used to: respectively calculate the center of gravity corresponding to multiple sub-images; connect multiple centers of gravity to obtain the image direction of the first image; and calculate the target angle that needs to be rotated for correcting the first image based on the image direction of the first image.

[0161] Specifically, the angle calculation unit 904 calculates the target angle that needs to be rotated for correction of the first image according to the image direction of the first image, which may specifically include: determining a first angle between the first image and the horizontal direction or the vertical direction according to the image direction of the first image; and calculating the target angle that needs to be rotated for the first image according to the first angle.

[0162] The present application also provides a server, which integrates any image correction device provided in the embodiments of the present application, such as Fig.10 As shown, it shows a schematic diagram of the structure of the server involved in the embodiment of the present application, specifically:

[0163] The server may include one or more processors 1001 of processing cores, one or more computer-readable storage media memories 1002, a power supply 1003, an input unit 1004 and other components. Those skilled in the art will appreciate that Fig.10The server structure shown in the figure does not constitute a limitation on the server, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0164] in:

[0165] The processor 1001 is the control center of the server, and uses various interfaces and lines to connect various parts of the entire server. By running or executing software programs and / or modules stored in the memory 1002, and calling data stored in the memory 1002, the processor 1001 performs various functions of the server and processes data, thereby monitoring the server as a whole. Optionally, the processor 1001 may include one or more processing cores; preferably, the processor 1001 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 1001.

[0166] The memory 1002 can be used to store software programs and modules. The processor 1001 executes various functional applications and data processing by running the software programs and modules stored in the memory 1002. The memory 1002 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the server, etc. In addition, the memory 1002 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 1002 may also include a memory controller to provide the processor 1001 with access to the memory 1002.

[0167] The server also includes a power supply 1003 for supplying power to various components. Preferably, the power supply 1003 can be logically connected to the processor 1001 through a power management system, so as to manage charging, discharging, power consumption and other functions through the power management system. The power supply 1003 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components.

[0168] The server may further include an input unit 1004, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.

[0169] Although not shown, the server may also include a display unit, etc., which will not be described in detail here. Specifically in this embodiment, the processor 1001 in the server will load the executable files corresponding to the processes of one or more applications into the memory 1002 according to the following instructions, and the processor 1001 will run the application stored in the memory 1002, thereby realizing various functions, as follows:

[0170] The initial image to be subjected to barcode recognition is preprocessed to obtain a first image corresponding to the barcode recognition area to be corrected. The first image is cropped to obtain a second image. The second image is segmented into a preset number of sub-images. The target angle to be rotated for the first image is calculated based on the multiple sub-images. The first image is rotated according to the target angle to obtain a corrected third image.

[0171] The present application also provides a computer-readable storage medium, which may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc. The storage medium stores a computer program, which is loaded by a processor to execute the steps in any character recognition model training method provided in the embodiments of the present application. For example, the computer program may be loaded by a processor to execute the following steps:

[0172] The initial image to be subjected to barcode recognition is preprocessed to obtain a first image corresponding to the barcode recognition area to be corrected. The first image is cropped to obtain a second image. The second image is segmented into a preset number of sub-images. The target angle to be rotated for the first image is calculated based on the multiple sub-images. The first image is rotated according to the target angle to obtain a corrected third image.

[0173] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of other embodiments above, and will not be repeated here.

[0174] In specific implementation, the above units or structures can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units or structures can refer to the previous method embodiments, which will not be repeated here.

[0175] The above is a detailed introduction to an image correction method, device, server and storage medium provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and embodiments of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific embodiments and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. An image correction method, characterized in that: The method comprises: Preprocessing the initial image to be subjected to barcode recognition to obtain a first image corresponding to the barcode recognition area to be corrected; Performing outer contour extraction processing on the first image to obtain a first outer contour image corresponding to the first image; Determine a plurality of corner points of the first outer contour image; the first outer contour image is a rectangular structure; the plurality of corner points of the first outer contour image are a plurality of corners of the first outer contour image; According to the multiple corner points, the first outer contour image is cropped to obtain a second outer contour image; Determine a plurality of equally divided points of the second outer contour image in a horizontal direction or a vertical direction; Using a plurality of the equally divided points and horizontal intersection lines or vertical intersection lines starting from the equally divided points, the second outer contour image is equally divided into a preset number of sub-images; wherein the horizontal intersection lines or the vertical intersection lines intersect with the second outer contour image; respectively calculating the center of gravity corresponding to each of the plurality of sub-images; Connecting a plurality of the centroids to obtain an image direction of the first image; Calculating a target angle at which the first image needs to be rotated according to an image direction of the first image; The first image is rotated according to the target angle to obtain a corrected third image.

2. The image correction method according to claim 1, characterized in that: The first outer contour image includes a plurality of edge lines, and the first outer contour image is cut according to the plurality of corner points to obtain a second outer contour image, including: Determine a first angle between the first outer contour image and a horizontal direction or a vertical direction according to a target edge line in the first outer contour image; Comparing the first angle with a preset angle to obtain a comparison result; According to the comparison result, taking the first target corner point corresponding to the target edge line as a starting point, an intersection line is drawn to intersect with the first outer contour image; and taking a second target corner point opposite to the first target corner point as a starting point, making another intersection line intersecting with the first outer contour image, and dividing the first outer contour image into a plurality of regions; A first target area corresponding to the first target corner point and a second target area corresponding to the second target corner point are cut off to obtain the second outer contour image.

3. The image correction method according to claim 1, characterized in that: Calculating a target angle by which the first image needs to be rotated according to an image direction of the first image includes: determining a first angle between the first image and a horizontal direction or a vertical direction according to an image direction of the first image; A target angle that needs to be rotated for correcting the first image is calculated based on the first angle.

4. An image correction device, characterized in that: The image correction device comprises: A preprocessing unit, the preprocessing unit is used to preprocess the initial image to be subjected to barcode recognition to obtain a first image corresponding to the barcode recognition area to be corrected; A cutting unit, the cutting unit is used to perform an outer contour extraction process on the first image to obtain a first outer contour image corresponding to the first image; determine multiple corner points of the first outer contour image; the first outer contour image is a rectangular structure; the multiple corner points of the first outer contour image are multiple corners of the first outer contour image; according to the multiple corner points, the first outer contour image is cut to obtain a second outer contour image; a segmentation unit, the segmentation unit being used to determine a plurality of equally divided points of the second outer contour image in a horizontal direction or a vertical direction; and using the plurality of equally divided points and horizontal intersection lines or vertical intersection lines with the equally divided points as starting points, the second outer contour image is equally divided into a plurality of sub-images of a preset number; wherein the horizontal intersection lines or the vertical intersection lines intersect with the second outer contour image; An angle calculation unit, the angle calculation unit is used to respectively calculate the center of gravity corresponding to each of the plurality of sub-images; connect the plurality of center of gravity to obtain the image direction of the first image; and calculate the target angle that the first image needs to be rotated according to the image direction of the first image; A rotation unit is used to rotate the first image according to the target angle to obtain a corrected third image.

5. A server, characterized in that: The server comprises: one or more processors; Memory; and One or more applications, wherein the one or more applications are stored in the memory and are configured to be executed by the processor to implement the steps in the image correction method according to any one of claims 1 to 3.

6. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in the image correction method according to any one of claims 1 to 3.