Disclosure of Invention
The application aims to provide a bar code positioning method which can effectively improve the accuracy of bar code positioning and ensure the normal identification of the subsequent bar codes; another object of the present application is to provide a bar code positioning device, apparatus and computer readable storage medium, which also have the above-mentioned advantageous effects.
In order to solve the technical problems, the application provides a bar code positioning method, which comprises the following steps:
receiving an image to be positioned acquired by image acquisition equipment;
dividing the image to be positioned by an adaptive threshold algorithm to determine a face sheet area;
performing edge detection on the surface sheet region by using a Sobel operator to obtain a gradient intensity map;
and (3) bar code positioning is carried out in the gradient intensity map, and bar code areas are determined.
Preferably, the method further includes, before the step of dividing the image to be localized by an adaptive threshold algorithm and determining the area of the face sheet, the steps of:
and carrying out gray level conversion on the image to be positioned to obtain a gray level image.
Preferably, the processing of dividing the image to be localized by an adaptive threshold algorithm to determine a face sheet area includes:
dividing the gray level image according to a preset dividing threshold value to obtain a first foreground image and a first background image;
calculating the gray average value of the first foreground image and the gray average value of the first background image;
calculating the average value of the gray average value of the first foreground image and the gray average value of the first background image to obtain a first segmentation threshold;
dividing the first foreground image according to the first dividing threshold value to obtain a second foreground image and a second background image;
calculating the gray average value of the second foreground image and the gray average value of the second background image;
judging whether the gray average value of the second foreground image is equal to the gray average value of the first foreground image or not, and whether the gray average value of the second background image is equal to the gray average value of the first background image or not;
if not, calculating the average value of the gray average value of the second foreground image and the average value of the gray average value of the first foreground image to obtain a second segmentation threshold; dividing the second foreground image according to the second dividing threshold value until the gray average value of the current foreground image is equal to the gray average value of the previous foreground image, and the gray average value of the current background image is equal to the gray average value of the previous background image;
and taking the current foreground image as the menu area.
Preferably, the processing of dividing the image to be localized by an adaptive threshold algorithm, after determining the area of the face sheet, further includes:
and carrying out normalization processing on the surface single region to obtain a standard surface single region.
Preferably, the performing edge detection on the surface sheet area by using a Sobel operator to obtain a gradient intensity map includes:
establishing an image coordinate system in the face sheet area;
establishing a preset number of Sobel operator groups in the image coordinate system according to preset angle intervals;
and sequentially carrying out edge detection on the single area by taking the start angle Sobel operator group as a starting point and the end angle Sobel operator group as an end point to obtain the gradient intensity map.
Preferably, the positioning of the bar code in the gradient intensity map, and determining the bar code area, includes:
carrying out Gaussian filtering treatment on the gradient intensity map to obtain a filtering map;
performing binarization processing on the filter map to obtain a binarized image;
performing expansion corrosion and void filling on the binary image through morphological operation to obtain a morphological image;
and determining the bar code area in the morphological image by using a maximum circumscribed rectangle algorithm.
Preferably, the method for positioning the bar code further comprises:
calculating a first deflection angle of the bar code area relative to the horizontal direction through a Hough transform algorithm;
calculating a second deflection angle of the bar code area relative to the horizontal direction through a contour searching algorithm;
calculating the average value of the first deflection angle and the second deflection angle;
and correcting the bar code area according to the average value to obtain a corrected bar code area.
In order to solve the technical problem, the application also provides a bar code positioning device, which comprises:
the image acquisition module is used for receiving the image to be positioned acquired by the image acquisition equipment;
the image segmentation module is used for carrying out segmentation processing on the image to be localized through a self-adaptive threshold algorithm to determine a face sheet area;
the edge detection module is used for carrying out edge detection on the face sheet area by utilizing a Sobel operator to obtain a gradient intensity graph;
and the bar code positioning module is used for positioning the bar code in the gradient intensity diagram and determining a bar code area.
In order to solve the technical problem, the present application further provides a barcode positioning device, including:
a memory for storing a computer program;
and the processor is used for realizing any one of the bar code positioning methods when executing the computer program.
To solve the above technical problem, the present application further provides a computer readable storage medium, on which a computer program is stored, which when executed by a processor, implements the steps of any one of the barcode positioning methods described above.
The application provides a bar code positioning method, which comprises the steps of receiving an image to be positioned, which is acquired by image acquisition equipment; dividing the image to be positioned by an adaptive threshold algorithm to determine a face sheet area; performing edge detection on the surface sheet region by using a Sobel operator to obtain a gradient intensity map; and (3) bar code positioning is carried out in the gradient intensity map, and bar code areas are determined.
Therefore, the barcode positioning method provided by the application can be used for dividing the image to be positioned by the self-adaptive threshold algorithm to obtain the area of the face sheet including the barcode after the image to be positioned is obtained and before the image to be positioned is positioned, so that the background part irrelevant to the barcode can be removed, various possible interferences such as the influence of burst noise interference, high gray level change complexity and the like caused by the background part can be effectively avoided, and further, the accuracy of the barcode positioning result can be greatly improved when the subsequent edge detection and positioning are carried out based on the area of the face sheet, thereby ensuring the normal proceeding of the subsequent barcode recognition process.
The bar code positioning device, the bar code positioning equipment and the computer readable storage medium provided by the application have the beneficial effects and are not repeated herein.
Detailed Description
The core of the application is to provide a bar code positioning method which can effectively improve the accuracy of bar code positioning and ensure the normal identification of the subsequent bar code; another core of the present application is to provide a bar code positioning device, apparatus and computer readable storage medium, which also have the above-mentioned advantageous effects.
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Referring to fig. 1, fig. 1 is a flow chart of a bar code positioning method provided by the present application, where the bar code positioning method may include:
s101: receiving an image to be positioned acquired by image acquisition equipment;
the method aims at acquiring an image to be positioned, wherein the image to be positioned is an image needing bar code positioning, the process can be realized based on image acquisition equipment, and the specific type and model of the image acquisition equipment are not limited, and the method can be a mobile terminal camera, a professional camera and the like; further, the image acquisition device can send the image to be positioned captured by the image acquisition device to a processor for realizing the bar code positioning function for subsequent flow.
S102: dividing an image to be positioned through a self-adaptive threshold algorithm to determine a face list area;
the method aims at realizing segmentation processing of the image to be positioned, and the specific implementation process can be realized based on an adaptive threshold algorithm, so that a face single region is obtained, wherein the face single region is a region which is used for filtering out irrelevant background parts in the image to be positioned and only comprises bar code information. For example, for a parcel, an express bill is typically attached to the parcel, but when image acquisition is performed based on an image acquisition device, only the operation of taking the express bill is generally difficult to achieve, so that most of the obtained images to be positioned include a part of the parcel, and due to the problems of uneven light, large gray level change and the like, the subsequent barcode positioning is likely to be greatly affected, and when the images to be positioned are subjected to segmentation processing through an adaptive threshold algorithm, an image only including the express bill, namely the above-mentioned area of the express bill, can be obtained.
For the adaptive threshold algorithm, the type of the corresponding threshold standard is not unique, for example, the type can be a median, a mean, gaussian convolution, and the like, and the implementation of the technical scheme is not affected.
As a preferred embodiment, the above-mentioned image to be located is subjected to segmentation processing by using an adaptive threshold algorithm, and before determining the area of the face sheet, the method may further include: and carrying out gray level conversion on the image to be positioned to obtain a gray level image.
Specifically, the images collected by the common image collecting device are mostly color photos, and the complexity of color change can bring great influence to the positioning work of the bar code, so that after the images to be positioned are obtained, the images can be subjected to gray level conversion to obtain corresponding gray level images, further, subsequent image segmentation operation can be performed based on the gray level images, and the accuracy of the positioning result of the bar code is effectively improved.
Preferably, the process of dividing the image to be positioned by the adaptive threshold algorithm to determine the area of the face sheet may specifically include: dividing the gray level image according to a preset dividing threshold value to obtain a first foreground image and a first background image; calculating a gray average value of the first foreground image and a gray average value of the first background image; calculating the average value of the gray average value of the first foreground image and the gray average value of the first background image to obtain a first segmentation threshold; dividing the first foreground image according to a first dividing threshold value to obtain a second foreground image and a second background image; calculating the gray average value of the second foreground image and the gray average value of the second background image; judging whether the gray average value of the second foreground image is equal to the gray average value of the first foreground image, and whether the gray average value of the second background image is equal to the gray average value of the first background image; if not, calculating the average value of the gray average value of the second foreground image and the average value of the gray average value of the first foreground image to obtain a second segmentation threshold value; dividing the second foreground image according to a second dividing threshold value until the gray average value of the current foreground image is equal to the gray average value of the previous foreground image and the gray average value of the current background image is equal to the gray average value of the previous background image; the current foreground image is taken as a menu area.
The process of obtaining the preset segmentation threshold may include: and calculating the maximum gray value and the minimum gray value of the gray map, calculating the average value of the maximum gray value and the minimum gray value, and taking the average value as the preset dividing threshold value.
The above image segmentation process is described in detail below by way of example:
firstly, acquiring a gray level image of an image to be positioned, and calculating a maximum gray level value X in the gray level image max And a minimum gray value X min Through T 0 =(X max +X min ) 2 obtaining a preset segmentation threshold T 0 The method comprises the steps of carrying out a first treatment on the surface of the Further, according to the preset segmentation threshold S 1 Dividing the gray scale map into foreground S 1 And background S 2 And calculates the foreground S 1 Is the gray average value a of (2) 1 And background S 2 Is the gray average value a of (2) 2 Thus, let t= (a 1 +a 2 ) 2 as a new segmentation threshold pair foreground S 1 Performing segmentation, and repeating the segmentation process until a 1 And a 2 No change occurs anymore, i.e. a obtained by the current iteration process 1 And a 2 Respectively with a obtained from the last iteration 1 And a 2 Equal, thus, it is stated that the foreground image currently obtained no longer includes a background portion unrelated to the bar code, i.e., the foreground image is a face-sheet region.
As a preferred embodiment, the above-mentioned image to be located is subjected to segmentation processing by an adaptive threshold algorithm, and after determining the area of the face sheet, the method may further include: and carrying out normalization processing on the face sheet area to obtain a standard face sheet area.
The step aims at realizing the normalization processing of the image, effectively simplifying the calculation and reducing the magnitude, and particularly can obtain a standard face single region within 800 x 600 of the obtained face single region normalization value, thereby being more convenient for the subsequent image edge detection and bar code positioning.
S103: performing edge detection on the face single region by using a Sobel operator to obtain a gradient intensity map;
the method aims at realizing edge detection of the face sheet area, and the specific implementation process can be realized based on a Sobel operator, so that a corresponding gradient map with stronger characteristics, namely the gradient intensity map, is further obtained.
As a preferred embodiment, the process of performing edge detection on the face sheet region by using the Sobel operator to obtain the gradient intensity map may specifically include: establishing an image coordinate system in the area of the face sheet; establishing a preset number of Sobel operator groups in an image coordinate system according to preset angle intervals; and sequentially carrying out edge detection on the surface single region by taking the starting angle Sobel operator group as a starting point and the ending angle Sobel operator group as an ending point to obtain a gradient intensity map.
In general, when the Sobel operator performs edge detection, the method is realized based on a group of Sobel operators, and in order to further ensure the accuracy of bar code positioning, a plurality of groups of Sobel operators are newly added to realize the acquisition of a gradient intensity map. Specifically, firstly, an image coordinate system is established in a face sheet area, and Sobel operator groups are set according to preset angle intervals, and of course, the specific values of the preset angle intervals and the number of Sobel operator groups are not specifically limited, for example, the preset angle intervals are set to be 30 degrees, the preset number is set to be 3 in the application, and therefore, the distribution situation of the 3 Sobel operator groups is as follows: sobel operator group of 0 degree direction (i.e., image coordinate system x-axis) and 90 degree direction (i.e., image coordinate system y-axis); 30-degree and 120-degree Sobel operator groups; sobel operator group in 60 degree direction and 150 degree direction. Further, with the start angle Sobel operator group (Sobel operator group in the 0 degree direction and the 90 degree direction) as a start point and the end angle Sobel operator group (Sobel operator group in the 60 degree direction and the 150 degree direction) as an end point, edge detection is sequentially performed on the opposite single region, that is, gradient graphs in two directions obtained by each Sobel operator group are subtracted sequentially, and therefore, the characteristics of the corresponding obtained gradient graphs are continuously enhanced, and a final gradient intensity graph is obtained.
S104: and (5) bar code positioning is carried out in the gradient intensity map, and bar code areas are determined.
This step aims at achieving the positioning of the bar code, so as to obtain the corresponding bar code area. Any of the prior art may be used for its specific positioning implementation, and the present application is not limited thereto.
Preferably, the process of positioning the bar code in the gradient intensity map and determining the bar code area may specifically include: carrying out Gaussian filtering treatment on the gradient intensity map to obtain a filtering map; performing binarization processing on the filter map to obtain a binarized image; performing expansion corrosion and void filling on the binary image through morphological operation to obtain a morphological image; and determining the bar code area in the morphological image by using a maximum circumscribed rectangle algorithm.
The application provides a specific bar code positioning realization method, in particular to a bar code region in a gradient intensity diagram obtained based on a Sobel operator has no obvious characteristics relative to other regions, therefore, the gradient intensity diagram can be firstly subjected to Gaussian filtering to obtain a corresponding filtering diagram so as to weaken an interference region of the gradient intensity diagram; further, the filtering diagram is subjected to binarization processing by utilizing a threshold value of 255 to obtain a binarized image, and at the moment, a bar code area on the binarized image is provided with gaps, so that the filtering diagram can be subjected to expansion corrosion and gap filling for a plurality of times through morphological operation to obtain a corresponding morphological image; and finally, finding all outlines in the morphological image by using a maximum circumscribed rectangle algorithm, and selecting the largest outline frame, wherein the area covered by the outline frame is a bar code area, thereby realizing the acquisition of the bar code area.
According to the bar code positioning method provided by the application, after the image to be positioned is obtained and before the bar code positioning is carried out, the image to be positioned is segmented through the self-adaptive threshold algorithm to obtain the face sheet area comprising the bar code, so that the background part irrelevant to the bar code can be removed, various possible interferences such as the influence of burst noise interference, high gray level change complexity and the like caused by the background part can be effectively avoided, and further, the accuracy of the bar code positioning result can be greatly improved when the subsequent edge detection and positioning are carried out based on the face sheet area, and the normal running of the subsequent bar code recognition process is ensured.
Generally, the barcode area obtained based on the positioning operation of the barcode has a certain angle deflection, so in order to facilitate the normal operation of the subsequent barcode identification process, the barcode identification method provided by the application increases the barcode correction process so as to improve the accuracy of barcode identification.
On the basis of the foregoing embodiments, as a preferred embodiment, please refer to fig. 2, fig. 2 is a flow chart of a bar code correction method provided by the present application, the bar code correction method may include:
s201: calculating a first deflection angle of the bar code area relative to the horizontal direction through a Hough transformation algorithm;
s202: calculating a second deflection angle of the bar code area relative to the horizontal direction through a contour searching algorithm;
s203: calculating the average value of the first deflection angle and the second deflection angle;
s204: and correcting the bar code area according to the average value to obtain a corrected bar code area.
The step combines the Hough transformation algorithm and the contour finding algorithm to determine the deflection angle of the bar code, calculates the deflection angle of the bar code based on the Hough transformation algorithm and the contour finding algorithm respectively, obtains a corresponding first deflection angle and a corresponding second deflection angle, further calculates the average value of the first deflection angle and the second deflection angle, and corrects the bar code area by taking the average value as the deflection angle of the bar code area, thereby obtaining the corrected bar code area and effectively reducing the deflection angle error. Wherein, the first deflection angle and the second deflection angle are relative to the horizontal direction. It should be noted that, the execution order of S201 and S202 is not limited, and the two may be executed simultaneously or sequentially, so that implementation of the technical scheme is not affected.
For the calculation of the first deflection angle, hough transformation can be directly performed in the obtained bar code area to find the black and white straight line, and the deflection angle between the bar code area and the horizontal direction is calculated, namely the first deflection angle is obtained.
For the calculation of the second deflection angle, as the inclination condition exists in the bar code area, firstly searching the bar code outline in the bar code area, fitting the bar code outline to an inclined rectangle, and obtaining the most compact external rectangle; further, the second deflection angle with respect to the horizontal direction can be determined from the long side of the most compact circumscribed rectangle. The process of searching the bar code outline may include: since the acquired bar code in the bar code area occupies the main body, the background information is less, and the bar code is formed by alternately arranging black and white bars, the black bar frame outline can be obtained by hollowing out the pixels in the black bars, specifically, each point in the bar code area can be traversed, one point in the encountering area is black (namely, the gray value is 255), and 8 adjacent points are black, which indicates that the point is an internal point, the point can be deleted, therefore, after traversing is completed, only edge pixel points are left, and the black bar frame outline is obtained; further, the bar code profiles are merged according to the similarity of the connected domains, and the merging conditions comprise: the main directions are consistent; the lengths in the horizontal direction are the same; the difference between the included angle formed by the connecting line of the centers of gravity of two adjacent subdomains and the horizontal axis and the included angle of the main direction is not more than 5 degrees; the distance between the circumscribed rectangles formed by two adjacent subfields is not more than the length of the two rectangles in the horizontal direction.
According to the bar code positioning method provided by the embodiment of the application, after bar code positioning is completed, the bar code area is further corrected, so that a more standard corrected bar code area is obtained, and the subsequent bar code recognition process is more convenient to carry out.
In order to solve the above-mentioned problems, please refer to fig. 3, fig. 3 is a schematic structural diagram of a bar code positioning device according to the present application, the bar code positioning device may include:
the image acquisition module 10 is used for receiving the image to be positioned acquired by the image acquisition equipment;
the image segmentation module 20 is used for carrying out segmentation processing on the image to be positioned through a self-adaptive threshold algorithm to determine a face list area;
the edge detection module 30 is configured to perform edge detection on the face sheet area by using a Sobel operator, so as to obtain a gradient intensity map;
and the bar code positioning module 40 is used for positioning the bar code in the gradient intensity map and determining the bar code area.
As a preferred embodiment, the bar code positioning device may further include:
the gray level conversion module is used for carrying out gray level conversion on the image to be positioned to obtain a gray level image.
As a preferred embodiment, the bar code positioning device may further include:
and the normalization module is used for carrying out normalization processing on the face single region to obtain a standard face single region.
As a preferred embodiment, the bar code positioning device may further include:
the bar code correction module is used for calculating a first deflection angle of the bar code area relative to the horizontal direction through a Hough transformation algorithm; calculating a second deflection angle of the bar code area relative to the horizontal direction through a contour searching algorithm; calculating the average value of the first deflection angle and the second deflection angle; and correcting the bar code area according to the average value to obtain a corrected bar code area.
For the description of the device provided by the present application, please refer to the above method embodiment, and the description of the present application is omitted herein.
In order to solve the above-mentioned problems, please refer to fig. 4, fig. 4 is a schematic structural diagram of a bar code positioning apparatus according to the present application, wherein the bar code positioning apparatus may comprise:
a memory 1 for storing a computer program;
a processor 2 for implementing the following steps when executing the computer program:
receiving an image to be positioned acquired by image acquisition equipment; dividing an image to be positioned through a self-adaptive threshold algorithm to determine a face list area; performing edge detection on the face single region by using a Sobel operator to obtain a gradient intensity map; and (5) bar code positioning is carried out in the gradient intensity map, and bar code areas are determined.
For the description of the apparatus provided by the present application, please refer to the above method embodiment, and the description of the present application is omitted herein.
To solve the above problems, the present application also provides a computer readable storage medium having a computer program stored thereon, the computer program when executed by a processor implementing the steps of:
receiving an image to be positioned acquired by image acquisition equipment; dividing an image to be positioned through a self-adaptive threshold algorithm to determine a face list area; performing edge detection on the face single region by using a Sobel operator to obtain a gradient intensity map; and (5) bar code positioning is carried out in the gradient intensity map, and bar code areas are determined.
The computer readable storage medium may include: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
For the description of the computer-readable storage medium provided by the present application, refer to the above method embodiments, and the disclosure is not repeated here.
In the description, each embodiment is described in a progressive manner, and each embodiment is mainly described by the differences from other embodiments, so that the same similar parts among the embodiments are mutually referred. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative elements and steps are described above generally in terms of functionality in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. The software modules may be disposed in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The bar code positioning method, the bar code positioning device, the bar code positioning equipment and the computer readable storage medium provided by the application are described in detail above. The principles and embodiments of the present application have been described herein with reference to specific examples, the description of which is intended only to facilitate an understanding of the method of the present application and its core ideas. It should be noted that it will be apparent to those skilled in the art that various changes and modifications can be made herein without departing from the principles of the application, which also falls within the spirit and scope of the application as defined by the appended claims.