Image rotation method, device, equipment and storage medium
By obtaining the image rotation angle and the coordinate information of pixel points in the sliding window for correction, the problem of low image rotation efficiency is solved, and high accuracy and fast rotation effect is achieved, which is suitable for a variety of devices.
Patent Information
- Application Number
- CN202011511972.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-18
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2040-12-18
AI Technical Summary
In the prior art, the image rotation is low and the effect is poor, especially when collecting images of bills or banknotes, which leads to a long rotation time and low efficiency.
By obtaining the rotation angle of the image to be rotated, using the original sliding window to obtain the original coordinate information of the target pixel point, and determining the target coordinate information of the target pixel point in the target window based on the rotation angle, performing reverse rotation correction, directly Assign values to correct coordinate information in the image to achieve image rotation.
It improves the accuracy and efficiency of image rotation and correction, reduces the calculation amount, is suitable for low-end devices, expands the application population, and does not need to perform rotation and correction operations on the rotation and correction image itself.
Smart Images

Figure CN113255656B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to an image rotation method, device, equipment and storage medium. Background Art
[0002] When collecting images of bills or banknotes, image tilt is prone to occur. At present, the method for rotating tilted images is usually to start the rotation operation after the entire tilted image is completely scanned. There are problems such as long rotation time, low efficiency and poor rotation effect.
[0003] Therefore, the prior art still needs to be developed and improved. Summary of the invention
[0004] Based on this, it is necessary to propose an image rotation method, device, equipment and storage medium to address the above problems, so as to solve the technical problem of low image rotation efficiency in the prior art.
[0005] In a first aspect, the present application provides an image rotation method, the image rotation method comprising:
[0006] Acquire an image to be rotated, and determine a rotation angle of the image to be rotated according to the image to be rotated;
[0007] Acquire original coordinate information of a target pixel point in the original sliding window area in the image to be rotated through the original sliding window, wherein the target pixel point is any pixel point in the original sliding window area;
[0008] Determine the target coordinate information of the target pixel point in the target window after rotation according to the original coordinate information of the target pixel point and the rotation angle;
[0009] Determine, according to the target coordinate information and the rotation angle, the corrected coordinate information of the target pixel point within the original sliding window after reverse rotation;
[0010] The pixel value at the position where the corrected coordinate information is located is determined as the pixel value of the target pixel point at the position corresponding to the target coordinate information, and the image in the target window is used as the rotated image of the image to be rotated.
[0011] Optionally, determining the target coordinate information of the target pixel point in the target window after rotation according to the original coordinate information of the target pixel point and the rotation angle includes:
[0012] Obtaining the rotation angle of the image to be rotated, the original coordinate information of the target pixel point and a preset rotation formula;
[0013] Look up the table to obtain the sine value and cosine value of the rotation angle;
[0014] The original coordinate information, the sine value and the cosine value of the rotation angle are substituted into the preset rotation formula to obtain the target coordinate information of the target pixel point in the target window.
[0015] Optionally, the target pixel point is used as the remaining pixel points except the center point of the target window, and the determining, according to the original coordinate information of the target pixel point and the rotation angle, the target coordinate information of the target pixel point in the target window after rotation includes:
[0016] Obtaining the proportional relationship between the center point position of the target window and the positions of the remaining pixels;
[0017] The target coordinate information corresponding to the remaining pixel points in the target window is determined according to the proportional relationship and the target coordinate information corresponding to the center point of the target window.
[0018] Optionally, determining, according to the target coordinate information and the rotation angle, corrected coordinate information of the target pixel point in the original sliding window after reverse rotation includes:
[0019] Obtaining the width and height of the original sliding window area and the target coordinate information corresponding to the target pixel point;
[0020] Determining a rotation direction of the image to be rotated, and selecting a reverse rotation formula corresponding to the rotation direction according to the rotation direction;
[0021] The width, height, rotation angle and target coordinate information corresponding to the target pixel point are substituted into the reverse rotation formula to obtain the corrected coordinate information of the target pixel point in the original sliding window after reverse rotation.
[0022] Optionally, if the window size of the original sliding window is smaller than the image to be rotated, the sliding step size of the original sliding window is configured to be greater than or equal to the window size of the original sliding window.
[0023] Optionally, before acquiring the image to be rotated, the process includes:
[0024] Get the original image;
[0025] Using the image in the original sliding window as a first image; wherein the first image is a partial image of the original image;
[0026] Based on the four edges of the first image, a plurality of target edge groups are determined, wherein each target edge group includes a reference edge and an edge to be rotated corresponding to the reference edge, and the reference edge is any edge of the first image;
[0027] Calculate the angle difference between the first angle corresponding to the reference edge in the current target edge group and the second angle corresponding to the edge to be rotated after rotation;
[0028] If the absolute value of the angle difference meets a preset condition, the first image corresponding to the target edge group is used as the image to be rotated.
[0029] Optionally, determining a rotation angle of the image to be rotated according to the image to be rotated includes:
[0030] Obtain preset horizontal and vertical parameters, and determine the proportional relationship between the horizontal and vertical parameters;
[0031] Acquire original coordinate information of a target pixel point on a target edge of the image to be rotated, and calculate a target edge slope of the image to be rotated according to the proportional relationship and the original coordinate information; wherein the target edge is any one of the four edges of the image to be rotated;
[0032] The rotation angle of the image to be rotated is calculated according to the target edge slope and a preset inverse trigonometric function formula.
[0033] In a second aspect, the present application provides an image rotation device, the image rotation device comprising:
[0034] An acquisition and rotation angle calculation unit is used to acquire the image to be rotated, and determine the rotation angle of the image to be rotated according to the image to be rotated;
[0035] An original coordinate acquisition unit, used for acquiring original coordinate information of a target pixel point in an original sliding window area in the image to be rotated through an original sliding window, wherein the target pixel point is any pixel point in the original sliding window area;
[0036] A target coordinate calculation unit, used to determine the target coordinate information of the target pixel point after rotation in the target window according to the original coordinate information of the target pixel point and the rotation angle;
[0037] A correction unit, configured to determine, according to the target coordinate information and the rotation angle, the corrected coordinate information of the target pixel point within the original sliding window after reverse rotation;
[0038] The target image determination unit is used to determine the pixel value of the position where the corrected coordinate information is located as the pixel value of the target pixel point at the position corresponding to the target coordinate information, and use the image in the target window as the image after rotation of the image to be rotated.
[0039] In a third aspect, an embodiment of the present application further provides a computer device, including a processor and a memory, wherein the memory is connected to the processor, and the memory stores one or more programs, and the one or more programs are executed by the processor to perform the following steps:
[0040] Acquire an image to be rotated, and determine a rotation angle of the image to be rotated according to the image to be rotated;
[0041] Acquire original coordinate information of a target pixel point in the original sliding window area in the image to be rotated through the original sliding window, wherein the target pixel point is any pixel point in the original sliding window area;
[0042] Determine the target coordinate information of the target pixel point in the target window after rotation according to the original coordinate information of the target pixel point and the rotation angle;
[0043] Determine, according to the target coordinate information and the rotation angle, the corrected coordinate information of the target pixel point within the original sliding window after reverse rotation;
[0044] The pixel value at the position where the corrected coordinate information is located is determined as the pixel value of the target pixel point at the position corresponding to the target coordinate information, and the image in the target window is used as the rotated image of the image to be rotated.
[0045] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor performs the following steps:
[0046] Acquire an image to be rotated, and determine a rotation angle of the image to be rotated according to the image to be rotated;
[0047] Acquire original coordinate information of a target pixel point in the original sliding window area in the image to be rotated through the original sliding window, wherein the target pixel point is any pixel point in the original sliding window area;
[0048] Determine the target coordinate information of the target pixel point in the target window after rotation according to the original coordinate information of the target pixel point and the rotation angle;
[0049] Determine, according to the target coordinate information and the rotation angle, the corrected coordinate information of the target pixel point within the original sliding window after reverse rotation;
[0050] The pixel value at the position where the corrected coordinate information is located is determined as the pixel value of the target pixel point at the position corresponding to the target coordinate information, and the image in the target window is used as the rotated image of the image to be rotated.
[0051] The embodiments of the present invention have the following beneficial effects:
[0052] The image rotation method provided by the embodiment of the present invention obtains the original coordinate information of the target pixel point in the original sliding window area in the image to be rotated by sliding the original sliding window, so as to determine the target coordinate information of the target pixel point in the target window. The calculation method is simple and the amount of calculation is small. The original coordinate information of the target pixel point is corrected by the target coordinate information of the target pixel point in the target window to ensure that the target pixel point in the target window is in the original sliding window after reverse rotation, thereby reducing the error and improving the rotation accuracy. The whole technical scheme assigns the pixel value of the position where the corrected coordinate information is located on the image to be rotated to the position where the target coordinate information is located in the target window through the original sliding window to realize the rotation of the image to be rotated. The image to be rotated itself does not need to be rotated. The rotation result has high accuracy, small amount of calculation, fast processing speed, and easy implementation of the device. It is especially suitable for low-end devices, thereby expanding the application group.
[0053] The image rotation device provided by the embodiment of the present invention has an acquisition and rotation angle calculation unit in which the rotation angle is calculated, and the original coordinate information of the target pixel point in the original sliding window area of the image to be rotated is obtained by the original coordinate acquisition unit, and the target coordinate calculation unit determines the target coordinate information of the target pixel point in the target window, and the calculation amount is small; the original coordinate information of the target pixel point is corrected by the correction unit to ensure that the target pixel point in the target window is in the original sliding window after reverse rotation, thereby reducing errors and improving the rotation accuracy, and the operation is simple, no high configuration is required, and the device is easy to implement.
[0054] The computer device provided in the embodiment of the present invention assigns the pixel value of the position where the correction coordinate information is located on the image to be rotated to the position where the target coordinate information is located in the target window through the original sliding window, so as to realize the rotation of the image to be rotated. The image to be rotated does not need to be rotated itself, the rotation result has high accuracy, does not need to use a higher configuration, and the device is easy to implement.
[0055] The computer-readable storage medium provided by the present invention implements the image defect detection method by executing the stored computer program by a processor, and is applicable to low-configuration and high-configuration devices, which is conducive to promotion. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0057] in:
[0058] Figure 1 A schematic diagram of a flow chart of an embodiment of an image rotation method provided by the present invention;
[0059] Figure 2 A schematic diagram of the overlapping area in the sliding process of the original sliding window in step 102;
[0060] Figure 3 It is a schematic diagram of the rotation of the image to be rotated;
[0061] Figure 4 A schematic diagram of a flow chart of another embodiment of an image rotation method is provided;
[0062] Figure 5 A flowchart of the detailed steps of step 201;
[0063] Figure 6 A schematic diagram of the distribution of edge points when the image sensor scans the bill or banknote to be straightened;
[0064] Figure 7 It is a schematic diagram of an image to be rotated in a rectangular coordinate system;
[0065] Figure 8 A flowchart of the detailed steps of step 203;
[0066] Fig. 9 A structural block diagram of an image rotation device provided by the present invention;
[0067] Fig.10 This is a structural block diagram of the computer device provided by the present invention. DETAILED DESCRIPTION
[0068] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0069] See also Figure 1 , Figure 1 FIG. 1 is a flow chart of an image rotation method according to an embodiment of the present invention. Figure 1 As shown, the image rotation method includes:
[0070] Step 101: Acquire an image to be rotated, and determine a rotation angle of the image to be rotated according to the image to be rotated.
[0071] In the embodiment of the present application, an image to be rectified can be obtained, and the image to be rectified refers to an image corresponding to a bill or a banknote, etc. The bill can be a broad-sense securities and vouchers such as stocks, corporate bonds, invoices, bills of lading, etc., or a narrow-sense securities such as bank drafts, checks, bills of exchange, etc., which are only used for the purpose of paying money.
[0072] In order to better understand the technical solution of the present invention, a bill is taken as an object to be rotated and its image to be rotated is taken as an example to be explained, as follows:
[0073] The image to be rotated can be an image obtained by collecting an image of the bill through an image sensor. The image sensor can be a contact image sensor, such as a CIS (Contact Image Sensor), which is in contact with the bill. When the contact image sensor is working, the light emitted by the light source inside it is vertically and directly irradiated onto the bill surface to form pixel points one by one. The contour points forming the image to be rotated are found from the pixel points one by one, and the contour points are fitted into straight lines to form the edges of the image to be rotated, thereby obtaining the image to be rotated.
[0074] The image sensor may also be a non-contact image sensor, which may use a high-resolution non-contact image sensor to scan the bill to obtain a high-resolution image to be straightened, or may use a low-resolution non-contact image sensor to scan the bill to obtain a low-resolution image to be straightened. It is understood that the above image sensor is not limited, as long as the image sensor is a device with an image imaging function.
[0075] It should be noted that the image to be rotated can be a regular image, such as a rectangle, square, etc., or an irregular image. In the embodiment of the present application, a regular image is preferably used as the image to be rotated to eliminate the influence of irregular image factors and further improve the rotation accuracy of the image to be rotated.
[0076] In an embodiment of the present application, the rotation angle of the image to be rotated is determined based on the image to be rotated, wherein the rotation angle refers to the angle required to rotate the image to be rotated. It can be understood that the rotation angle is the tilt angle of the image to be rotated. Usually, the image to be rotated is rotated by an angle in the opposite direction of the original direction. For example, a rectangular coordinate system is established in the row and column directions scanned by the image sensor, and the image to be rotated is located at a position where the rectangular coordinate system is rotated 60° clockwise in the horizontal direction. The 60° is used as the rotation angle, and the image to be rotated can be rotated by rotating the image to be rotated 60° counterclockwise.
[0077] Step 102, obtaining original coordinate information of a target pixel point in the original sliding window area of the image to be rotated through the original sliding window, wherein the target pixel point is any pixel point in the original sliding window area;
[0078] Specifically, the window is a rectangular area, and the window can be divided into a sliding window and a fixed window, wherein a fixed window refers to a window with a certain size but no sliding step, and the fixed window does not slide, while a sliding window refers to a window with a certain size and a sliding step and can slide, and the sliding step is used to indicate the distance of each sliding of the sliding window. Therefore, in the embodiment of the present application, the image rotation method of the image to be rotated is implemented in the form of a window, which not only makes the device easy to implement, especially low-configuration devices can also implement the image rotation method, which expands the promotion, and based on the characteristics of the window, the processing speed of the image to be rotated is improved, and the rotation efficiency is improved.
[0079] In the embodiment of the present application, the original sliding window is slid to obtain the target pixel points in the image to be rotated, and the target pixel points in the corresponding original sliding window on the image to be rotated are subjected to relevant processing, the processed target pixel points are received through the fixed window, and the processed target pixel points are output. It can be understood that the fixed window is the target window, and the target image is output through the target window. The target image is an image composed of the processed target pixel points. It should be understood that the target image is the image after the image to be rotated is rotated.
[0080] Among them, the original coordinate information of the target pixel point in the original sliding window area in the image to be rotated is obtained through the original sliding window, and the target pixel point is any pixel point in the original sliding window area. It can be understood that the original sliding window obtains the same window size area on the image to be rotated for each sliding step length of the original sliding window on the image to be rotated, and the window size is the original sliding window area. Usually, the original sliding window is a rectangular window, and the window size is the product of the length and width of the rectangular window. Then, the number of target pixel points in the original sliding window area is the product of the length and width of the rectangular window. For example, if the window size of the original sliding window is 3*3 and the sliding step length is 1, then the original sliding window obtains 3*3=9 target pixel points in the row direction and the vertical direction at the position of the original sliding window on the image to be rotated for each sliding distance of the original sliding window on the image to be rotated.
[0081] In a feasible manner, the window size of the original sliding window may be equal to the size of the image to be rotated. That is, the area of the original sliding window is equal to the area of the image to be rotated. At this time, the area of the original sliding window is the area of the image to be rotated. It can be understood that at this time, the original sliding window does not need to slide, and the original coordinate information of any target pixel point on the image to be rotated is directly obtained through the original sliding window.
[0082] In another feasible manner, the window size of the original sliding window may be smaller than the size of the image to be rotated. In other words, the area of the original sliding window is smaller than the area of the image to be rotated, and then, each time the original sliding window slides a sliding step distance, only the target pixel points in a partial area of the image to be rotated are obtained. Usually, the sliding direction of the original sliding window is consistent with the scanning direction of the image sensor, so as to improve the accuracy of the original coordinate information of the target pixel points corresponding to the image to be rotated.
[0083] It should be noted that although the window size of the original sliding window can be larger than the size of the image to be rotated, if the window size of the original sliding window is larger than the size of the image to be rotated, only the target pixels in a part of the original sliding window area (the area corresponding to the image to be rotated) are obtained, which will lead to the waste of the rest of the original sliding window area, not only occupying too much storage space, but also causing waste of resources and increasing costs.
[0084] Therefore, before implementing the rotation method of the image to be rotated, the window size and sliding step of the original sliding window need to be pre-configured. In the embodiment of the present application, the window size of the configured original sliding window is smaller than the size of the image to be rotated, and the length of the window size is greater than the value corresponding to the step length, so that the original sliding window slides a sliding step distance each time, so that the original sliding window area corresponding to the previous sliding step length and the original sliding window area corresponding to the next sliding step length have an overlapping area, so that the missing point phenomenon is not easy to occur, and the accuracy of image rotation is improved.
[0085] For example: Figure 2 As shown, the window size of the original sliding window is 48*48, the sliding step is set to 24, and the upper left corner vertex of the original sliding window initially coincides with the upper left corner vertex of the image to be rotated. The original sliding window moves horizontally by a sliding step distance. Since the sliding step 24 is less than the length of the window size 48, the original sliding window area initially has a first overlapping area with the original sliding window area after horizontal movement. The first overlapping area corresponds to Figure 2 Similarly, the original sliding window moves vertically by a sliding step length, and then the original sliding window area at the beginning and the original sliding window area after the vertical movement have a second overlapping area, and the second overlapping area corresponds to Figure 2The vertical lines shown fill the area.
[0086] It should be noted that the window size of the original sliding window may also be equal to the sliding step length, and the original sliding window does not have an overlapping area during the sliding process. In other words, the previous original sliding window area and the next original sliding window area are adjacent and non-separated areas.
[0087] The original coordinate information of the target pixel point within the original sliding window area on the image to be rotated is obtained through the original sliding window as follows: the vertex in the upper left corner of the image to be rotated is taken as the origin, the row direction scanned by the image sensor is taken as the vertical axis direction, and the column direction is taken as the horizontal axis direction to establish a rectangular coordinate system, so as to obtain the original coordinate information of any target pixel point according to the rectangular coordinate system.
[0088] In another feasible way, in order to reduce the amount of calculation, the center pixel point on the image to be rotated can be used as the origin, the row direction scanned by the image sensor can be used as the vertical axis direction, and the column direction can be used as the horizontal axis direction to establish a rectangular coordinate system. There is a certain proportional relationship between the center pixel point and the remaining pixel points. Therefore, the original coordinate information of the remaining pixel points can be obtained only based on the original coordinate information and proportional relationship of the center pixel point. In other words, when a rectangular coordinate system is established with the center point in the original sliding window area as the origin, and the target coordinate information when the target pixel point is the center point is calculated, for the remaining pixel points in the original sliding window, the target coordinate information corresponding to the remaining pixel points in the target window is determined according to the proportional relationship and the center coordinate information of the target window. Among them, the center coordinate information of the target window is the target coordinate information corresponding to the center point of the original sliding window in the target window.
[0089] Step 103, determining the target coordinate information of the target pixel point in the target window after rotation according to the original coordinate information of the target pixel point and the rotation angle;
[0090] In the embodiment of the present application, the target window is a fixed window, and the target window is used to output the target pixel point after rotation, so as to obtain the target image. That is to say, the target pixel point in the original sliding window area in step 102 is rotated and then output in the target window. It can be understood that the original coordinate information of the target pixel point in the original sliding window area is rotated by an angle to obtain the target coordinate information of the target pixel point, and the target pixel point is output through the target window according to the target coordinate information.
[0091] The preset rotation formula is derived from the original coordinate information of the target pixel, the target coordinate information and the corresponding mapping relationship. The derivation process of the rotation formula is:
[0092] like Figure 3As shown in the figure, it is assumed that the original coordinate information of a pixel point in the original sliding window area of the image to be rotated is (x 0 ,y 0 ), the target coordinate information of the pixel point is (x, y), the pixel point at the original coordinate information is rotated through an angle of θ to reach the target coordinate information, the distance between the pixel point and the vertex corresponding to the image to be rotated is r, wherein the angle between the pixel point at the original coordinate information and the row direction scanned by the image sensor is α.
[0093] Then, the original coordinate information of the pixel point (x 0 ,y 0 ) The corresponding formula is:
[0094]
[0095] The formula corresponding to the target coordinate information (x, y) of the pixel point after rotation by angle θ is expressed as:
[0096]
[0097] By transforming formula (2) and substituting formula (1) into the transformed formula (2), we can obtain formula (3) corresponding to the target coordinate information (x, y), as shown below:
[0098]
[0099] Formula (3) is used as the preset rotation formula. Therefore, according to the preset rotation formula, the original coordinate information of the target pixel point and the rotation angle, the target coordinate information corresponding to the target pixel point in the target window after rotation can be calculated.
[0100] Step 104: determining, according to the target coordinate information and the rotation angle, corrected coordinate information of the target pixel point in the original sliding window after reverse rotation;
[0101] In the embodiment of the present application, the image corresponding to the original sliding window area is continuously rotated during the sliding process of the original sliding window. The rotation process is essentially just the coordinate conversion of any target pixel point on the image to be rotated, from the original coordinate information to the target coordinate information. The pixel value of the target pixel point remains unchanged during the rotation process. In other words, the pixel value corresponding to the target pixel point at the original coordinate information can be used as the pixel value of the target pixel point at the target coordinate information.
[0102] Since the target pixel point corresponding to the original coordinate information in the original sliding window deduced from the calculated target coordinate information may be empty, the target pixel point may be a floating point, so that the pixel value of the target pixel point obtained by the target window is an empty value. Therefore, in order to improve data accuracy and reduce errors, it is necessary to correct the coordinate information of the target pixel point in the original sliding window through the target coordinate information of the target pixel point in the target window, and use the corrected coordinate information as the original coordinate information of the target pixel point in the original sliding window after reverse rotation, that is, the corrected coordinate information as the corrected coordinate information.
[0103] That is to say, the target window calculates the corrected coordinate information corresponding to the target pixel after reverse rotation in the original sliding window through a preset reverse derivation rotation formula, the target coordinate information of the target pixel point and the rotation angle.
[0104] Step 105: determine the pixel value at the position where the corrected coordinate information is located as the pixel value of the target pixel point at the position corresponding to the target coordinate information, and use the image in the target window as the rotated image of the image to be rotated.
[0105] In the embodiment of the present application, based on step 104, the calculated corrected coordinate information of the target pixel point in the original sliding window after reverse rotation is obtained. Then, based on the corrected coordinate information of the target pixel point, the pixel value at the corrected coordinate information on the image to be rotated is obtained. Then, the target window assigns the pixel value to the position where the target coordinate information is located, that is, the pixel value at the position where the corrected coordinate information is located is used as the pixel value at the corresponding position of the target coordinate information. In this way, when the original sliding window slides to the end pixel point of the image to be rotated, the final target image is obtained through the target window, and the target image is the image after the image to be rotated is rotated.
[0106] Based on step 101 to step 105, the original coordinate information of the target pixel point in the original sliding window area in the image to be rotated is obtained by sliding the original sliding window, so as to determine the target coordinate information of the target pixel point in the target window. The calculation is simple and the amount of calculation is small, which reduces the calculation complexity. In addition, the corresponding image in the original sliding window area is continuously rotated during the sliding process of the original sliding window, and the rotated image is output by the target window, which shortens the rotation time and improves the rotation efficiency. In addition, the original coordinate information of the target pixel point is corrected according to the target coordinate information of the target pixel point in the target window to ensure that the target pixel point in the target window is in the original sliding window after reverse rotation, thereby reducing errors and improving the rotation accuracy. Then, the pixel value of the position where the corrected coordinate information is located on the image to be rotated is assigned to the position where the target coordinate information is located in the target window, so as to achieve the purpose of rotation. In this way, there is no need to rotate the image to be rotated itself, which greatly improves the image rotation effect.
[0107] To better understand the technical solutions in the embodiments of this application, please refer to Figure 4 , is another flow chart of the image rotation method in an embodiment of the present application, the method comprising:
[0108] Step 201, obtaining an image to be rotated;
[0109] It is understandable that the content described in this step is the same as Figure 1 Part of the contents described in step 101 in the embodiment shown are similar, and can be found in detail. Figure 1 The relevant contents in step 101 in the illustrated embodiment are not described in detail here.
[0110] In one possible approach, see Figure 5 , Figure 5 The detailed steps of step 201 include:
[0111] S2011, obtaining a number of pixel points of the image to be rotated by scanning the object to be measured;
[0112] S2012, determining edge points corresponding to any three sides of the image to be rotated from a plurality of pixel points in the horizontal and vertical directions for fitting;
[0113] S2013, using the least square method to fit the edge points corresponding to any three sides of the image to be rotated, respectively, to obtain three fitting straight lines;
[0114] S2014: Determine the image to be rotated by using the three fitting straight lines.
[0115] Specifically, the object to be straightened refers to a bill or banknote to be straightened, which can be scanned by an image sensor. In order to better understand the technical solution of this embodiment, the bill to be straightened is used as the object to be measured, and the image of the bill to be straightened is used as the image to be straightened as an example for explanation, specifically:
[0116] The image sensor may be a contact image sensor, such as a CIS. Since the outline of the bill to be straightened is regular, the image to be straightened can be determined by determining any three edges of the image to be straightened, thereby reducing the processing load and improving the detection efficiency.
[0117] When the image sensor collects the image to be rotated, it scans the bill from top to bottom to form scattered pixels, and it is necessary to find the contour points constituting the image to be rotated from the scattered pixels, that is, the edge points in the embodiment of the present application. After finding the edge points of any three sides of the image to be rotated, the edge points corresponding to the same side are fitted to obtain a straight line (or edge), and then the other sides are fitted using the same method, so as to finally combine the image to be rotated.
[0118] In the process of fitting edge points into edges, there are some points on non-straight lines that are added to the fitting operation. This will reduce the fitting accuracy, affect the quality of the image to be rotated, and then affect the accuracy of the subsequent slope calculation of the edge, increasing the error. Therefore, in the embodiment of the present application, the fitting operation is performed by adopting the least squares method. The least squares method can minimize the error between the fitted edge and the actual edge of the bill, and in the fitting process, the best matching edge point with the fitted edge can be found by minimizing the square of the error, thereby improving the fitting accuracy, improving the quality of the image to be rotated, and improving the accuracy of the calculation.
[0119] To further understand the technical solution of steps S2011-2014, please refer to Figure 6 and Figure 7 , Figure 6 The diagram shows the distribution of edge points when the image sensor scans the bill to be straightened. Figure 7 The following is a schematic diagram of an image to be rotated in a rectangular coordinate system. Figure 6 and Figure 7 As shown, the image sensor scans the bill from top to bottom, the row direction scanned by the image sensor is the y direction in the rectangular coordinate system, and the column direction scanned by the image sensor is the x direction in the rectangular coordinate system. Figure 6 In the method, the starting point of scanning is the corner point in the bill to be rotated, which is located at the starting position where the row direction and the column direction intersect. The points in the row direction include the starting point and the tail point, and the points in the column direction include the upper edge point and the lower edge point. It is determined that the left side of the image to be rotated includes the starting point and the upper edge point, the upper side includes the upper edge point and the tail point, the lower side includes the lower edge point and the starting point, and the right side includes the tail point. In this way, when scanning the bill, the edge points of any three sides of the image to be rotated are first determined, for example: the edge points corresponding to the upper side, the left side and the lower side of the image to be rotated are first determined, and then the edge points of the three sides are fitted by the least square method to obtain three fitting lines. The three fitting lines are connected, and the fourth side of the image to be rotated is parallel to the left side, and then the image to be rotated is obtained.
[0120] Step 202, obtaining original coordinate information of a target pixel point in an original sliding window area in the image to be rotated through the original sliding window;
[0121] It is understandable that the content described in this step is the same as Figure 1 Part of the contents described in step 102 in the embodiment shown are similar, and can be found in detail. Figure 1 The relevant contents in step 102 in the illustrated embodiment are not described in detail here.
[0122] Step 203: Determine the rotation angle of the image in the original sliding window area according to the original coordinate information of the target pixel point, the preset horizontal dpi parameter and the vertical dpi parameter.
[0123] In the embodiment of the present application, dpi (Deep Packet Inspection) refers to the number of sampled, displayable or output points in each inch of length. The horizontal dpi parameter refers to the horizontal resolution of the light source scanning inside the image sensor, that is, the number of pixels in one inch of length in the horizontal direction (or X-axis, horizontal direction); the vertical dpi parameter refers to the vertical resolution of the image sensor scanning, that is, the number of pixels in one inch of length in the vertical direction (or Y-axis, vertical direction).
[0124] For example: the resolution of an image is 4800*1200dpi, where 4800 is the horizontal dpi parameter value, so 4800 pixels can be placed on every inch of length in the horizontal direction, and 1200 is the vertical dpi parameter value, so 1200 pixels can be placed on every inch of length in the vertical direction.
[0125] In one possible approach, Figure 8 As shown, step 203 is a detailed step, including:
[0126] Step 2031, obtaining preset horizontal dpi parameters and vertical dpi parameters, and determining the proportional relationship between the horizontal and vertical dpi parameters;
[0127] Step 2032: obtaining original coordinate information of a target pixel point on a target edge of the image to be rotated, and calculating a slope of a target edge curve of the image to be rotated according to the proportional relationship, the original coordinate information and a preset slope calculation formula;
[0128] Step 2033: Obtain a rotation angle of the image to be rotated according to the target edge curve slope and a preset inverse trigonometric function formula.
[0129] Specifically, the image in the original sliding window area is taken as the first image. Then, the target edge curve slope of the first image can be calculated according to the preset slope calculation formula, the proportional relationship of the horizontal and vertical dpi parameters, and the original coordinate information of the target pixel point on the first image. Wherein, the slope refers to the amount of inclination of a straight line (or the tangent of the curve) with respect to the coordinate axis, which is usually expressed by the tangent of the angle between the straight line (or the tangent of the curve) and the coordinate axis, or the ratio of the difference between the ordinates of two points and the difference between the abscissas. It can be understood that the original coordinate information is the horizontal and vertical coordinate information of any pixel point on the target edge in the first image, and the target edge is any one of the four sides on the first image. Then, the target edge curve slope is the tangent of the angle between the target edge and the abscissa axis or the ordinate axis of the plane rectangular coordinate system. That is to say, the target edge curve slope can be the horizontal edge curve slope or the vertical edge curve slope. The above preset slope calculation formula can be a tangent function formula. The preset inverse trigonometric function formula can be an inverse tangent function formula.
[0130] Then, the value of the slope of the target edge curve is substituted into the inverse tangent function formula to calculate the rotation angle of the first image.
[0131] In another feasible manner, in order to reduce the amount of calculation, the angle corresponding to the value of the slope of the target edge curve may be directly queried through an inverse tangent function table, and the angle may be used as the rotation angle of the first image.
[0132] It should be noted that since the first image is a partial image of the original image, the original image is the entire image corresponding to the bill, that is, the original image includes the first image, and the first image may be tilted or not. Therefore, before calculating the rotation angle of the first image, it is necessary to confirm whether the first image is tilted, so that the tilted first image is used as the image to be rotated.
[0133] Among them, determining whether the first image is the image to be rotated specifically includes: based on the four sides of the first image, determining a plurality of target edge groups, each target edge group including a reference edge and an edge to be rotated corresponding to the reference edge, and the reference edge is any edge of the first image; then calculating the angle difference between a first angle corresponding to the reference edge in the current target edge group and a second angle corresponding to the edge to be rotated after rotation; if the absolute value of the angle difference meets a preset condition, determining that the first image corresponding to the target edge group is the image to be rotated.
[0134] Among them, the first angle corresponding to the reference edge is obtained by the slope of the first edge curve corresponding to the reference edge, and the second angle corresponding to the edge to be rotated after rotation is obtained by the slope of the second edge curve corresponding to the rotated edge to be rotated. The calculation method of the first edge curve slope and its first angle adopts the same method as steps 2031 to 2033, so it will not be repeated. Similarly, the calculation method of the second edge curve slope corresponding to the edge to be rotated after a preset angle and its corresponding second angle also adopts the same method as steps 2031 to 2033, so it will not be repeated. Among them, the preset angle is preferably 90° in the embodiment of the present application, so that the edge to be rotated can be parallel to the reference edge after rotation of 90°, so as to judge whether the first image is the image to be rotated based on the parallelism.
[0135] It should be noted that the first edge curve slope includes the horizontal edge curve slope or the vertical edge curve slope. The second edge curve slope also includes the horizontal edge curve slope or the vertical edge curve slope. If the first edge curve slope is the horizontal edge curve slope, the second edge curve slope is the vertical edge curve slope. If the first edge curve slope is the vertical edge curve slope, the second edge curve slope is the horizontal edge curve slope.
[0136] The above-mentioned preset condition may be a preset angle threshold. The first angle is subtracted from the second angle to obtain an angle difference. Since the first angle may be less than the second angle, or greater than the second angle, or equal to the second angle, the angle difference may be less than zero, greater than zero, or equal to zero. Therefore, the absolute value of the angle difference is compared with the preset angle threshold, and then the comparison result is used to determine whether the first image can be used as the image to be rotated. If the absolute value of the angle difference calculated for a target edge group is less than or equal to the preset angle threshold, the first image corresponding to the target edge group is used as the image to be rotated. If the absolute value of the angle difference is greater than the preset angle threshold, the next target edge group is selected and the same operation is performed. If the angle differences of all target edge groups are greater than or equal to the preset angle threshold, the first image corresponding to any target edge group is not the image to be rotated, indicating that the image has defects or angle folds.
[0137] In order to further understand this step, a specific example is used to illustrate it as follows:
[0138] The corresponding relationship between the reference edge in the target edge group and the edge to be rotated corresponding to the reference edge is as follows:
[0139] Reference Edge Waiting for turning Left side (edge) right Right side (edge) left Top edge left Top edge right Bottom edge left Bottom edge right
[0140] A. Select the left edge as the reference edge and the right edge as the edge to be rotated, and rotate the edge to be rotated by a preset angle to obtain the edge to be rotated after rotation. In the embodiment of the present application, the preset angle is preferably 90°. The setting of the preset angle is not limited and can be set according to needs, such as -270°.
[0141] Then the slope of the reference side is calculated as The corresponding first angle is θ l And the slope of the edge to be rotated after rotation is The corresponding second angle, the angle difference satisfies |θ l -θ r_90 |<preset angle threshold. In the present embodiment, the preset angle threshold is preferably 0.5°. It should be noted that the preset angle threshold is not limited. As long as the side to be rotated is parallel to the reference side after rotation, once the absolute value of the angle difference meets the preset condition, it is preliminarily determined that the first image is tilted and can be used as the image to be rotated. If the preset condition is not met, the process jumps to case B.
[0142] B. Use the same operation method as A, that is, select the right edge as the reference edge, the left edge as the edge to be rotated, and the edge obtained by rotating the edge to be rotated by a preset angle as the rotated edge to be rotated. In this embodiment, the preset angle is preferably 90°. The setting of the preset angle is not limited and can be set according to needs, such as -270°.
[0143] Then the slope of the reference side is calculated as The corresponding first angle is θ r And the slope of the side to be rotated after rotation is The corresponding second angle θ l_90 , whether the absolute value of the angle difference satisfies |θ r -θ l_90 |<0.5°, once the absolute value of the angle difference meets the preset condition, it is preliminarily determined that the first image is tilted and can be used as the image to be rotated. If it does not meet the preset condition, it jumps to situation C;
[0144] C. Select the upper edge as the reference edge and the left edge as the edge to be rotated, and rotate the edge to be rotated by a preset angle to obtain the edge to be rotated after rotation. In this embodiment, the preset angle is preferably 90°. The setting of the preset angle is not limited and can be set according to needs, such as -270°.
[0145] Then the slope of the reference side is calculated as The corresponding first angle is θ up And the slope of the side to be rotated after rotation is The corresponding second angle θ l_90 , whether the absolute value of the angle difference satisfies |θ up -θl_90 |<0.5°, once the absolute value of the angle difference meets the preset condition, it is preliminarily determined that the first image is tilted and can be used as the image to be rotated. If the preset condition is not met, jump to situation D;
[0146] D. Select the upper edge as the reference edge and the right edge as the edge to be rotated, and rotate the edge to be rotated by a preset angle to obtain the edge to be rotated after rotation. In this embodiment, the preset angle is preferably 90°. The setting of the preset angle is not limited and can be set according to needs, such as -270°.
[0147] Then the slope of the reference side is calculated as The corresponding first angle is θ up And the slope of the edge to be rotated after rotation is The corresponding second angle θ r_90 , whether the absolute value of the angle difference satisfies |θ up -θ r_90 |<0.5°, once the absolute value of the angle difference meets the above conditions, it is preliminarily determined that the first image is tilted and can be used as the image to be rotated. If the preset conditions are not met, jump to situation E;
[0148] E. If none of the above conditions are met, it is determined that the first image does not belong to the image to be rotated, and it has defects or large fold angles, and an error is reported.
[0149] Among them, the above k r , k up , k l They are respectively the slope of the target edge curve corresponding to the right edge, the slope of the target edge curve corresponding to the upper edge, and the slope of the target edge curve corresponding to the left edge. r is the dpi ratio in the horizontal and vertical directions, a is the dpi parameter in the horizontal direction, b is the dpi parameter in the vertical direction, and θ is the angle between the reference edge and the y-axis.
[0150] It should be understood that to determine whether the first image can be used as the image to be rotated, at most three judgments are performed, that is, at most, whether the first image is the image to be rotated can be determined by whether the absolute value of the angle difference between the three reference edges and their corresponding edges to be rotated meets the rotation condition. Of course, if one edge satisfies the angle difference and meets the rotation condition, the first image can be determined to be the image to be rotated, and there is no need to judge again whether the absolute value of the angle difference corresponding to other edges meets the rotation condition. If the absolute value of the angle difference between the first angle of the slope of the edge curve corresponding to any reference edge of the first image and the second angle of the slope of the edge curve after the corresponding edge to be rotated does not meet the preset condition, it is determined that the first image is not the image to be rotated.
[0151] Step 204: Determine the target coordinate information of the target pixel point in the target window after rotation according to the original coordinate information of the target pixel point and the rotation angle;
[0152] In the embodiment of the present application, the preset rotation formula is the formula (3) illustrated in step 103:
[0153]
[0154] Therefore, the detailed steps of step 204 include: obtaining the rotation angle of the first image, looking up the table to obtain the sine value and cosine value corresponding to the rotation angle, substituting the original coordinate information of the target pixel point, the sine value and cosine value corresponding to the rotation angle into formula (3), and calculating the target coordinate information of the target pixel point in the target window. The target coordinate information of the remaining target pixel points on the first image is calculated in the same way as the target coordinate information of the target pixel point. It should be noted that the original coordinate information of the above-mentioned target pixel point is obtained by establishing a rectangular coordinate system with the upper left corner vertex of the first image as the origin, and the target coordinate information of the target pixel point in the target window is also obtained by establishing a rectangular coordinate system with the upper left corner vertex of the image in the target window area as the origin.
[0155] In another feasible method, in order to reduce the amount of calculation of the original coordinate information of the target pixel point and the corresponding target coordinate information and reduce the calculation complexity, a rectangular coordinate system can be established with the central pixel point of the first image as the origin, so that the horizontal and vertical coordinate values corresponding to the original coordinate information of the remaining pixel points in the first image are reduced, and then the amount of calculation of the target coordinate information calculated based on the original coordinate information of the remaining pixel points is also reduced.
[0156] That is to say, before the first image is rotated, the original coordinate information of each target pixel in the first image is transformed based on the center pixel of the first image, so as to obtain the relative coordinate information of the remaining target pixels equivalent to the center pixel of the first image. The relative coordinate information of the remaining target pixels is used as the new original coordinate information of the remaining target pixels. Specifically, the center point on the first image is used as the origin for illustration. Assume that the original coordinate information of any remaining target pixel on the first image is (x 0 ,y 0 ), rotation angle θ, number of rows m, number of columns n, width W, height H of the original image, the ratio of the remaining target pixels to the center pixel (0,0) is p, then the original coordinate information corresponding to the remaining target pixels of the first image is converted into the new original coordinate information (x 1 ,y 1 ), which is expressed as follows:
[0157]
[0158] Based on formula (4), the new original coordinate information of each target pixel on the first image is obtained, the sine value and cosine value of the rotation angle of the first image are obtained, and the new original coordinate information of each target pixel, the sine value and cosine value of the rotation angle are substituted into the following formula (5) to obtain the new target coordinate information (x) of each target pixel on the first image within the target window. 1 ,y 1 ), which is expressed as follows:
[0159]
[0160] In another feasible method, if a rectangular coordinate system is established with the center point of the first image as the origin, it is only necessary to calculate the target coordinate information corresponding to the target pixel point being the center point of the first image; wherein the target coordinate information corresponding to the center point of the first image in the target window is the center coordinate information of the target window; the proportional relationship between the position of the center point in the target window and the positions of the remaining points is obtained; based on the proportional relationship and the center coordinate information of the target window, the target coordinate information corresponding to the target pixel in the target window for the remaining points can be obtained.
[0161] Step 205: Determine, according to the target coordinate information and the rotation angle, the corrected coordinate information of the target pixel point in the original sliding window after reverse rotation;
[0162] In the embodiment of the present application, since the rotation angle is determined according to the slope of the target edge curve, when calculating the slope of the target edge curve, since the correlation between the slope of the horizontal edge curve and the slope of the vertical edge curve is related to the dpi parameters of the image sensor in the horizontal and vertical directions for collecting the image to be rotated, it is necessary to consider the dpi parameters of the image sensor in the horizontal and vertical directions when calculating the slope of the target edge curve.
[0163] Specifically, if the dpi parameters in the horizontal and vertical directions are equal, it means that the rotation angle θ corresponding to the slope of the edge curve in the horizontal direction and the rotation angle α corresponding to the slope of the edge curve in the vertical direction are equal, that is, θ=α. Then, the preset reverse derivation rotation formula adopted according to the rotation direction is as follows:
[0164]
[0165] Among them, the corrected coordinate information is (x_pian, y_pian).
[0166] If the dpi parameters in the horizontal and vertical directions are not equal, the rotation angle θ corresponding to the slope of the edge curve in the horizontal direction and the rotation angle α corresponding to the slope of the edge curve in the vertical direction are not equal, then,
[0167] The preset reverse rotation formula used according to the rotation direction is as follows:
[0168]
[0169] It should be noted that the process of converting the original coordinate information of the target pixel point into the target coordinate information through the original sliding window also needs to determine the rotation direction of the first image. The rotation direction of the first image is determined specifically as follows: obtaining the slope of the target edge curve obtained in step 2032, and then comparing the slope of the target edge curve with zero; if the slope of the target edge curve is greater than zero, it means that the slope of the target edge curve is a positive value, thereby determining that the rotation direction of the original coordinate information of the target pixel point converted into the target coordinate information is a clockwise direction; if the slope of the target edge curve is less than zero, it means that the slope of the target edge curve is a negative value, thereby determining that the rotation direction of the original coordinate information of the target pixel converted into the target coordinate information is a counterclockwise direction.
[0170] Taking the case where the dpi parameters in the horizontal and vertical directions are equal and a rectangular coordinate system is established with the center point of the first image as the origin as an example, the calculation process of the corrected coordinate information of the target pixel point is explained. The details are as follows:
[0171] If the rotation direction is clockwise, the corresponding relationship between the target coordinate information and the rotation angle of the target pixel point is as follows:
[0172]
[0173] According to formula (8), the sine value, cosine value and new target coordinate information of the rotation angle are obtained. Substitute the data obtained by formula (8) into formula (6) to obtain the target pixel point (x 1 ,y 1 ) is the corrected coordinate information (x_pian, y_pian) within the original sliding window after reverse rotation.
[0174] If the rotation direction is counterclockwise, the corresponding relationship between the target coordinate information and the rotation angle is as follows:
[0175]
[0176] According to formula (9), the sine value, cosine value and new target coordinate information of the rotation angle are obtained. Substituting the data obtained by formula (9) into formula (6), the target pixel point (x 1 ,y 1 ) is the corrected coordinate information (x_pian, y_pian) within the original sliding window after reverse rotation.
[0177] Step 206: determine the pixel value at the position where the corrected coordinate information is located as the pixel value of the target pixel point at the position corresponding to the target coordinate information, and use the image in the target window as the rotated image of the image to be rotated.
[0178] In the embodiment of the present application, the corrected coordinate information (x_pian, y_pian) corresponding to step 205 is obtained, the target pixel point at the corrected coordinate information (x_pian, y_pian) in the image to be rotated is searched, and the pixel value of the target pixel point is obtained.
[0179] Then the target window assigns the pixel value to the position where the target coordinate information is located, that is, the pixel value at the position where the corrected coordinate information is located is used as the pixel value at the position corresponding to the target coordinate information. In this way, several images after the first image is rotated are obtained through the target window. When the original sliding window slides to the end pixel point of the image to be rotated, the image after the image to be rotated is obtained through the target window, that is, the target image.
[0180] It should be noted that the window size of the target window is configured according to the window size of the original sliding window. Assuming that the window length of the original sliding window is nl and the width is nw, determine the maximum rotation angle that can support the rotation of the image to be rotated. In the embodiment of the present application, the maximum rotation angle is 45° to ensure that the image to be rotated can implement the image rotation method. Based on the maximum rotation angle corresponding to the rotation of the image to be rotated, the maximum value of the window length of the target window is the product of the window length of the original sliding window and the cosine value of the maximum rotation angle. In other words, the window length of the target window only needs to be in the interval of (0, nl*cos maximum rotation angle), then the image after the rotation of the image to be rotated can be output through the target window.
[0181] It is understandable that if the calculated rotation angle exceeds the maximum rotation angle, it means that the image to be rotated is abnormal, and there may be a folded angle or defect, and there is no need to perform subsequent image rotation operations.
[0182] In this way, the technical solution provided by the embodiment of the present invention obtains the original coordinate information of the target pixel point in the original sliding window area in the image to be rotated by sliding the original sliding window, so as to determine the target coordinate information of the target pixel point in the target window. The calculation is simple and the amount of calculation is small, which reduces the calculation complexity. In addition, the corresponding image in the original sliding window area is continuously rotated during the sliding process of the original sliding window, and the rotated image is output by the target window, which shortens the rotation time and improves the rotation efficiency. Moreover, the original coordinate information of the target pixel point is corrected according to the target coordinate information of the target pixel point in the target window to ensure that the target pixel point in the target window is in the original sliding window after reverse rotation, thereby reducing errors and improving the rotation accuracy. Then, the pixel value of the position where the corrected coordinate information is located on the image to be rotated is assigned to the position where the target coordinate information is located in the target window, so as to achieve the purpose of rotation. It is not necessary to rotate the image to be rotated itself, which greatly improves the image rotation effect.
[0183] See also Fig. 9 , is a schematic diagram of the structure of an image rotation device in an embodiment of the present application, the device comprises:
[0184] The acquisition and rotation angle calculation unit 10 is used to acquire the image to be rotated and determine the rotation angle of the image to be rotated according to the image to be rotated;
[0185] An original coordinate acquisition unit 20 is used to acquire original coordinate information of a target pixel point in an original sliding window area in the image to be rotated through an original sliding window, wherein the target pixel point is any pixel point in the original sliding window area;
[0186] A target coordinate calculation unit 30 is used to determine the target coordinate information of the target pixel point after rotation in the target window according to the original coordinate information of the target pixel point and the rotation angle;
[0187] A correction unit 40, configured to determine, according to the target coordinate information and the rotation angle, the corrected coordinate information of the target pixel point in the original sliding window after reverse rotation;
[0188] The target image determination unit 50 is used to determine the pixel value at the position where the correction coordinate information is located as the pixel value of the target pixel point at the position corresponding to the target coordinate information, and use the image in the target window as the image after rotation of the image to be rotated.
[0189] It should be noted that the relevant contents of the above-mentioned acquisition and rotation angle calculation unit 10, the original coordinate acquisition unit 20, the target coordinate calculation unit 30, the correction unit 40 and the target image determination unit 50 can be referred to. Figures 1 to 8 The contents described in are not repeated here.
[0190] The image rotation device provided by the embodiment of the present invention has an acquisition and rotation angle calculation unit in which the rotation angle is calculated, and the original coordinate information of the target pixel point in the original sliding window area of the image to be rotated is obtained by the original coordinate acquisition unit, and the target coordinate calculation unit determines the target coordinate information of the target pixel point in the target window, and the calculation amount is small; the original coordinate information of the target pixel point is corrected by the correction unit to ensure that the target pixel point in the target window is in the original sliding window after reverse rotation, thereby reducing errors and improving the rotation accuracy, and the operation is simple, no high configuration is required, and the device is easy to implement.
[0191] Fig.10 FIG. 1 shows an internal structure diagram of a computer device in an embodiment. The computer device may be a terminal or a server. Fig.10 As shown, the computer device includes a processor, a memory and a network interface connected via a system bus. The memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system and may also store a computer program. When the computer program is executed by the processor, the processor can implement the age recognition method. The internal memory may also store a computer program. When the computer program is executed by the processor, the processor can implement the age recognition method. Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0192] In one embodiment, a computer device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the following steps:
[0193] Acquire an image to be rotated, and determine a rotation angle of the image to be rotated according to the image to be rotated;
[0194] Acquire original coordinate information of a target pixel point in the original sliding window area in the image to be rotated through the original sliding window, wherein the target pixel point is any pixel point in the original sliding window area;
[0195] Determine the target coordinate information of the target pixel point in the target window after rotation according to the original coordinate information of the target pixel point and the rotation angle;
[0196] Determine, according to the target coordinate information and the rotation angle, the corrected coordinate information of the target pixel point within the original sliding window after reverse rotation;
[0197] The pixel value at the position where the corrected coordinate information is located is determined as the pixel value of the target pixel point at the position corresponding to the target coordinate information, and the image in the target window is used as the rotated image of the image to be rotated.
[0198] The computer device provided in the embodiment of the present invention assigns the pixel value of the position where the correction coordinate information is located on the image to be rotated to the position where the target coordinate information is located in the target window through the original sliding window, so as to realize the rotation of the image to be rotated. The image to be rotated does not need to be rotated itself, the rotation result has high accuracy, does not need to use a higher configuration, and the device is easy to implement.
[0199] In one embodiment, a computer-readable storage medium is provided, storing a computer program, wherein when the computer program is executed by a processor, the processor performs the following steps:
[0200] Acquire an image to be rotated, and determine a rotation angle of the image to be rotated according to the image to be rotated;
[0201] Acquire original coordinate information of a target pixel point in the original sliding window area in the image to be rotated through the original sliding window, wherein the target pixel point is any pixel point in the original sliding window area;
[0202] Determine the target coordinate information of the target pixel point in the target window after rotation according to the original coordinate information of the target pixel point and the rotation angle;
[0203] Determine, according to the target coordinate information and the rotation angle, the corrected coordinate information of the target pixel point within the original sliding window after reverse rotation;
[0204] The pixel value at the position where the corrected coordinate information is located is determined as the pixel value of the target pixel point at the position corresponding to the target coordinate information, and the image in the target window is used as the rotated image of the image to be rotated.
[0205] The computer-readable storage medium provided by the present invention implements the image defect detection method by executing the stored computer program by a processor, and is applicable to low-configuration and high-configuration devices, which is conducive to promotion.
[0206] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0207] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0208] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. An image rotation method, the image rotation method comprising: Acquire an image to be rotated, and determine a rotation angle of the image to be rotated according to the image to be rotated; Acquire original coordinate information of a target pixel point in the original sliding window area in the image to be rotated through the original sliding window, wherein the target pixel point is any pixel point in the original sliding window area; Determine the target coordinate information of the target pixel point in the target window after rotation according to the original coordinate information of the target pixel point and the rotation angle; Determine, according to the target coordinate information and the rotation angle, the corrected coordinate information of the target pixel point within the original sliding window after reverse rotation; The pixel value at the position where the corrected coordinate information is located is determined as the pixel value of the target pixel point at the position corresponding to the target coordinate information, and the image in the target window is used as the rotated image of the image to be rotated.
2. The method according to claim 1, characterized in that The step of determining target coordinate information of the target pixel point in the target window after rotation according to the original coordinate information of the target pixel point and the rotation angle includes: Obtaining the rotation angle of the image to be rotated, the original coordinate information of the target pixel point and a preset rotation formula; Obtaining the sine value and cosine value of the rotation angle; The original coordinate information, the sine value and the cosine value of the rotation angle are substituted into the preset rotation formula to obtain the target coordinate information of the target pixel point in the target window.
3. The method according to claim 2, characterized in that The target pixel point is used as the remaining pixel points except the center point of the target window, and the target coordinate information of the target pixel point after rotation in the target window is determined according to the original coordinate information of the target pixel point and the rotation angle, including: Obtaining the proportional relationship between the center point position of the target window and the positions of the remaining pixels; The target coordinate information corresponding to the remaining pixel points in the target window is determined according to the proportional relationship and the target coordinate information corresponding to the center point of the target window.
4. The method according to claim 1, characterized in that The step of determining, according to the target coordinate information and the rotation angle, the corrected coordinate information of the target pixel point in the original sliding window after reverse rotation, comprises: Obtaining the length and width of the image to be rotated and the target coordinate information corresponding to the target pixel point; Determining a rotation direction of the image to be rotated, and selecting a reverse rotation formula corresponding to the rotation direction according to the rotation direction; The length, width, rotation angle and target coordinate information corresponding to the target pixel point are substituted into the reverse rotation formula to obtain the corrected coordinate information of the target pixel point in the original sliding window after reverse rotation.
5. The method according to claim 1, characterized in that If the window size of the original sliding window is smaller than the image to be rotated, the sliding step size of the original sliding window is configured to be greater than or equal to the window size of the original sliding window.
6. The method according to claim 5, characterized in that Before obtaining the image to be rotated, the method includes: Get the original image; Using the image in the original sliding window as a first image; wherein the first image is a partial image of the original image; Based on the four edges of the first image, a plurality of target edge groups are determined, wherein each target edge group includes a reference edge and an edge to be rotated corresponding to the reference edge, and the reference edge is any edge of the first image; Calculate the angle difference between the first angle corresponding to the reference edge in the current target edge group and the second angle corresponding to the edge to be rotated after rotation; If the absolute value of the angle difference meets a preset condition, the first image corresponding to the target edge group is used as the image to be rotated.
7. The method according to claim 1, characterized in that The step of determining the rotation angle of the image to be rotated according to the image to be rotated comprises: Obtain preset horizontal and vertical parameters, and determine the proportional relationship between the horizontal and vertical parameters; Obtaining original coordinate information of a target pixel point on a target edge of the image to be rotated, and calculating a slope of a target edge curve of the image to be rotated according to the proportional relationship, the original coordinate information, and a preset slope calculation formula; wherein the target edge is any one of the four edges of the image to be rotated; The rotation angle of the image to be rotated is obtained according to the target edge curve slope and a preset inverse trigonometric function formula.
8. An image rotation device, characterized in that: The image rotation device comprises: An acquisition and rotation angle calculation unit is used to acquire the image to be rotated, and determine the rotation angle of the image to be rotated according to the image to be rotated; An original coordinate acquisition unit, used for acquiring original coordinate information of a target pixel point in an original sliding window area in the image to be rotated through an original sliding window, wherein the target pixel point is any pixel point in the original sliding window area; A target coordinate calculation unit, used to determine the target coordinate information of the target pixel point after rotation in the target window according to the original coordinate information of the target pixel point and the rotation angle; A correction unit, configured to determine, according to the target coordinate information and the rotation angle, the corrected coordinate information of the target pixel point within the original sliding window after reverse rotation; The target image determination unit is used to determine the pixel value of the position where the corrected coordinate information is located as the pixel value of the target pixel point at the position corresponding to the target coordinate information, and use the image in the target window as the image after rotation of the image to be rotated.
9. A computer device, characterized in that: The computer device includes a processor and a memory, the memory is connected to the processor, the memory stores one or more programs, and the one or more programs are executed by the processor to implement the steps in the image rotation method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs are executed by a processor to implement the steps in the image rotation method according to any one of claims 1 to 7.
