Barcode image acquisition method and related device
By identifying the angle between the camera and the barcode plane in the terminal device and using edge detection and angle correction technology, the problem of terminal devices recognizing barcodes at large angles is solved, and efficient decoding and fast scanning are achieved.
Patent Information
- Application Number
- CN202310217523.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-27
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2043-02-27
AI Technical Summary
When the angle between the user and the barcode is large, it is difficult for the terminal device to quickly and accurately identify the barcode, resulting in increased decoding delay and decreased decoding success rate.
When acquiring a barcode image through a camera, the angle between the camera and the barcode plane is determined, and edge detection algorithms and angle correction technology are used to identify the area where the barcode is located. The scan line algorithm or straight line detection algorithm is used to accurately locate the barcode boundary, and angle correction is performed to obtain an easily recognizable barcode image.
It improves the decoding success rate, reduces the decoding delay, and improves the scanning speed and user experience.
Smart Images

Figure CN116225270B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminals, and in particular to a method for acquiring barcode images and related devices. Background Art
[0002] With the advancement of technology, barcodes are ubiquitous in our lives. They can be used to facilitate quick payments, navigate web pages, access information, and track origins, among other tasks. However, when a user scans a barcode with a terminal, the terminal may struggle to recognize the barcode, or even fail to recognize it, due to factors such as the angle between the user and the barcode. Summary of the Invention
[0003] This application provides a barcode image acquisition method and related devices, which can reduce decoding delay, improve decoding efficiency, and increase the scanning speed of barcode scanning applications while ensuring the decoding success rate, giving users a better user experience.
[0004] In a first aspect, a method for acquiring a barcode image is provided, which is applied to an electronic device and may include: receiving a user operation for triggering a code scan; acquiring a first image containing a barcode through a camera, wherein a first angle is formed between a shooting direction of the camera and a vertical direction of a plane where the barcode is located, and the first angle is greater than 0; if the area ratio of a white background area of the barcode in the first image is greater than or equal to a threshold, using a scanning line algorithm to identify a first area where the barcode is located in the first image; if the area ratio of the white background area of the barcode in the first image is less than a threshold, using a straight line detection algorithm to identify a second area where the barcode is located in the first image.
[0005] By implementing the method provided in the first aspect, the area where the barcode is located in the image containing the barcode obtained by the camera can be accurately detected, thereby increasing the proportion of the barcode in the obtained image. In addition, this method can avoid the problem of barcode information loss due to inaccurate barcode edge recognition, accurately obtain the barcode image, and improve the decoding success rate. In addition, the edge detection algorithm used in the embodiment of the present application is highly efficient, and the area where the barcode is located is accurately located. While ensuring the decoding success rate, it can reduce the decoding delay, improve the decoding efficiency, and increase the scanning speed of code scanning applications, giving users a better user experience.
[0006] In combination with the first aspect, in some embodiments, the method further includes: performing angle correction on the second area to obtain a second image.
[0007] Through the above embodiment, the barcode image captured at a certain angle can be corrected to obtain an easily recognizable barcode image, thereby improving the decoding success rate.
[0008] In conjunction with the previous embodiment, electronic merging can identify the corner points of the second area and use them to perform angle correction on the second area to obtain a second image. By identifying the corner points, the second area can be corrected more quickly and accurately, resulting in an easily recognizable barcode image.
[0009] In combination with the previous embodiment, the electronic device may use a perspective transformation algorithm or an affine transformation algorithm to perform angle correction on the second area to obtain a second image.
[0010] In combination with the above-mentioned various embodiments of performing angle correction on the second area to obtain the second image, in some embodiments, the method may further include: identifying information represented by the barcode in the second image; and performing a corresponding first operation according to the information.
[0011] In combination with the first aspect, in some embodiments, before the electronic device identifies the first area or the second area, the method may also include: binarizing the first image to obtain a binarized image of the first image; determining the contour with the largest area in the binarized image; and determining the area of the area enclosed by the contour in the first image as the area of the white background area of the barcode in the first image.
[0012] In combination with the previous embodiment, in some embodiments,
[0013] Identifying a first area in the first image where the barcode is located using a scan line algorithm, specifically comprising: scanning an area enclosed by a contour in the first image using the scan line algorithm, determining a row on the upper side where a black pixel value first appears, a row on the lower side where a black pixel value last appears, a column on the left side where a black pixel value first appears, and a column on the right side where a black pixel value last appears; and determining an area enclosed by the determined rows and columns as the first area;
[0014] or,
[0015] Using a straight line detection algorithm to identify the second area where the barcode is located in the first image specifically includes: using the straight line detection algorithm to detect straight lines whose outlines are in the area enclosed by the first image, selecting some or all of the detected straight lines; and determining the area enclosed by the selected some or all of the straight lines as the second area.
[0016] In conjunction with the first aspect, in some embodiments, the first angle is greater than the first value, and the first value is greater than 0. The first angle can be dynamically set according to actual needs, for example, the first angle can be set to 30 degrees. In this way, when the electronic device is scanning a barcode at a large angle, it can detect the area where the barcode is located in the image containing the barcode captured by the camera, and can accurately identify the area where the barcode is located, avoiding the problem of barcode information loss due to inaccurate barcode edge recognition, and obtaining an easily recognizable barcode image, thereby improving the decoding success rate.
[0017] In conjunction with the first aspect, in some embodiments, before the electronic device identifies the first area or the second area, the method may further include: identifying that the barcode in the first image has been deformed. When the barcode is deformed, the electronic device may determine that a certain angle exists between the current camera shooting direction and a direction perpendicular to the plane on which the barcode resides.
[0018] In conjunction with the previous embodiment, in some embodiments, the degree of deformation of the barcode in the first image is greater than a second value. When the degree of deformation is greater than the second value, the electronic device may determine that the angle between the current camera shooting direction and the perpendicular direction of the plane where the barcode is located is greater than a certain value.
[0019] In some embodiments, the degree of deformation of the barcode in the first image can be measured based on the aspect ratio of the detection frame containing the barcode returned by the detection model of the electronic device. For example, if the aspect ratio is greater than 1.14, the degree of deformation can be considered to be greater than the second value.
[0020] In combination with the first aspect, in some embodiments, after identifying the first area or the second area, the method may further include: identifying information represented by the barcode in the first area or the second area; and performing a corresponding first operation according to the information.
[0021] In some embodiments, the information represented by the barcode may include but is not limited to: text, numerical values, pictures, web links, payment information (such as payment amount, payee), contact links, official account links, mini-program links, etc.
[0022] In some embodiments, the first operation performed based on the information represented by the barcode may include but is not limited to: displaying text, pictures, displaying a payment interface, displaying an add friend interface, opening a mini-program, etc.
[0023] In a second aspect, an electronic device is provided, comprising: a memory and one or more processors; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code includes computer instructions, and the one or more processors call the computer instructions to enable the electronic device to execute a method executed by the electronic device in the first aspect or any one of the embodiments of the first aspect.
[0024] In a third aspect, an embodiment of the present application provides a computer-readable storage medium comprising instructions, which, when executed on an electronic device, enables the electronic device to execute a method as executed by the electronic device in the first aspect or any one of the embodiments of the first aspect.
[0025] In a fourth aspect, an embodiment of the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the method executed by the electronic device in the first aspect or any one of the embodiments of the first aspect.
[0026] In a fifth aspect, an embodiment of the present application provides a chip system, which includes at least one processor for implementing the method executed by the electronic device in the first aspect or any one embodiment of the first aspect.
[0027] By implementing the technical solution provided in this application, electronic devices can detect the area containing the barcode within an image captured by a camera when scanning barcodes at a wide angle. This method accurately identifies the area containing the barcode, avoiding the loss of barcode information due to inaccurate barcode edge recognition, and captures the barcode image to improve the decoding success rate. Furthermore, while maintaining the decoding success rate, it can reduce decoding latency, improve decoding efficiency, and increase the scanning speed of barcode scanning applications, providing users with a better user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 A flowchart of a method for obtaining a barcode image provided in an embodiment of the present application;
[0029] Figure 2A-2C A set of user interfaces provided for embodiments of the present application;
[0030] Figure 3A-3C Schematic diagram of the acquisition process of three different groups of barcode images provided in the embodiment of the present application;
[0031] Figure 4 A schematic diagram of the angles of an electronic device scanning a code according to an embodiment of the present application;
[0032] Figure 5 A schematic diagram of the deformation of a QR code when an electronic device scans the code at a large angle according to an embodiment of the present application;
[0033] Figure 6 A flowchart of an electronic device identifying corner points of a barcode area provided in an embodiment of the present application;
[0034] Figure 7 A schematic diagram of an electronic device correcting a barcode image according to an embodiment of the present application;
[0035] Figure 8 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;
[0036] Figure 9 A module block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] The following is a clear and detailed description of the technical solutions in the embodiments of the present application, with reference to the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " represents the meaning of "or." For example, A / B can represent A or B. "and / or" in the text is merely a description of the association relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone.
[0038] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood to imply or suggest relative importance or implicitly indicate the number of the technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of this application, unless otherwise specified, "plurality" means two or more.
[0039] The term "user interface (UI)" in the following embodiments of this application refers to a medium interface for interaction and information exchange between an application or operating system and a user, which realizes the conversion between the internal form of information and the form acceptable to the user. The user interface is a source code written in a specific computer language such as Java and extensible markup language (XML). The interface source code is parsed and rendered on an electronic device and finally presented as content that the user can recognize. The commonly used form of user interface is graphical user interface (GUI), which refers to a user interface related to computer operations that is displayed in a graphical manner. It can be a visual interface element such as text, icons, buttons, menus, tabs, text boxes, dialog boxes, status bars, navigation bars, widgets, etc. displayed on the display screen of an electronic device.
[0040] The following embodiments of the present application provide a method and related apparatus for acquiring a barcode image, which can be applied to scenarios where an electronic device scans a barcode at a large angle.
[0041] The electronic device for executing the method provided in the embodiment of the present application is configured with a camera, and the electronic device may include various types. For example, the electronic device may be a mobile phone, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) device, a virtual reality (VR) device, an artificial intelligence (AI) device, a wearable device, an in-vehicle device, a smart home device and / or a smart city device, etc. The embodiment of the present application does not impose any special restrictions on the specific type of the electronic device.
[0042] The barcodes provided in the embodiments of the present application may include, but are not limited to, one-dimensional barcodes, two-dimensional barcodes, three-dimensional barcodes, and the like.
[0043] Two-dimensional barcodes, also known as QR codes, include common formats such as QR codes (quick response codes), PDF417, Datamatrix, Maxicode, Code 49, Code 16K, and Code One. A QR code uses a specific black and white geometric pattern arranged in a regular pattern on a plane (two-dimensionally) to record information. Leveraging the concept of "0" and "1" bit streams, fundamental to computer logic, QR codes use geometric patterns corresponding to binary numbers to represent information. Of course, other types of barcodes, such as one-dimensional and three-dimensional barcodes, also have their own ways of expressing information, which will not be discussed in detail here.
[0044] The information represented by the barcode may include but is not limited to: text, numbers, pictures, web links, payment information (such as payment amount, payee), contact links, official account links, mini-program links, etc.
[0045] The shape of a one-dimensional code is usually rectangular, but it can also be square. The shape of a two-dimensional code is usually square, but it can also be circular or other shapes.
[0046] The barcode scanning process can be explained as the process in which an electronic device captures an image including a barcode through a camera, analyzes the barcode in the image, and obtains the information represented by the barcode.
[0047] In the barcode image acquisition method provided in the embodiments of the present application, when an electronic device is scanning a barcode at a large angle, an edge detection algorithm can be used to accurately detect the area containing the barcode in an image captured by a camera containing the barcode. In some embodiments, this area can also be angle-corrected to obtain a corrected, front-facing barcode image. The electronic device can then identify the barcode in the corrected barcode image to obtain the information represented by the barcode.
[0048] By implementing this method, electronic devices can accurately identify the area where the barcode is located, avoiding the problem of barcode information loss caused by inaccurate barcode edge recognition, accurately obtaining easily recognizable barcode images, and improving the decoding success rate. In addition, the edge detection algorithm used in the embodiment of the present application is highly efficient, which can reduce decoding latency and improve decoding efficiency while ensuring the decoding success rate, thereby increasing the scanning speed of barcode scanning applications and providing users with a better user experience.
[0049] The following will describe in detail the barcode image acquisition method provided by the embodiments of the present application in conjunction with the accompanying drawings.
[0050] refer to Figure 1 , Figure 1 A flowchart of a method for acquiring a barcode image provided in an embodiment of the present application. Figure 1 The method is described by taking the electronic device 100 as an example. Figure 1 As shown, the method may include the following steps:
[0051] S101, the electronic device 100 receives a user operation for triggering a code scan.
[0052] The electronic device 100 of the embodiment of the present application may provide a code scanning function.
[0053] The code scanning function of the electronic device 100 can be provided by any one or more of the following applications: 1. A standalone application that specifically provides the code scanning function. 2. A comprehensive application that integrates the code scanning function and also has other functions. For example, a payment application can provide a code scanning function, an instant messaging application can also provide a code scanning function, a camera application can also provide a code scanning function, and a video application can also provide a code scanning function. Without limitation, in some embodiments, the webpages, mini-programs, etc. accessed by the electronic device 100 can also provide a code scanning function.
[0054] The code scanning function of the electronic device 100 can be provided by any one or more of the following types of applications: 1. System applications, such as system camera applications, can provide code scanning functions. 2. Third-party applications, such as third-party payment applications and third-party instant messaging applications, can also provide code scanning functions.
[0055] In the embodiment of the present application, an application that provides a code scanning function may be referred to as a code scanning application.
[0056] In S101, the user operation for triggering the code scanning received by the electronic device 100 may be a user operation input to a code scanning application. If the code scanning application directly enables the code scanning function after startup, the user operation for triggering the code scanning may be an operation for starting the code scanning application (such as a click operation on the code scanning application icon on the desktop). If the code scanning application requires the user to find the entry to the code scanning function after startup, the user operation for triggering the code scanning may be an operation for turning on the code scanning function after starting the code scanning application, such as a user operation for turning on the scan function of an instant messaging application, a user operation for turning on the scan function of a payment application, etc.
[0057] There may be multiple forms of user operations for triggering code scanning, such as click operations, touch operations, long press operations, voice commands, floating gestures, etc., which are not limited in the embodiments of the present application.
[0058] S101 is further described below in conjunction with the UI implemented on the electronic device 100 .
[0059] Figure 2A The example shows a user operation input by a user to trigger a code scanning in a code scanning scenario.
[0060] like Figure 2A As shown, the electronic device 100 can display an interface 210 with a desktop. A page with application icons is displayed in the interface 210. Among them, the page may include multiple application icons (for example, an independent application icon 211 specifically providing a code scanning function, a settings application icon, a payment application icon, a chat application icon, etc.). Optionally, a page indicator can be displayed below the page with application icons, and the page indicator can indicate the total number of pages on the desktop and the positional relationship between the currently displayed page and other pages. Optionally, a status bar, a dock area containing multiple application icons, and the like are also displayed above the page with application icons.
[0061] like Figure 2A As shown, the electronic device 100 can receive an input (such as a single click operation) acting on the icon 211. In response to the input, the electronic device 100 starts the code scanning function and displays the following on the display screen of the electronic device 100: Figure 2B The code scanning interface 220 is shown. The content of the code scanning interface 220 is referred to later and will not be expanded here.
[0062] Not limited to Figure 2AThe scanning function of the electronic device 100 is activated by launching an independent application that specifically provides the scanning function. In other embodiments, the electronic device 100 can also activate the scanning function in other ways. For example, the electronic device 100 can also activate the scanning function by opening a camera application or opening the scan function of a payment application.
[0063] S102: The electronic device 100 starts a camera and obtains a first image including a barcode through the camera.
[0064] After receiving the user operation for triggering the barcode scan in S101, the electronic device 100 can activate the camera. If the user currently intends to scan the barcode, the position of the electronic device 100 will be moved so that the barcode is within the viewing range of the camera of the electronic device 100. In this way, the electronic device 100 can obtain a first image containing the barcode through the camera.
[0065] The camera activated by the electronic device 100 can be a main camera or other cameras, which is not limited here. In some embodiments, the user can also select or switch the camera used for scanning the code.
[0066] The first image may be an image obtained by processing the original image captured by the camera of the electronic device 100. The parameters for capturing and processing the image here may be referred to as shooting parameters, and the shooting parameters may include the width of the image, the height of the image, the focus mode (including autofocus mode, manual focus mode and fixed focus mode), the zoom mode (such as digital zoom, physical zoom, etc.), the focus ratio, the frame rate, the resolution, the format of the image, and the like. It can be seen that the first image here may be an image obtained by cropping the image captured by the camera. The shooting parameters may be determined by the electronic device 100 based on the current scene, such as the content initially captured by the camera, the image clarity and other information, and the specific determination method is not limited. The process of capturing and processing the original image may be performed in conjunction with the focus motor, image sensor, central processing unit (CPU) and other devices of the electronic device 100.
[0067] refer to Figure 2B , Figure 2B The example shows a code scanning interface 220 displayed after the electronic device 100 starts the camera and obtains the first image containing the barcode.
[0068] For example, refer to Figure 3A and Figure 3B , which respectively show two examples of the first image captured by the electronic device 100.
[0069] exist Figure 3AIn the first image, the background area of the QR code is white, and the white background area is slightly wider than the QR code, so the QR code can be completely displayed on the white background, and the surrounding area outside the white background is other colors.
[0070] exist Figure 3B and Figure 3C In the first image, the background area of the QR code is white, and the white background area is much wider than the QR code, which is equivalent to the QR code having a large white background and no surrounding areas of other colors outside the white background, or the surrounding areas of other colors outside the white background account for a small proportion. Figure 3B and Figure 3C The difference is that Figure 3B The QR code in is a square. Figure 3C The QR code in the is circular.
[0071] S103: The electronic device 100 determines whether it is in a scene where a barcode is photographed at a large angle.
[0072] Due to the long distance between the user and the barcode, the large number of people around the barcode, or the user holding the electronic device 100 at a relatively biased angle (such as the electronic device 100 photographing the barcode at a slanted or upward angle), after the electronic device 100 starts the scanning function, a scene of photographing the barcode at a large angle may occur.
[0073] The scenario where an electronic device scans a barcode at a large angle refers to a scenario where there is a certain angle between the shooting direction of the camera used by the electronic device to scan the barcode and the vertical direction of the plane where the barcode is located. In some embodiments, it can be considered that the angle between the two directions needs to be greater than a certain threshold before the electronic device is in a scenario of scanning the barcode at a large angle. The angle threshold can be set as needed by the device manufacturer of the electronic device 100 and preset in the electronic device, and of course it can also be set by the user independently, which is not limited here. Exemplarily, the angle threshold can be set to 30 degrees or other angles.
[0074] In the embodiment of the present application, the angle between the shooting direction of the camera of the electronic device for scanning the barcode and the vertical direction of the plane where the barcode is located can be called the first angle. The corresponding angle threshold can be called the first value.
[0075] For example, refer to Figure 4 , Figure 4 The following example shows the angle between the electronic device and the barcode when the camera is turned on to scan the barcode. Figure 4 As shown, the plane where the QR code is located is the plane formed by the x-axis and the y-axis, and the vertical direction of the plane where the QR code is located is the z-axis direction. The electronic device shoots from the right side of the QR code toward the direction of the QR code. The angle between the shooting direction and the z-axis direction is the shooting angle referred to in the embodiment of this application. Figure 4The shooting angle shown is approximately 60 degrees. Figure 4 As shown, since the electronic device shoots the QR code at a certain shooting angle, the QR code obtained by the electronic device is deformed.
[0076] The electronic device 100 can determine whether it is currently in a scene where a barcode is photographed at a large angle by:
[0077] Since barcodes are deformed when photographed at a wide angle, the electronic device 100 can identify the area containing the barcode in the first image captured by the camera to determine whether the barcode in that area is deformed or distorted. If deformation occurs, it can be determined that the electronic device is currently photographing the barcode at a wide angle. The electronic device 100 can use an image analysis algorithm to identify the shape of the barcode in the first image.
[0078] In some embodiments, the electronic device 100 may determine that the barcode is currently being photographed at a large angle only when the barcode in the first image is deformed or distorted to a degree greater than a certain level. Here, the threshold value of the degree of deformation may be referred to as a second value.
[0079] For example, if the electronic device 100 recognizes that the captured first image contains a parallelogram, rectangle, or trapezoidal QR code, it can be considered that the current shooting angle has caused the square QR code in the real space to be deformed into a parallelogram, rectangle, or trapezoid. In this case, it can be considered that the electronic device 100 is in a scene where the barcode is captured at a large angle.
[0080] In some other embodiments, after the electronic device 100 recognizes that the QR code has been deformed, it is also necessary to detect the aspect ratio of the front quadrilateral to which the rectangle or parallelogram in the first image belongs. Only when the aspect ratio is greater than a certain threshold value is it considered that the shooting angle has reached a certain value, and then it is determined that the current scene is a large-angle shooting of the barcode. The aspect ratio threshold can be set as needed, for example, it can be set to 1.14 or other values, which are not limited here. Figure 5 , Figure 5 The diagram exemplifies the parallelogram in which the deformed QR code in the first image recognized by the electronic device 100 is located, and also shows the front quadrilateral to which the parallelogram belongs, whose aspect ratio is greater than 1.14.
[0081] For example, if the electronic device 100 recognizes that the captured first image contains an elliptical QR code, it can be assumed that the circular QR code in the captured real space has been deformed into an elliptical shape due to the current shooting angle. In this case, it can be assumed that the electronic device 100 is in a scene where the barcode is captured at a large angle.
[0082] In some other embodiments, after the electronic device 100 detects a deformation of the QR code, it further detects the aspect ratio of the frontal quadrilateral to which the oval in the first image belongs. Only when this ratio exceeds a certain threshold is the shooting angle considered to have reached a certain value, and the scene of the barcode being photographed at a high angle is determined. The aspect ratio threshold can be set as needed and is not limited here.
[0083] In some embodiments, the electronic device 100 may utilize an artificial intelligence (AI) model to identify the shape of the barcode in the first image and the degree of deformation of the barcode.
[0084] If the determination result of S103 is no, it indicates that the current shooting angle of the electronic device 100 is appropriate, and the electronic device 100 can easily and quickly identify the information represented by the barcode from the first image, and then perform subsequent operations according to the information.
[0085] If the result of S103 is yes, then due to the deformation of the barcode, the electronic device 100 may not be able to directly obtain a clear, positive image of the barcode from the first image, and thus cannot fully recognize the information represented by the barcode. Based on this, in the embodiment of the present application, if the result of S103 is no, the subsequent steps S104-S106 are executed to eliminate the influence of the barcode deformation, so that the electronic device 100 can fully and quickly recognize the information represented by the barcode.
[0086] S104: If the determination result of S103 is yes, the electronic device 100 processes the first image and identifies the area where the barcode is located in the first image.
[0087] In the embodiment of the present application, the process of the electronic device 100 processing the first image to identify the area where the barcode is located may include: Figure 6 Several steps are shown as examples. Figure 6 As shown, the process is performed by the electronic device 100 and may specifically include the following steps:
[0088] S1041 , performing binarization processing on the first image to obtain a binarized image of the first image.
[0089] In a specific implementation, the electronic device 100 first grayscales the first image and then binarizes the grayscale-processed first image to obtain a binarized image of the first image. The binarized image of the first image can still reflect the overall and local features of the image.
[0090] Thresholding is one of the most common methods for image segmentation. Binarization can convert a grayscale image into a binary image. All pixels in a grayscale image with a grayscale greater than or equal to a threshold can be judged as belonging to a specific object, and the grayscale of pixels greater than or equal to the grayscale threshold is set to the grayscale maximum value (such as 255); all pixels in a grayscale image with a grayscale less than the threshold represent areas outside the background object, and the grayscale of pixels less than the threshold is set to the grayscale minimum value (such as 0). This completes the binarization of the image. The binary image can present a clear black and white effect, and the object and background can be clearly separated. Binarization is beneficial in that when further processing the image, the multi-level values of the pixels are no longer involved, making the processing simpler and reducing the amount of data processing and compression.
[0091] The binarization method used in the embodiments of the present application may include but is not limited to: a bimodal method, a P parameter method, an iterative method, or an OTSU method.
[0092] refer to Figure 3A-3C , which respectively show the binarized images of different first images.
[0093] Optional step S1042: pre-processing the binarized image.
[0094] Pretreatment may include any one or more of the following: dilation, corrosion.
[0095] Specifically, the electronic device 100 may first perform dilation processing on the binary image, and then perform erosion processing on it.
[0096] When eroding a binary image, if all black dots in the structural element are identical to the corresponding pixels in the larger image, the dots are black; otherwise, they are white. Dilation of the binary image can expand the white area of the QR code, simplifying the internal information.
[0097] When dilating a binary image, if at least one black dot in the structuring element matches its corresponding pixel in the larger image, that dot is black; otherwise, it is white. In other words, if none of the black dots in the structuring element match their corresponding pixel in the larger image, that dot is white; otherwise, it is black. Erosion of the dilated binary image removes the white pixels created during the dilation process, resulting in a clearer outline.
[0098] The above structural element can be a 3*3 convolution kernel.
[0099] Through preprocessing, small pixel blocks with the same grayscale value in the binary image can be connected together, the white part can be expanded, the black part can be reduced, and the impact of noise on the image can be reduced.
[0100] S1042 is an optional step. Even if S1042 is not executed, it will not affect the execution of subsequent steps and the effect of the overall solution.
[0101] S1043: Select the contour with the largest area in the binary image.
[0102] Images typically contain high-frequency components and low-frequency components. High-frequency components refer to areas where image intensity (brightness / grayscale) changes dramatically, i.e., where pixels suddenly change, often referred to as edges (outlines). Low-frequency components refer to areas where image intensity (brightness / grayscale) changes smoothly, i.e., where large blocks of color appear.
[0103] For example, in an image containing a barcode, the high-frequency component can be considered as the outline of the important features in the first image, and the outline with the largest area can be considered as the outline of the barcode in the first image. Therefore, in this embodiment of the present application, the electronic device 100 can identify the high-frequency component in the binary image, find one or more candidate outlines, and then find the outline with the largest area among the candidate outlines.
[0104] The electronic device 100 may use an edge and contour feature extraction algorithm to extract candidate contours in the binary image. The algorithm may include but is not limited to: Sobel operator, Isotropic Sobel operator, Roberts operator, Prewitt operator, etc., which is not limited in this application.
[0105] refer to Figure 3A The electronic device 100 can extract the outline formed by the boundary line between the white background area and the black background area where the two-dimensional code is located from the binary image.
[0106] refer to Figure 3B and Figure 3C The electronic device 100 can extract the outline formed by the boundary of the white background area where the two-dimensional code is located from the binary image.
[0107] S1044 , determining whether the area of the region enclosed by the contour with the largest area in the first image accounts for an area greater than or equal to a threshold.
[0108] The area threshold here can be set according to actual needs, and is not limited in the embodiments of the present application. For example, the area threshold can be set to 90%, 95%, etc.
[0109] If the judgment result of S1044 is no, execute S1045-S1046; if the judgment result of S1044 is yes, execute S1047.
[0110] S1045 , using a line detection algorithm to detect straight lines in the area where the contour is located in the first image, so as to identify a boundary of the area where the barcode is located in the first image.
[0111] If the area ratio of the region enclosed by the largest outline in the first image is smaller than the threshold, it means that there is not only a white background region around the barcode in the first image, but also a large number of background regions of other colors.
[0112] In this case, if the white background area in the first image is an area enclosed by straight lines (i.e., the boundary line between the white background area and other color background areas includes a straight line), then by scanning the contour with the largest area in the first image using a straight line detection algorithm, it is possible to detect the straight line contained in the contour, that is, the straight line where the boundary of the white background area is located (i.e., the straight line included in the boundary line between the white background area and other color background areas). In a specific implementation, the electronic device 100 first uses a straight line detection algorithm to scan the contour with the largest area in the first image to obtain multiple straight lines, and then classifies, merges, and selects these multiple straight lines, and finally selects the straight line where the boundary of the white background area is located. Then, the electronic device 100 can determine the area enclosed by the selected straight line segments as the boundary of the area where the barcode is located in the first image.
[0113] Among them, the strategy for classifying, merging and selecting multiple straight lines can be: first, divide the multiple straight lines into horizontal and vertical straight lines according to the extension direction of the straight lines, and divide the multiple straight lines into four directions of up, down, left and right according to the orientation between the center point of the straight line and the center point of the area enclosed by the contour with the largest area; then merge the straight lines with the same extension direction (such as all horizontal directions) and the same orientation (such as all upwards), and the merging conditions can consider the slope difference between the two straight lines (such as the slope difference is less than a certain value), the distance between the midpoints of the two straight lines, the distance between the points, and the distance between the points and the lines, etc. If the distances between the two straight lines are close, they can be merged into a long straight line; the multiple straight lines finally merged are the straight lines where the boundary of the white background area in the first image is located.
[0114] In one specific case, if the white background area where the barcode is located in the first image is a parallelogram, rectangle, or trapezoid, the electronic device 100 can identify the boundary of the parallelogram, rectangle, or trapezoid using a line detection algorithm. Of course, in other embodiments, if the white background area where the barcode is located in the first image is a shape composed of other straight lines, the electronic device 100 can also recognize other shapes.
[0115] The line detection algorithm may include but is not limited to: Hough_line line detection algorithm, LSD line detection algorithm, FLD line detection algorithm, EDlines line detection algorithm, etc.
[0116] refer to Figure 3A , Figure 3AThe area ratio of the area surrounded by the largest outline in the first image shown in FIG is less than the threshold value, so the electronic device 100 can use a line detection algorithm to identify the boundary of the area where the barcode is located. Figure 3A As shown, the electronic device 100 can identify the straight lines in the contour area through a straight line detection algorithm, and then select some or all of the straight lines therein to obtain the boundary of the area where the barcode is located based on fitting.
[0117] It can be seen that the boundary of the area where the barcode is located determined in S1045 is larger than the actual boundary of the barcode, which can ensure that the electronic device 100 can subsequently read the information represented by the barcode completely to avoid information loss.
[0118] S1046: Determine the corner points of the boundary of the area where the barcode is located.
[0119] For the boundaries of the area where the barcode is located in the first image detected by the line detection algorithm, the intersection of adjacent boundaries is the corner point.
[0120] Because the area enclosed by the boundary of the barcode region can have various shapes, the corner points of the region can also include various situations. If the region is a quadrilateral, electronic device 100 can determine four corner points: the upper left corner point, the lower left corner point, the upper right corner point, and the lower right corner point. If the region is a pentagon, electronic device 100 can determine five corner points, and so on.
[0121] S1047: Scan the outline in the first image using a scanning line algorithm to identify the boundary of the area where the barcode is located in the first image.
[0122] If the area ratio of the region enclosed by the largest outline in the first image is greater than or equal to the threshold, it indicates that a relatively large white background region exists around the barcode in the first image.
[0123] In this case, the area where the largest contour in the first image is located is scanned by the scanning line algorithm. Specifically, it can be scanned from left to right and from top to bottom, or scanned in the opposite direction to find the rows and columns where the black pixel values first appear on the upper and left sides of the contour area, and the rows and columns where the black pixel values appear last on the lower and right sides. The four boundaries of the area enclosed by the two rows and two columns are the boundaries of the area where the barcode is located.
[0124] In a specific case, if the barcode in the first image appears as a parallelogram, rectangle or trapezoid, the electronic device 100 can accurately identify the boundary of the parallelogram, rectangle or trapezoid through a straight line detection algorithm.
[0125] refer to Figure 3B and Figure 3C , Figure 3B and Figure 3CThe area ratio of the area surrounded by the largest outline in the first image shown in FIG is greater than the threshold value, so the electronic device 100 can use the scanning line algorithm to identify the boundary of the area where the two-dimensional code is located. Figure 3B and Figure 3C As shown, the electronic device 100 can identify the boundary where black pixel values appear in the contour area through the scan line algorithm.
[0126] Compared to directly detecting the edge of the barcode, which may result in inaccurate recognition and loss of information due to the fact that the barcode edge is not continuously enclosed, the scan line algorithm used in S1047 can identify the area where the barcode is located that is larger than the actual boundary of the barcode.
[0127] The above steps S1045 and S1047 can both accurately locate the area where the barcode is located in the first image, thereby increasing the proportion of the barcode in the obtained image. This can ensure that the subsequent electronic device 100 can completely read the information represented by the barcode, avoid information loss, and can also more quickly identify the information represented by the barcode, thereby improving scanning efficiency.
[0128] As can be seen from the previous steps, the largest outline determined in S1043 is only an approximate outline of the barcode area and does not fully accurately reflect the barcode area. Therefore, depending on the size of the outline area, S1045 or S1047 must be selected to accurately identify the boundaries of the barcode area. By selecting different methods to identify the boundaries of the barcode area based on the size of the outline area, targeted processing can be performed on different barcodes, ensuring that barcode information is not lost and speeding up scanning efficiency.
[0129] In an embodiment of the present application, the area where the barcode is located in the first image identified using the scan line algorithm in S1047 can be called the first area; the area where the barcode is located in the first image identified using the straight line detection algorithm in S1045 can be called the second area.
[0130] Optional S105, the electronic device 100 performs angle correction on the area where the barcode is located in the first image to obtain a corrected second image.
[0131] If the electronic device 100 has executed steps S1045-S1046 above, i.e., has detected the boundary of the area where the barcode is located in the first image using the line detection algorithm and identified the corner points of the boundary, then step S105 can be executed. Of course, even if the electronic device 100 has executed steps S1045-S1046 above, step S105 can be omitted. Not correcting the barcode area does not affect the execution of subsequent steps, and the information represented by the barcode can still be identified from the precisely located barcode area.
[0132] If the electronic device 100 has executed the above step S1047 , the electronic device 100 may not execute S105 .
[0133] Specifically, when executing S105 , the electronic device 100 may use the identified corner point to map the corner point to a plane according to certain conditions, so as to perform angle correction on the area where the barcode is located in the identified first image.
[0134] Specifically, the electronic device 100 can extract the area where the barcode is located in the first image, and use a perspective transformation algorithm, an affine transformation algorithm, etc. to perform angle correction on the area, correcting the area to a form of being photographed in a direction perpendicular to or close to the perpendicular direction of the plane where the barcode is located, thereby obtaining a corrected second image. Perspective transformation refers to a transformation that uses the condition that the perspective center, the image point, and the target point are collinear to rotate the image receiving surface (perspective surface) around the trace line (perspective axis) by a certain angle according to the perspective rotation law, thereby destroying the original projection light beam and still maintaining the projected geometric figure on the image receiving surface unchanged.
[0135] Figure 7 An example of a method for correcting the angle is shown. Figure 7 As shown, the electronic device 100 can correct the image through the following steps:
[0136] (1) Extract the barcode area.
[0137] The electronic device 100 can extract the image area of the barcode and simultaneously record the center coordinates (x1, y1) of the barcode and the center coordinates O (x0, y0) of the screen.
[0138] (2) Adjust the barcode position.
[0139] Based on the barcode's center coordinates, the electronic device 100 adjusts the image area containing the barcode to the center of a coordinate system with the screen's center coordinates as its origin. Thus, the barcode's center coordinates are transformed from (x1, y1) to (x0, y0). Furthermore, the electronic device 100 can also appropriately scale and crop the barcode image.
[0140] (3) Correct the barcode.
[0141] The electronic device 100 can convert and map the barcode using an image transformation algorithm (eg, an affine transformation algorithm, a perspective transformation algorithm) to obtain a normal view of the barcode image.
[0142] refer to Figure 3A , which shows the second image obtained after the electronic device 100 corrects the first image.
[0143] S106, the electronic device 100 identifies the information represented by the barcode.
[0144] If the electronic device 100 does not execute S105, it can identify the information represented by the barcode in the area where the QR code is identified using the scan line algorithm or the line detection algorithm.
[0145] If the electronic device 100 executes S105, it can identify the information represented by the barcode in the corrected second image.
[0146] The electronic device 100 can identify the barcode in the image, obtain the corresponding bitstream, and obtain the barcode information corresponding to the barcode through the bitstream. The information represented by the barcode may include, but is not limited to: text, numerical value, picture, web link, payment information (such as payment amount, payee), contact link, public account link, and so on.
[0147] S107, the electronic device 100 performs a corresponding first operation according to the information represented by the barcode.
[0148] The electronic device 100 can determine the type of the barcode information and perform the corresponding operation. If the barcode information is information such as text, picture, etc., the first operation can be for the electronic device 100 to display the text, picture. If the barcode information is a web link, the first operation can be to display the page corresponding to the web link. If the barcode information is payment information, the first operation can be to display a payment interface and display the payment amount in the payment interface. If the barcode information is a contact link, the first operation can be to display the interface for adding a friend corresponding to the contact link. If the barcode information is a mini-program link, the first operation can be to open the mini-program.
[0149] Exemplarily, refer to Figure 2C , Figure 2C Exemplarily shows the user interface 230 displayed after the electronic device 100 identifies the barcode information. As Figure 2C shown, the text "Honor" identified by the electronic device 100 is displayed in the user interface 230.
[0150] Implement Figure 1The barcode image acquisition method shown can accurately detect the area where the barcode is located in the image containing the barcode acquired by the camera using an edge detection algorithm in the scenario of scanning the barcode at a large angle. In some embodiments, the angle of the area can also be corrected to obtain a barcode image that is viewed straight after correction. In this way, the electronic device can accurately identify the area where the barcode is located, avoid the problem of barcode information loss due to inaccurate barcode edge recognition, and accurately obtain an easily recognizable barcode image to improve the decoding success rate. In addition, the edge detection algorithm used in the embodiment of the present application is highly efficient and can reduce the decoding delay and improve the decoding efficiency while ensuring the decoding success rate, thereby increasing the scanning speed of code scanning applications and providing users with a better user experience.
[0151] The electronic device provided by the embodiments of the present application is introduced below.
[0152] Figure 8 A hardware structure diagram of the electronic device 100 provided in an embodiment of the present application is shown.
[0153] Electronic device 100 may include a processor 101, memory 102, a wireless communication module 103, a mobile communication module 104, an antenna 103A, an antenna 104A, a power switch 105, a sensor module 106, a focus motor 107, a camera 108, a display screen 109, and the like. Sensor module 106 may include a gyroscope sensor 106A, an acceleration sensor 106B, an ambient light sensor 106C, an image sensor 106D, a distance sensor 106E, and the like. Wireless communication module 103 may include a WLAN communication module, a Bluetooth communication module, and the like. These multiple components may transmit data via a bus.
[0154] The processor 101 may include one or more processing units. For example, the processor 101 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). The different processing units may be independent devices or integrated into one or more processors.
[0155] The memory 102 can be used to store computer executable program code, which can include instructions. The processor 101 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the memory 102. The memory 102 can include a program storage area and a data storage area. In a specific implementation, the memory 102 can include a high-speed random access memory and can also include a non-volatile memory, such as one or more disk storage devices, flash memory devices, or other non-volatile solid-state storage devices.
[0156] The wireless communication function of the electronic device 100 can be implemented through the antenna 103A, the antenna 104A, the mobile communication module 104, the wireless communication module 103, the modem processor and the baseband processor.
[0157] Antenna 103A and antenna 104A can be used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve antenna utilization.
[0158] The mobile communication module 104 can provide wireless communication solutions, including 2G / 3G / 4G / 5G, for the electronic device 100. The mobile communication module 104 can include at least one filter, a switch, a power amplifier, a low-noise amplifier (LNA), and the like. The mobile communication module 104 can receive electromagnetic waves through the antenna 104A, filter and amplify the received electromagnetic waves, and transmit them to the modem processor for demodulation. The mobile communication module 104 can also amplify the signals modulated by the modem processor and convert them into electromagnetic waves for radiation via the antenna 104A.
[0159] The modem processor may include a modulator and a demodulator. The modulator is used to modulate the low-frequency baseband signal to be transmitted into a medium- or high-frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After processing by the baseband processor, the low-frequency baseband signal is passed to the application processor. The application processor outputs audio signals through an audio device or displays images or videos on the display screen 109.
[0160] The wireless communication module 103 can provide wireless communication solutions including wireless local area networks (WLAN), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc. applied to the electronic device 100. The wireless communication module 103 can be one or more devices integrating at least one communication processing module. The wireless communication module 103 receives electromagnetic waves via the antenna 103A, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 101. The wireless communication module 103 can also receive the signal to be sent from the processor 101, frequency modulate it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 103A.
[0161] The power switch 105 may be used to control the supply of power to the electronic device 100 .
[0162] The gyroscope sensor 106A can be used to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., x, y, and z axes) can be determined by the gyroscope sensor 106A. The gyroscope sensor 106A can be used for anti-shake shooting. For example, when the shutter is pressed, the gyroscope sensor 106A detects the angle of the electronic device 100 shaking, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to offset the shaking of the electronic device 100 through reverse movement to achieve anti-shake. The gyroscope sensor 106A can also be used for navigation and somatosensory game scenes.
[0163] Accelerometer 106B can detect the magnitude of acceleration of electronic device 100 in all directions (generally three axes). When electronic device 100 is stationary, it can detect the magnitude and direction of gravity. It can also be used to identify the electronic device's posture. For example, accelerometer 106B can be used in applications such as landscape and portrait screen switching and pedometers.
[0164] The ambient light sensor 106C is used to sense the brightness of the ambient light. The electronic device 100 can adaptively adjust the brightness of the display screen 109 based on the sensed ambient light brightness. The ambient light sensor 106C can also be used to automatically adjust the white balance when taking pictures.
[0165] Image sensor 106D, also known as a photosensitive element, utilizes the photoelectric conversion function of a photoelectric device to convert the light image on the photosensitive surface into an electrical signal proportional to the light image. The image sensor can be a charge coupled device (CCD) sensor or a complementary metal oxide semiconductor (CMOS) sensor.
[0166] The distance sensor 106E can be used to measure distance. The electronic device 100 can measure distance using infrared or laser. In some shooting scenarios, the electronic device 100 can use the distance sensor 106E to measure distance to achieve fast focusing.
[0167] The focus motor 107 can be used for fast focusing. The electronic device 100 can control the movement of the lens through the focus motor 107 to achieve automatic focusing.
[0168] The electronic device 100 can implement a shooting function through an ISP, a camera 108, a video codec, a GPU, a display screen 109, and an application processor.
[0169] The ISP processes data fed back by camera 108. For example, when taking a photo, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, which is then passed to the ISP for processing and transformed into a visible image. The ISP can also perform algorithmic optimization for image noise, brightness, and skin tone. It can also optimize parameters such as exposure and color temperature of the captured scene. In some embodiments, the ISP can be located within camera 108.
[0170] The camera 108 can be used to capture still images or videos. An object's optical image is projected onto the image sensor through the lens. The image sensor converts the optical signal into an electrical signal, which is then transmitted to the ISP for conversion into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard format, such as RGB or YUV. In some embodiments, the electronic device 100 may include one or N cameras 193, where N is a positive integer greater than one.
[0171] Video codecs are used to compress or decompress digital images. The electronic device 100 may support one or more video codecs. In this way, the electronic device 100 can open or save pictures or videos in multiple encoding formats.
[0172] Electronic device 100 can implement display functions using a GPU, display screen 109, and an application processor. A GPU is a microprocessor for image processing that connects display screen 109 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 101 may include one or more GPUs that execute program instructions to generate or modify display information.
[0173] Display screen 109 is used to display images, videos, etc. Display screen 109 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-oLed, or a quantum dot light-emitting diode (QLED). In some embodiments, electronic device 100 may include one or N display screens 109, where N is a positive integer greater than 1.
[0174] It should be understood that the structure illustrated in the embodiments of the present invention does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0175] In the embodiment of the present application, the camera 108, the focus motor 107, the AP in the processor 101, the image sensor 106D, etc. can be used in conjunction to obtain a first image containing a barcode.
[0176] The AP in the processor 101 can be used to determine whether the electronic device 100 is in a scene where a barcode is photographed at a large angle. It is also used to identify the area where the barcode is located in the first image when the electronic device 100 is in a scene where a barcode is photographed at a large angle. It can also perform angle correction on the area to obtain a corrected straight-on barcode image.
[0177] The display screen 109 may be used to display the user interface implemented on the electronic device 100 provided in the above-mentioned embodiment of the present application, for example Figure 2A-2C The user interface shown.
[0178] The operations performed by the various components in the electronic device 100 may be specifically referred to the relevant description of the above method embodiment, which will not be elaborated here.
[0179] Figure 9 It is a module block diagram of the electronic device 100 provided by an embodiment of the present invention.
[0180] The module block diagram shows the application layer, application framework layer, hardware abstract interface layer, hardware abstract layer (HAL) implementation layer, hardware driver layer and some modules of the hardware layer of the electronic device 100.
[0181] The application layer may include a series of application packages, including code scanning application 301, camera, payment, short message and other applications.
[0182] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes predefined functions. For example, the application framework layer may include a window manager, content provider, view system, telephony manager, resource manager, and notification manager. The application framework layer may also include an activity manager, which can retrieve the activity names corresponding to different activities.
[0183] After the electronic device 100 receives a user operation to trigger a code scan, the code scanning application 301 of the application program can start a code scanning activity and send the parameter information of the code scanning application to the barcode scene control unit 302 of the hardware abstraction layer through the camera function interface of the application framework layer (for example, the configureStreams interface). The camera function interface of the application framework layer can obtain the activity name corresponding to the activity (for example, com.saoma.CaptureActivity) from the activity manager through a specified interface (for example, getTopActivity) and send the obtained activity name to the barcode scene control unit 302. Among them, the activity is the program component responsible for interacting with the user, providing the user with a window, button, icon, etc. for interacting with the electronic device 100. The user can interact with the device through the activity window (button, icon, etc.).
[0184] The hardware abstraction interface layer can include multiple library modules. Each module implements a set of interfaces for a specific type of hardware component. When the application framework layer requests access to device hardware, the operating system loads the corresponding library module for that hardware.
[0185] In some application scenarios, the hardware abstract interface layer may include a code scanning interface (not shown), which may be used to transmit the code scanning mode and state information of the code scanning mode to the code scanning determination module 303.
[0186] The hardware abstraction implementation layer may include a barcode scene control unit 302 , an image signal processing unit 310 , a barcode image processing unit 320 , an image sensor module 307 , and the like.
[0187] The barcode scene control unit 302 includes a barcode scanning judgment module 303 and the like.
[0188] In an embodiment of the present application, the code scanning determination module 303 may further determine whether the electronic device 100 is in a scene where the barcode is being photographed at a wide angle when determining that the electronic device 100 is in a code scanning scene. For a specific determination method, please refer to the relevant description of the method embodiment above. After determining that the electronic device 100 is in a scene where the barcode is being photographed at a wide angle, the code scanning determination module 303 may send an instruction to the barcode image processing unit 320 to cause the barcode image processing unit 320 to perform subsequent operations.
[0189] The image signal processing unit 310 may include an image front-end processing module 311 and an image back-end processing module 312. Optionally, the image signal processing unit 310 may further include other image processing modules.
[0190] The image front-end processing module 311 may be used to correct the color of an image, reduce signal noise, optimize image brightness, perform color space conversion, and the like.
[0191] The image sensor module 307 can acquire a frame of original image and send the acquired original image to the image front-end processing module 311 of the image signal processing unit 310 .
[0192] The image backend processing module 312 can be used to further optimize the quality of the image output by the frontend processing module, including image bad pixel removal, detail enhancement, HDR processing, etc. For example, the image backend processing module 312 can obtain and optimize the image output by the image frontend processing module 311.
[0193] Other image processing modules can be used to optimize image quality, for example, beautify the image, blur the background, detect motion, detect scenes, etc. Optionally, other image processing modules can process the image output by the image front-end processing module 311 or the image output by the image back-end processing module 312 .
[0194] The barcode image processing unit 320 may include a barcode region recognition module 321 and a barcode correction module 322 .
[0195] The barcode region recognition module 321 can be used to identify the region where the barcode is located in the first image, and can also be used to identify the corner points in the region. For the specific process, please refer to Figure 6 In some embodiments, the barcode region identification module 321 can upload the QR code region identified by the scan line algorithm to a barcode scanning application, which can then identify the information represented by the barcode in the region and schedule the relevant components of the electronic device 100 to perform corresponding operations based on the information.
[0196] The barcode correction module 322 may be used to perform angle correction on the area where the barcode is located in the first image according to the corner points to obtain a corrected second image. For specific implementation, reference may be made to the relevant description of the above method embodiment.
[0197] After the barcode correction module 322 obtains the corrected second image, it can upload the second image to the barcode scanning application, which recognizes the information represented by the barcode in the second image and schedules the relevant components of the electronic device 100 to perform corresponding operations based on the information.
[0198] The hardware driver layer is the layer between hardware and software. This hardware driver layer includes at least the focus motor driver, image sensor driver, image signal processor driver, etc. Electronic devices can communicate with hardware through the driver.
[0199] The hardware layer can include various hardware devices, such as a lens, a focus motor integrated circuit (IC), an image sensor, an image signal processor, etc. Among them, the focus motor IC can move the lens for focusing.
[0200] It is understandable that the above Figure 9 The illustrated embodiment does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer layers than shown, or may combine or split some layers, or have different layer arrangements. The illustrated layers may be implemented in hardware, software, or a combination of software and hardware.
[0201] It should be understood that each step in the above method embodiment can be completed by hardware integrated logic circuits in a processor or by software instructions. The method steps disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware processor, or by a combination of hardware and software modules in a processor.
[0202] The present application also provides an electronic device, which may include a memory and a processor. The memory may be used to store a computer program; the processor may be used to call the computer program in the memory to enable the electronic device to execute the method executed by the electronic device 100 in any of the above embodiments.
[0203] The present application also provides a chip system, which includes at least one processor for implementing the functions involved in the electronic device 100 in any of the above embodiments.
[0204] In one possible design, the chip system further includes a memory, which is used to store program instructions and data, and the memory is located inside or outside the processor.
[0205] The chip system can be composed of chips, or can include chips and other discrete devices.
[0206] Optionally, there may be one or more processors in the chip system. The processor may be implemented in hardware or software. When implemented in hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented in software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.
[0207] Optionally, the memory in the chip system may be one or more. The memory may be integrated with the processor or may be provided separately from the processor, which is not limited in the embodiments of the present application. For example, the memory may be a non-transient processor, such as a read-only memory (ROM), which may be integrated with the processor on the same chip or provided on different chips. The embodiments of the present application do not specifically limit the type of memory or the configuration of the memory and the processor.
[0208] Exemplarily, the chip system can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.
[0209] The present application also provides a computer program product, which includes: a computer program (also referred to as code, or instructions), which, when executed, enables a computer to execute the method executed by the electronic device 100 in any of the above embodiments.
[0210] The present application also provides a computer-readable storage medium storing a computer program (also referred to as code or instruction). When the computer program is executed, the computer executes the method executed by the electronic device 100 in any of the above embodiments.
[0211] The various implementation modes of this application can be combined arbitrarily to achieve different technical effects.
[0212] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments may be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described herein are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated therein. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
[0213] Those skilled in the art will appreciate that all or part of the process steps in the above-described method embodiments can be implemented by a computer program instructing the relevant hardware. The program can be stored in a computer-readable storage medium, and when executed, the program can include the process steps in the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
[0214] In short, the above description is only an embodiment of the technical solution of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent replacements, improvements, etc. made based on the disclosure of this application should be included in the scope of protection of this application.
Claims
1. A method for acquiring a barcode image, characterized in that: The method is applied to an electronic device, and includes: A user operation for triggering code scanning is received, and a first image is captured through a camera, where the first image includes a code image; a first angle is formed between a shooting direction of the camera and a perpendicular direction of a plane where the code image is located, and the first angle is greater than 0; identifying whether the code image is deformed; Determining that the code image is deformed, and detecting the aspect ratio of a front quadrilateral corresponding to the code image; When the aspect ratio is greater than a first threshold, binarizing the first image to obtain a binarized image; Extracting a first contour from the binary image, wherein the first contour is a contour with the largest area in the binary image; Determining whether the area ratio of the region enclosed by the first contour in the first image is greater than or equal to a second threshold; When the area ratio is less than a second threshold, scanning the first image to obtain a first region, where the first region is a region enclosed by a straight line on which a boundary of a white background region is located in the region enclosed by the first outline; When the area ratio is greater than or equal to a second threshold, scanning the first image to obtain a second area, where the second area is an area enclosed by rows and columns where black pixel values appear first on the upper side and the left side, and rows and columns where black pixel values appear last on the lower side and the right side of the area enclosed by the first outline; Correcting the first area or the second area to obtain a second image; Information corresponding to the code image in the second image is identified.
2. The method according to claim 1, characterized in that Correcting the first region or the second region to obtain a second image specifically includes: Identify corner points of the first region or the second region, and use the corner points to perform angle correction on the first region or the second region to obtain a second image.
3. The method according to claim 1, characterized in that Correcting the first region or the second region to obtain a second image specifically includes: A perspective transformation algorithm or an affine transformation algorithm is used to perform angle correction on the first region or the second region to obtain a second image.
4. The method according to any one of claims 1 to 3, characterized in that After identifying information corresponding to the code image in the second image, the method further includes: A corresponding first operation is performed according to the information.
5. The method according to any one of claims 1 to 3, characterized in that When the area ratio is less than a second threshold, scanning the first image to obtain a first region specifically includes: when the area ratio is less than the second threshold, scanning the first image using a line detection algorithm to obtain the first region; When the area ratio is greater than or equal to a second threshold, scanning the first image to obtain a second area specifically includes: when the area ratio is greater than or equal to the second threshold, using a scan line algorithm to identify the first image to obtain the second area.
6. An electronic device, characterized in that: include: One or more processors, one or more memories, and one or more cameras; wherein the one or more cameras and the one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program code, and the computer program code includes computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes the method according to any one of claims 1 to 5.
7. A computer-readable storage medium comprising instructions, characterized in that: When the instruction is executed on an electronic device, the electronic device is caused to execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
OCR (Optical Character Recognition) method, device and system
CN114627459A
Two-dimensional code positioning method and device and computer readable storage medium
CN115713556A
QR code recognition method and related apparatus
WO2022166619A1