Image defect detection method, device, equipment and storage medium
By calculating the angle difference between the slope of the image edge curve and the slope of the adjacent edge curve, the image defect is automatically detected, which solves the problem of low detection efficiency in the prior art and realizes an efficient and automated detection process.
Patent Information
- Application Number
- CN202011511988.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-18
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2040-12-18
AI Technical Summary
In the prior art, image defect detection efficiency is low, and an automated detection method is needed to replace manual detection.
By obtaining the image to be tested, the angle difference between the edge curve slope and the slope of the adjacent edge curve is calculated. If the absolute value of the included angle difference does not meet the preset conditions, the image loss is determined.
It realizes automated image defect detection, improves detection efficiency, small calculation volume, fast processing speed, and is suitable for low-end equipment.
Smart Images

Figure CN113256550B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image detection technology, and in particular to an image defect detection method, device, equipment and storage medium. Background Art
[0002] Before scanning each medium such as bills or banknotes, it is often necessary to manually check whether each bill or banknote has a folded corner or defect to ensure the image quality of the scanned bill or banknote. However, this manual inspection of whether the bill or banknote has a folded corner or defect is time-consuming and inefficient. Therefore, an image defect detection method is urgently needed to replace the manual inspection method and improve the inspection efficiency. Summary of the invention
[0003] Based on this, it is necessary to propose an image defect detection method, device and computer equipment to address the above problems, so as to solve the technical problem of low efficiency of image defect detection in the prior art.
[0004] In a first aspect, the present application provides an image defect detection method, the image defect detection method comprising:
[0005] Acquire the image to be tested;
[0006] Calculate a first edge curve slope and a second edge curve slope of the image to be tested according to a preset horizontal direction parameter, a preset vertical direction parameter and the original coordinate information of the image to be tested, wherein the first edge curve slope is the slope of any edge in the image to be tested, and the second edge curve slope is the slope of an adjacent edge of the any edge in the image to be tested;
[0007] Calculating a first angle between the slope of the first edge curve and a second angle between the slope of the second edge curve;
[0008] If the absolute value of the angle difference between the first angle and the second angle does not satisfy a preset condition, it is determined that the image to be measured is defective.
[0009] Optionally, calculating the first edge curve slope and the second edge curve slope of the image to be tested according to a preset horizontal direction parameter, a preset vertical direction parameter and original coordinate information of the image to be tested includes:
[0010] Determining the original coordinate information of the image to be measured;
[0011] Obtaining a preset horizontal dpi parameter and a preset vertical dpi parameter, and determining a ratio coefficient between the horizontal dpi parameter and the vertical dpi parameter;
[0012] Convert the original coordinate information according to the scale factor to obtain target coordinate information of the target point;
[0013] The target edge curve slope of the target edge is obtained according to a preset slope calculation formula and the target coordinate information of the target point.
[0014] Optionally, converting the original coordinate information according to the scale factor to obtain target coordinate information of the target point includes:
[0015] The horizontal coordinate value in the original coordinate information of the target point is used as the horizontal coordinate value in the target coordinate information of the target point, and the product obtained by multiplying the vertical coordinate value in the original coordinate information of the target point by the proportional coefficient is used as the vertical coordinate value in the target coordinate information of the target point.
[0016] Optionally, calculating the first edge curve slope and the second edge curve slope of the image to be measured according to a preset horizontal direction parameter, a preset vertical direction parameter and original coordinate information of the image to be measured includes:
[0017] Obtaining the first edge curve slope according to a preset horizontal dpi parameter, a preset vertical dpi parameter, and original coordinate information of the image to be measured;
[0018] According to a preset edge curve slope conversion formula, the second edge curve slope is calculated by taking the horizontal dpi parameter, the vertical dpi parameter and the first edge curve slope as independent variables.
[0019] Optionally, the step of calculating the second edge curve slope according to a preset edge curve slope conversion formula with the horizontal dpi parameter, the vertical dpi parameter and the first edge curve slope as independent variables includes:
[0020] When the first edge curve slope is the row direction edge curve slope, the second edge curve slope is calculated based on the ratio coefficient of the longitudinal dpi parameter to the transverse dpi parameter and the first edge curve slope;
[0021] When the first edge curve slope is the column direction edge curve slope, the second edge curve slope is calculated based on the ratio coefficient between the horizontal dpi parameter and the vertical dpi parameter and the first edge curve slope.
[0022] Optionally, calculating a first angle of the slope of the first edge curve and a second angle of the slope of the second edge curve includes:
[0023] Get the preset inverse trigonometric function formula;
[0024] Substitute the target edge curve slope into the inverse trigonometric function formula to obtain the target angle corresponding to the target edge curve slope.
[0025] Optionally, acquiring the image to be tested includes:
[0026] By scanning the object to be tested, a number of pixel points of the image to be tested are obtained;
[0027] Determine a plurality of pixel points in the horizontal and vertical directions for fitting into edge points corresponding to any three sides of the image to be measured;
[0028] The edge points corresponding to any three sides of the image to be measured are fitted respectively by using the least square method to obtain three fitting straight lines;
[0029] The image to be measured is determined by the three fitting straight lines.
[0030] In a second aspect, the present application provides an image defect detection device, the device comprising:
[0031] An acquisition unit, used for acquiring an image to be tested;
[0032] An edge curve slope calculation unit, used to calculate a first edge curve slope and a second edge curve slope of the image to be tested according to a preset horizontal dpi parameter, a preset vertical dpi ratio parameter and original coordinate information of the image to be tested, wherein the first edge curve slope is the slope of any edge in the image to be tested, and the second edge curve slope is the slope of an adjacent edge of the any edge in the image to be tested;
[0033] An angle calculation unit, used for calculating a first angle of the slope of the first edge curve and a second angle of the slope of the second edge curve;
[0034] A comparison and determination unit is used to determine that the image to be measured is defective if the absolute value of the angle difference between the first angle and the second angle is greater than a preset angle threshold.
[0035] 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:
[0036] Acquire the image to be tested;
[0037] Calculate a first edge curve slope and a second edge curve slope of the image to be tested according to a preset horizontal direction parameter, a preset vertical direction parameter and the original coordinate information of the image to be tested, wherein the first edge curve slope is the slope of any edge in the image to be tested, and the second edge curve slope is the slope of an adjacent edge of the any edge in the image to be tested;
[0038] Calculating a first angle between the slope of the first edge curve and a second angle between the slope of the second edge curve;
[0039] If the absolute value of the angle difference between the first angle and the second angle does not satisfy a preset condition, it is determined that the image to be measured is defective.
[0040] 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:
[0041] Acquire the image to be tested;
[0042] Calculate a first edge curve slope and a second edge curve slope of the image to be tested according to a preset horizontal direction parameter, a preset vertical direction parameter and the original coordinate information of the image to be tested, wherein the first edge curve slope is the slope of any edge in the image to be tested, and the second edge curve slope is the slope of an adjacent edge of the any edge in the image to be tested;
[0043] Calculating a first angle between the slope of the first edge curve and a second angle between the slope of the second edge curve;
[0044] If the absolute value of the angle difference between the first angle and the second angle does not meet a preset condition, it is determined that the image to be measured is defective.
[0045] The embodiments of the present invention have the following beneficial effects:
[0046] An image defect detection method provided by an embodiment of the present invention calculates the slope of the side of the image to be tested through pre-set horizontal and vertical parameters and the original coordinate information of the image to be tested. The calculation method is simple and the amount of calculation is small. The angles corresponding to the two adjacent sides are calculated through the slopes of any two adjacent sides of the image to be tested. The angle can be calculated using only basic mathematical methods. The method is simple, and whether the image to be tested is defective is determined by whether the absolute value of the angle difference between the angles meets the preset conditions, thereby replacing manual detection with intelligent image defect detection, thereby improving detection efficiency. The overall technical solution has a small amount of calculation, fast processing speed, high accuracy of detection results, and easy equipment implementation. It is particularly suitable for low-end devices, thereby expanding the application group.
[0047] An image defect detection device provided by an embodiment of the present invention has an edge curve slope calculation unit in which the slope of the edge of the image to be tested is calculated by pre-set horizontal and vertical direction parameters and the original coordinate information of the image to be tested, with a small amount of calculation and easy implementation; an angle unit calculates the angles corresponding to any two adjacent edges of the image to be tested by the slopes of the two adjacent edges, and the angle can be calculated using only basic mathematical methods. The method is simple, and a comparison and judgment unit determines whether the image to be tested is defective by determining whether the absolute value of the angle difference between the angles meets a preset condition, thereby realizing intelligent detection of image defects instead of manual detection, and is simple to operate, does not require a high configuration, and is easy to implement.
[0048] A computer device provided in an embodiment of the present invention calculates the slope of the side of the image to be tested through preset horizontal and vertical direction parameters and the original coordinate information of the image to be tested. The calculation method is simple and the amount of calculation is small. The angles corresponding to any two adjacent sides of the image to be tested are calculated through the slopes of the two adjacent sides. The angle can be calculated using only basic mathematical methods. The method is simple, and whether the image to be tested is defective is determined by whether the absolute value of the angle difference between the angles meets preset conditions, thereby replacing manual detection with intelligent image defect detection. The operation is simple, no higher configuration is required, and the device is easy to implement.
[0049] A computer-readable storage medium provided by an embodiment of the present invention implements an image defect detection method by executing a stored computer program by a processor. The medium is applicable to low-configuration and high-configuration devices and is easy to promote. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] 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.
[0051] in:
[0052] Figure 1 Schematic diagram of the process of image defect detection method in an embodiment of the present application;
[0053] Figure 2 Another schematic diagram of the process of the image defect detection method in the embodiment of the present application;
[0054] Figure 3 This is a schematic diagram of the detailed step flow of step 201 in the embodiment of the present application;
[0055] Figure 4This is a schematic diagram of the distribution of edge points when scanning a bill or banknote to be tested in an embodiment of the present application;
[0056] Figure 5 This is a schematic diagram of an image to be measured in a rectangular coordinate system in an embodiment of the present application;
[0057] Figure 6 This is a schematic diagram of the structure of an image defect detection device in an embodiment of the present application;
[0058] Figure 7 It is a structural block diagram of a computer device in an embodiment of the present application. DETAILED DESCRIPTION
[0059] 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.
[0060] See also Figure 1 , is a flow chart of an image defect detection method in an embodiment of the present application, the method comprising:
[0061] Step 101, obtaining an image to be tested;
[0062] In the embodiment of the present application, an image to be tested can be obtained, and the image to be tested refers to an image of a bill or a banknote to be tested. The image to be tested can be an image of a bill to be tested, or an image of a banknote to be tested. Among them, 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 notes, checks, bills of exchange, etc. that are only used for the purpose of paying money. Specifically, the image to be tested can be an image obtained by collecting images of bills or banknotes 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 or banknote. When the contact image sensor is working, the light emitted by the light source inside it is vertically directed to the surface of the bill or banknote to form pixel points one by one, and the contour points constituting the image to be tested are found from these pixel points one by one, and these contour points are fitted into straight lines to form the edges of the image to be tested, thereby obtaining the image to be tested.
[0063] The image sensor may also be a non-contact image sensor, which may use a high-resolution non-contact image sensor to scan bills or banknotes to obtain a high-resolution image to be tested, or may use a low-resolution non-contact image sensor to scan bills or banknotes to obtain a low-resolution image to be tested. 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.
[0064] It should be noted that the intact image to be tested is a regular image, such as a square, a trapezoid, etc., that is, two adjacent sides of the intact image to be tested are perpendicular, and the angle between them is 90°.
[0065] Step 102: Calculate a first edge curve slope and a second edge curve slope of the image to be tested according to a preset horizontal parameter, a preset vertical parameter and the original coordinate information of the image to be tested, wherein the first edge curve slope is the slope of any edge in the image to be tested, and the second edge curve slope is the slope of an adjacent edge of the any edge in the image to be tested;
[0066] 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 parameter refers to the horizontal dpi parameter, which refers to the horizontal resolution of the light source scanning inside the image sensor, that is, the number of pixels in one inch length in the horizontal direction (or X-axis, horizontal direction); the vertical parameter refers to the vertical dpi parameter, which refers to the vertical resolution of the image sensor scanning, that is, the number of pixels in one inch length in the vertical direction (or Y-axis, vertical direction).
[0067] For example: the resolution of the image to be tested is 4800*1200dpi, where 4800 is the horizontal dpi parameter value, then 4800 pixels can be placed on each inch of length in the horizontal direction, and 1200 is the vertical dpi parameter value, then 1200 pixels can be placed on each inch of length in the vertical direction.
[0068] The first edge curve slope and the second edge curve slope of the image to be tested can be calculated according to the preset horizontal dpi parameter, the preset vertical dpi parameter and the original coordinate information of the image to be tested. The original coordinate information is the horizontal and vertical coordinate information of any pixel point on a certain edge of the image to be tested, and 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 vertical coordinates of two points and the difference between the horizontal coordinates. It can be understood that a certain edge can be any of the four edges of the image to be tested, then the first edge curve slope is the tangent of the angle between the certain edge and the horizontal axis or the vertical axis of a certain plane rectangular coordinate system, or the ratio of the difference between the vertical coordinates of any two pixel points on the edge and the difference between the horizontal coordinates. In other words, the first edge curve slope can be the horizontal edge curve slope or the vertical edge curve slope.
[0069] The second edge curve slope is the slope of the adjacent side of any of the above-mentioned sides, which is the tangent of the angle between the adjacent side and the horizontal axis or the vertical axis of the plane rectangular coordinate system, or the ratio of the difference between the vertical coordinates and the horizontal coordinates of any two pixel points on the adjacent side. In other words, the second edge curve slope can also be the horizontal edge curve slope or the vertical edge curve slope.
[0070] When calculating the first edge curve slope or the second edge curve slope, since the correlation between the horizontal edge curve slope and the vertical edge curve slope is related to the dpi parameters of the image sensor that captures the image to be measured in the horizontal and vertical directions, the dpi parameters of the image sensor in the horizontal and vertical directions need to be considered when calculating the first edge curve slope and the second edge curve slope. Specifically, the first edge curve slope and the second edge curve slope can be calculated according to the horizontal and vertical dpi and original coordinate information of the image sensor.
[0071] Step 103, calculating a first angle of the slope of the first edge curve and a second angle of the slope of the second edge curve;
[0072] In the embodiment of the present application, step 102 describes that the first edge curve slope can be the tangent of the angle between any edge and the horizontal axis or the vertical axis of the plane rectangular coordinate system. Based on the tangent relationship, the first angle of the first edge curve slope can be obtained according to the inverse trigonometric function formula and the value of the first edge curve slope. Specifically, the angle obtained by substituting the value of the first edge curve slope into the inverse trigonometric function formula is used as the first angle.
[0073] In one feasible method, the above-mentioned inverse trigonometric function formula can be an inverse trigonometric function table, which records the relationship between the slope value and the angle corresponding to the slope value. The method of obtaining the first angle can also be to search the inverse trigonometric function table for an angle that matches the slope of the first edge curve, and use the matching angle as the first angle.
[0074] The second angle is calculated in a similar manner to the second angle, and the second angle of the second edge curve slope can be obtained according to the inverse trigonometric function formula and the value of the second edge curve slope. Specifically, the value of the second edge curve slope is substituted into the inverse trigonometric function formula to obtain the angle as the second angle. In a feasible manner, an inverse trigonometric function table can also be used to find an angle matching the second edge curve slope from the inverse trigonometric function table, and the angle is used as the second angle.
[0075] It should be noted that if the first angle is the angle between any side and the horizontal axis, the second angle is the angle between the adjacent side and the vertical axis; if the first angle is the angle between any side and the vertical axis, the second angle is the angle between the adjacent side and the horizontal axis. In other words, if there is no defect in the image to be tested, since the two adjacent sides of the image to be tested are perpendicular, the first angle is equal to the second angle.
[0076] Step 104: If the absolute value of the angle difference between the first angle and the second angle does not meet a preset condition, it is determined that the image to be measured is defective.
[0077] In the embodiment of the present application, the 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 smaller than the second angle, or greater than the second angle, or equal to the second angle, the angle difference may be smaller than zero, greater than zero, or equal to zero. Therefore, the absolute value of the angle difference is compared with the preset angle threshold to reduce invalid comparisons, and then determine whether the image to be tested is defective through the comparison result.
[0078] Among them, since any two adjacent sides of the image to be tested, such as the image of the bill to be tested or the image of the banknote to be tested, are perpendicular when there is no defect, based on this point, in the embodiment of the present invention, if the absolute value of the angle difference between the first angle and the second angle is less than or equal to the preset angle threshold, it is considered that the image to be tested has no defect and is a normal image. It is understandable that if the absolute value of the angle difference between the first angle and the second angle is greater than the preset angle threshold, it is considered that the image to be tested has a defect and is an abnormal image.
[0079] Of course, the above preset angle threshold can be set according to actual conditions. The preset condition can also be a preset angle threshold interval. For example, if the preset angle threshold range is set to 5° to 10°, it is determined whether the angle difference is in the preset angle range. If so, it is considered that the angle difference meets the preset condition, and if not, it is considered that the angle difference does not meet the preset condition.
[0080] In the embodiment of the present application, the preset condition is a preset angle threshold, and the preset angle threshold is preferably 5°, thereby further improving the defect detection accuracy of the image to be tested.
[0081] It should be noted that the above steps 102 to 104 are to calculate the angle difference between the slopes of one side in the image to be tested and the adjacent side of the side to determine the defect of the image to be tested. Therefore, it can only be determined whether there is a defect between the side and the adjacent side. The image to be tested has four sides. In order to completely determine whether the image to be tested has a defect and to improve the detection accuracy, it can be determined that there is no defect based on the absolute value of the difference between the angle between one side and the adjacent side of the side. Then, it can be determined that the absolute value of the difference between the angle between the next side and the adjacent side is less than the preset angle threshold according to the above steps 102 to 104. If it is greater, it is determined that the image to be tested is defective. If it is less than, it is determined that the absolute value of the difference between the angle between the next side and the adjacent side is less than the preset angle threshold according to the above steps 102 to 104 until all four sides of the image to be tested are determined. It can be understood that as long as the absolute value of the angle between the slope corresponding to any side and the adjacent side among the four sides is greater than the preset angle threshold, the image to be tested is considered to be defective. If the absolute values of the angles of the slopes of all four sides and their corresponding adjacent sides are all less than the preset angle threshold, it is considered that the image to be tested is normal and has no defects.
[0082] For example, the image to be tested includes edge 1, edge 2, edge 3 and edge 4, and corresponds to four edges of the bill or banknote to be tested in a clockwise direction. If the absolute value of the difference between the angle between edge 1 and its adjacent edge 2 based on the above method is less than the preset angle threshold, then continue to determine whether it is less than the preset angle threshold based on the absolute value of the difference between the angle between edge 2 and its adjacent edge 3; if it is less than, continue to determine whether it is less than the preset angle threshold based on the absolute value of the difference between the angle between edge 3 and its adjacent edge 4; if it is less than, continue to determine whether it is less than the preset angle threshold based on the absolute value of the difference between the angle between edge 4 and its adjacent edge 1; if it is less than, determine that the image to be tested is normal; if it is greater, determine that the image to be tested is defective.
[0083] In the embodiment of the present invention, the slope of the side of the image to be tested is calculated by pre-set horizontal and vertical parameters and the original coordinate information of the image to be tested. The calculation method is simple and the amount of calculation is small. The angles corresponding to the two adjacent sides are calculated by the slopes of any two adjacent sides of the image to be tested. The angle can be calculated using only basic mathematical methods. The method is simple, and whether the image to be tested is defective is determined by whether the absolute value of the angle difference between the angles meets the preset conditions. Intelligent image defect detection replaces manual detection, which improves detection efficiency. The overall technical solution has a small amount of calculation, fast processing speed, high accuracy of detection results, and easy equipment implementation. It is especially suitable for low-end devices, thereby expanding the application group.
[0084] To better understand the technical solutions in the embodiments of this application, please refer to Figure 2 , is another flow chart of the image defect detection method in an embodiment of the present application, the method comprising:
[0085] Step 201, obtaining an image to be tested;
[0086] 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.
[0087] In one possible approach, see Figure 3 , Figure 3 The detailed steps of step 201 include:
[0088] S2011, obtaining a plurality of pixel points of the image to be tested by scanning the object to be tested;
[0089] S2012, determining a plurality of pixel points in the horizontal and vertical directions for fitting into edge points corresponding to any three sides of the image to be measured;
[0090] S2013, using the least square method to fit the edge points corresponding to any three sides of the image to be measured respectively, to obtain three fitting straight lines;
[0091] S2014: Determine the image to be measured by using the three fitting straight lines.
[0092] The object to be tested refers to the bill or banknote to be tested. The object is scanned by an image sensor. The image sensor may be a contact image sensor, such as a CIS. Since the outline of the bill or banknote to be tested is regular, the image to be tested can be determined by determining any three edges of the image to be tested, thereby reducing the processing volume and improving the detection efficiency.
[0093] When the image sensor collects the image to be tested, it scans the bill or banknote from top to bottom to form scattered pixel points. It is necessary to find the contour points constituting the image to be tested, that is, the edge points in the embodiment of the present application, from the scattered pixel points. After finding the edge points of any three sides of the image to be tested, 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 into the image to be tested.
[0094] 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 tested, 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 or banknote, 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 tested, and improving the accuracy of the calculation.
[0095] To further understand the technical solution of steps S2011-2014, please refer to Figure 4 and Figure 5 , Figure 4 The diagram illustrates the distribution of edge points when the image sensor scans the bill or banknote to be tested. Figure 5 The following is a schematic diagram of an image to be tested in a rectangular coordinate system. Figure 4 and Figure 5 As shown, the image sensor scans the bill or banknote 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 4 In the scanning process, the starting point of the scan is the corner point in the bill or banknote to be tested, 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. The left side of the image to be tested 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 bills or banknotes, the edge points of any three sides of the image to be tested 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 tested are first determined, and then the edge points of the three sides are fitted by the least square method to obtain three fitting lines, and the three fitting lines are connected. The fourth side of the image to be tested is parallel to the left side, and then the image to be tested is obtained.
[0096] Step 202, determining target coordinate information of the target point according to preset horizontal dpi parameters, vertical dpi parameters and original coordinate information of the target point on the target edge in the image to be measured in a preset rectangular coordinate system; wherein the target point is any point on the target edge;
[0097] In the embodiments of the present application, Figure 5 As shown, the preset rectangular coordinate system assumes that (0,0) is the origin, its horizontal axis is the column direction of the image sensor scanning, and its vertical axis is the row direction of the image sensor scanning. The target edge can be any edge of the four edges in the image to be tested, or it can be an adjacent edge of the arbitrary edge in the image to be tested. The original coordinate information of any point on the target edge is expressed as (x 0 ,y 0 ), where x 0 is the horizontal axis value, y 0 is the ordinate value, and during the scanning process, the horizontal and vertical coordinate information of the target point, that is, the target coordinate information, is associated with the dpi parameters of the image sensor that collects the image to be measured in the horizontal and vertical directions. It can be understood that the horizontal coordinate value in the target coordinate information is the horizontal coordinate value in the original coordinate information of the target point, and the vertical coordinate value in the target coordinate information is multiplied by the vertical coordinate value in the original coordinate information of the target point. The proportional coefficient refers to the ratio of the horizontal dpi parameter to the vertical dpi parameter.
[0098] It can be understood that if the horizontal dpi parameter is equal to the vertical dpi parameter, the proportional coefficient is 1, and the vertical coordinate value in the target coordinate information is the coordinate value in the original coordinate information. In this embodiment, when the horizontal dpi parameter is not equal to the vertical dpi parameter, the image defect detection processing speed that can be achieved is faster and the detection accuracy is higher.
[0099] Step 203: Obtain the target edge curve slope of the target edge according to a preset slope calculation formula and the target coordinate information of the target point;
[0100] Wherein, when the target edge is any edge of the image to be measured, the slope of the target edge curve is the slope of the first edge curve; when the target edge is an adjacent edge of the arbitrary edge, the slope of the target edge curve is the slope of the second edge curve;
[0101] In the embodiment of the present application, the above-mentioned preset slope calculation formula can be a tangent function formula. Since the target edge curve slope can be the tangent of the angle between the target edge and the horizontal axis, or the tangent of the angle between the target edge and the vertical axis, the first edge curve slope can be the tangent of the angle between the target edge and the vertical axis. Therefore, the first edge curve slope can be the tangent of the lateral edge curve slope or the longitudinal edge curve slope. Similarly, the second edge curve slope can be the lateral edge curve slope or the longitudinal edge curve slope.
[0102] It should be noted that, in order to facilitate the subsequent defect judgment of the image to be tested, if the slope of the first edge curve is the slope of the horizontal edge curve, the slope of the second edge curve is the slope of the vertical edge curve; if the slope of the first edge curve is the slope of the vertical edge curve, the slope of the second edge curve is the slope of the horizontal edge curve.
[0103] Among them, the method of calculating the first edge curve slope and the method of calculating the second edge curve slope can be the same, specifically: according to the horizontal dpi parameter, the vertical dpi parameter and the original coordinate information of the target point on any edge of the image to be tested, the first edge curve slope is obtained, and according to the horizontal dpi parameter, the vertical dpi parameter and the original coordinate information of the target point on the adjacent edge corresponding to the arbitrary edge of the image to be tested, the second edge curve slope is obtained.
[0104] Taking the calculation of the first edge curve slope as an example, the first edge curve slope corresponds to any edge, specifically, Figure 5 As shown, assuming that any side is the upper side, the original coordinate information of point C on the upper side is (x 0 , 0), the original coordinate information of point D is (0, y 0 ), the angle between the upper edge and the y-axis is θ, and the corresponding original edge curve slope is k h , the horizontal dpi parameter is A, the vertical dpi parameter is B, then the ratio coefficient of A and B is r, and the target coordinate information of point C is (x 0 , 0), the target coordinate information of point D is The slope k' of the target edge curve corresponding to the upper edge h
[0105]
[0106]
[0107] From formula (1) and formula (2), it can be deduced that:
[0108]
[0109] The slope k' of the edge curve on the upper side is h is the horizontal edge curve slope, which is used as the first edge curve slope. The vertical edge curve slope corresponding to the adjacent side above it, that is, the left side, is used as the second edge curve slope k′ z The angle between its left side and the ordinate axis is α, and the slope of the original edge curve on its left side is k Z , the target edge curve slope, that is, the second edge curve slope is k′ z ,
[0110] In calculating the slope k' of the second edge curve z When , the same method as the slope of the first edge curve is used to calculate, thus obtaining:
[0111]
[0112] It is understandable that the above description is to respectively calculate the first edge curve slope and the second edge curve slope in the same manner. In a feasible manner, the second edge curve slope can also be calculated in another manner, wherein, since the ratio of two adjacent edges to the horizontal and vertical dpi parameters has a certain correlation, after obtaining the first edge curve slope, the second edge curve slope can be obtained according to the first edge curve slope and the corresponding correlation. The correlation is the proportional relationship of the horizontal and vertical dpi parameters.
[0113] Specifically, the horizontal dpi parameter is defined as A, the vertical dpi parameter is defined as B, and the ratio coefficient of horizontal and vertical dpi is defined as r, then r is:
[0114]
[0115]
[0116] Substituting formula (2), formula (3) and formula (6) into formula (5), we obtain:
[0117]
[0118] From formula (7), it can be determined that the second edge curve slope can be calculated according to the first edge curve slope, the horizontal dpi parameter and the vertical dpi parameter.
[0119] Step 204: Calculate a target angle corresponding to the target edge curve slope according to the target edge curve slope and a preset inverse trigonometric function formula, wherein when the target edge curve slope is the first edge curve slope, the target angle is the first angle; when the target edge curve slope is the second edge curve slope, the target angle is the second angle;
[0120] Step 205, calculate the angle difference between the first angle and the second angle, and compare the absolute value of the angle difference with a preset angle threshold. If the absolute value of the angle difference is greater than the preset angle threshold, it is determined that the image to be tested is defective; if it is less than or equal to the preset angle threshold, it is determined that the image to be tested is not defective.
[0121] In the embodiment of the present application, it can be understood that the contents described in step 204 and step 205 are the same as those described in step 206. Figure 1 Part of the contents described in step 103 and step 104 in the embodiment shown are similar, and can be found in detail. Figure 1The relevant contents in step 103 and step 104 in the illustrated embodiment are not described in detail here.
[0122] In order to better understand the technical solutions in the embodiments of the present invention, examples are given below for illustration.
[0123] For example, if the calculated value of the slope of the first edge curve is 1, then the first angle is arctan(1)=45°;
[0124] If the calculated value of the slope of the second edge curve is 1.73, then the second angle is arctan(1.73)=60°.
[0125] The absolute value of the angle difference obtained by subtracting the second angle from the first angle = 15°. If the preset angle threshold is set to 5°, 15° is greater than 5°. Therefore, the image to be tested is considered to be defective. If it is determined that the image to be tested is defective, there is no need to determine whether the image to be tested is defective based on other edges and their adjacent edges.
[0126] If the absolute value of the above angle difference is less than the preset angle threshold, such as the absolute value of the angle difference is 4°, it is necessary to continue to select other edges and their corresponding adjacent edges, and use the same method to calculate whether the absolute value of the angle difference between other edges and their corresponding adjacent edges is greater than the preset angle threshold. If after two calculations, the comparison result is still less than or equal to the preset angle threshold, it is considered that the image to be tested is not defective. In other words, the number of times steps 201-205 are executed is at most 4 times to determine whether the image to be tested is defective.
[0127] Based on steps 201 to 205, the first angle is calculated by the slope of the first edge curve, and the second angle is calculated by the slope of the second edge curve. The amount of calculation is small and the processing efficiency is improved. Moreover, if the absolute value of the angle difference between the first angle corresponding to the slope of the first edge curve and the second angle corresponding to the slope of the second edge curve is greater than a preset angle threshold, it is considered that the first angle is not equal to the second angle to determine that the image to be tested is defective. This replaces manual detection and realizes intelligence. It is simple to operate and the device is easy to implement.
[0128] See also Figure 6 , is a schematic diagram of the structure of an image defect detection device in an embodiment of the present application, the device comprising:
[0129] The acquisition unit 10 is used to acquire the image to be tested;
[0130] An edge curve slope calculation unit 20 is used to calculate a first edge curve slope and a second edge curve slope of the image to be tested according to a preset horizontal direction parameter, a preset vertical direction ratio parameter and the original coordinate information of the image to be tested, wherein the first edge curve slope is the slope of any edge in the image to be tested, and the second edge curve slope is the slope of an adjacent edge of the any edge in the image to be tested;
[0131] An angle calculation unit 30, used to calculate a first angle of the slope of the first edge curve and a second angle of the slope of the second edge curve;
[0132] The comparison and determination unit 40 is configured to determine that the image to be measured is defective if the absolute value of the angle difference between the first angle and the second angle is greater than a preset angle threshold.
[0133] It should be noted that the relevant contents of the above-mentioned acquisition unit 10, edge curve slope calculation unit 20, angle calculation unit 30 and comparison and determination unit 40 can be found in Figures 1 to 5 The contents described in are not repeated here.
[0134] In the embodiment of the present application, the target angle is calculated by the slope of the target edge curve, which reduces the amount of calculation and improves processing efficiency. Moreover, if the absolute value of the angle difference between a first angle corresponding to the slope of the first edge curve and a second angle corresponding to the slope of the second edge curve is greater than a preset angle threshold, then the first angle is considered to be unequal to the second angle to determine that the image to be measured is defective. This replaces manual detection and realizes intelligence. It is simple to operate, does not require a higher configuration, and is easy to implement on the device.
[0135] Figure 7 FIG. 1 shows an internal structure diagram of a computer device in an embodiment. The computer device may be a terminal or a server. Figure 7 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 Figure 7 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.
[0136] 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:
[0137] Acquire the image to be tested;
[0138] Calculate a first edge curve slope and a second edge curve slope of the image to be tested according to a preset horizontal direction parameter, a preset vertical direction parameter and the original coordinate information of the image to be tested, wherein the first edge curve slope is the slope of any edge in the image to be tested, and the second edge curve slope is the slope of an adjacent edge of the any edge in the image to be tested;
[0139] Calculating a first angle between the slope of the first edge curve and a second angle between the slope of the second edge curve;
[0140] If the absolute value of the angle difference between the first angle and the second angle is greater than a preset angle threshold, it is determined that the image to be measured is defective.
[0141] In the embodiment of the present application, the slope of the side of the image to be tested is calculated by pre-set horizontal and vertical parameters and the original coordinate information of the image to be tested. The calculation method is simple and the amount of calculation is small. The angle corresponding to each of the two adjacent sides is calculated by the slope of any two adjacent sides of the image to be tested. The angle can be calculated using only basic mathematical methods. The method is simple, and whether the image to be tested is defective is determined by whether the absolute value of the angle difference between the angles meets preset conditions, thereby replacing manual detection with intelligent image defect detection.
[0142] 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:
[0143] Acquire the image to be tested;
[0144] Calculate a first edge curve slope and a second edge curve slope of the image to be tested according to a preset horizontal direction parameter, a preset vertical direction parameter and the original coordinate information of the image to be tested, wherein the first edge curve slope is the slope of any edge in the image to be tested, and the second edge curve slope is the slope of an adjacent edge of the any edge in the image to be tested;
[0145] Calculating a first angle between the slope of the first edge curve and a second angle between the slope of the second edge curve;
[0146] If the absolute value of the angle difference between the first angle and the second angle is greater than a preset angle threshold, it is determined that the image to be measured is defective.
[0147] A computer-readable storage medium provided in an embodiment of the present invention implements an image defect detection method by executing a stored computer program by a processor. The medium is applicable to low-configuration and high-configuration devices and is conducive to promotion.
[0148] 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).
[0149] 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.
[0150] 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 defect detection method, characterized in that: The image defect detection method comprises: Acquire the image to be tested; Calculate a first edge curve slope and a second edge curve slope of the image to be tested according to a preset horizontal direction parameter, a preset vertical direction parameter and the original coordinate information of the image to be tested, wherein the first edge curve slope is the slope of any edge in the image to be tested, and the second edge curve slope is the slope of an adjacent edge of the any edge in the image to be tested; Calculate a first angle of the slope of the first edge curve and a second angle of the slope of the second edge curve; wherein, if the first angle is the angle between any edge and the abscissa axis, the second angle is the angle between the adjacent edge and the ordinate axis; if the first angle is the angle between any edge and the ordinate axis, the second angle is the angle between the adjacent edge and the abscissa axis; If the absolute value of the angle difference between the first angle and the second angle does not meet a preset condition, it is determined that the image to be measured is defective; wherein the preset condition is that the absolute value of the angle difference between the first angle and the second angle is less than a preset angle threshold; The method of obtaining the image to be tested specifically includes: obtaining a number of pixel points of the object to be tested by scanning the object to be tested; determining edge points corresponding to any three sides of the image to be tested from a number of pixel points in the horizontal and vertical directions; fitting the edge points corresponding to any three sides of the image to be tested respectively by using the least squares method to obtain three fitting straight lines; and determining the image to be tested by using the three fitting straight lines.
2. The image defect detection method according to claim 1, characterized in that: The step of calculating the first edge curve slope and the second edge curve slope of the image to be tested according to the preset horizontal direction parameter, the preset vertical direction parameter and the original coordinate information of the image to be tested specifically includes: Determining the original coordinate information of the image to be measured; Obtaining a preset horizontal dpi parameter and a preset vertical dpi parameter, and determining a ratio coefficient between the horizontal dpi parameter and the vertical dpi parameter; Convert the original coordinate information according to the scale factor to obtain target coordinate information of the target point; According to a preset slope calculation formula and the target coordinate information of the target point, the target edge curve slope of the target edge is obtained.
3. The image defect detection method according to claim 2, characterized in that: The converting the original coordinate information according to the scale factor to obtain the target coordinate information of the target point includes: The horizontal coordinate value in the original coordinate information of the target point is used as the horizontal coordinate value in the target coordinate information of the target point, and the product obtained by multiplying the vertical coordinate value in the original coordinate information of the target point by the proportional coefficient is used as the vertical coordinate value in the target coordinate information of the target point.
4. The image defect detection method according to claim 1, characterized in that: The step of calculating the first edge curve slope and the second edge curve slope of the image to be tested according to the preset horizontal direction parameter, the preset vertical direction parameter and the original coordinate information of the image to be tested comprises: Obtaining the first edge curve slope according to a preset horizontal dpi parameter, a preset vertical dpi parameter, and original coordinate information of the image to be measured; According to a preset edge curve slope conversion formula, the second edge curve slope is calculated by taking the horizontal dpi parameter, the vertical dpi parameter and the first edge curve slope as independent variables.
5. The image defect detection method according to claim 4, characterized in that: The step of calculating the second edge curve slope according to a preset edge curve slope conversion formula with the horizontal dpi parameter, the vertical dpi parameter and the first edge curve slope as independent variables specifically includes: When the first edge curve slope is the row direction edge curve slope, the second edge curve slope is calculated based on the ratio coefficient of the longitudinal dpi parameter to the transverse dpi parameter and the first edge curve slope; When the first edge curve slope is the column direction edge curve slope, the second edge curve slope is calculated based on the ratio coefficient between the horizontal dpi parameter and the vertical dpi parameter and the first edge curve slope.
6. The image defect detection method according to claim 1, characterized in that: The calculating of the first angle of the first edge curve slope and the second angle of the second edge curve slope specifically includes: Get the preset inverse trigonometric function formula; Substitute the target edge curve slope into the inverse trigonometric function formula to obtain the target angle corresponding to the target edge curve slope.
7. An image defect detection device, characterized in that: The image defect detection device comprises: An acquisition unit, used for acquiring an image to be tested; An edge curve slope calculation unit, used to calculate a first edge curve slope and a second edge curve slope of the image to be tested according to a preset horizontal direction parameter, a preset vertical direction ratio parameter and the original coordinate information of the image to be tested, wherein the first edge curve slope is the slope of any edge in the image to be tested, and the second edge curve slope is the slope of an adjacent edge of the any edge in the image to be tested; An angle calculation unit, used to calculate a first angle of the slope of the first edge curve and a second angle of the slope of the second edge curve; wherein, if the first angle is the angle between any edge and the horizontal axis, the second angle is the angle between the adjacent edge and the vertical axis; if the first angle is the angle between any edge and the vertical axis, the second angle is the angle between the adjacent edge and the horizontal axis; A comparison and determination unit, configured to determine that the image to be tested is defective if the absolute value of the angle difference between the first angle and the second angle does not meet a preset condition; wherein the preset condition is that the absolute value of the angle difference between the first angle and the second angle is less than a preset angle threshold; The acquisition unit is specifically used to obtain a number of pixel points of the object to be tested by scanning the object to be tested; determine the edge points corresponding to any three sides of the image to be tested from the several pixel points in the horizontal and vertical directions; use the least squares method to fit the edge points corresponding to any three sides of the image to be tested respectively to obtain three fitting straight lines; and determine the image to be tested through the three fitting straight lines.
8. 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 defect detection method according to any one of claims 1 to 6.
9. 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 defect detection method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Banknote identification method and device
CN108665605A
Calculation method and device for edge slope of regular image
CN108717708A