Code scanning method, electronic device, and storage medium

By performing distortion correction processing on callback image frames in code scanning applications, the problem of recognition failure caused by poor code scanning angles is solved, and the code scanning success rate and user experience are improved.

WO2024179064A1PCT designated stage expired Publication Date: 2024-09-06HONOR DEVICE CO LTD

Patent Information

Application Number
PCT/CN2023/133755
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-02-27
Filing Date
2023-11-23
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

During the scanning process, the barcode may not be recognized due to factors such as the position of the barcode or the scanning angle. The user needs to adjust the scanning angle so that the terminal can scan the code successfully, resulting in a poor user experience.

Method used

By performing distortion correction on the QR code in the callback image frame and regenerating the callback image frame, the code scanning application can perform recognition based on the regenerated image frame, ensuring that the position of the QR code is consistent and preventing the positioning mark from being displayed on the preview image. Improper location.

Benefits of technology

It improves the success rate of QR code positioning and recognition by code scanning applications, solves the problem of long-term unsuccessful code scanning or even failure due to poor scanning angles of users, and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023133755_06092024_PF_FP
    Figure CN2023133755_06092024_PF_FP
Patent Text Reader

Abstract

Embodiments of the present application provide a code scanning method, an electronic device, and a storage medium. In this method, the electronic device acquires a first callback image frame in response to an enabling operation on a code scanning function of an application, and performs distortion correction on a first two-dimensional code image in the image frame to obtain a second two-dimensional code image; a second callback image frame is re-generated on the basis of the second two-dimensional code image, so that the position of the second two-dimensional code image in the second callback image frame is consistent with the position of the first two-dimensional code image in the first callback image frame; the second callback image frame is sent to the application for identification; when the application identifies the two-dimensional code on the basis of the second callback image frame, the electronic device displays a positioning identifier on a preview image, wherein the position of the positioning identifier is determined on the basis of the position of the second two-dimensional code image in the second callback image frame. In this way, the problem that code scanning is unsuccessful for a long time and even fails due to a poor code scanning angle of a user can be solved, and the problem of an improper display position of a two-dimensional code positioning identifier on a preview image can also be avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Code scanning method, electronic device and storage medium

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of China on February 27, 2023, with application number 202310207187.1 and application name “Code scanning method, electronic device and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of smart terminal technology, and in particular to a code scanning method, electronic device and storage medium. Background Art

[0003] With the development of technology, barcodes are ubiquitous in our lives. They enable us to quickly make payments, add friends, follow public accounts, and more. However, when users scan barcodes with a terminal, the barcode may not be recognized due to factors such as its position or scanning angle. In such cases, users need to adjust the scanning angle repeatedly to ensure the terminal can successfully scan the code, which can result in a poor user experience.

[0004] Summary of the Invention

[0005] In order to solve the above-mentioned technical problems, the embodiments of the present application provide a code scanning method, an electronic device and a storage medium. In this method, the electronic device performs distortion correction processing on the QR code in the callback image frame, and regenerates the callback image frame based on the distortion-corrected QR code image, so that the code scanning application performs code scanning and recognition based on the regenerated callback image frame. Among them, the position of the QR code in the regenerated callback image frame is consistent with the position of the QR code in the original callback image frame. In this way, the code scanning method provided by this embodiment can not only solve the problem of long-term unsuccessful or even failed code scanning due to poor scanning angles of the user, but also avoid the problem of the QR code positioning mark being displayed in an inappropriate position on the preview image.

[0006] In a first aspect, an embodiment of the present application provides a code scanning method. The method includes: the electronic device obtains a first callback image frame and a first preview image frame in response to an operation to activate a code scanning function of a target application; the electronic device extracts a first QR code image from the first callback image frame; the electronic device performs distortion correction processing on the first QR code image to obtain a second QR code image; the electronic device creates a blank image frame, determines the position of the first QR code image in the first callback image frame, and adds the second QR code image to the blank image frame to obtain a second callback image frame, so that the position of the second QR code image in the second callback image frame is consistent with the position of the first QR code image in the first callback image frame; wherein the blank image frame and the first callback image frame have the same image size; the electronic device sends the second callback image frame to the target application for code scanning recognition; the electronic device displays the first preview image; when the target application recognizes the QR code based on the second callback image frame, the electronic device displays a QR code positioning mark on the first preview image; wherein the position of the QR code positioning mark is determined based on the position of the second QR code image in the second callback image frame.

[0007] Among them, the target application refers to a third-party application with a code scanning function, such as WeChat application, Alipay application, etc.

[0008] In an embodiment of the present application, the callback image frame is used by the code scanning application to perform a code scanning and recognition operation, and the preview image frame is used by the code scanning application to perform an image preview operation. The image acquisition time of the first callback image frame is similar to the image acquisition time of the first preview image frame, and since the callback image frame and the preview image frame correspond to the same image acquisition scene, the screen information in the first callback image frame is almost identical to the screen information in the first preview image frame, with very little difference. Therefore, the position of the QR code in the first callback image frame is also similar to the position of the QR code in the first preview image frame, such as the position of the center point of the QR code is similar. This can also be said to be the case where the QR code area in the first callback image frame and the QR code area in the first preview image frame largely overlap, or even completely overlap.

[0009] When the target application recognizes the QR code based on the second callback image frame, the electronic device determines the position of the QR code in the second callback image frame, such as the coordinates of the center point of the QR code in the second callback image frame. Furthermore, the electronic device displays a QR code positioning marker on the first preview image based on the coordinates, such that the coordinates of the center point of the QR code positioning marker in the first preview image are the same as the coordinates of the center point of the QR code in the second callback image frame.

[0010] When the angle between the plane where the QR code to be scanned is located and the plane of the mobile phone image acquisition is too large (such as 45 degrees to 75 degrees), the QR code in the callback image frame will have image distortion problems. The electronic device performs distortion correction processing on the QR code image in the first callback image frame, and regenerates the second callback image frame based on the distortion-corrected QR code image for the scanning application to identify. In this way, the scanning application can improve the positioning and recognition success rate of the QR code, and solve the problem of long-term unsuccessful or even failed scanning due to poor scanning angles of the user. In addition, since the shooting scenes corresponding to the first preview image frame and the first callback image frame are consistent, and the interval between the image acquisition times is relatively small, the screen information of the first preview image frame and the screen information of the first callback frame are relatively small, and the QR code area in the first callback image frame mostly overlaps with the QR code area in the first preview image frame, or even completely overlaps. Since the position of the QR code in the regenerated second callback image frame is consistent with the position of the distorted QR code in the first callback image frame, the QR code positioning marker determined by the scanning application based on the regenerated second callback image frame will be displayed in the QR code area in the first preview image, thereby avoiding the problem of the QR code positioning marker being displayed in an incorrect position in the first preview image.

[0011] According to the first aspect, the method also includes: the electronic device obtains a third callback image frame, which is a callback image frame after the first callback image frame; the electronic device sends the third callback image frame to the target application for code scanning and recognition; the electronic device obtains a fourth callback image frame, which is a callback image frame after the third callback image frame; the electronic device extracts a third QR code image from the fourth callback image frame, performs distortion correction processing on the third QR code image, and obtains a fourth QR code image; the electronic device creates a blank image frame, determines the position of the third QR code image in the fourth callback image frame, and adds the fourth QR code image to the blank image frame to obtain a fifth callback image frame, so that the position of the fourth QR code image in the fifth callback image frame is consistent with the position of the third QR code image in the fourth callback image frame; the electronic device sends the fifth callback image frame to the target application for code scanning and recognition.

[0012] Exemplarily, the third callback image frame is the next callback image frame after the first callback image frame, and the fourth callback image frame is the next callback image frame after the third callback image frame.

[0013] In the callback image frames received by the scanning application, distortion-corrected callback image frames alternate with undistorted callback image frames. The scanning application then scans and recognizes the QR code based on each callback image frame in the order in which they were received. This prevents the scanning application from failing to recognize the distortion-corrected callback image frames, leading to prolonged QR code recognition failures. Once the scanning application can recognize the undistorted callback image frames, the QR code can still be successfully recognized, thus ensuring the success rate of the scanning method.

[0014] According to the first aspect, or any implementation of the first aspect above, the method further includes: the electronic device obtaining a third callback image frame, the third callback image frame being a callback image frame subsequent to the first callback image frame; the electronic device sending the third callback image frame to a target application for code scanning and recognition. The electronic device displays a preview image; when the target application recognizes a QR code based on the third callback image frame, the electronic device displays a QR code location marker on the corresponding preview image; wherein the position of the QR code location marker is consistent with the position of the QR code in the third callback image frame.

[0015] Similarly, when the target application recognizes the QR code based on the fifth callback image frame, the QR code positioning mark is displayed on the corresponding preview image; wherein the position of the QR code positioning mark is consistent with the position of the fourth QR code image in the fifth callback image frame.

[0016] The scanning application may locate and recognize the QR code based on the callback image frame N1 that has undergone distortion correction. In this case, the position of the QR code locating marker is determined based on the QR code position in the callback image frame N1. The scanning application may also locate and recognize the QR code based on the callback image frame N2 that has not undergone distortion correction. In this case, the position of the QR code locating marker is determined based on the QR code position in the callback image frame N2. After the scanning application completes the QR code positioning and recognition operation based on a callback image frame, it will no longer perform the positioning and recognition operation based on the next callback image frame.

[0017] According to the first aspect, or any implementation method of the first aspect above, the position of the second QR code image in the second callback image frame is consistent with the position of the first QR code image in the first callback image frame, including: the coordinates of the center point of the second QR code image in the second callback image frame are consistent with the coordinates of the center point of the first QR code image in the first callback image frame.

[0018] This can avoid the problem of the QR code positioning mark being displayed in an incorrect position in the preview image.

[0019] According to the first aspect, or any implementation method of the first aspect above, the electronic device performs distortion correction processing on the first QR code image in the first callback image frame, including: when the first QR code image in the first callback image frame does not meet the zoom condition, the electronic device performs distortion correction processing on the first QR code image in the first callback image frame.

[0020] According to the first aspect, or any implementation method of the first aspect above, when the first QR code image in the first callback image frame meets the zoom condition, the electronic device performs zoom processing on the first callback image frame to enlarge the QR code image to obtain a sixth callback image frame; the electronic device sends the sixth callback image frame to the target application for code scanning and recognition.

[0021] In this way, before the electronic device returns the callback image frame of the code scanning application to the code scanning application, when the QR code image in the callback image frame is small, it zooms the callback image frame to enlarge the QR code image, so that the callback image frame after zoom processing is easier for the code scanning application to recognize, thereby improving the scanning success rate and scanning efficiency of the callback image frame of the code scanning application and enhancing the user experience.

[0022] According to the first aspect, or any implementation of the first aspect above, the method also includes: the electronic device displays a second preview image; when the target application recognizes the QR code based on the sixth callback image frame, the electronic device displays a QR code positioning marker on the second preview image; wherein the position of the QR code positioning marker is consistent with the position of the QR code image in the sixth callback image frame.

[0023] In this way, when the QR code to be scanned occupies a relatively small portion of the callback image, the electronic device zooms the callback image frame to magnify the QR code image for recognition by the scanning application. At this point, if the scanning application recognizes the QR code based on the zoomed callback image frame, it determines the position of the QR code locator based on the position of the QR code in the callback image frame and displays the QR code locator on the preview image based on this position.

[0024] According to the first aspect, or any implementation of the first aspect above, distortion correction processing is performed on the first two-dimensional code image, including: when the maximum rotation angle of the first two-dimensional code image is greater than a first threshold, distortion correction processing is performed on the first two-dimensional code image in the first callback image frame according to a perspective transformation. The maximum rotation angle is the maximum value of the first angle, the second angle, the third angle, and the fourth angle, the first angle is the angle between the left boundary of the first two-dimensional code image and the vertical direction, the second angle is the angle between the upper boundary of the first two-dimensional code image and the horizontal direction, the third angle is the angle between the right boundary of the first two-dimensional code image and the vertical direction, and the fourth angle is the angle between the lower boundary of the first two-dimensional code image and the horizontal direction.

[0025] For the relevant explanations about the first angle, the second angle, the third angle and the fourth angle, please refer to FIG. 7c and the related explanations below, which will not be repeated here.

[0026] According to the first aspect, or any implementation of the first aspect above, the zoom condition includes: the image ratio of the QR code image in the callback image frame is less than a second threshold, and the target zoom ratio corresponding to the QR code is greater than a third threshold; wherein the target zoom ratio is used to indicate the maximum zoom ratio value allowed when the callback image frame is zoomed to enlarge the QR code image.

[0027] For example, the electronic device can calculate the image ratio r0 of the QR code image in the callback image frame based on the outline of the QR code image, where r0 = S0 / S, S0 is the pixel area of ​​the QR code image, and S is the pixel area of ​​the callback image frame.

[0028] The target zoom ratio is referred to as the maximum allowable zoom ratio r1 below. The electronic device can calculate the maximum allowable zoom ratio r1 corresponding to the QR code in the callback image frame based on the QR code image size information and the position information of the QR code image in the callback image frame. For a detailed description of the maximum allowable zoom ratio r1, please refer to Figure 7b and the related explanation below and will not be repeated here.

[0029] According to the first aspect, or any implementation of the first aspect above, the zoom condition includes: an image ratio of the QR code image in the callback image frame is less than a second threshold.

[0030] According to the first aspect, or any implementation of the first aspect above, the electronic device performs zoom processing on the first callback image frame, including: the electronic device performs zoom processing on the first callback image frame according to a target zoom ratio.

[0031] In this way, under the premise of ensuring the integrity of the QR code image, the QR code image in the callback image frame is enlarged as much as possible, so that a certain boundary of the QR code image is infinitely close to a certain boundary of the callback image frame, or even coincides with this boundary, which is more conducive to the scanning application to locate and identify the QR code.

[0032] According to the first aspect, or any implementation method of the first aspect above, the electronic device performs distortion correction processing on the first two-dimensional code image in the first callback image frame, including: the electronic device determines the four vertex coordinates of the first two-dimensional code image; the electronic device determines the side length of the second two-dimensional code image based on the four vertex coordinates of the first two-dimensional code image; the electronic device determines the coordinates of a vertex of the second two-dimensional code image, and calculates the coordinates of the other three vertices of the second two-dimensional code image based on the side length of the second two-dimensional code image; the electronic device calculates the perspective transformation matrix based on the four vertex coordinates of the first two-dimensional code image and the four vertex coordinates of the second two-dimensional code image; the electronic device performs perspective transformation processing on the first two-dimensional code image according to the perspective transformation matrix to obtain the second two-dimensional code image.

[0033] The coordinates of the first vertex of the second QR code image determined by the electronic device may also be the coordinates of the upper left vertex. For example, the coordinates of the upper left vertex may be set to the upper left corner area of ​​the image so that all four vertices of the second QR code image fall within the image area.

[0034] According to the first aspect, or any implementation method of the first aspect above, the electronic device determines the side length of the first two-dimensional code image based on the four vertex coordinates of the first two-dimensional code image, including: the electronic device calculates the four side lengths of the first two-dimensional code image based on the four vertex coordinates of the first two-dimensional code image; the electronic device uses the maximum side length of the four side lengths of the first two-dimensional code image as the side length of the second two-dimensional code image.

[0035] In this way, the electronic device uses the largest side length of the four sides of the first QR code image as the side length of the second QR code image. Compared with selecting one of the other three side lengths as the side length of the second QR code image, the image size of the second QR code image obtained after distortion correction of the first QR code image is larger, which is conducive to recognition by scanning applications.

[0036] In a second aspect, embodiments of the present application provide an electronic device. The electronic device includes: one or more processors; a memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by the one or more processors, the electronic device performs the code scanning method of the first aspect and any one of the first aspects.

[0037] The second aspect and any implementation of the second aspect correspond to the first aspect and any implementation of the first aspect, respectively. The technical effects corresponding to the second aspect and any implementation of the second aspect can be referred to the technical effects corresponding to the first aspect and any implementation of the first aspect, and will not be repeated here.

[0038] In a third aspect, embodiments of the present application provide a computer-readable storage medium comprising a computer program, which, when executed on an electronic device, causes the electronic device to execute the code scanning method of the first aspect and any one of the first aspects.

[0039] The third aspect and any implementation of the third aspect correspond to the first aspect and any implementation of the first aspect, respectively. The technical effects corresponding to the third aspect and any implementation of the third aspect can be referred to the technical effects corresponding to the first aspect and any implementation of the first aspect, and will not be repeated here.

[0040] In a fourth aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is run, the computer executes the code scanning method as described in the first aspect or any one of the first aspects.

[0041] The fourth aspect and any implementation of the fourth aspect correspond to the first aspect and any implementation of the first aspect, respectively. The technical effects corresponding to the fourth aspect and any implementation of the fourth aspect can be referred to the technical effects corresponding to the first aspect and any implementation of the first aspect, and will not be repeated here.

[0042] In a fifth aspect, the present application provides a chip comprising a processing circuit and a transceiver pin. The transceiver pin and the processing circuit communicate with each other via an internal connection path, and the processing circuit executes the code scanning method according to the first aspect or any one of the first aspects to control the receiving pin to receive a signal and to control the transmitting pin to send a signal.

[0043] The fifth aspect and any implementation of the fifth aspect correspond to the first aspect and any implementation of the first aspect, respectively. The technical effects corresponding to the fifth aspect and any implementation of the fifth aspect can be referred to the technical effects corresponding to the first aspect and any implementation of the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] FIG1 is an exemplary application scenario;

[0045] FIG2 is an exemplary diagram of a wide-angle code scanning scenario;

[0046] FIG3 is a schematic diagram showing an exemplary hardware structure of an electronic device;

[0047] FIG4 is a schematic diagram illustrating a software structure of an electronic device;

[0048] FIG5 is a schematic diagram illustrating a flow chart of a code scanning method provided by this embodiment;

[0049] FIG6 is a schematic diagram showing an exemplary processing flow of a callback image frame;

[0050] FIG7 a is an exemplary diagram showing a result of a two-dimensional code detection;

[0051] FIG7 b is a schematic diagram showing an exemplary position of a two-dimensional code image in a callback image frame;

[0052] FIG7c is a schematic diagram showing an exemplary rotation angle of a two-dimensional code image;

[0053] FIG7 d is an exemplary diagram showing perspective transformation of a two-dimensional code image;

[0054] FIG7e is an exemplary diagram showing the callback image frame before and after being processed;

[0055] FIG7f is a schematic diagram illustrating an exemplary code scanning positioning scenario;

[0056] FIG8 is a flowchart illustrating an exemplary method of scanning a code according to this embodiment. DETAILED DESCRIPTION

[0057] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0058] The term "and / or" in this article is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.

[0059] In the description and claims of the embodiments of this application, the terms "first" and "second" are used to distinguish different objects, rather than to describe a specific order of objects. For example, the terms "first target object" and "second target object" are used to distinguish different objects, rather than to describe a specific order of objects.

[0060] In the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be interpreted as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.

[0061] In the description of the embodiments of this application, unless otherwise specified, "multiple" means two or more. For example, "multiple processing units" means two or more processing units; "multiple systems" means two or more systems.

[0062] With the development of technology, barcodes are everywhere in our lives. Barcodes can help us quickly make payments, add friends, follow public accounts, and more. Examples of barcodes include, but are not limited to, barcodes and QR codes.

[0063] At present, more and more applications (APPs) on electronic devices have added the function of using the camera, so that the APP can use the camera to realize the code scanning function. Taking the code scanning APP as WeChat and the barcode as the QR code as an example, Figure 1 shows an application scenario. As shown in Figure 1 (1), the user clicks the icon 101 of the WeChat application, the mobile phone detects the user operation, opens the WeChat application and displays the interface of the WeChat application. The user performs relevant operations in the WeChat application, so that the WeChat application displays the interface including the "Scan" function, as shown in Figure 1 (2). Continuing to refer to Figure 1 (2), the user clicks the "Scan" function option 102, the mobile phone detects the user operation, and displays the "Scan" interface, as shown in Figure 1 (3). Continuing to refer to Figure 1 (3), in the "Scan" interface of the WeChat application, a preview window 103 is displayed, which displays a preview image captured by the mobile phone camera and a scan line 1031. Among them, the scan line 1031 continuously moves from top to bottom to show the user the effect of scanning. In this process, the WeChat application locates and recognizes the QR code in the image. After the WeChat application completes the positioning and recognition operation of the QR code, the mobile phone displays the code scanning and positioning interface (see (4) in Figure 1) and immediately jumps to the code scanning result interface corresponding to the QR code content information (not shown in the figure). Among them, the code scanning and positioning interface is used to indicate the positioning result of the QR code in the image, and the code scanning and result interface is used to indicate the content recognition result of the QR code. Exemplarily, the code scanning and result interface can be an operation interface corresponding to the QR code content (such as a payment interface, adding friends, etc.) or an information display interface (public account interface, etc.). As shown in (4) in Figure 1, the code scanning and positioning interface displays the currently displayed preview image frame 104 of the WeChat application and the code scanning and positioning identifier (or QR code positioning identifier) ​​1041. Among them, the code scanning and positioning identifier 1041 is used to indicate the position information of the QR code recognized by the WeChat application in the scanned image, so that the user can understand the positioning situation of the QR code in the image by the WeChat application. For example, in the WeChat application, the code scanning and positioning identifier 1041 is a green dot.

[0064] If the WeChat application cannot complete the positioning and recognition operation of the QR code, the scan line 1031 will continue to move from top to bottom, always showing the user the effect of scanning. In one case, if the position of the QR code is not good or the scanning angle is too large, it may be that the WeChat application cannot complete the positioning and recognition of the QR code, so the scan line 1031 will continue to move from top to bottom. Figure 2 shows an example of an application scenario. As shown in Figure 2, when the user holds the mobile phone 100_1 and uses the "Scan" function in the WeChat application, if the angle between the plane where the QR code 200 is located and the image acquisition plane of the mobile phone is too large, the QR code 200 will be distorted in the scanned image of the WeChat application, causing the WeChat application to be unable to complete the positioning and recognition operation of the QR code. The scan line 1031 will continue to move from top to bottom, always showing the user the effect of scanning. At this point, the user can only continuously adjust the image acquisition direction of the mobile phone 100_1 to make the image acquisition plane of the mobile phone as parallel as possible to the plane where the QR code 200 is located, thereby reducing the degree of distortion of the QR code 200 in the scanned image and enabling the WeChat application to complete the positioning and recognition of the QR code. The image acquisition plane of the mobile phone can be understood as the plane where the lens of the mobile phone camera is located, or a plane parallel to the plane where the lens is located.

[0065] Therefore, when the angle between the plane of the barcode to be scanned and the image acquisition plane of the electronic device is too large (such as 45 degrees to 75 degrees), how to improve the positioning and recognition success rate of the barcode scanning application is an urgent problem to be solved.

[0066] FIG3 is a schematic diagram of the hardware structure of the electronic device 100. Optionally, the electronic device 100 may be referred to as a terminal or a terminal device. The electronic device 100 may be a device with a camera, such as a mobile phone, a tablet computer, or a wearable device. This application does not limit the type of the electronic device 100. It should be noted that the schematic diagram of the structure of the electronic device 100 is applicable to the mobile phone in FIG1 and FIG2.

[0067] It should be understood that the electronic device 100 shown in FIG3 is merely an example of an electronic device, and that the electronic device 100 may have more or fewer components than shown, may combine two or more components, or may have a different component configuration. The various components shown in FIG3 may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.

[0068] As shown in FIG3 , the electronic device 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display 194, and a subscriber identification module (SIM) card interface 195. The sensor module 180 may include a pressure sensor, a gyroscope sensor, an acceleration sensor, a temperature sensor, a motion sensor, an air pressure sensor, a magnetic sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, and the like.

[0069] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, 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.

[0070] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0071] The processor 110 may further include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory.

[0072] Electronic device 100 implements display functionality through a GPU, display screen 194, and an application processor. A GPU is a microprocessor for image processing that connects display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or modify display information.

[0073] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. In some embodiments, the electronic device 100 may include one or N display screens 194, where N is a positive integer greater than one.

[0074] The electronic device 100 can implement a shooting function through an ISP, a camera 193, a video codec, a GPU, a display screen 194, and an application processor.

[0075] The ISP processes data fed back by camera 193. 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 converted into a visible image. The ISP can also perform algorithmic optimization on 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 193.

[0076] The camera 193 is used to capture static images or videos. For example, in a barcode scanning scenario, the camera 193 can capture an image including a barcode. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then passes the electrical signal 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 RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.

[0077] The internal memory 121 can be used to store computer executable program code, which includes instructions. The processor 110 executes the instructions stored in the internal memory 121 to execute various functional applications and data processing of the electronic device 100, such as enabling the electronic device 100 to implement the code scanning method in the embodiment of the present application.

[0078] The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present application, the Android system with a layered architecture is used as an example to illustrate the software structure of the electronic device 100.

[0079] FIG4 is a block diagram of the software structure of the electronic device 100 according to an embodiment of the present application.

[0080] The layered architecture of electronic device 100 divides the software into several layers, each with distinct roles and responsibilities. Layers communicate with each other via software interfaces. In some embodiments, the Android system is divided into four layers: from top to bottom, the application layer, the application framework layer, the HAL (Hardware Abstraction Layer), and the kernel layer (also known as the driver layer).

[0081] It is understood that Figure 4 is merely an example. For example, between the application framework layer and the HAL, there may also be an Android runtime and system library layer. The Android Runtime includes core libraries and a virtual machine, responsible for scheduling and management of the Android system. The system library may include multiple functional modules, such as a surface manager, media libraries, a 3D graphics processing library (e.g., OpenGL ES), and a 2D graphics engine (e.g., SGL).

[0082] The application layer can include a series of application packages. As shown in Figure 4, the application package may include a camera, gallery, QR code scanning application (third-party application), scene recognition module, etc. The application package may also include call, calendar, map, navigation, music, video, short message, WLAN, Bluetooth and other applications.

[0083] In an embodiment of the present application, the scene recognition module can be used to determine the value of the flag bit FLAG corresponding to the current scene. The value of the flag bit FLAG is used to indicate whether a callback flow needs to be created. For example, if the scene recognition module determines that the FLAG corresponding to the current scene is 1, then the current scene needs to create a callback flow; if the scene recognition module determines that the FLAG corresponding to the current scene is 0, then the current scene does not need to create a callback flow.

[0084] The application framework layer provides an application programming interface (API) and programming framework for applications in the application layer. The application framework layer includes some predefined functions.

[0085] As shown in FIG4 , the application framework layer may include a window manager, a content provider, a resource manager, a view system, a notification manager, a camera service, and the like.

[0086] The camera service can be used to manage the camera, including starting and stopping the camera, creating preview streams (previewStream) and callback streams (callbackStream), obtaining preview image frames and callback image frames, reporting preview streams to upper-layer applications, and reporting callback streams to upper-layer applications through callback functions. Among them, the preview stream is composed of multiple preview image frames, which are generated based on the preview image data collected by the camera sensor; the callback stream is composed of multiple callback image frames, which are generated based on the callback image data collected by the camera sensor.

[0087] In an embodiment of the present application, the camera service can determine whether a callback flow needs to be created based on the value of the flag FLAG determined by the scene recognition module.

[0088] The window manager is used to manage window programs. The window manager can obtain the display size, determine whether there is a status bar, lock the screen, take screenshots, etc.

[0089] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0090] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0091] The view system includes visual controls, such as those for displaying text and images. The view system is used to build applications. A display interface can consist of one or more views. For example, a display interface containing a text notification icon might include a view for displaying text and a view for displaying images.

[0092] The Notification Manager allows applications to display notifications in the status bar. These messages can be used to convey informational messages and can disappear automatically after a short pause, without requiring user interaction. For example, notifications are used to notify the completion of downloads, message reminders, and so on. Notifications can also appear in the system's top status bar as icons or scrolling text, such as notifications from background applications, or as dialog windows on the screen. Notifications can also take the form of text messages in the status bar, beeping sounds, vibrating electronic devices, or flashing indicator lights.

[0093] The HAL abstracts the underlying hardware and provides unified, abstracted services to the upper layers. The HAL encapsulates kernel-layer drivers and provides a callable interface to the application framework layer, shielding the implementation details of the lower-level hardware. As shown in Figure 4, the HAL can include, for example, the Camera HAL.

[0094] Camera HAL is the core software framework of Camera, which includes sensor node, image processing module, barcode detection module, barcode distortion correction module, barcode zoom module, etc.

[0095] The sensor node may be a control node for a camera sensor, and the sensor node may control the camera sensor through a camera driver to expose and output an image.

[0096] The image processing module can be used for but not limited to image signal front-end processing, spatial alignment transformation processing, image signal back-end processing, image format conversion processing (such as format conversion between GRB images and YUV images), barcode distortion detection processing, barcode size detection processing, and image creation operations, etc.

[0097] The barcode detection module can be used to detect the barcode in the image and determine the barcode image area. Optionally, the barcode detection module is a QR code detection module, which is used to detect the QR code in the image and determine the QR code image area.

[0098] The barcode distortion correction module can be used to perform distortion correction processing on barcode images that meet the distortion conditions. Specifically, the barcode distortion correction module can perform distortion correction processing on barcode images that meet the distortion conditions based on the principle of perspective transformation. Optionally, the barcode distortion correction module is a QR code distortion correction module, which is used to perform distortion correction processing on QR code images that meet the distortion conditions based on the principle of perspective transformation.

[0099] The barcode zoom module can be used to focus an image that meets the zoom conditions to increase the image ratio of the barcode image in the entire frame image. Optionally, the barcode zoom module is a QR code zoom module, which is used to focus an image that meets the zoom conditions to increase the image ratio of the QR code image in the entire frame image.

[0100] It should be noted that the barcode detection module, barcode distortion correction module, and barcode zoom module are divided based on function, and each module is used to implement a specific function. This application does not limit the division of the barcode detection module, barcode distortion correction module, and barcode zoom module. The barcode detection module, barcode distortion correction module, and barcode zoom module can be provided separately or integrated together, for example, integrated into the image processing module.

[0101] The kernel layer is the layer between hardware and software. It includes at least the camera driver and display driver. Hardware includes at least the processor, camera, display, and sensors.

[0102] It is understood that the layers in the software structure shown in FIG4 and the components contained in each layer do 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, and each layer may include more or fewer components, and this application does not limit this.

[0103] It is understandable that, in order to implement the code scanning method in the embodiment of the present application, the electronic device includes hardware and / or software modules corresponding to the execution of each function. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of this application.

[0104] Referring to the examples shown in Figures 1 and 2, the WeChat app's "Scan" function is implemented based on the electronic device's camera function. When implementing this function, the WeChat app uses the preview image frames captured by the camera app for interface preview and the callback image frames captured by the camera app for code scanning and recognition.

[0105] The following takes the third-party application as WeChat application and the code scanning function as the "Scan" function as an example, and combines Figure 5 to explain the code scanning method provided in the embodiment of the present application. Among them, the third-party application can also be other applications with a code scanning function, such as the Alipay application.

[0106] Referring to (1) in Figure 1, the user clicks on the WeChat application icon 101, and the WeChat application starts. After the WeChat application starts, an activity thread corresponding to the WeChat application is generated. Continuing to refer to (2) in Figure 1, the user clicks on the "Scan" function option 102. In response to the user operation, the WeChat SDK (Software Development Kit) in the mobile phone starts the camera SDK, as shown in Figure 5. After the "Scan" function is started, the activity thread corresponding to the WeChat application sends the interface scene parameters to the scene recognition module. Among them, the interface scene parameters are used to describe the scene and state of the current interface of the mobile phone. The interface scene parameters may include but are not limited to the application package name (PackegeName), the activity name (ActivityName), or the interface scene parameters may include but are not limited to the application package name, the activity name and the fragment name (FragmentName) (or page name), etc. Furthermore, the scene recognition module can determine the value of the scene flag FLAG based on the interface scene parameters. Among them, the value of the scene flag FLAG is used to indicate whether the current scene needs to create a callback flow. For example, when FLAG=1, it indicates that the current scene needs to create a callback stream; when FLAG=0, it indicates that the current scene does not need to create a callback stream.

[0107] It should be noted that the preview stream is composed of multiple preview image frames, which are generated based on the preview image data collected by the camera sensor. The preview image data is the image data collected by the camera sensor based on the preview image frame request. The callback stream is composed of multiple callback image frames, which are generated based on the callback image data collected by the camera sensor. The callback image data is the image data collected by the camera sensor based on the callback image frame request. Among them, the preview stream is used for third-party applications to display preview images, while the callback stream is used for third-party applications to implement specific functions. In this application, the callback stream is specifically used for the WeChat application to implement the code scanning and recognition function.

[0108] For example, the scene recognition module can match the received interface scene parameters with the interface scene parameters corresponding to the preset scene. The value of the flag bit FLAG corresponding to the preset scene is 1. If the match is successful, the scene recognition module can determine that the flag bit FLAG corresponding to the current scene is 1; if the match is unsuccessful, the scene recognition module can determine that the flag bit FLAG corresponding to the current scene is 0. After the scene recognition module determines the FLAG value corresponding to the current scene, it sends the FLAG value to the camera SDK.

[0109] Since the WeChat application performs code scanning and recognition operations based on the callback image frame when implementing the "Scan" function, the value of the scene flag FLAG corresponding to the WeChat application's "Scan" function is "1", and the scene recognition module sends the indication information "FLAG=1" to the camera SDK.

[0110] 5 , after the camera SDK receives the start instruction sent by the WeChat SDK, it sends a preview instruction to the camera service. The camera service generates a preview image frame request according to the preview instruction and sends the preview image frame request to the camera HAL.

[0111] In this embodiment of the present application, the scene recognition module sends the indication information "FLAG=1" to the camera SDK. After receiving the indication information "FLAG=1", the camera SDK sends the indication information "FLAG=1" to the camera service. The camera service generates a callback image frame request based on the indication information "FLAG=1" and sends the callback image frame request to the camera HAL.

[0112] After the camera HAL receives the preview image frame request, the Sensor node in the camera HAL sends the preview image frame request to the camera driver, which controls the camera sensor to perform exposure and image output operations to obtain preview image data.

[0113] After the camera HAL receives the callback image frame request, the Sensor node in the camera HAL sends the callback image frame request to the camera driver, which controls the camera sensor to perform exposure and image output operations to obtain the callback image data.

[0114] Due to the rotating buffer mechanism between the application framework layer and HAL in the camera system of the Android architecture. After the camera service receives the preview indication, the camera service will first continuously send multiple (for example, 8) preview image frame requests to the camera HAL, and after each preview image frame is received from the camera HAL, it will send another preview image frame request to the camera HAL until the preview is completed. In the camera HAL, the sensor node will sequentially control the camera sensor through the camera driver to perform exposure and image output operations based on these multiple preview image frame requests. Similarly, after the camera service receives the indication information "FLAG=1", the camera service will first continuously send multiple (for example, 8) callback image frame requests to the camera HAL, and after each callback image frame is received from the camera HAL, it will send another callback image frame request to the camera HAL until the code scanning and recognition is completed. In the camera HAL, the sensor node will sequentially control the camera sensor through the camera driver to perform exposure and image output operations based on these multiple callback image frame requests.

[0115] In this way, the camera service implements the creation of a preview stream and a callback stream. The preview image frames in the preview stream are continuously acquired and updated, meaning that the WeChat app's preview screen is generated based on the sequentially acquired preview image frames. The callback image frames in the callback stream are also continuously acquired and updated, meaning that the WeChat app implements the code scanning and recognition function based on the sequentially acquired callback image frames.

[0116] It should be noted that the present embodiment does not limit the order in which the camera service creates the preview stream and the callback stream. For example, the camera service may first create the preview stream and then create the callback stream. For another example, the camera service may create the preview stream and the callback stream in parallel.

[0117] If the camera service receives a preview indication and the indication information "FLAG = 0", the camera service generates a preview image frame request according to the preview indication and sends the preview image frame request to the camera HAL. Since the indication information "FLAG = 0" indicates that the current scene does not require the creation of a callback stream, the camera service does not generate a callback image frame request in this case.

[0118] Continuing with Figure 5, after the camera sensor generates preview image data through exposure, the preview image data is sent to the image processing module via the camera driver. The image processing module performs relevant processing on the preview image data, including but not limited to front-end processing, spatial alignment transformation, and back-end processing, to generate the corresponding preview image frame. The preview image frame generated by the image processing module is then sent to the WeChat SDK UI module via the camera service for display.

[0119] After the camera sensor generates callback image data through exposure, the callback image data is sent to the image processing module via the camera driver. The image processing module performs relevant processing on the callback image data, including but not limited to front-end processing, spatial alignment transformation, and back-end processing, to obtain the corresponding callback image frame.

[0120] In the embodiment of the present application, unlike the preview image frame, the callback image frame is not sent directly to the WeChat SDK, but needs to be further processed in the camera HAL.

[0121] Referring to Figure 5, in an optional embodiment, before feeding the callback image frame back to the camera service, the image processing module also performs distortion correction processing on it. Specifically, the image processing module calls the QR code detection module to extract the QR code image outline in the callback image frame, and cuts out the QR code image in the callback image frame based on the QR code image outline. The image processing module determines whether the QR code image meets the distortion correction conditions. If so, it calls the QR code distortion correction module to perform distortion correction processing on the QR code image, and regenerates the callback image frame based on the distortion-corrected QR code image as the processed callback image frame. After obtaining the processed callback image frame, the image processing module sends the processed callback image frame to the camera service.

[0122] Furthermore, the camera service returns the processed callback image frame to the recognition interface in the WeChat SDK through the callback function set by the WeChat SDK. Among them, the WeChat SDK can determine the timing of setting the callback function according to its own business logic (for example, after the focus processing), and call the callback function interface in the camera SDK interface at this time to set the callback function. After the WeChat SDK receives the callback image frame through the recognition interface, it sends the callback image frame to the recognition module, and the recognition module locates and recognizes the QR code in the callback image frame. After the recognition module of the WeChat SDK obtains the processed callback image frame through the recognition interface, it can locate and recognize the QR code of the callback image frame. Among them, the recognition module positioning the QR code can refer to determining the position information of the QR code in the image, and recognizing the QR code can refer to determining the content information contained in the QR code, such as link information, text information, etc.

[0123] When the angle between the plane of the QR code to be scanned and the plane of the mobile phone's image acquisition is too large (e.g., 45 to 75 degrees), the QR code in the callback image frame will be distorted. Because the image processing module performs distortion correction on the QR code image in the callback image frame before feeding it back to the camera service, and sends the processed callback frame image to the recognition module in the WeChat SDK through the camera service for recognition, the QR code image recognized by the recognition module in the WeChat SDK is free of distortion, making it easier for the WeChat SDK's recognition module to perform QR code positioning and recognition operations, thereby improving the WeChat SDK's recognition module's success rate in positioning and recognizing QR codes, and also speeding up the WeChat SDK's recognition module's efficiency in positioning and recognizing QR codes.

[0124] After the recognition module completes the positioning and recognition processing of the QR code in the callback image frame, it determines the QR code positioning result and sends the QR code positioning result to the UI module. The QR code positioning result is used to indicate the position information of the QR code in the callback image frame, for example, it can be the coordinate information of the center point of the QR code in the callback image frame. Furthermore, the UI module can determine the display position of the scan code positioning mark 1041 in the preview image based on the QR code positioning result, for example, using the coordinates indicated by the QR code positioning result as the coordinates of the center point of the scan code positioning mark 1041 in the preview image, and displaying the scan code positioning mark on the currently displayed preview image frame, at this time, you can refer to (4) in Figure 1.

[0125] It should be noted that the above explanation uses the example of a callback frame image containing a single QR code. If the callback image frame contains multiple QR codes, the image processing module can invoke the QR code detection module to extract the outlines of each QR code image in the callback image frame, extract a QR code image from each QR code image based on the outlines, and perform distortion correction on each QR code image, ensuring that each QR code in the callback image frame is free of distortion after processing.

[0126] After the recognition module in the WeChat SDK performs QR code positioning processing on the processed callback image frame, if only one QR code is located, the recognition module sends the positioning result corresponding to the QR code to the UI module. At this time, the UI module can determine the display position of the scan code positioning mark 1041 in the preview image based on the QR code positioning result, and display the scan code positioning mark 1041 on the currently displayed preview image frame. At this time, as shown in (4) in Figure 1, only one scan code positioning mark is displayed. In this case, the recognition module performs recognition processing on the QR code obtained by positioning to obtain the QR code information content, and the WeChat application interface immediately jumps to the scan code result interface corresponding to the QR code content information, such as the operation interface corresponding to the QR code content information (such as the payment interface, adding friends, etc.) or the information display interface (public account interface, etc.).

[0127] After the recognition module in the WeChat SDK performs QR code positioning processing on the processed callback image frame, if multiple QR codes are located, the recognition module sends the positioning results corresponding to each QR code to the UI module. At this time, the UI module can determine the display position of each scan code positioning mark 1041 in the preview image based on the positioning results of each QR code, and display each scan code positioning mark on the currently displayed preview image frame. In this case, in response to the user's selection operation of a scan code positioning mark, such as a click operation, the recognition module recognizes the QR code selected by the user (that is, the QR code corresponding to the scan code positioning mark selected by the user) to obtain the QR code information content, and the WeChat application interface immediately jumps to the scan code result interface corresponding to the QR code indicated by the scan code positioning mark. Among them, the recognition module can also recognize each located QR code separately before the user selects the scan code positioning mark, so that after the user selects a scan code positioning mark, the WeChat application interface can directly jump to display the scan code result interface corresponding to the QR code indicated by the scan code positioning mark. This embodiment does not limit this.

[0128] If the image processing module determines that the cropped QR code image does not meet the distortion correction conditions, the callback image frame will not be processed, and the callback image frame will be directly sent to the camera service, so that the camera service returns the callback image frame to the recognition interface in the WeChat SDK through the callback function of the WeChat SDK, and then the recognition module of the WeChat SDK can locate and recognize the QR code on the callback image frame.

[0129] Referring to Figure 5 , in another optional embodiment, the image processing module invokes the QR code detection module to extract the QR code image outline from the callback image frame and crops the QR code image from the callback image frame based on the QR code image outline. The image processing module first determines whether the QR code image in the callback image frame meets the zoom condition. If the QR code image in the callback image frame meets the zoom condition, the image processing module invokes the QR code zoom module to perform zoom processing on the callback image frame to enlarge the QR code image. Since the image size of the callback image frame remains unchanged before and after the zoom process, the image proportion of the QR code image in the callback image frame increases after the zoom process. The image processing module then uses the zoomed callback image frame as the processed callback image frame and sends it to the camera service. If the QR code image in the callback image frame does not meet the zoom condition, the image processing module then determines whether the cropped QR code image meets the distortion correction condition. If the cropped QR code image meets the distortion correction conditions, the image processing module calls the QR code distortion correction module to perform distortion correction processing on the QR code image, and regenerates the callback image frame based on the QR code image after distortion correction as the processed callback image frame, and sends the processed callback image frame to the camera service. If the cropped QR code image does not meet the distortion correction conditions, the image processing module does not process the callback image frame and directly sends the callback image frame to the camera service. Furthermore, the camera service can return the received callback image frame to the recognition interface in the WeChat SDK through the callback function of the WeChat SDK, and the recognition module of the WeChat SDK performs QR code positioning and recognition processing on the received callback image frame. Regarding the processing flow after the WeChat SDK recognition module receives the callback image frame, please refer to the previous text and will not be repeated here.

[0130] When the angle between the plane where the QR code to be scanned is located and the plane of the mobile phone image acquisition is too large (such as 45 to 75 degrees), the QR code in the callback image frame may be too small or distorted. Because the image processing module zooms or corrects the QR code image in the callback image frame before feeding it back to the camera service, and sends the processed callback frame image to the recognition module in the WeChat SDK through the camera service for recognition, the QR code recognized by the recognition module in the WeChat SDK is of the right size in the image and is not distorted, which facilitates the WeChat SDK's recognition module to perform QR code positioning and recognition operations, thereby improving the WeChat SDK's recognition module's success rate in positioning and recognizing QR codes, and also speeding up the WeChat SDK's recognition module's efficiency in positioning and recognizing QR codes.

[0131] For example, as shown in Figure 6, a callback image frame is used as an example to illustrate the processing performed by the image processing module in Figure 6 before sending it to the camera service. The processing flow shown in Figure 6 is explained using the structure shown in Figure 6 as an example. This processing flow can also be completed by the image processing module alone. For example, the operations performed by the QR code detection module, the QR code zoom module, and the QR code distortion correction module can all be completed by the image processing module.

[0132] As shown in FIG6 , taking callback image frame A as an example, after the image processing module generates callback image frame A based on the callback image data it receives, the image processing module processes callback image frame A, which may include the following steps:

[0133] S301: The image processing module obtains a callback image frame A.

[0134] Assuming that callback image frame A refers to the nth callback image frame, callback image frame A corresponds to the nth callback image frame request. The camera sensor captures callback image data based on the nth callback image frame request and sends this callback image data to the image processing module via the camera driver. The image processing module performs relevant processing on this callback image data, such as front-end image signal processing, spatial alignment transformation processing, and back-end image signal processing, to obtain callback image frame A. The image format of callback image frame A is YUV.

[0135] S302 : The image processing module converts the image format of the callback image frame A from YUV to RGB to obtain the callback image frame B.

[0136] S303: The image processing module calls the QR code detection module to extract the QR code image outline in the callback image frame B.

[0137] As shown in FIG. 7 a , the image processing module inputs the callback image frame B 401 into the two-dimensional code detection module, and the two-dimensional code detection module extracts a two-dimensional code image outline 402 from the callback image frame B 401 .

[0138] Exemplarily, the two-dimensional code detection module extracts the vertex coordinates of the two-dimensional code image outline 402 in the callback image frame B 401 .

[0139] In one example, the QR code detection module is a pre-trained AI (Artificial Intelligence) QR code detection module. The callback image frame B 401 is input into the QR code AI detection module, and the QR code AI detection module marks the QR code image outline 402 on the callback image frame B 401.

[0140] When training a QR code AI detection module, a standard AI detection model (e.g., a machine learning model) can be trained based on multiple sets of image samples to obtain a QR code AI detection module. Each set of image samples includes an image containing a QR code and its corresponding QR code image outline.

[0141] In another example, the QR code detection module includes an image mean filtering submodule, an image grayscale submodule, an image edge detection submodule, an image binarization submodule, an image dilation and corrosion submodule, and an image contour extraction submodule.

[0142] The Image Mean Filter submodule performs mean filtering (also known as linear filtering) on ​​images to achieve image denoising. This submodule uses a neighborhood averaging method, the basic principle of which is to replace each pixel value in the original image with its mean. For the current pixel (x, y) to be processed, a template is selected (composed of several pixels in its immediate neighborhood). The mean of all pixels in the template is calculated, and this mean is then assigned to the current pixel (x, y) as the pixel value at that point in the processed image.

[0143] The image grayscale submodule is used to convert the image from RGB image to grayscale image.

[0144] The image edge detection submodule is used to perform edge detection on grayscale images to identify pixels in the grayscale image with significant brightness changes. The image edge detection submodule can be implemented using a search-based method or a zero-crossing-based method. The search-based method detects boundaries by finding the maximum and minimum values ​​in the first-order derivative of the image, typically locating the boundary in the direction of the maximum gradient. The zero-crossing-based method finds boundaries by finding the zero crossing of the second-order derivative of the image, typically the zero crossing of the Laplacian or the zero crossing of the nonlinear differential representation.

[0145] The image binarization submodule is used to binarize a grayscale image, setting the grayscale values ​​of pixels in the grayscale image to 0 or 255 to convert the grayscale image into a binary image. Exemplarily, the image binarization submodule binarizes the grayscale image based on a threshold value, setting the grayscale values ​​of pixels with grayscale values ​​greater than the threshold value to 255, and setting the grayscale values ​​of pixels with grayscale values ​​less than or equal to the threshold value to 0.

[0146] The Image Dilation and Erosion submodule is used to dilate and / or erode binary images. Image erosion and dilation are two basic morphological operations, mainly used to find the maximum and minimum regions in binary images.

[0147] The image contour extraction submodule is used to extract the external contour features of the image from the binary image. The image contour extraction submodule can use common contour extraction algorithms, such as threshold segmentation and extraction of high-frequency information from Fourier transform.

[0148] In this example, the callback image frame B is processed in sequence by the image mean filtering submodule, the image grayscale submodule, the image edge detection submodule, the image binarization submodule, the image dilation and corrosion submodule, and the image contour extraction submodule to obtain the QR code contour in the callback image frame B.

[0149] S304, the image processing module determines whether the QR code image in the callback image frame B meets the zoom condition, if not, execute S305, if yes, execute S309.

[0150] Among them, exemplarily, the zoom condition includes that the image ratio of the QR code image in the callback image frame is less than a preset ratio threshold. Meeting the zoom condition means that the callback image frame needs to be zoomed to enlarge the image ratio of the QR code image in the callback image frame.

[0151] In an optional embodiment, the image processing module calculates the image ratio r0 of the QR code image in the callback image frame based on the outline of the QR code image, where r0 = S0 / S, S0 is the pixel area of ​​the QR code image, and S is the pixel area of ​​the callback image frame.

[0152] The image processing module also calculates a maximum allowable zoom ratio r1 for the QR code in the callback image frame based on the QR code image size information and the QR code image's position in the callback image frame. The maximum allowable zoom ratio r1 indicates the maximum allowable zoom ratio when zooming the callback image frame to enlarge the QR code image. If the zoom ratio is greater than r1 during zooming, the QR code image will extend beyond the boundaries of the callback image frame, meaning that the QR code image in the zoomed callback image frame will no longer be complete.

[0153] In the embodiments of the present application, zooming the callback image frame to magnify the QR code image means that the size of the callback image frame remains unchanged before and after zooming, but the field of view changes (i.e., the field of view of the image decreases). Since the size of the callback image frame remains unchanged before and after zooming, it can be understood that the boundary position of the callback image frame does not change.

[0154] As shown in Figure 7b, the width w and height h of the QR code image are determined, and the distance w1 from the center of the QR code image to the left edge of the callback image frame, the distance h1 from the center of the QR code image to the top edge of the callback image frame, the distance w2 from the center of the QR code image to the right edge of the callback image frame, and the distance h2 from the center of the QR code image to the bottom edge of the callback image frame are calculated. The maximum allowable zoom ratio r1 = min{w1 / 0.5w, h1 / 0.5h, w2 / 0.5w, h2 / 0.5h}.

[0155] Optionally, the zoom condition also includes a limit on the maximum allowable zoom ratio r1, for example, the maximum allowable zoom ratio r1 corresponding to the QR code in the callback image frame is greater than a threshold value B. In this embodiment, the zoom condition may be: the image ratio r0 of the QR code image in the callback image frame is less than a threshold value A, and the maximum allowable zoom ratio r1 corresponding to the QR code is greater than a threshold value B.

[0156] If the image ratio r0 occupied by the QR code image in the callback image frame B is not less than the threshold A, or the maximum allowable zoom ratio r1 corresponding to the QR code in the callback image frame is not greater than the threshold B, then the QR code image in the callback image frame B does not meet the zoom condition.

[0157] If the image ratio r0 occupied by the QR code image in the callback image frame B is less than the threshold A, and the maximum allowable zoom ratio r1 corresponding to the QR code in the callback image frame is greater than the threshold B, then the QR code image in the callback image frame B meets the zoom condition.

[0158] S305, the image processing module determines whether the two-dimensional code image meets the distortion correction condition, if so, executes S306, if not, executes S311.

[0159] When the two-dimensional code image in the callback image frame B does not meet the zoom condition, the image processing module continues to determine whether the two-dimensional code image meets the distortion correction condition.

[0160] In an optional embodiment, the image processing module determines whether the QR code image meets the distortion correction condition based on the maximum rotation angle M of the QR code image. The distortion correction condition may be that the maximum rotation angle M is greater than a threshold C. An exemplary threshold C is 10°.

[0161] The maximum rotation angle M of the QR code image is the maximum of the horizontal and vertical rotation angles of the QR code image. As shown in Figure 7c, angle a1 is the angle between the left edge of the QR code image and the vertical direction, angle a2 is the angle between the upper edge of the QR code image and the horizontal direction, angle a3 is the angle between the right edge of the QR code image and the vertical direction, and angle a4 is the angle between the lower edge of the QR code image and the horizontal direction. Angles a1 and a3 are the vertical rotation angles, while angles a2 and a4 are the horizontal rotation angles. Maximum rotation angle M = max{angle a1, angle a2, angle a3, angle a4}.

[0162] S306: The image processing module calls the QR code distortion correction module to perform distortion correction processing on the QR code image.

[0163] When the QR code image meets the distortion correction conditions, the image processing module calls the QR code distortion correction module to perform distortion correction on the QR code image. The QR code distortion correction module performs perspective transformation on the QR code image to obtain a distortion-corrected QR code image.

[0164] Perspective transformation refers to a transformation that uses the condition that the perspective center, image point, and target point are collinear, and according to the perspective rotation law, rotates the receiving surface (perspective plane) around the trace line (perspective axis) by a certain angle, destroying the original projection light bundle while still maintaining the projected geometric figures on the receiving surface unchanged. In short, it projects a plane onto a specified plane using a projection matrix. The general transformation formula is as follows:

[0165] Among them, the perspective transformation matrix

[0166] Represents image linear transformation, T2=[a 13 a 23 ] T Used to generate image perspective transformation, T3 = [a 31 a 32 ] indicates image translation.

[0167] Among them, u and v are the original image coordinates, the parameter w is equal to 1, and x and y are the image coordinates obtained after perspective transformation.

[0168] The above splits the perspective transformation matrix into 4 parts. The T1 matrix is ​​mainly used for image scaling and rotation operations, the T3 matrix is ​​used for image translation operations, and the T2 matrix is ​​used to generate perspective transformation. 33 =1. Since the perspective transformation matrix has 8 parameters, 4 coordinate pairs are required to solve it. The expressions of x and y after perspective transformation are:

[0169] Therefore, given the four pairs of pixel coordinates corresponding to the perspective transformation, the perspective transformation matrix Transform can be obtained, and then the original image can be perspective transformed according to the perspective transformation matrix to obtain the image after perspective transformation.

[0170] In an embodiment of the present application, the image processing module extracts the coordinates of the four vertices of the QR code image and sorts the four vertices in a clockwise order, such as the upper left vertex P1 (u1, v1), the upper right vertex P2 (u2, v2), the lower right vertex P3 (u3, v3) and the lower left vertex P4 (u4, v4).

[0171] The image processing module determines the side length L of the distortion-corrected QR code image based on the pixel coordinates of vertices P1, P2, P3, and P4. In this embodiment, the image processing module uses the length of the longest side of the QR code image as the side length L of the distortion-corrected QR code image. Wherein, the side length L of the distortion-corrected QR code image = max{P1P2, P2P3, P3P4, P4P1}

[0172] Assuming that the image processing module sets the coordinates of the upper-left vertex P1' of the distortion-corrected QR code image to (u0, v0), the image processing module can calculate the upper-right vertex P2'(u0+L, v0), the lower-right vertex P3'(u0+L, v0+L), and the lower-left vertex P4'(u0, v0+L) based on the side length L of the distortion-corrected QR code image. The upper-left vertex P1'(u0, v0) can be set in the upper-left corner of the image. For example, u0 is greater than 20, and v0 is greater than 20.

[0173] In this way, the image processing module obtains four pairs of pixel coordinates: pixel coordinates of P1 and P1', pixel coordinates of P2 and P2', pixel coordinates of P3 and P3', and pixel coordinates of P4 and P4'. Furthermore, the image processing module calculates the perspective transformation matrix Transform based on the pixel coordinates of vertices P1, P2, P3, and P4 of the source QR code image (i.e., the QR code image to be corrected for distortion) and the pixel coordinates of vertices P1', P2', P3', and P4' of the target QR code image (i.e., the QR code image after distortion correction).

[0174] After calculating the perspective transformation matrix Transform, the image processing module can perform perspective transformation on the source QR code image according to the perspective transformation matrix Transform to obtain the target QR code image, that is, the QR code image after distortion correction. Please refer to the perspective transformation processing example shown in Figure 7d.

[0175] S307 : The image processing module regenerates the callback image frame C according to the distortion-corrected QR code image, and converts the image format of the callback image frame C from RGB to YUV to obtain the callback image frame D.

[0176] The image processing module creates a new blank image frame, and adds the two-dimensional code image after the distortion correction processing to the blank image frame to generate a callback image frame C.

[0177] The image size of callback image frame C is the same as that of callback image frame B. That is, the image size of the blank image frame is the same as that of callback image frame B. The position of the QR code image after distortion correction in callback image frame C is consistent with the position of the QR code image before distortion correction in callback image frame B (or position alignment).

[0178] Optionally, the coordinates of the center point of the QR code image after distortion correction in the callback image frame C are the same as the coordinates of the center point of the QR code image before distortion correction in the callback image frame B. The image processing module determines the coordinates of the center point of the QR code image before distortion correction in the callback image frame B, and based on the coordinates, adds the QR code image after distortion correction to the blank image frame to generate the callback image frame C.

[0179] FIG7e exemplarily shows an example of a callback image frame C and a callback image frame B. FIG7e (1) shows an example of a callback image frame B, in which the two-dimensional code image satisfies the distortion correction condition and needs to be subjected to distortion correction processing. FIG7e (2) shows a callback image frame C corresponding to the callback image frame B shown in FIG7e (1). As shown in FIG7e (2), the image size of the callback image frame C is the same as the image size of the callback image frame B. The callback image frame C can be obtained by adding the two-dimensional code image after the distortion correction processing to a blank image frame with the same image size as the callback image frame B. Among them, the coordinates of the center point of the two-dimensional code image after the distortion correction processing in the callback image frame C are the same as the coordinates of the center point of the two-dimensional code image before the distortion correction processing in the callback image frame B.

[0180] If the image processing module randomly adds the QR code image after the distortion correction processing to the blank image frame, for example, the image processing module adds the QR code image after the distortion correction processing to the upper left corner of the blank image frame to generate the callback image frame C, then in combination with the process shown in Figure 5, it can be seen that the recognition module in the WeChat SDK will perform QR code positioning and recognition based on the callback image frame D (obtained by the callback image frame C through image format conversion, see S308 for details). Among them, when the recognition module performs QR code positioning processing based on the callback image frame D, the QR code positioning result (that is, the display position of the scan code positioning mark 1041 in the image) is related to the position of the QR code image after the distortion correction processing in the blank image frame. If the image processing module adds the QR code image after the distortion correction processing to the upper left corner of the blank image frame, the display position of the scan code positioning mark 1041 in the image is also the upper left corner of the image. Since the preview image frame and the callback image frame A displayed correspond to the same shooting scene and the image acquisition time is relatively close, the image information in the callback image frame A (or callback image frame B) is almost identical to the image information in the preview image frame, with very little difference. Therefore, the position of the QR code in the callback image frame A (or callback image frame B) is also close to the position of the QR code in the preview image frame, such as the position of the center of the QR code is close. It can also be said that the QR code area in the callback image frame A (or callback image frame B) and the QR code area in the preview image frame overlap for the most part, or even completely overlap. If the image processing module randomly adds the distortion-corrected QR code image to the blank image frame to generate the callback image frame C, there will be a problem that the QR code position in the callback image frame C is inconsistent with the QR code position in the callback image frame B, that is, it is inconsistent with the QR code position in the preview image frame, and then there will be a problem that the scan code positioning mark 1041 determined based on the QR code position in the callback image frame C is not aligned with the QR code image in the preview image frame. That is to say, the code scanning and positioning mark 1041 displayed on the code scanning and positioning interface of the WeChat application will appear in the non-QR code area, as shown in Figure 7f.

[0181] In an embodiment of the present application, the position of the QR code image after distortion correction processing is consistent with the position of the QR code image before distortion correction processing, such as the center points of the QR code image are aligned, and the position of the QR code image before distortion correction processing is consistent with the QR code position in the corresponding preview image frame, so that when the recognition module of the WeChat SDK calls back the image frame D to perform QR code positioning and recognition, it can ensure that the display position of the scan code positioning mark 1041 is consistent with the QR code position in the preview image frame displayed by the WeChat application, so that the scan code positioning mark 1041 is displayed in the QR code area in the preview image, avoiding the problem of the scan code positioning mark 1041 being displayed in the incorrect position in the preview image frame.

[0182] S308 , the image processing module converts the image format of the callback image frame C from RGB to YUV to obtain the callback image frame D, and sends the callback image frame D to the WeChat SDK via the camera service.

[0183] In this case, callback image frame D is sent to the WeChat SDK instead of callback image frame A. Since the QR code image in callback image frame D has been distortion corrected, it can improve the WeChat SDK's recognition module's positioning and recognition success rate of the QR code, and can also speed up the WeChat SDK's recognition module's positioning and recognition efficiency of the QR code, thereby improving the user experience.

[0184] S309 , the image processing module calls the QR code zoom module to perform zoom processing on the callback image frame B to obtain the callback image frame E.

[0185] When the QR code image in the callback image frame B meets the zoom condition, the image processing module calls the QR code zoom module to perform zoom processing on the callback image frame B, enlarge the image ratio of the QR code image in the callback image frame B, and obtain the callback image frame E.

[0186] Exemplarily, the QR code zoom module can determine a suitable zoom ratio based on the maximum allowable zoom ratio r1 corresponding to the QR code in the callback image frame, which is less than the maximum allowable zoom ratio r1, and zoom the callback image frame B according to the zoom ratio to enlarge the image ratio of the QR code image in the callback image frame B, so that the image ratio of the QR code image in the callback image frame B is more in line with the scanning requirements, so as to facilitate the recognition module of the WeChat SDK to locate and identify the QR code.

[0187] For example, the QR code zoom module can zoom the callback image frame B according to the maximum allowable zoom ratio r1 corresponding to the QR code in the callback image frame, thereby increasing the proportion of the QR code image in the callback image frame B. In this way, while ensuring the integrity of the QR code image, the QR code image in the callback image frame is magnified as much as possible, so that a certain boundary of the QR code image is as close as possible to a certain boundary of the callback image frame, or even overlaps with this boundary, which is more conducive to the WeChat SDK's recognition module to locate and recognize the QR code.

[0188] S310, the image processing module converts the image format of the callback image frame E from RGB to YUV to obtain the callback image frame F, and sends the callback image frame F to the WeChat SDK via the camera service.

[0189] In this case, callback image frame F is sent to the WeChat SDK instead of callback image frame A. Since the QR code image in callback image frame F has been enlarged, it can speed up the positioning and recognition efficiency of the WeChat SDK's recognition module for the QR code, thereby improving the user experience.

[0190] In an optional implementation, the image processing module may also call the QR code zoom module to perform zoom processing on the preview image frame, and display the zoomed preview image frame.

[0191] After generating a preview image frame in RGB format, the image processing module determines whether the QR code image in the preview image frame meets a zoom condition. For example, the zoom condition is: the image ratio r0 of the QR code image in the callback image frame is less than a threshold value A; another example is: the image ratio r0 of the QR code image in the callback image frame is less than a threshold value A, and the maximum allowable zoom ratio r1 corresponding to the QR code is greater than a threshold value B.

[0192] If the QR code image in the preview image frame meets the zoom condition, the image processing module calls the QR code zoom module to perform zoom processing on the preview image frame, and sends the preview image frame after zoom processing for display.

[0193] When the callback image frame is zoomed to enlarge the QR code image, if the preview image frame is not zoomed to enlarge the QR code image, there may also be a problem of improper display position of the code scanning positioning mark 1041, causing the code scanning positioning mark 1041 to be displayed on the non-QR code area of ​​the preview image frame.

[0194] In this way, while the callback image frame is zoomed to enlarge the QR code image, the preview image frame is also zoomed to enlarge the QR code image. When the recognition module of the WeChat SDK locates and identifies the QR code based on the callback image frame F after zoom processing, it can ensure that the display position of the scan code positioning mark is consistent with the QR code position in the preview image frame displayed by the WeChat application, avoiding the problem of incorrect display position of the scan code positioning mark in the preview image frame.

[0195] S311, the image processing module sends the callback image frame A to the WeChat SDK via the camera service.

[0196] If the QR code image in the callback image frame B does not meet the zoom condition and the QR code image does not meet the distortion correction condition, the image processing module directly sends the callback image frame A to the WeChat SDK via the camera service, so that the recognition module of the WeChat SDK locates and recognizes the QR code based on the callback image frame A.

[0197] In this case, if the image processing module caches callback image frame A, it can directly send the cached callback image frame A to the WeChat SDK via the camera service. If the image processing module does not cache callback image frame A, it converts the image format of callback image frame B from RGB to YUV to obtain callback image frame A again, and then sends callback image frame A to the WeChat SDK via the camera service.

[0198] In this embodiment, continuing to refer to Figure 5, the callback image frame received by the WeChat SDK is either a callback image frame that has been zoomed, or a callback image frame after the QR code image has been subjected to distortion correction, or a callback image frame that does not require zoom and distortion correction. Therefore, the callback image frame received by the WeChat SDK is more convenient for the recognition module to locate and identify the QR code, thereby improving the success rate of the WeChat SDK's recognition module in locating and identifying the QR code, and also speeding up the WeChat SDK's recognition module's efficiency in locating and identifying the QR code.

[0199] In this way, in the scanning method provided in the embodiment of the present application, the electronic device performs zoom processing or distortion correction processing on the callback image frame of the scanning application before returning the callback image frame of the scanning application to the scanning application, thereby improving the scanning success rate of the scanning application on the callback image frame, solving the problem of long-term unsuccessful scanning or even scanning failure due to poor scanning angle of the user, and improving the user experience.

[0200] On the basis of the aforementioned embodiment, FIG8 exemplifies another optional embodiment. Continuing with the example of the third-party application being the WeChat application and the code scanning function being the "Scan" function, as shown in FIG8 , the user opens the "Scan" function of the WeChat application, and the scene recognition module determines that the flag FLAG=1 corresponding to the current scene. The camera service generates a preview image frame request based on the preview indication sent by the camera application and sends it to the camera HAL, and generates a callback image frame request based on the indication information "FLAG=1" sent by the camera application and sends it to the camera HAL. The Sensor node in the camera HAL controls the camera sensor to expose the image through the camera driver, and obtains preview image data corresponding to the preview image frame request and callback image data corresponding to the callback image frame request. Among them, the preview image data can obtain a preview image frame through processing by the image processing module, and the preview image frame is sent to the WeChat application for display.

[0201] In this embodiment, after the image processing module processes the received callback image data to obtain callback image frame n, the image processing module also performs distortion correction processing or zoom processing on it (such as processing according to the processing flow shown in Figure 6), and sends the processed callback image frame n to the WeChat SDK through the camera service for QR code positioning and recognition. Regarding the next frame of callback image frame n, that is, callback image frame n+1, after the image processing module processes the received callback image data to obtain callback image frame n+1, the callback image frame n+1 is directly sent to the WeChat SDK through the camera service for QR code positioning and recognition. For the next frame of callback image frame n+1, that is, callback image frame n+2, after the image processing module processes the received callback image data to obtain callback image frame n+2, the image processing module continues to perform distortion correction processing or zoom processing on it (such as processing according to the processing flow shown in Figure 6), and sends the processed callback image frame n+2 to the WeChat SDK through the camera service for QR code positioning and recognition. The same can be said for other callback image frames.

[0202] Among them, regarding the callback image frame 1, the image processing module can directly send it to the WeChat SDK through the camera service for QR code positioning and recognition, or perform distortion correction or zoom processing on it (such as processing according to the processing flow shown in Figure 6), and send the processed callback image frame 1 to the WeChat SDK through the camera service for QR code positioning and recognition. This embodiment does not limit this.

[0203] Among the callback image frames received in sequence by the recognition interface of the WeChat SDK, callback image frames processed by the processing flow shown in Figure 6 and callback image frames not processed by the processing flow shown in Figure 6 appear alternately. The recognition module of the WeChat SDK recognizes each callback image frame in sequence according to the order in which the callback image frames are received until the positioning and recognition operations of the QR code are completed according to a certain callback image frame.

[0204] It should be noted that the WeChat SDK's recognition module may complete the positioning and recognition of the QR code based on callback image frame N1 processed according to the processing flow shown in Figure 6. In this case, the QR code positioning result output by the recognition module is based on callback image frame N1. The WeChat SDK's recognition module may also complete the positioning and recognition of the QR code based on callback image frame N2 that has not been processed according to the processing flow shown in Figure 6. In this case, the QR code positioning result output by the recognition module is based on callback image frame N2. After the WeChat SDK's recognition module completes the positioning and recognition of the QR code based on a callback image frame, it will no longer perform the positioning and recognition operation on the QR code based on the next callback image frame.

[0205] For any parts of the code scanning process shown in FIG8 that are not fully explained in detail, please refer to the previous explanation of the code scanning process shown in FIG5 , which will not be repeated here.

[0206] In this way, for two adjacent callback image frames, the image processing module uses different processing methods. One of the callback image frames is processed by the process shown in Figure 6 and then sent to the WeChat SDK for QR code positioning and recognition, while the other callback image frame is sent directly to the WeChat SDK for QR code positioning and recognition (that is, processed using the native process). This can avoid the problem that the WeChat SDK's recognition module cannot recognize the callback image frame processed by the process shown in Figure 6, resulting in long-term unsuccessful QR code recognition. Once the WeChat SDK's recognition module can recognize the callback image frame that has not been processed by the process shown in Figure 6, the QR code can still be successfully recognized, thereby ensuring the success rate of the code scanning method.

[0207] Optionally, in this embodiment, after the image processing module processes the received callback image data to obtain the callback image frame n, the image processing module also performs distortion correction processing or zoom processing (such as processing according to the processing flow shown in Figure 6), and sends the processed callback image frame n to the WeChat SDK through the camera service for QR code positioning and recognition. Regarding the callback image frame after the callback image frame n, for example, the callback image frame n+m1 (m1 is an integer greater than 1), after the image processing module processes the received callback image data to obtain the callback image frame n+m1, the callback image frame n+m1 is directly sent to the WeChat SDK through the camera service for QR code positioning and recognition. Among them, the callback image frame between the callback image frame n and the callback image frame n+m1 is the same as the processing method of the callback image frame n, which will not be repeated here.

[0208] For the callback image frame after callback image frame n+m1, for example, callback image frame n+m1+m2 (m2 is an integer greater than 1, and m1 and m2 may be equal or unequal), after the image processing module processes the received callback image data to obtain callback image frame n+m1+m2, the image processing module continues to perform distortion correction or zoom processing on it (such as processing according to the processing flow shown in Figure 6), and sends the processed callback image frame n+m1+m2 to the WeChat SDK through the camera service for QR code positioning and recognition. Among them, the callback image frames between callback image frame n+m1 and callback image frame n+m1+m2 are processed in the same way as callback image frame n+m1, and will not be repeated here.

[0209] The same logic can be applied to other callback image frames. In this way, among the callback image frames received in sequence by the recognition interface of WeChat SDK, callback image frames processed by the processing flow shown in FIG6 and callback image frames that have not been processed by the processing flow shown in FIG6 appear alternately. The recognition module of WeChat SDK recognizes each callback image frame in sequence according to the order in which the callback image frames are received, until the positioning and recognition operation of the QR code is completed according to a certain callback image frame. This can avoid the problem that the recognition module of WeChat SDK cannot recognize the callback image frame processed by the process shown in FIG6, resulting in the long-term unsuccessful recognition of the QR code.

[0210] This embodiment also provides a computer storage medium, which stores computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the code scanning method in the above-mentioned embodiment.

[0211] This embodiment also provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute the above-mentioned related steps to implement the code scanning method in the above-mentioned embodiment.

[0212] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory to enable the chip to execute the code scanning method in the above-mentioned method embodiments.

[0213] Among them, the electronic devices (such as mobile phones, etc.), computer storage media, computer program products or chips provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.

[0214] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0215] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0216] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A code scanning method, characterized in that: include: In response to an operation of starting a code scanning function of a target application, obtaining a first callback image frame and a first preview image frame; Extracting a first QR code image from the first callback image frame; Performing distortion correction processing on the first two-dimensional code image to obtain a second two-dimensional code image; Creating a blank image frame, determining the position of the first two-dimensional code image in the first callback image frame, and adding the second two-dimensional code image to the blank image frame to obtain a second callback image frame, so that the position of the second two-dimensional code image in the second callback image frame is consistent with the position of the first two-dimensional code image in the first callback image frame; wherein the blank image frame and the first callback image frame have the same image size; Sending the second callback image frame to the target application for code scanning and recognition; displaying the first preview image; When the target application recognizes the QR code based on the second callback image frame, a QR code positioning mark is displayed on the first preview image; wherein the position of the QR code positioning mark is determined based on the position of the second QR code image in the second callback image frame.

2. The method according to claim 1, characterized in that Also includes: Acquire a third callback image frame, where the third callback image frame is a callback image frame subsequent to the first callback image frame; Sending the third callback image frame to the target application for code scanning and recognition; Acquire a fourth callback image frame, where the fourth callback image frame is a callback image frame subsequent to the third callback image frame; Extracting a third two-dimensional code image from the fourth callback image frame, and performing distortion correction processing on the third two-dimensional code image to obtain a fourth two-dimensional code image; Creating the blank image frame, determining the position of the third two-dimensional code image in the fourth callback image frame, and adding the fourth two-dimensional code image to the blank image frame to obtain a fifth callback image frame, so that the position of the fourth two-dimensional code image in the fifth callback image frame is consistent with the position of the third two-dimensional code image in the fourth callback image frame; The fifth callback image frame is sent to the target application for code scanning and recognition.

3. The method according to claim 1, characterized in that The position of the second two-dimensional code image in the second callback image frame is consistent with the position of the first two-dimensional code image in the first callback image frame, including: The coordinates of the center point of the second two-dimensional code image in the second callback image frame are consistent with the coordinates of the center point of the first two-dimensional code image in the first callback image frame.

4. The method according to claim 1, characterized in that: Performing distortion correction processing on the first two-dimensional code image in the first callback image frame includes: When the first two-dimensional code image in the first callback image frame does not meet the zoom condition, the first callback The first two-dimensional code image in the image frame is subjected to distortion correction processing.

5. The method according to claim 4, characterized in that Also includes: When the first two-dimensional code image in the first callback image frame meets the zoom condition, zoom processing is performed on the first callback image frame to enlarge the two-dimensional code image to obtain a sixth callback image frame; The sixth callback image frame is sent to the target application for code scanning and recognition.

6. The method according to claim 5, characterized in that Also includes: displaying a second preview image; When the target application recognizes the QR code based on the sixth callback image frame, the QR code positioning mark is displayed on the second preview image; wherein the position of the QR code positioning mark is consistent with the position of the QR code image in the sixth callback image frame.

7. The method according to claim 1, characterized in that Performing distortion correction processing on the first two-dimensional code image includes: When the maximum rotation angle of the first two-dimensional code image is greater than a first threshold, performing distortion correction processing on the first two-dimensional code image in the first callback image frame according to perspective transformation; Among them, the maximum rotation angle is the maximum value of the first angle, the second angle, the third angle, and the fourth angle. The first angle is the angle between the left boundary of the first two-dimensional code image and the vertical direction, the second angle is the angle between the upper boundary of the first two-dimensional code image and the horizontal direction, the third angle is the angle between the right boundary of the first two-dimensional code image and the vertical direction, and the fourth angle is the angle between the lower boundary of the first two-dimensional code image and the horizontal direction.

8. The method according to claim 4 or 5, characterized in that: The zoom conditions include: The image ratio of the two-dimensional code image in the callback image frame is less than the second threshold, and the target zoom ratio corresponding to the two-dimensional code is greater than the third threshold; The target zoom ratio is used to indicate the maximum zoom ratio allowed when zooming the callback image frame to enlarge the two-dimensional code image.

9. The method according to claim 8, characterized in that Performing zoom processing on the first callback image frame includes: The first callback image frame is zoomed according to the target zoom ratio.

10. The method according to claim 4, characterized in that Performing distortion correction processing on the first two-dimensional code image in the first callback image frame includes: Determine the coordinates of four vertices of the first two-dimensional code image; Determine the side length of the second two-dimensional code image according to the four vertex coordinates; Determine the coordinates of a vertex of the second two-dimensional code image, and calculate the coordinates of other three vertices of the second two-dimensional code image based on the side length; Calculating a perspective transformation matrix according to the coordinates of four vertices of the first two-dimensional code image and the coordinates of four vertices of the second two-dimensional code image; The first two-dimensional code image is processed by perspective transformation according to the perspective transformation matrix to obtain the second two-dimensional code image.

11. The method according to claim 10, characterized in that Determining the side length of the first two-dimensional code image according to the four vertex coordinates includes: Calculate four side lengths of the first two-dimensional code image according to the four vertex coordinates; The maximum side length among the four side lengths is used as the side length of the second two-dimensional code image.

12. An electronic device, characterized in that: include: one or more processors; Memory; And one or more computer programs, wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by the one or more processors, the electronic device executes the code scanning method as described in any one of claims 1-11.

13. A computer-readable storage medium comprising a computer program, characterized in that: When the computer program runs on an electronic device, the electronic device executes the code scanning method as described in any one of claims 1 to 11.

Citation Information

Patent Citations

  • Nested two-dimensional code attack double detection method and system

    CN109145675A

  • Callback flow processing method and equipment

    CN112492193A

  • Code scanning method and device

    CN113919382A

  • Code scanning method, electronic equipment and storage medium

    CN116341586A

  • Method and system for video recording

    US20180046353A1

Cited By

  • Adaptive angle adjusting method and system for code scanning camera and electronic equipment

    CN119788969A