Image recognition method and device, computer device and computer readable storage medium
By acquiring gradient information from images to identify edge sequences and determine target angle information, the problem of low location efficiency in traditional image recognition methods is solved, achieving more efficient and accurate target object localization.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN SMARTMORE TECH CO LTD
- Filing Date
- 2022-11-01
- Publication Date
- 2026-06-23
AI Technical Summary
Traditional image recognition methods are inefficient and inaccurate in determining the location of a target object in an image, mainly because the abundance of straight lines in the image leads to high algorithm complexity.
By acquiring gradient information of the image to be identified, edge sequences are identified, and the target angle information of the target object is determined based on the edge sequences and the preset morphological features of the target object, thus finally determining its location in the image.
It improves the efficiency and accuracy of locating target objects in images and reduces algorithm complexity.
Smart Images

Figure CN115908841B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to an image recognition method, apparatus, computer device, and computer-readable storage medium. Background Technology
[0002] With the rapid development of the mobile internet, more and more important information is being carried through target objects such as QR codes. Scanning the target object in an image after acquiring it has gradually become an important means of information retrieval. However, due to issues such as shooting angle, lighting, and background patterns during image acquisition, it can be difficult to determine the location of the target object within the image.
[0003] Traditional techniques typically determine the location of a target object in an image by finding straight lines and then matching them. However, because images often contain many straight lines, the algorithm becomes very complex, resulting in low efficiency in determining the location of the target object. Summary of the Invention
[0004] Therefore, it is necessary to provide an image recognition method, apparatus, computer device, and computer-readable storage medium to address the aforementioned technical problems, which can improve the efficiency and accuracy of determining the location of a target object in an image.
[0005] In a first aspect, this application provides an image recognition method, comprising:
[0006] Obtain the image to be identified; the image to be identified contains the target object;
[0007] Based on the gradient information of each pixel in the image to be identified, one or more edge sequences are identified from the image to be identified; the edge sequence is composed of corresponding pixels whose gradient information satisfies the preset gradient difference condition;
[0008] Based on one or more edge sequences, determine the target angle information corresponding to the target object;
[0009] Based on the preset morphological features and target angle information of the target object, the location of the target object in the image to be recognized is determined.
[0010] Secondly, this application also provides an image recognition device, comprising:
[0011] The acquisition module is used to acquire the image to be recognized; the image to be recognized contains the target object.
[0012] The recognition module is used to identify one or more edge sequences from the image to be recognized based on the gradient information of each pixel in the image to be recognized; the edge sequence is composed of corresponding pixels whose gradient information satisfies the preset gradient difference condition;
[0013] The determination module is used to determine the target angle information corresponding to the target object based on one or more edge sequences;
[0014] The positioning module is used to determine the location of the target object in the image to be recognized based on the preset morphological features and target angle information of the target object.
[0015] Thirdly, this application also provides a computer device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the steps in the image recognition method described above.
[0016] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the image recognition method described above.
[0017] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps in the image recognition method described above.
[0018] The aforementioned image recognition method, apparatus, computer equipment, and computer-readable storage medium acquire an image to be recognized containing a target object, determine the gradient information of each pixel in the image to be recognized, determine the corresponding pixels whose gradient information satisfies a preset gradient difference condition based on the gradient information of each pixel, form an edge sequence from the corresponding pixels, the edge sequence can be candidate edge lines of the target object in the image to be recognized, determine the target angle information corresponding to the target object based on the edge sequence, the target angle information can be the edge corner of the target object, and determine the location of the target object in the image to be recognized based on the preset morphological features of the target object and the target angle information, thereby improving the efficiency and accuracy of determining the location of the target object in the image. Attached Figure Description
[0019] Figure 1 A flowchart illustrating an image recognition method provided in an embodiment of this application;
[0020] Figure 2 A flowchart illustrating the process of determining an edge sequence is provided for an embodiment of this application;
[0021] Figure 3 This is a schematic diagram of a process for determining target angle information provided in an embodiment of this application;
[0022] Figure 4This is a schematic diagram of pixels in an edge sequence provided in an embodiment of this application;
[0023] Figure 5 A schematic diagram of an edge sequence provided in an embodiment of this application;
[0024] Figure 6 A flowchart illustrating another image recognition method provided in an embodiment of this application;
[0025] Figure 7 A structural block diagram of an image recognition device provided in an embodiment of this application;
[0026] Figure 8 An internal structural diagram of a computer device provided in an embodiment of this application;
[0027] Figure 9 This is a schematic diagram of a computer-readable storage medium provided in an embodiment of this application. Detailed Implementation
[0028] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0029] In some embodiments, such as Figure 1 As shown, an image recognition method is provided. This embodiment illustrates the method by applying it to a computer device, and includes the following steps:
[0030] Step S101: Obtain the image to be recognized.
[0031] In this step, the image to be identified contains a target object. For example, the image to be identified can be an image taken by a computer device; the target object can be a QR code or barcode, such as one of the members of a QR code, the datamatrix code.
[0032] Step S102: Based on the gradient information of each pixel in the image to be identified, identify one or more edge sequences from the image to be identified.
[0033] In this step, the edge sequence is composed of corresponding pixels whose gradient information satisfies the preset gradient difference condition; wherein, the gradient information can be gradient intensity and gradient direction, and the preset gradient difference condition can be a pre-set gradient intensity difference condition and gradient direction difference condition, such as gradient intensity difference condition and gradient direction difference condition.
[0034] Specifically, the computer device determines the gradient information of each pixel in the image to be recognized, and based on the gradient information of each pixel, selects the corresponding pixels that meet the preset gradient difference conditions from the image to be recognized, and forms one or more edge sequences from the corresponding pixels.
[0035] Step S103: Determine the target angle information corresponding to the target object based on one or more edge sequences.
[0036] In this step, the target angle information can consist of two straight lines and the intersection of the two straight lines. For example, the target object can be a quadrilateral (such as a parallelogram), and the target angle information can be two adjacent sides of the target object and the intersection of the two adjacent sides. The intersection point can be a vertex of the target object.
[0037] Specifically, the computer device identifies the edge lines of the target object based on one or more edge sequences, determines candidate angles that meet the angular features from the edge lines, and then determines the target angle information that best matches the angular information of the target object from the candidate angles.
[0038] Step S104: Determine the location of the target object in the image to be recognized based on the preset morphological features and target angle information of the target object.
[0039] In this step, the preset shape features can be the inherent shape features or common shape features of the target object, such as parallelograms, squares, or rectangles.
[0040] Specifically, after determining the target angle information of the target object, the computer device can obtain a region that conforms to the preset shape characteristics of the target object from the target angle information since the preset shape characteristics of the target object are known in advance. This region is the positioning position of the target object in the image to be recognized.
[0041] In the above image recognition method, the scheme acquires an image to be recognized containing a target object, determines the gradient information of each pixel in the image to be recognized, determines the corresponding pixel that satisfies the preset gradient difference condition based on the gradient information of each pixel, forms an edge sequence of the corresponding pixels, the edge sequence can be the candidate edge line of the target object in the image to be recognized, determines the target angle information corresponding to the target object based on the edge sequence, the target angle information can be the edge corner of the target object, and determines the location of the target object in the image to be recognized based on the preset morphological features of the target object and the target angle information, thereby improving the efficiency and accuracy of determining the location of the target object in the image.
[0042] In some embodiments, step S102 above, which identifies one or more edge sequences from the image to be identified based on the gradient information of each pixel in the image to be identified, specifically includes:
[0043] Based on the gradient direction and gradient intensity of each pixel in the image to be identified, the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition are used to form one or more edge sequences in the image to be identified.
[0044] In this embodiment, the gradient information includes the gradient direction and the gradient intensity; the preset gradient difference conditions include gradient direction difference conditions and gradient intensity difference conditions, such as gradient direction difference conditions and gradient intensity difference conditions.
[0045] Specifically, the computer device, based on the gradient direction and gradient intensity of each pixel in the image to be identified, forms one or more edge sequences in the image to be identified by combining the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition.
[0046] For example, the computer device uses a first-order edge extraction algorithm to extract edges from the image to be recognized, and obtains the gradient intensity response map and gradient direction (angle) response map of the image to be recognized. It determines the gradient direction and gradient intensity of each pixel in the image to be recognized. Based on the gradient direction and gradient intensity of each pixel, the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition are used to form one or more edge sequences in the image to be recognized.
[0047] The technical solution of this embodiment forms an edge sequence by combining corresponding pixels whose gradient directions satisfy the gradient direction difference condition and whose gradient intensities satisfy the gradient intensity difference condition. This helps to obtain a more accurate edge sequence, thereby improving the accuracy of determining the location of the target object in the image.
[0048] In some embodiments, the above method may further compose one or more edge sequences comprising the image to be identified through the following steps, specifically including:
[0049] Based on the gradient direction and gradient intensity of each pixel in the image to be identified, the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition are used to form the current segment edge sequence of the image to be identified.
[0050] Based on the gradient direction and gradient intensity of the pixels in the image to be identified, excluding the pixels included in the current segment edge sequence, the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition are used to form the next segment edge sequence included in the image to be identified.
[0051] The next edge sequence is taken as the current edge sequence, and the process jumps to the step of forming the next edge sequence of the image to be identified by combining the corresponding pixels whose gradient direction and gradient intensity satisfy the gradient direction difference condition and gradient intensity difference condition, based on the gradient direction and gradient intensity of the pixels in the image to be identified other than those included in the current edge sequence. This process continues until the next edge sequence is the last edge sequence of the image to be identified.
[0052] In this embodiment, the number of edge sequences is multiple segments; the current segment edge sequence can be the first segment edge sequence or other segment edge sequences after the first segment edge sequence; the next segment edge sequence can be the second segment edge sequence or other segment edge sequences after the second segment edge sequence.
[0053] Specifically, such as Figure 2 As shown, the computer device, based on the gradient direction and gradient intensity of each pixel in the image to be recognized, forms the current edge sequence by grouping pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition. Pixels that have been added to / formed an edge sequence are marked as traversed (while pixels that have not been added to / formed an edge sequence are in an untraversed state). Based on the gradient direction and gradient intensity of pixels in the image to be recognized other than those included in the current edge sequence (pixels in the image to be recognized other than those included in the current edge sequence are in an untraversed state), the computer device forms the next edge sequence by grouping pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition, and marks pixels that have been added to / formed an edge sequence as traversed. The process involves taking the latest edge sequence as the current edge sequence and then proceeding to the next edge sequence step. This step involves selecting pixels in the image to be identified that satisfy both the gradient direction difference condition and the gradient intensity difference condition, based on the gradient direction and gradient intensity of the pixels in the image to be identified, excluding those in the current edge sequence. This continues until the next edge sequence is the last edge sequence in the image to be identified, meaning all pixels in the image have been marked as traversed. All the obtained edge sequences are then treated as multiple edge sequences and can be added to the edge sequence array. For example, edge sequences with a length of no more than 10 (e.g., the number of pixels in the edge sequence is no more than 10) are not used for subsequent searching / determining of candidate angle information or target angle information.
[0054] The technical solution of this embodiment, after obtaining the first edge sequence, iteratively selects corresponding pixels from the remaining pixels that have not been added to / formed the edge sequence to form an edge sequence, thereby obtaining multiple edge sequences. This is beneficial for obtaining more candidate edge sequences. Subsequently, corner recognition / corner matching is performed on the multiple candidate edge sequences, which is beneficial for obtaining more accurate target corner information, thereby improving the accuracy of determining the location of the target object in the image.
[0055] In some embodiments, the above method may further compose the current segment edge sequence of the image to be identified by the following steps, specifically including:
[0056] Select the pixel with the largest gradient intensity from all pixels in the image to be identified, and use it as the current round seed point of the current segment edge sequence included in the image to be identified;
[0057] From the neighboring pixels of the current seed point in the current segment edge sequence, select the corresponding pixel whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition, and use it as the next seed point in the current segment edge sequence.
[0058] The next seed point of the current segment edge sequence is taken as the current seed point of the current segment edge sequence, and the process jumps to the neighboring pixels of the current seed point of the current segment edge sequence. The corresponding pixel whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition is selected as the next seed point of the current segment edge sequence. This process continues until no next seed point of the current segment edge sequence can be selected from the neighboring pixels of the current seed point of the current segment edge sequence.
[0059] The selected seed points of each round of the current segment edge sequence are used to form the current segment edge sequence.
[0060] In this embodiment, as Figure 2 As shown, the neighboring pixels of the current round seed point can be the eight neighboring pixels of the current round seed point, that is, the pixels at the eight positions above, below, left, right, upper left, lower left, upper right, and lower right of the current round seed point; the gradient direction difference condition can refer to the gradient direction difference condition between the next round seed point and the current round seed point, for example, the absolute value of the gradient direction difference between the next round seed point and the current round seed point is less than A, where A can be 45 degrees; the gradient intensity difference condition can refer to the gradient intensity difference condition between the next round seed point and the current round seed point, for example, the absolute value of the gradient intensity difference between the next round seed point and the current round seed point is less than B, where B can be 30.
[0061] Specifically, such as Figure 2As shown, the computer device selects the pixel with the largest gradient intensity from all pixels as the current round seed point of the current segment edge sequence. From the pixels in the neighborhood of the current round seed point, it determines the pixel with the largest gradient intensity as the next round seed point to be verified. It then checks whether the absolute value of the difference in gradient direction between the next round seed point and the current round seed point is less than A, and whether the absolute value of the difference in gradient intensity between the next round seed point and the current round seed point is less than B. If both are true, the next round seed point meets the requirements and can be used as the next round seed point of the current segment edge sequence. If neither is true (i.e., if one condition is not met), the next round seed point does not meet the requirements, indicating that no next round seed point can be selected from the pixels in the neighborhood of the current round seed point of the current segment edge sequence. The selected seed points of each round of the current segment edge sequence are then used to form the current segment edge sequence. The process then proceeds to determine / compose the next segment edge sequence. If the seed point meets the requirements and can be used as the next seed point of the current segment edge sequence, it is used as the current seed point of the current segment edge sequence. The process then jumps to selecting pixels from the neighborhood of the current seed point whose gradient direction and gradient intensity satisfy the gradient direction difference condition and are used as the next seed point of the current segment edge sequence. This process continues until no next seed point can be selected from the neighborhood of the current seed point of the current segment edge sequence. Finally, the selected seed points of each round of the current segment edge sequence are used to form the current segment edge sequence.
[0062] For example, the selected seed points are all pixels that have not been added to / formed the edge sequence (i.e., the selected seed points are all in an untraversed state, that is, they have not yet been marked as traversed).
[0063] The technical solution of this embodiment, after obtaining the current round seed point of the current segment edge sequence, iteratively selects the corresponding pixel point from the remaining pixel points that have not been added to / formed the edge sequence as the next round seed point of the current segment edge sequence, thereby forming the current segment edge sequence with the selected seed points. This is beneficial to obtaining a more accurate current segment edge sequence, which in turn is beneficial to improving the accuracy and efficiency of determining the location of the target object in the image.
[0064] In some embodiments, the above method may further compose the next edge sequence of the image to be identified by the following steps, specifically including:
[0065] From the pixels in the image to be identified, excluding the pixels included in the current edge sequence, select the pixel with the largest gradient intensity as the current round seed point for the next edge sequence included in the image to be identified;
[0066] From the neighboring pixels of the current seed point of the next edge sequence, select the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition, and use them as the next seed point of the next edge sequence.
[0067] The process of taking the next seed point of the next edge sequence as the current seed point of the next edge sequence, and jumping to the neighboring pixels of the current seed point of the next edge sequence, selecting the corresponding pixel whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition, as the next seed point of the next edge sequence, continues until no next seed point of the next edge sequence can be selected from the neighboring pixels of the current seed point of the next edge sequence.
[0068] The seed points of each round of the selected next edge sequence are used to form the next edge sequence.
[0069] Specifically, the computer device selects the pixel with the largest gradient intensity from the pixels in the image to be recognized, excluding those included in the current edge sequence (i.e., pixels that have not been traversed), as the current round seed point for the next edge sequence. Then, from the neighborhood pixels of the current round seed point of the next edge sequence, it selects the pixel with the largest gradient intensity as the next round seed point for the next edge sequence to be verified. It then determines whether the absolute value of the difference between the gradient direction of the next round seed point and the current round seed point is less than A, and whether the absolute value of the difference between the gradient intensity of the next round seed point and the current round seed point is less than B. If both are true, the next round seed point meets the requirements and can be used as the next round seed point for the next edge sequence. If neither is true (i.e., if one condition is not met), the next round seed point does not meet the requirements, indicating that the current round seed point for the next edge sequence is not valid. If no seed point for the next edge sequence can be selected from the pixels in the neighborhood of a sub-point, then the selected seed points for the next edge sequence are combined to form the next edge sequence. Then, the process of judging / composing the next edge sequence begins. If the seed point meets the requirements and can be used as the seed point for the next edge sequence, then the seed point for the next edge sequence is used as the current seed point for the next edge sequence. The process then jumps to selecting the corresponding pixel from the pixels in the neighborhood of the current seed point for the next edge sequence whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition, and this step continues until no seed point for the next edge sequence can be selected from the pixels in the neighborhood of the current seed point for the next edge sequence. Finally, the selected seed points for the next edge sequence are combined to form the next edge sequence.
[0070] For example, after obtaining all edge sequences, the computer device determines the positional relationship between the start and end points of each edge sequence and the start and end points of nearby edge sequences (the start and end points are the first and last pixels of the edge sequence). When the two start and end points of two edge sequences (such as the start or end point of one edge sequence and the start or end point of another edge sequence) satisfy the gradient direction difference condition and the gradient intensity difference condition (for example, the gradient intensity difference is less than 30 and the gradient direction difference is less than 45 degrees), the two edge sequences are spliced into one edge sequence.
[0071] The technical solution of this embodiment, after obtaining the current seed point of the next edge sequence, iteratively selects the corresponding pixel from the remaining pixels that have not been added to / formed the edge sequence as the next seed point of the next edge sequence, thereby forming the selected seed points into the next edge sequence. This is beneficial to obtaining a more accurate next edge sequence, which in turn helps to improve the accuracy and efficiency of determining the location of the target object in the image.
[0072] In some embodiments, step S103 above, which determines the target angle information corresponding to the target object based on one or more edge sequences, specifically includes:
[0073] Perform linear fitting on one or more edge sequences to obtain multiple fitted lines corresponding to one or more edge sequences;
[0074] By combining multiple fitted lines, multiple candidate angle information corresponding to the target object can be obtained;
[0075] Based on the line fitting error and line length information corresponding to each candidate angle, the target angle information is determined from multiple candidate angle information.
[0076] In this embodiment, as Figure 3 As shown, the line fitting process can be a process of fitting a line using the least squares method; the fitted line can be a fitted line obtained by fitting a line to the pixels in the edge sequence; the candidate angle information can be composed of two lines and an intersection point of the two lines; the line fitting error can be the fitting error corresponding to the fitted line obtained by performing line fitting processing on the pixels; the line length information can be the length of the line.
[0077] Specifically, the computer equipment performs line fitting on the edge sequence to obtain multiple fitted lines corresponding to the edge sequence. These fitted lines can form angle information, and each angle information can be composed of two lines (where the two lines intersect at a point). This yields candidate angle information corresponding to the target object. Based on the line fitting error and line length information of the two lines in each candidate angle information, the line fitting error and line length information of the two lines can be used as a judgment score (where the line fitting error is smaller and the line length is larger, the score is higher). The candidate angle information with the highest score is output as the target angle information.
[0078] For example, such as Figure 3 As shown, for each edge sequence, the computer device selects the leftmost endpoint of the edge sequence as the initial seed point. It then takes C points (C can be 5) along the left direction of the seed point (the left direction can be understood as the pixels added earlier in the edge sequence), adding them to the left line point sequence. A least-squares method is used to fit a straight line, and the fitting error is checked to see if it is less than E (E can be 5). If it is, the process of taking C points along the left direction of the seed point and adding them to the left line point sequence is repeated until the fitting error is not less than E. Similarly, D points (D can be 5) are taken along the right direction of the seed point (the right direction can be understood as the pixels added later in the edge sequence), adding them to the right line point sequence, and the least-squares method is used to fit a straight line, checking if the fitting error is less than E (E can be 5). If yes, then repeatedly take D points along the right direction of the seed point and add them to the right line point sequence until the fitting error is not less than E. Then, determine whether the angle between the two lines meets the angle range (e.g., greater than 60 degrees and less than 120 degrees). If yes, add candidate angle information (add candidate angle information to the data structure composed of the two lines). If no, move the seed point position one position to the right and determine whether the seed point position coincides with the rightmost end (i.e., whether it reaches the last pixel of the edge sequence). If no, repeat the above steps (i.e., start from the step of taking C points along the left direction of the seed point and adding them to the left line point sequence) until the seed point position coincides with the rightmost end. If the seed point position coincides with the rightmost end, filter the candidate angle information, use the fitting error of the two lines and the length of the two lines as the judgment score, and output the candidate angle information with the highest score as the target angle information.
[0079] The technical solution of this embodiment obtains candidate angle information through edge sequences, and then determines the target angle information from the candidate angle information, which helps to improve the accuracy of determining the location of the target object in the image.
[0080] In some embodiments, the above method can also identify one or more edge sequences from the processed image to be identified through the following steps, specifically including:
[0081] The image to be recognized is subjected to noise reduction and grayscale mapping to obtain the processed image to be recognized.
[0082] Based on the gradient information of each pixel in the processed image to be identified, one or more edge sequences can be identified from the processed image to be identified.
[0083] In this embodiment, noise cancellation processing can be smoothing filtering processing.
[0084] Specifically, after acquiring the image to be recognized, the computer device performs noise reduction and grayscale mapping on the image to be recognized to obtain the processed image to be recognized. Based on the gradient information of each pixel in the processed image to be recognized, the edge sequence is identified from the processed image to be recognized.
[0085] For example, such as Figure 2 As shown, after acquiring the image to be recognized, the computer device performs noise reduction and grayscale mapping on the image to obtain the processed image to be recognized. Pixels with gradient strength less than the F value (F value can be 30) are filtered out. The remaining pixels in the image are sorted by gradient strength (so that the pixel with the largest gradient strength among the untraversed pixels can be quickly identified later). The strongest untraversed gradient point is selected as the seed point, and it is determined whether the gradient of the entire image has been traversed. If not, the seed point is added to the edge sequence. Eight-neighborhood region growing is performed based on the gradient direction and gradient strength of the seed point. The traversed points are marked as traversed. The gradient strength of the eight neighbors is sorted, and the point with the strongest gradient is selected as the next seed point. The edge sequence is obtained step by step. If the gradient of the entire image has been traversed, the edge sequence array is finally output (the edge sequence array contains all edge sequences).
[0086] The technical solution of this embodiment, by performing noise reduction and grayscale mapping processing on the image to be recognized, helps to eliminate the problems of noise and grayscale unevenness caused by image acquisition, and helps to obtain a more accurate edge sequence, thereby improving the accuracy of determining the location of the target object in the image.
[0087] In some embodiments, step S104, which determines the location of the target object in the image to be identified based on the preset morphological features and target angle information of the target object, specifically includes:
[0088] Based on the target angle information, determine the positioning box that satisfies the preset shape characteristics of the target object, and use the positioning box that satisfies the preset shape characteristics of the target object as the positioning box of the target object.
[0089] Based on the bounding box of the target object, determine the location of the target object in the image to be recognized.
[0090] In this embodiment, the positioning frame can be a parallelogram, a square, or a rectangle.
[0091] Specifically, the computer device determines a positioning box that meets the preset shape characteristics of the target object based on the target angle information, uses the positioning box that meets the preset shape characteristics of the target object as the positioning box of the target object, and determines the positioning position of the target object in the image to be recognized based on the positioning box of the target object.
[0092] For example, such as Figure 4 and Figure 5 As shown, the computer device calculates the vertex of the angle (such as the intersection of two straight lines) based on the preset shape characteristics of the target object. Figure 4 and Figure 5 (corner point) relative to the two endpoints (e.g.) Figure 4 and Figure 5 The symmetrical point of the line connecting vertices 1 and 2 in the image is used to complete the angle information into a parallelogram, which serves as the bounding box for the target object. Based on the bounding box, the location of the target object in the image to be recognized is determined. For example, Figure 4 and Figure 5 The hollow dots shown correspond to pixels in the edge sequence. By performing line fitting on these pixels, we obtain the following... Figure 5 The two arrows shown are straight lines ( Figure 5 The two arrow lines shown can be represented as edge sequences of the same segment.
[0093] The technical solution of this embodiment determines the location of the target object in the image to be identified by a positioning box, which helps to improve the accuracy and efficiency of determining the location of the target object in the image.
[0094] In some embodiments, the above method can also obtain object information of the target object through the following steps, specifically including:
[0095] Based on the location, the target object is decoded to obtain the decoded information of the target object;
[0096] The decoded information is then identified to obtain the object information of the target object.
[0097] In this embodiment, the object information of the target object can be information contained in the target object, such as information contained in a QR code.
[0098] Specifically, after determining the location of the target object in the image to be recognized based on the preset morphological features and target angle information of the target object, the computer equipment decodes the target object according to the location to obtain the decoded information of the target object, and then recognizes the decoded information to obtain the object information of the target object.
[0099] For example, the computer device projects a transformation onto an image based on the positioning result (location), samples and binarizes the transformed image, then decodes the target object based on its decoding definition, translates the decoded ASCII code (American Standard Code for Information Interchange), and finally outputs the result (object information of the target object) to the front end. For instance, such as... Figure 6 As shown, the computer equipment first acquires images, then performs corner search and matching positioning, and finally identifies the target object and outputs the results.
[0100] The technical solution of this embodiment obtains the object information of the target object by decoding and recognizing the target object, thereby improving the efficiency of recognizing / scanning the target object after locating it.
[0101] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps.
[0102] Based on the same inventive concept, this application also provides an image recognition device. The solution provided by this device is similar to the solution described in the above method. Therefore, the specific limitations in the image recognition device embodiments provided below can be found in the limitations of the image recognition method above, and will not be repeated here.
[0103] In some embodiments, such as Figure 7 As shown, an image recognition device 700 is provided, which may include:
[0104] The acquisition module 701 is used to acquire the image to be recognized; the image to be recognized contains the target object;
[0105] The recognition module 702 is used to identify one or more edge sequences from the image to be recognized based on the gradient information of each pixel in the image to be recognized; the edge sequence is composed of corresponding pixels whose gradient information satisfies a preset gradient difference condition;
[0106] The determination module 703 is used to determine the target angle information corresponding to the target object based on one or more edge sequences;
[0107] The positioning module 704 is used to determine the positioning position of the target object in the image to be recognized based on the preset morphological features and target angle information of the target object.
[0108] In some embodiments, gradient information includes gradient direction and gradient intensity; preset gradient difference conditions include gradient direction difference conditions and gradient intensity difference conditions; in identifying one or more edge sequences from an image to be identified based on the gradient information of each pixel in the image to be identified, the identification module 702 is specifically used for:
[0109] Based on the gradient direction and gradient intensity of each pixel in the image to be identified, the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition are used to form one or more edge sequences in the image to be identified.
[0110] In some embodiments, the number of edge sequences is multiple segments; in terms of forming one or more edge sequences included in the image to be identified by combining corresponding pixels whose gradient directions satisfy gradient direction difference conditions and whose gradient intensities satisfy gradient intensity difference conditions according to the gradient direction and gradient intensity of each pixel in the image to be identified, the device 700 further includes: an edge sequence composition module, specifically used to form the current segment edge sequence included in the image to be identified by combining corresponding pixels whose gradient directions satisfy gradient direction difference conditions and whose gradient intensities satisfy gradient intensity difference conditions according to the gradient direction and gradient intensity of each pixel in the image to be identified; and to form the current segment edge sequence included in the image to be identified by combining corresponding pixels whose gradient directions satisfy gradient direction difference conditions and whose gradient intensities satisfy gradient intensity difference conditions according to the gradient direction and gradient intensity of each pixel in the image to be identified; and to form the current segment edge sequence included in the image to be identified by combining corresponding pixels whose gradient directions satisfy gradient direction difference conditions and whose gradient intensities satisfy gradient intensity difference conditions according to the gradient direction and gradient intensity of each pixel in the image to be identified. The gradient direction and gradient intensity of pixels other than those included in the current edge sequence are used to form the next edge sequence of the image to be identified. The next edge sequence is used as the current edge sequence, and the process continues until the next edge sequence is the last edge sequence of the image to be identified.
[0111] In some embodiments, in forming the current segment edge sequence of the image to be identified by selecting corresponding pixels whose gradient directions satisfy the gradient direction difference condition and whose gradient intensities satisfy the gradient intensity difference condition, based on the gradient direction and gradient intensity of each pixel in the image to be identified, the apparatus 700 further includes: a current segment edge sequence composition module, specifically configured to select the pixel with the largest gradient intensity from each pixel in the image to be identified as the current round seed point of the current segment edge sequence of the image to be identified; and select pixels from the neighboring pixels of the current round seed point of the current segment edge sequence whose gradient directions satisfy the gradient direction difference condition and whose gradient intensities satisfy the gradient intensity difference condition. The corresponding pixel point of the intensity difference condition is used as the next round seed point of the current segment edge sequence; the next round seed point of the current segment edge sequence is used as the current round seed point of the current segment edge sequence, and the process jumps to the neighboring pixels of the current round seed point of the current segment edge sequence, selecting the corresponding pixel point whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition, as the next round seed point of the current segment edge sequence, until no next round seed point of the current segment edge sequence can be selected from the neighboring pixels of the current round seed point of the current segment edge sequence; the selected round seed points of the current segment edge sequence are combined to form the current segment edge sequence.
[0112] In some embodiments, in determining the target angle information corresponding to the target object based on one or more edge sequences, the determining module 703 is specifically used to perform straight line fitting processing on one or more edge sequences to obtain multiple fitted straight lines corresponding to one or more edge sequences; to perform combination processing on the multiple fitted straight lines to obtain multiple candidate angle information corresponding to the target object; and to determine the target angle information from the multiple candidate angle information based on the straight line fitting error and straight line length information corresponding to each candidate angle information.
[0113] In some embodiments, the device 700 further includes: a module for obtaining an image to be identified, specifically configured to perform noise reduction processing and grayscale mapping processing on the image to be identified to obtain a processed image to be identified; and an identification module 702, further configured to identify one or more edge sequences from the processed image to be identified based on the gradient information of each pixel in the processed image to be identified.
[0114] In some embodiments, in determining the location of the target object in the image to be recognized based on the preset morphological features and target angle information of the target object, the positioning module 704 is specifically used to determine a positioning box that satisfies the preset morphological features of the target object based on the target angle information, and use the positioning box that satisfies the preset morphological features of the target object as the positioning box of the target object; and determine the location of the target object in the image to be recognized based on the positioning box of the target object.
[0115] In some embodiments, the device 700 further includes: an object information obtaining module, specifically configured to decode the target object according to the positioning location to obtain the decoded information of the target object; and to identify the decoded information to obtain the object information of the target object.
[0116] Each module in the aforementioned image recognition device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0117] In some embodiments, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 8 As shown, the computer device includes a processor, memory, input / output interfaces (I / O), communication interfaces, a display screen, and input devices. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interfaces, input devices, and display screen are also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. The I / O interfaces are used for exchanging information between the processor and external devices. When the computer program is executed by the processor, it implements the steps in the image recognition method described above. The display screen of the computer device can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs or touchpads set on the casing of the computer device, or external keyboards, touchpads or mice, etc.
[0118] Those skilled in the art will understand that Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0119] In some embodiments, a computer device is also provided, the computer device including a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the steps in the above method embodiments.
[0120] In some embodiments, such as Figure 9 As shown, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps in the above-described method embodiments.
[0121] In some embodiments, a computer program product is provided, which includes a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0122] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data shall comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0123] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0124] The technical features of the above embodiments can be combined in any way. For the sake of brevity, 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.
[0125] The above embodiments are merely illustrative of several implementation methods of this application, and their descriptions are relatively specific and detailed. However, they should not be construed as limiting the scope of this application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. An image recognition method, characterized in that, include: Acquire an image to be identified; the image to be identified contains a target object; Based on the gradient information of each pixel in the image to be identified, one or more edge sequences are identified from the image to be identified; the edge sequence is composed of corresponding pixels whose gradient information satisfies a preset gradient difference condition; Based on the one or more edge sequences, determine the target angle information corresponding to the target object; Based on the preset morphological features of the target object and the target angle information, the positioning position of the target object in the image to be identified is determined; The gradient information includes gradient direction and gradient intensity; the preset gradient difference condition includes gradient direction difference condition and gradient intensity difference condition; the step of identifying one or more edge sequences from the image to be identified based on the gradient information of each pixel in the image to be identified includes: When the number of edge sequences is multiple segments, according to the gradient direction and gradient intensity of each pixel in the image to be identified, the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition are used to form the current segment edge sequence of the image to be identified. Based on the gradient direction and gradient intensity of the pixels in the image to be identified, excluding the pixels included in the current segment edge sequence, the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition are used to form the next segment edge sequence included in the image to be identified. The next edge sequence is taken as the current edge sequence, and the process jumps to the step of forming the next edge sequence of the image to be identified by combining the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition, based on the gradient direction and gradient intensity of the pixels in the image to be identified other than those included in the current edge sequence, until the next edge sequence is the last edge sequence of the image to be identified.
2. The method according to claim 1, characterized in that, The step of forming the current segment edge sequence of the image to be identified by grouping corresponding pixels whose gradient directions satisfy the gradient direction difference condition and whose gradient intensities satisfy the gradient intensity difference condition, based on the gradient direction and gradient intensity of each pixel in the image to be identified, includes: Select the pixel with the largest gradient intensity from all pixels in the image to be identified, and use it as the current round seed point of the current segment edge sequence included in the image to be identified; From the neighboring pixels of the current seed point of the current segment edge sequence, select the corresponding pixel whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition, and use it as the next seed point of the current segment edge sequence. The next seed point of the current segment edge sequence is used as the current seed point of the current segment edge sequence, and the process jumps to the step of selecting the corresponding pixel from the neighboring pixels of the current seed point of the current segment edge sequence whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition, as the next seed point of the current segment edge sequence, until no next seed point of the current segment edge sequence can be selected from the neighboring pixels of the current seed point of the current segment edge sequence; The selected seed points of each round of the current segment edge sequence are used to form the current segment edge sequence.
3. The method according to claim 1, characterized in that, The step of determining the target angle information corresponding to the target object based on the one or more edge sequences includes: Perform linear fitting on the one or more edge sequences to obtain multiple fitted lines corresponding to the one or more edge sequences; The multiple fitted straight lines are combined to obtain multiple candidate angle information corresponding to the target object; The target angle information is determined from the plurality of candidate angle information based on the line fitting error and line length information corresponding to each candidate angle information.
4. The method according to claim 1, characterized in that, After acquiring the image to be recognized, the process also includes: The image to be identified is subjected to noise reduction and grayscale mapping to obtain the processed image to be identified; The step of identifying one or more edge sequences from the image to be identified based on the gradient information of each pixel in the image to be identified includes: Based on the gradient information of each pixel in the processed image to be identified, one or more edge sequences are identified from the processed image to be identified.
5. The method according to claim 1, characterized in that, Determining the location of the target object in the image to be identified based on the preset morphological features of the target object and the target angle information includes: Based on the target angle information, a positioning frame that satisfies the preset shape characteristics of the target object is determined, and the positioning frame that satisfies the preset shape characteristics of the target object is used as the positioning frame of the target object; Based on the bounding box of the target object, the location of the target object in the image to be identified is determined.
6. The method according to claim 1, characterized in that, After determining the location of the target object in the image to be identified based on the preset morphological features of the target object and the target angle information, the method further includes: Based on the location, the target object is decoded to obtain the decoded information of the target object; The decoded information is identified to obtain the object information of the target object.
7. An image recognition device, characterized in that, include: The acquisition module is used to acquire the image to be identified; the image to be identified contains the target object; The recognition module is used to identify one or more edge sequences from the image to be recognized based on the gradient information of each pixel in the image to be recognized; the edge sequence is composed of corresponding pixels whose gradient information satisfies a preset gradient difference condition; The determining module is used to determine the target angle information corresponding to the target object based on the one or more edge sequences; The positioning module is used to determine the positioning position of the target object in the image to be identified based on the preset morphological features of the target object and the target angle information; Wherein, the gradient information includes gradient direction and gradient intensity; the preset gradient difference condition includes gradient direction difference condition and gradient intensity difference condition; in terms of identifying one or more edge sequences from the image to be identified based on the gradient information of each pixel in the image to be identified, the recognition module is specifically used for: When the number of edge sequences is multiple segments, according to the gradient direction and gradient intensity of each pixel in the image to be identified, the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition are used to form the current segment edge sequence of the image to be identified. Based on the gradient direction and gradient intensity of the pixels in the image to be identified, excluding the pixels included in the current segment edge sequence, the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition are used to form the next segment edge sequence included in the image to be identified. The next edge sequence is taken as the current edge sequence, and the process jumps to the step of forming the next edge sequence of the image to be identified by combining the corresponding pixels whose gradient direction satisfies the gradient direction difference condition and whose gradient intensity satisfies the gradient intensity difference condition, based on the gradient direction and gradient intensity of the pixels in the image to be identified other than those included in the current edge sequence, until the next edge sequence is the last edge sequence of the image to be identified.
8. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.