Method and apparatus for recognizing two-dimensional code
By sensing the scanning operation of the application through the terminal device system, adjusting the focus distance, and utilizing multi-frame image recognition technology, the problem of low QR code recognition rate at long distances was solved, the recognition success rate and accuracy were improved, and the user experience was enhanced.
Patent Information
- Application Number
- CN202210144951.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-17
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2042-02-17
AI Technical Summary
In scenarios involving scanning QR codes at long distances, the application may fail to recognize the QR code, resulting in a low recognition rate and a reduced user experience.
The terminal device senses the scanning operation of the application through the system, adjusts the focus distance, obtains a clear preview image of the QR code, and uses multiple consecutive frames of images for content recognition.
It improves the success rate and accuracy of QR code recognition at long distances, enhancing the user's scanning experience.
Smart Images

Figure CN116663587B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of image processing, and more particularly, to a method and device for recognizing a two-dimensional code. BACKGROUND
[0002] Currently, a user can use a scanning function of an application (APP) to scan a to-be-recognized object. For example, a user can use a WeChat scanning function to scan a two-dimensional code. In general, the user can use the two-dimensional code to make a payment or transfer money, use the two-dimensional code to settle fees at an exit of a parking lot, use the two-dimensional code to register and query information when entering or leaving a public place, and the like.
[0003] In the above scanning code scenario, if the user scans the two-dimensional code at a long distance, the application program often fails to successfully recognize the two-dimensional code, and the user needs to be close to the two-dimensional code for recognition. Therefore, in a long-distance scanning code scenario, the success rate of the application program in recognizing the two-dimensional code can be reduced, thereby reducing the user experience. SUMMARY
[0004] The present application provides a method and device for recognizing a two-dimensional code, which is beneficial to improving the success rate of the application program in recognizing the two-dimensional code in a long-distance scanning code scenario.
[0005] In a first aspect, a method for recognizing a two-dimensional code is provided, and is applied to a terminal device with a camera. The method includes: obtaining a first preview image of the two-dimensional code based on a first focusing distance, the first focusing distance being greater than or equal to a preset threshold. If an identifier of the two-dimensional code is not detected from the first preview image, or if a size of the identifier of the two-dimensional code in the first preview image does not meet a preset size, adjusting the focusing distance until a second preview image of the two-dimensional code is obtained, the second preview image including content of the two-dimensional code, the identifier of the two-dimensional code being at a preset position of the second preview image, and the size of the identifier of the two-dimensional code meeting the preset size. Performing content recognition on the two-dimensional code based on the second preview image.
[0006] In the present application, the terminal device can perceive an operation of scanning the two-dimensional code by the system in a long-distance scanning code scenario. When the identifier of the two-dimensional code cannot be detected from the first preview image due to the long distance, or the size of the detected identifier of the two-dimensional code does not meet the preset size, the terminal device can adjust the focusing distance by the system intervention, perform a zoom-in operation, and obtain a clearer second preview image. The content of the two-dimensional code can be recognized through the second preview image, thereby improving the success rate of the application program in scanning the two-dimensional code.
[0007] In combination with the first aspect, in some implementations of the first aspect, the second preview image is a plurality of continuous images.
[0008] In the present application, the terminal device can perform content recognition of the two-dimensional code based on continuous multiple frames of second preview images, which is beneficial to improve the accuracy of content recognition.
[0009] With reference to the first aspect, in some implementations of the first aspect, before the first preview image of the two-dimensional code to be recognized is obtained based on the first focusing distance, the method further includes: obtaining a preview request, the preview request being used to start the camera to obtain a preview image. The camera is started to focus based on the preview request, and the first focusing distance is determined.
[0010] With reference to the first aspect, in some implementations of the first aspect, before the camera is started to focus based on the preview request, and the first focusing distance is determined, the method further includes: displaying a scanning interface, and determining a preview view frame in the scanning interface, the preview view frame being used to display the two-dimensional code. The camera is started to focus based on the preview request, and the first focusing distance is determined, including: the camera is started to focus in the preview view frame based on the preview request, and the first focusing distance is determined.
[0011] In the present application, the terminal device can determine a suitable preview view frame according to the size of the screen, the capability of the camera and other factors, which is beneficial to the display of the preview image.
[0012] With reference to the first aspect, in some implementations of the first aspect, after the scanning interface is displayed, the method further includes: obtaining an activity name of the scanning interface. It is determined whether the scanning interface is a two-dimensional code scanning interface according to the activity name of the scanning interface. After the first focusing distance is determined, the method further includes: in the case that the scanning interface is a two-dimensional code scanning interface, it is determined that the first focusing distance is greater than or equal to the preset threshold.
[0013] In the present application, the terminal device can determine that the current scanning interface is a two-dimensional code scanning interface according to the activity name of the scanning interface, so that the system of the terminal device can perceive the current scanning operation, and thus the system intervenes in the detection of the size of the first focusing distance and the preset threshold, which is beneficial to the system of the terminal device to determine the current long-distance scanning scenario.
[0014] With reference to the first aspect, in some implementations of the first aspect, adjusting the focusing distance until the second preview image is obtained, including: adjusting the first focusing distance by a preset step to obtain a second focusing distance. Based on the second focusing distance obtained each time, a candidate preview image of the two-dimensional code is obtained until the identification of the two-dimensional code is detected from the obtained candidate preview image, and the content of the two-dimensional code is included in the candidate preview image, and the candidate preview image is determined as the second preview image. The identification of the two-dimensional code is in a preset position of the candidate preview image, and the size of the identification of the two-dimensional code meets a preset size.
[0015] In the present application, the terminal device can adjust the focusing distance step by step according to a preset step length, which is beneficial to the smooth convergence of the focusing distance and avoids the range of the complete two-dimensional code from being unable to be obtained due to the preview image being enlarged too much.
[0016] In a second aspect, a two-dimensional code recognition apparatus is provided, comprising an acquisition module and a processing module. The acquisition module is configured to acquire a first preview image of a two-dimensional code based on a first focusing distance, the first focusing distance being greater than or equal to a preset threshold. The processing module is configured to adjust the focusing distance until a second preview image of the two-dimensional code is obtained if an identifier of the two-dimensional code is not detected from the first preview image, or if a size of the identifier of the two-dimensional code in the first preview image does not conform to a preset size, the second preview image comprising content of the two-dimensional code, the identifier of the two-dimensional code being located at a preset position of the second preview image, and the size of the identifier of the two-dimensional code conforming to the preset size. The processing module is further configured to perform content recognition on the two-dimensional code based on the second preview image.
[0017] With reference to the second aspect, in some implementations of the second aspect, the second preview image is a plurality of continuous images.
[0018] With reference to the second aspect, in some implementations of the second aspect, the acquisition module is configured to acquire a preview request, the preview request being configured to start the camera to acquire the preview image. The processing module is configured to start the camera to focus based on the preview request, and determine the first focusing distance.
[0019] With reference to the second aspect, in some implementations of the second aspect, the processing module is configured to display a scanning interface, and determine a preview view frame in the scanning interface, the preview view frame being configured to display the two-dimensional code; start the camera to focus in the preview view frame based on the preview request, and determine the first focusing distance.
[0020] With reference to the second aspect, in some implementations of the second aspect, the acquisition module is configured to acquire an activity name of the scanning interface. The processing module is configured to determine whether the scanning interface is a two-dimensional code scanning interface according to the activity name of the scanning interface; and determine that the first focusing distance is greater than or equal to the preset threshold in a case where the scanning interface is the two-dimensional code scanning interface.
[0021] In some implementations of the second aspect, the processing module is configured to adjust the first focus distance by a preset step to obtain a second focus distance. The acquisition module is configured to acquire a candidate preview image of the two-dimensional code based on the second focus distance, and acquire the candidate preview image of the two-dimensional code based on the second focus distance obtained by each adjustment until an identifier of the two-dimensional code is detected from the acquired candidate preview image and the candidate preview image includes content of the two-dimensional code, and determine the candidate preview image as the second preview image. The identifier of the two-dimensional code is located at a preset position of the candidate preview image, and the size of the identifier of the two-dimensional code meets a preset size.
[0022] In a third aspect, another apparatus for identifying a two-dimensional code is provided. The apparatus includes a processor configured to implement a method recited in any of the possible implementation manners of the first aspect. Optionally, the apparatus further includes a memory coupled to the processor. Optionally, the apparatus further includes a communication interface coupled to the processor.
[0023] In one implementation manner, the apparatus for identifying a two-dimensional code is a terminal device. When the apparatus for identifying a two-dimensional code is a terminal device, the communication interface can be a transceiver, or an input / output interface.
[0024] In another implementation manner, the apparatus for identifying a two-dimensional code is a chip configured in a terminal device. When the apparatus for identifying a two-dimensional code is a chip configured in a terminal device, the communication interface can be an input / output interface.
[0025] In a fourth aspect, a processor is provided. The processor includes an input circuit, an output circuit, and a processing circuit. The processing circuit is configured to receive a signal through the input circuit and transmit a signal through the output circuit, so that the processor performs a method recited in any of the possible implementation manners of the first aspect.
[0026] In the implementation process, the processor can be a chip, the input circuit can be an input pin, the output circuit can be an output pin, and the processing circuit can be a transistor, a gate circuit, a flip-flop, and various logic circuits, etc. The input signal received by the input circuit can be received and input by, for example but not limited to, a receiver, the output signal output by the output circuit can be output to and transmitted by, for example but not limited to, a transmitter, and the input circuit and the output circuit can be the same circuit which is used as the input circuit and the output circuit at different times. The specific implementation manners of the processor and various circuits are not limited in the present application.
[0027] In a fifth aspect, a processing apparatus is provided. The processing apparatus includes a processor and a memory. The processor is configured to read instructions stored in the memory, and can receive a signal through a receiver and transmit a signal through a transmitter to perform a method recited in any of the possible implementation manners of the first aspect.
[0028] Optionally, the processor is one or more, and the memory is one or more.
[0029] Optionally, the memory can be integrated with the processor, or the memory is arranged separately from the processor.
[0030] In the implementation process, the memory can be a non-transitory memory, for example, a read only memory (ROM), which can be integrated on the same chip with the processor, or arranged separately on different chips. The type of the memory and the arrangement manner of the memory and the processor are not limited in the present application.
[0031] It should be understood that the related data interaction process, for example, the sending of the indication information, can be a process of outputting the indication information from the processor, and the receiving of the capability information can be a process of receiving the input capability information by the processor. Specifically, the processed output data can be output to a transmitter, and the input data received by the processor can come from a receiver. The transmitter and the receiver can be collectively referred to as a transceiver.
[0032] The processing device in the fifth aspect described above can be a chip, and the processor can be implemented by hardware or software. When implemented by hardware, the processor can be a logic circuit, an integrated circuit, etc. When implemented by software, the processor can be a general-purpose processor, which is implemented by reading software codes stored in a memory. The memory can be integrated in the processor, or can exist independently outside the processor.
[0033] In a sixth aspect, a computer program product is provided, which includes computer program codes. When the computer program codes are run, the computer program codes make a computer execute the method in any possible implementation manner of the first aspect described above.
[0034] In a seventh aspect, a computer readable storage medium is provided, which stores a computer program. When the computer program is run, the computer program makes a computer execute the method in any possible implementation manner of the first aspect described above. BRIEF DESCRIPTION OF DRAWINGS
[0035] Figure 1 is a schematic flowchart of a method of applying a two-dimensional code scanning;
[0036] Figure 2 is a schematic diagram of a two-dimensional code scanning scenario;
[0037] Figure 3 is a structural schematic diagram of a terminal device to which the embodiments of the present application are applicable;
[0038] Figure 4 is a software structure block diagram of a terminal device to which embodiments of the present application are applicable;
[0039] Figure 5 is a schematic flow chart of a two-dimensional code recognition method provided by embodiments of the present application;
[0040] Figure 6 is a schematic flow chart of another two-dimensional code recognition method provided by embodiments of the present application;
[0041] Figure 7 is a schematic block diagram of a two-dimensional code recognition apparatus provided by embodiments of the present application;
[0042] Figure 8 is a schematic block diagram of another two-dimensional code recognition apparatus provided by embodiments of the present application. DETAILED DESCRIPTION
[0043] The technical solutions in the present application will be described below with reference to the accompanying drawings.
[0044] In the Android ecosystem, it is a common use case to use an application to scan a two-dimensional code. The scan code recognition logic of various applications is not completely consistent, and some applications can successfully recognize a two-dimensional code when a user is close to and directly facing the two-dimensional code. For ease of description, the application can also be referred to as an application, and scanning a two-dimensional code can also be referred to as scanning a code in the following.
[0045] Exemplarily, the application described in embodiments of the present application can be a third-party application, for example, WeChat, Taobao, Alipay and the like, which are applications having a scan code function, and the type of the application is not limited in embodiments of the present application.
[0046] Figure 1 is a schematic flow chart of a method 100 for an application to scan a two-dimensional code, and the method 100 includes the following steps:
[0047] S101, in response to an operation of a user opening a scan interface, the application constructs a preview view frame.
[0048] S102, the application sends a preview stream request message to a hardware abstraction layer (hardware abstraction layer, HAL), the preview stream request message is used to request to start a data stream of a camera outputting a preview image, and the preview stream request message can carry a resolution configuration.
[0049] S103, the hardware abstraction layer sends a preview stream configuration message to the camera based on the preview stream request message, the preview stream configuration message is used to start and configure a data stream of the camera outputting a preview image, and the preview stream configuration message can carry a resolution configuration.
[0050] S104, the camera sends and displays the preview image into the preview view frame built by the application according to the preview outflow configuration message, and completes focusing.
[0051] S105, the camera sends the data stream of the preview image to the application through the hardware abstraction layer.
[0052] S106, the application detects the identification of the two-dimensional code according to the data stream of the preview image.
[0053] S107, if the identification of the two-dimensional code is detected, but the definition and size of the two-dimensional code cannot support the application to recognize the content of the two-dimensional code, the application adjusts the camera to perform zoom-in operation, and after the application recognizes the valid information in the data stream of the preview image, the application completes the current scanning code operation.
[0054] As can be seen from the above method 100, when the application scans the two-dimensional code, the terminal device detects the identification of the two-dimensional code and recognizes the content of the two-dimensional code through the application. The scanning code operation at the application level is not perceived by the system of the terminal device, that is, the system of the terminal device does not perceive that the current application is performing the scanning code operation. The system of the terminal device only sends corresponding configurations to the camera or performs start-stop operation according to the request of the application.
[0055] Figure 2 is a schematic diagram of a scanning two-dimensional code scene. As shown in Figure 2 , the scene shows a terminal device 11 and a two-dimensional code. Exemplarily, the terminal device 11 is installed with an application capable of scanning the two-dimensional code, for example, WeChat, Taobao, etc. When the terminal device 11 is far away from the two-dimensional code, the application often cannot recognize the two-dimensional code, so that the success rate of scanning the two-dimensional code is relatively low. If the system of the terminal device 11 can perceive the scanning code operation of the application, and optimizes the scanning code operation of the application in the far distance scanning scene, the success rate of scanning the two-dimensional code can be improved, and the scanning code experience of the user can be improved.
[0056] In view of the problem that the success rate of the scanning code operation of the application is low in the far distance scanning code scene, the embodiments of the present application provide a two-dimensional code recognition method and a recognition device. The method can make the system of the terminal device perceive the scanning code operation of the application, perform zoom-in processing on the preview image of the two-dimensional code at the system side, realize pre-recognition of the two-dimensional code, and obtain a more clear preview image of the two-dimensional code. This is beneficial to improve the success rate of the application to recognize the two-dimensional code, thereby improving the scanning code experience of the user.
[0057] Before introducing the two-dimensional code recognition method and recognition device provided by the embodiments of the present application, the following points are explained.
[0058] First, in the embodiments shown below, each term and English abbreviation, such as preview image, focusing distance, activity name, preview view frame, etc., are exemplary examples given for the convenience of description, and should not constitute any limitation on the present application. The present application does not exclude the possibility of defining other terms capable of achieving the same or similar functions in existing or future protocols.
[0059] Second, in the embodiments shown below, the first, second, and various numerical numbers are only distinguished for the convenience of description, and are not used to limit the scope of the embodiments of the present application. For example, to distinguish different preview images, to distinguish different focusing distances, etc.
[0060] Third, "at least one" means one or more, and "multiple" means two or more. The association relationship of "and / or" describing the associated objects means that there can be three relationships, for example, A and / or B can represent: A exists alone, A and B exist together, B exists alone, where A and B can be singular or plural. The character " / " generally represents an "or" relationship between the associated objects before and after it. "At least one of the following" or similar expressions means any combination of these items, including any combination of single or multiple items. For example, at least one of a, b and c can mean: a, or b, or c, or a and b, or a and c, or b and c, or a, b and c, where a, b, and c can be single or multiple.
[0061] The terminal device of the embodiments of the present application can be a handheld device, a vehicle-mounted device, etc. with wireless connection function, and the terminal device can also be referred to as a terminal, a user equipment (UE), a mobile station (MS), a mobile terminal (MT), etc. At present, some examples of the terminal are: a mobile phone, a tablet computer, a smart television, a notebook computer, a tablet computer (Pad), a palm computer, a mobile internet device (MID), a virtual reality (VR) device, an augmented reality (AR) device, a wireless terminal in industrial control, a wireless terminal in self driving, a wireless terminal in remote medical surgery, a wireless terminal in smart grid, a wireless terminal in transportation safety, a wireless terminal in smart city, a wireless terminal in smart home, a cellular phone, a cordless phone, a session initiation protocol (SIP) phone, a wireless local loop (WLL) station, a personal digital assistant (PDA), a handheld device with wireless communication function, a computing device or other processing device connected to a wireless modem, a vehicle-mounted device, a wearable device, a terminal device in a 5G network, or a terminal device in a future evolved public land mobile network (PLMN), etc. The embodiments of the present application do not limit the specific technology and specific device form adopted by the terminal device.
[0062] As an example but not limitation, in the embodiments of the present application, the terminal device can also be a wearable device. The wearable device can also be referred to as a wearable smart device, which is a general term for devices that are designed and developed by applying wearable technology to daily wear, such as glasses, gloves, watches, clothing, and shoes. The wearable device is a portable device that can be directly worn on the body or integrated into the clothes or accessories of the user. The wearable device is not only a hardware device, but also has powerful functions through software support, data interaction, and cloud interaction. The general wearable smart device includes devices with full functions and large sizes, which can realize complete or partial functions without relying on a smart phone, such as smart watches or smart glasses, and devices that focus on a certain application function and need to be used in cooperation with other devices, such as smart phones, such as various smart wristbands and smart jewelry for monitoring vital signs.
[0063] It should be understood that in the embodiments of the present application, the terminal device can be a device for realizing the function of the terminal device, or a device capable of supporting the terminal device to realize the function, such as a chip system, which can be installed in the terminal. In the embodiments of the present application, the chip system can be composed of a chip, or can include a chip and other discrete devices.
[0064] The terminal device in the embodiments of the present application can also be referred to as a user equipment (UE), a mobile station (MS), a mobile terminal (MT), an access terminal, a subscriber unit, a subscriber station, a mobile station, a mobile terminal, a remote station, a remote terminal, a mobile device, a user terminal, a terminal, a wireless communication device, a user agent, or a user device, etc.
[0065] Figure 3 is a structural schematic diagram of a terminal device applicable in the embodiments of the present application. As shown in Figure 3As shown, the terminal device 300 can 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 loudspeaker 170A, a receiver 170B, a microphone 170C, a headset jack 170D, a sensor 180, a key 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. It can be understood that the structure shown in the embodiment does not constitute a specific limitation on the terminal device 300. In some other embodiments of the application, the terminal device 300 can include more or fewer components than shown, or combine certain components, or split certain components, or different arrangement of components. The components shown can be implemented in hardware, software, or a combination of software and hardware.
[0066] The processor 110 can include one or more processing units, for example: the processor 110 can include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, a display process unit (DPU), and / or a neural-network processing unit (NPU), etc. Among them, different processing units can be independent devices, or can be integrated in one or more processors. In some embodiments, the terminal device 300 can also include one or more processors 110. Among them, the processor can be the nerve center and command center of the terminal device 300. The processor can generate operation control signals according to instruction operation codes and timing signals, complete the control of fetching instructions and executing instructions. The processor 110 can also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory can save instructions or data used or recycled by the processor 110. If the processor 110 needs to use the instruction or data again, it can be directly called from the memory. This avoids repeated access and reduces the waiting time of the processor 110, thereby improving the efficiency of the terminal device 300.
[0067] In some embodiments, the processor 110 can include one or more interfaces. The interfaces can include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a USB interface, etc. The USB interface 130 is an interface conforming to the USB standard specification, and can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the terminal device 300, and can also be used to transmit data between the terminal device 300 and a peripheral device. It can also be used to connect a headset to play audio through the headset.
[0068] It can be understood that the interface connection relationship between the modules shown in the embodiments of the present application is illustrative and does not constitute a structural limitation of the terminal device 300. In some other embodiments of the present application, the terminal device 300 can also use different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.
[0069] The wireless communication function of the terminal device 300 can be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor, etc. The antenna 1 and the antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the terminal device 300 can be used to cover a single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization rate of the antennas. For example, the antenna 1 can be multiplexed as a diversity antenna of a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0070] The mobile communication module 150 can provide a solution for wireless communication including 2G / 3G / 4G / 5G, etc. applied to the terminal device 300. The mobile communication module 150 can include at least one filter, a switch, a power amplifier, a low noise amplifier, etc. The mobile communication module 150 can receive electromagnetic waves by the antenna 1, and perform filtering, amplification, etc. on the received electromagnetic waves, and transfer the processed signals to the modem processor for demodulation. The mobile communication module 150 can also amplify the signals modulated by the modem processor, and radiate the signals as electromagnetic waves through the antenna 1. In some embodiments, at least part of the functional modules of the mobile communication module 150 can be disposed in the processor 110. In some embodiments, at least part of the functional modules of the mobile communication module 150 can be disposed in the same device as at least part of the modules of the processor 110.
[0071] The modem processor can include a modulator and a demodulator. The modulator is configured to modulate a low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is configured to demodulate a received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. The low-frequency baseband signal processed by the baseband processor is transmitted to the application processor. The application processor outputs a sound signal through an audio device (not limited to the speaker 170A, the microphone 170B, etc.), or displays an image or a video through the display screen 194. In some embodiments, the modem processor can be a separate device. In other embodiments, the modem processor can be independent of the processor 110, and disposed in the same device as the mobile communication module 150 or other functional modules.
[0072] The wireless communication module 160 can provide a solution for wireless communication including wireless local area networks (WLAN), Bluetooth, global navigation satellite system (GNSS), frequency modulation (FM), NFC, infrared technology (IR), etc. applied to the terminal device 300. The wireless communication module 160 can be one or more devices integrated with at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, performs frequency modulation and filtering processing on the electromagnetic wave signals, and transmits the processed signals to the processor 110. The wireless communication module 160 can also receive signals to be transmitted from the processor 110, perform frequency modulation and amplification on the signals, and radiate the signals as electromagnetic waves through the antenna 2.
[0073] In some embodiments, antenna 1 and mobile communication module 150 of terminal device 300 are coupled, and antenna 2 and wireless communication module 160 are coupled, so that terminal device 300 can communicate with a network and other devices through wireless communication technology. The wireless communication technology can include GSM, GPRS, CDMA, WCDMA, TD-SCDMA, LTE, GNSS, WLAN, NFC, FM, and / or IR technology, etc. The above-mentioned GNSS can include global positioning system (GPS), global navigation satellite system (GLONASS), beidou navigation satellite system (BDS), quasi-zenith satellite system (QZSS), and / or satellite based augmentation systems (SBAS).
[0074] Terminal device 300 can realize display function through GPU, display screen 194, and application processor, etc. The application processor can include NPU and / or DPU. GPU is a microprocessor for image processing, connected with display screen 194 and application processor. GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 can include one or more GPUs that execute instructions to generate or change display information. NPU is a neural-network (NN) computing processor that quickly processes input information by drawing on the structure of biological neural networks, such as the transmission mode between human brain neurons, and can also constantly self-learn. Through NPU, intelligent cognition and other applications of terminal device 300 can be realized, such as image recognition, face recognition, speech recognition, text understanding, etc. DPU is also called display sub-system (DSS). DPU is used to adjust the color of display screen 194. DPU can adjust the color of display screen through a color 3D look up table (3D LUT). DPU can also perform scaling, noise reduction, contrast enhancement, backlight brightness management, hdr processing, display parameter Gamma adjustment, and other processing on the picture.
[0075] The display screen 194 is configured to display images, videos, and the like. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flex light-emitting diode (FLED), a Miniled, a MicroLed, a Micro-oLed, or a quantum dot light emitting diode (QLED). In some embodiments, the terminal device 300 can include one or N display screens 194, where N is a positive integer greater than 1.
[0076] The terminal device 300 can implement a photographing function through an ISP, one or more cameras 193, a video codec, a GPU, one or more display screens 194, and an application processor, and the like.
[0077] The external memory interface 120 can be configured to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the terminal device 300. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, music, photo, video, and the like data files are saved in the external memory card.
[0078] The internal memory 121 can be configured to store one or more computer programs including instructions. The processor 110 can cause the terminal device 300 to perform various functional applications and data processing, and the like by running the above-mentioned instructions stored in the internal memory 121. The internal memory 121 can include a program storage area and a data storage area. The program storage area can store an operating system, and can further store one or more application programs (such as a gallery, contacts, and the like), and the like. The data storage area can store data (such as photos, contacts, and the like) created during use of the terminal device 300, and the like. In addition, the internal memory 121 can include a high-speed random access memory, and can further include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, a universal flash storage (UFS), and the like. In some embodiments, the processor 110 can cause the terminal device 300 to perform various functional applications and data processing by running instructions stored in the internal memory 121 and / or instructions stored in a memory disposed in the processor 110.
[0079] The terminal device 300 can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor, etc. For example, music playing, recording, etc. Among them, the audio module 170 is used to convert digital audio information into an analog audio signal output, and is also used to convert an analog audio input into a digital audio signal. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or part of the function modules of the audio module 170 are arranged in the processor 110. The speaker 170A, also known as a "loudspeaker", is used to convert an audio electrical signal into a sound signal. The terminal device 300 can listen to music or listen to a hands-free call through the speaker 170A. The receiver 170B, also known as a "earpiece", is used to convert an audio electrical signal into a sound signal. When the terminal device 300 answers a call or a voice message, the receiver 170B can be held close to the ear to listen to the voice. The microphone 170C, also known as a "microphone" or "sound transducer", is used to convert a sound signal into an electrical signal. When making a call or sending a voice message, the user can speak into the microphone 170C by holding the mouth close to the microphone 170C to input the sound signal into the microphone 170C. The terminal device 300 can be provided with at least one microphone 170C. In other embodiments, the terminal device 300 can be provided with two microphones 170C, in addition to collecting sound signals, it can also implement noise reduction functions. In other embodiments, the terminal device 300 can also be provided with three, four or more microphones 170C, in addition to collecting sound signals and noise reduction, it can also identify the source of the sound, implement directional recording functions, etc. The earphone interface 170D is used to connect a wired earphone. The earphone interface 170D can be a USB interface 130, or a 3.5mm open mobile terminal platform (OMTP) standard interface, or a cellular telecommunications industry association of the USA (CTIA) standard interface.
[0080] The sensor 180 can include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0081] The software system of the terminal device 300 can employ a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. Embodiments of the present application take an Android system with a layered architecture as an example to illustrate the software structure of the terminal device 300.
[0082] Figure 4 is a software structure block diagram of a terminal device to which embodiments of the present application are applicable. The layered architecture divides the software system of the terminal device 300 into several layers, each of which has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system can be divided into an application layer (application, APP), an application framework layer, an Android runtime and a system library, a hardware abstraction layer (hardware abstraction layer, HAL), and a kernel layer. In some embodiments, the terminal device 300 also includes hardware (e.g., a camera).
[0083] The application layer can include a series of application packages, and the application layer runs the applications by calling the application programming interfaces (application programming interface, API) provided by the application framework layer. As shown in Figure 4 , the application packages can include camera, calendar, map, phone, music, WLAN, Bluetooth, video, social, gallery, navigation, short message, etc.
[0084] The application framework layer provides APIs and programming frameworks for the applications of the application layer. The application framework layer includes some pre-defined functions. As shown in Figure 4 , the application framework layer can include a window manager, a content provider, a resource manager, a notification manager, a view system, a phone manager, etc.
[0085] The window manager is used to manage window programs. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, and take screenshots, etc.
[0086] The content provider is used to store and obtain data, and make the data accessible to the applications. The data can include video images, audio, dialed and received calls, browsing history and bookmarks, phonebook, etc. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc.
[0087] A view system can be used to build an application. A display interface can be composed of one or more views. For example, a display interface including a short message notification icon can include a view to display text and a view to display a picture.
[0088] A telephony manager is used to provide communication functions of the terminal device 300. For example, management of a call state (including call connection, call disconnection, etc.).
[0089] A resource manager provides various resources for an application, such as localized strings, icons, pictures, layout files, video files, etc.
[0090] A notification manager enables an application to display notification information in a status bar. The notification information can be used to convey a message of an informing type, which can automatically disappear after a short time without user interaction. For example, the notification manager is used to inform of a download completion, a message reminder, etc. The notification manager can also be a notification appearing in a top status bar of the system in a form of a graph or a scroll bar text, a notification of an application running in the background, or a notification appearing on a screen in a form of a dialog window. For example, a text message is prompted in a status bar, a prompt sound is emitted, the terminal device 300 vibrates, an indicator light blinks, etc.
[0091] An Android runtime includes a core library and a virtual machine. The Android runtime is responsible for scheduling and managing the Android system. The core library includes two parts: one part is a function function called by a java language used in a java API framework, and the other part is a core library of the Android. An application layer and an application framework layer are executed in the virtual machine. The virtual machine executes a java file of the application layer and the application framework layer as a binary file. The virtual machine is used to perform functions of management of an object life cycle, stack management, thread management, security and exception management, and garbage collection, etc. A system library can include a plurality of function modules. For example, a surface manager, media libraries, a three-dimensional graphics processing library (for example, OpenGL ES), a 2D graphics engine (for example, SGL), etc.
[0092] The surface manager is used to manage a display subsystem and provides fusion of 2D and 3D layers for a plurality of applications. The media libraries support playback and recording of a plurality of commonly used audio, video formats, and still image files, etc. The media libraries can support a plurality of audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc. The three-dimensional graphics processing library is used to implement three-dimensional graphics drawing, image rendering, synthesis, and layer processing, etc. The 2D graphics engine is a drawing engine for 2D drawing.
[0093] The hardware abstraction layer is an abstract interface of the device kernel driver, which implements an application programming interface for providing access to underlying devices to a higher-level Java API framework. The hardware abstraction layer can include a plurality of library modules, each of which can implement an interface for a specific type of hardware component, such as a code scanning interface, a Wi-Fi interface, an audio interface, a Bluetooth interface, and the like. When the framework API requires access to a device hardware, the Android system will load the library module for the hardware component.
[0094] The kernel layer is a layer between hardware and software. The kernel layer is used to drive hardware to work. The kernel layer at least includes a camera driver, an audio driver, a Bluetooth driver, a Wi-Fi driver, and the like, which are not limited in the embodiments of the present application.
[0095] Exemplarily, in the embodiments of the present application, the hardware abstraction layer can provide the code scanning interface for accessing the underlying camera driver to the application framework layer of the upper layer, and the kernel layer adopts the camera driver to drive the camera 193 in the terminal device 300 to acquire the preview image of the two-dimensional code.
[0096] Figure 5 FIG. 5 is a schematic flowchart of a two-dimensional code recognition method 500 provided by the embodiments of the present application. The method 500 can be applied to the scenario shown in FIG. 1, and the steps of the method 500 can be executed by the terminal device 11 in the scenario. The terminal device 11 can have the architecture shown in FIG. 2, but the embodiments of the present application are not limited thereto. The method 500 includes the following steps. Figure 2 Figure 3 Figure 4
[0097] S501, acquiring a first preview image of a two-dimensional code based on a first focusing distance, the first focusing distance being greater than or equal to a preset threshold;
[0098] S502, if an identifier of the two-dimensional code is not detected from the first preview image, or if a size of the identifier of the two-dimensional code in the first preview image does not conform to a preset size, adjusting the focusing distance until a second preview image of the two-dimensional code is obtained, the second preview image including content of the two-dimensional code, the identifier of the two-dimensional code being at a preset position of the second preview image, and the size of the identifier of the two-dimensional code conforming to the preset size;
[0099] S503, performing content recognition on the two-dimensional code based on the second preview image.
[0100] In the embodiments of the present application, when the user uses the terminal device to scan the two-dimensional code, the user does not need to move the terminal device close to the two-dimensional code, and the terminal device can perceive the operation of scanning the two-dimensional code by the system in a scenario where the two-dimensional code cannot be detected due to a long distance, and perform a zoom-in operation to realize pre-recognition of the two-dimensional code, so as to obtain a clearer preview image, thereby improving the success rate of scanning the two-dimensional code by the application.
[0101] Exemplarily, the preset threshold can be 1 meter, and when the code scanning distance (which can also be referred to as the focusing distance) between the terminal device and the two-dimensional code is greater than 1 meter, it can be considered that the current is a long-distance code scanning scenario of the user. It should be understood that the preset threshold in the embodiments of the present application is only an example, and the code scanning distance between the terminal device and the two-dimensional code within a preset distance range can also be considered as a long-distance code scanning scenario. The preset distance range can be 1 meter to 1.5 meters, or 0.8 meters to 1.5 meters, which is not limited in the embodiments of the present application.
[0102] In the embodiments of the present application, the terminal device can detect the focusing distance between the terminal device and the two-dimensional code when scanning the two-dimensional code by the application. When it is detected that the first focusing distance is greater than or equal to the preset threshold, the terminal device can input the first preview image obtained at the first focusing distance into the two-dimensional code detection algorithm to detect the identifier of the two-dimensional code.
[0103] The identifier of the two-dimensional code can also be referred to as the feature of the two-dimensional code. When the terminal device detects the identifier of the two-dimensional code, it can first obtain three positioning corner points of the two-dimensional code by performing operations such as smoothing filtering, binarization, and contour finding on the preview image. Then, the positions of the three positioning corner points are judged, and the range of the two-dimensional code is determined according to the positions of the three positioning corner points.
[0104] In a possible case, the terminal device cannot detect the identifier of the two-dimensional code in the first preview image by the two-dimensional code detection algorithm, or the terminal device detects the identifier of the two-dimensional code in the first preview image by the two-dimensional code detection algorithm, but the size of the identifier of the two-dimensional code does not meet the preset size. In this case, the terminal device can perform a zoom-in operation by adjusting the focusing distance until a second preview image of the two-dimensional code is obtained. The terminal device can detect the identifier of the two-dimensional code from the second preview image, the second preview image includes the content of the two-dimensional code, the identifier of the two-dimensional code is in a preset position of the second preview image, and the preset position is a position where the terminal device can obtain the range of the complete two-dimensional code. The size of the identifier of the two-dimensional code meets the preset size, and the preset size is the size at which the terminal device can clearly identify the content of the two-dimensional code.
[0105] Optionally, the second preview image is a plurality of continuous images, so that the content of the two-dimensional code is identified after a plurality of continuous second preview images including the content of the two-dimensional code are obtained, thereby improving the accuracy of the content identification of the two-dimensional code.
[0106] After the terminal device obtains the second preview image, the terminal device can identify the content of the two-dimensional code according to the content of the two-dimensional code included in the second preview image, and after obtaining the valid information of the two-dimensional code, the terminal device can display the scanning result, thereby completing the current scanning operation.
[0107] In another possible case, the terminal device can detect, by using the two-dimensional code detection algorithm, an identifier of a two-dimensional code that is in a preset position in the first preview image, meets a preset size, and includes the content of the two-dimensional code. In this case, the terminal device can not perform the zoom-in operation, but can identify the content of the two-dimensional code according to the content of the two-dimensional code in the first preview image, and after obtaining the valid information of the two-dimensional code, the terminal device can display the scanning result, thereby completing the current scanning operation.
[0108] As an optional embodiment, before S501, the method 500 further includes obtaining a preview request, where the preview request is used to trigger the terminal device to start the camera to obtain a preview image. Based on the preview request, the camera is started to focus, and a first focusing distance is determined. Optionally, the preview request can carry a resolution configuration of the camera.
[0109] In the embodiments of the present application, the condition for triggering the terminal device to obtain the preview request can include that the terminal device responds to a scanning operation of an application, for example, a user opens a scanning function of WeChat.
[0110] As an optional embodiment, before the camera is started to focus based on the preview request and the first focusing distance is determined, the method 500 further includes displaying a scanning interface and determining a preview view frame in the scanning interface, where the preview view frame is used to display the two-dimensional code. The camera is started to focus based on the preview request, and the first focusing distance is determined, which includes that the camera is started to focus in the preview view frame based on the preview request, and the first focusing distance is determined.
[0111] In the embodiments of the present application, the terminal device can construct the preview view frame based on the screen size of the terminal device, the capability of the camera, and other information, and start the camera to focus in the preview view frame and display the preview image.
[0112] As an optional embodiment, after displaying the scanning interface, the method 500 further includes: obtaining an activity name of the scanning interface. According to the activity name of the scanning interface, it is determined whether the scanning interface is a two-dimensional code scanning interface. After determining the first focusing distance, the method 500 further includes: in the case that the scanning interface is a two-dimensional code scanning interface, it is determined that the first focusing distance is greater than or equal to a preset threshold.
[0113] The activity is one of application components of Android, which can provide an interface for user interaction to enable the user to perform operations such as scanning a two-dimensional code, making a call, taking a photo, sending an email, viewing a map, and the like. Each activity obtains a window for drawing its user interface, and the window usually fills the screen, but can also be smaller than the screen and float above other windows. Generally, the interface provided by each activity corresponds to an activity name, for example, the scanning interface of WeChat for scanning a two-dimensional code corresponds to an activity name, and the dialing interface during a call corresponds to an activity name.
[0114] In the embodiments of the present application, the terminal device can determine whether the current scanning interface is a two-dimensional code scanning interface according to the activity name of the scanning interface. In the case that the current scanning interface is determined to be a two-dimensional code scanning interface, the terminal device can obtain a first focusing distance between the terminal device and the two-dimensional code, and detect whether the first focusing distance is greater than or equal to a preset threshold.
[0115] In one possible case, the terminal device determines that the first focusing distance is greater than or equal to the preset threshold, and then the terminal device can be triggered to detect the first preview image by a two-dimensional code detection algorithm at the first focusing distance.
[0116] In another possible case, the terminal device does not identify a two-dimensional code within a preset time length, and in this case, the size of the first focusing distance and the preset threshold can not be considered. Once the terminal device identifies a two-dimensional code for a time greater than or equal to the preset time length, the terminal device can be triggered to detect the first preview image by a two-dimensional code detection algorithm at the first focusing distance. Exemplarily, the preset time length can be 3 seconds, and the embodiments of the present application are not limited in this regard.
[0117] In yet another possible case, the terminal device determines that the first focusing distance is less than the preset threshold, and then the terminal device can perform operations similar to S104 to S107 in the above method 100, which will not be described herein again.
[0118] As an optional embodiment, the adjusting the focusing distance until the second preview image is obtained in S502 comprises: adjusting the first focusing distance by a preset step to obtain a second focusing distance. Based on the second focusing distance obtained by each adjustment, a candidate preview image of the two-dimensional code is acquired until the identification of the two-dimensional code is detected from the acquired candidate preview image and the candidate preview image includes the content of the two-dimensional code, and the candidate preview image is determined as the second preview image. Wherein, the identification of the two-dimensional code is in a preset position of the candidate preview image, and the size of the identification of the two-dimensional code meets a preset size.
[0119] In the embodiment of the application, the terminal device can adjust the focusing distance of the camera according to a preset step. For example, the first focusing distance is 1.5 meters, and the preset step is 0.2 meters. Then the second focusing distance obtained after the first adjustment is 1.3 meters. The candidate preview image is obtained under the second focusing distance. If the terminal device does not detect the identification of the two-dimensional code from the candidate preview image, or the size of the identification of the two-dimensional code in the candidate preview image does not meet the preset size, the terminal device can continue to adjust the second focusing distance according to the preset step to obtain a new second focusing distance of 1.1 meters. The second focusing distance is adjusted gradually until the terminal device can obtain a candidate preview image that meets the condition under the new second focusing distance, and the candidate preview image is determined as the second preview image.
[0120] Figure 6 is a schematic flowchart of another two-dimensional code recognition method 600 provided by the embodiment of the application. The method 600 can be applied to Figure 2 the scenario shown in FIG. 6, and the steps of the method 600 can be implemented by the interaction between layers of the software system of the terminal device 11 in the scenario and the interaction between the software system and the hardware components. The terminal device 11 can have the architecture shown in FIG. 6, but the embodiment of the application is not limited in this regard. The method 600 comprises the following steps: Figure 3 and / or Figure 4 The method 600 comprises the following steps:
[0121] S601, in response to the operation of the user opening the scanning interface, the application constructs a preview view frame.
[0122] For example, the application can be a third-party application such as WeChat, Taobao, Alipay, etc. The embodiment of the application is not limited in this regard. It should be understood that the application of the embodiment of the application is in the application program layer as shown in FIG. 6. Figure 4
[0123] S602, the application sends a call request message to the application program framework layer, and the call request message is used to call the application program framework layer algorithm for opening the preview. Correspondingly, the application program framework layer receives the call request message.
[0124] S603, the application framework layer sends a preview outflow request message to the hardware abstraction layer, the preview outflow request message is used to request to start a data stream of the camera outputting a preview image, and the preview outflow request message can carry a resolution configuration. Correspondingly, the hardware abstraction layer receives the preview outflow request message.
[0125] S604, the application sends an activity name of a scanning interface to the application framework layer, the activity name of the scanning interface is used to identify the type of the scanning interface. Correspondingly, the application framework layer receives the activity name of the scanning interface.
[0126] S605, the application framework layer identifies the scanning interface as a two-dimensional code scanning interface based on the activity name of the scanning interface.
[0127] S606, the application framework layer sends a tag message to the hardware abstraction layer, the tag message is used to indicate that the current scanning interface is a two-dimensional code scanning interface. Correspondingly, the hardware abstraction layer receives the tag message.
[0128] S607, the hardware abstraction layer sends a preview outflow configuration message to the camera based on the preview outflow request message and the tag message, the preview outflow configuration message is used to start and configure a data stream of the camera outputting a preview image, and the preview outflow configuration message can carry a resolution configuration. Correspondingly, the camera receives the preview outflow configuration message.
[0129] S608, the camera completes focusing in a preview view frame built by the application based on the preview outflow configuration message, and obtains a focusing distance and a preview image of a two-dimensional code.
[0130] S609, the camera sends the focusing distance and the preview image of the two-dimensional code to the hardware abstraction layer. Correspondingly, the hardware abstraction layer receives the focusing distance and the preview image of the two-dimensional code.
[0131] S610, the hardware abstraction layer judges whether the focusing distance meets a distance condition.
[0132] Exemplarily, the distance condition can be a preset threshold, for example, 1 meter or 1.5 meters. When the focusing distance is greater than or equal to the preset threshold, the hardware abstraction layer can consider that the current is a long-distance code scanning scene.
[0133] Exemplarily, the distance condition can be a preset range, for example, 0.8 meters to 1.5 meters. When the focusing distance is within the preset range, the hardware abstraction layer can consider that the current is a long-distance code scanning scene.
[0134] S611, if the focusing distance meets the distance condition, the hardware abstraction layer calls a two-dimensional code detection algorithm to detect the preview image of the two-dimensional code.
[0135] Exemplarily, the hardware abstraction layer can detect the preview image each time the hardware abstraction layer acquires the preview image.
[0136] S612, if the identification of the two-dimensional code is not detected in the preview image, or the size of the identification of the two-dimensional code in the preview image does not meet the preset size, the hardware abstraction layer sends an adjustment message to the camera, and the adjustment message is used to instruct the camera to adjust the focusing distance to perform a zoom-in operation. Correspondingly, the camera receives the adjustment message.
[0137] S613, the camera adjusts the focusing distance to perform a zoom-in operation based on the adjustment message, and obtains a new preview image.
[0138] In this step, the zoom-in operation of the camera is beneficial to obtain the identification of the two-dimensional code meeting the preset size requirement and the preview image of the two-dimensional code being more clear.
[0139] S614, the camera sends the new preview image to the hardware abstraction layer. Correspondingly, the hardware abstraction layer receives the new preview image.
[0140] S615, the hardware abstraction layer calls the two-dimensional code detection algorithm to detect the new preview image until M frames of continuous and stable preview images are obtained, where M is a positive integer greater than or equal to 1.
[0141] It should be understood that before the M frames of continuous and stable preview images are obtained, the hardware abstraction layer can instruct the camera to continuously adjust the focal length to perform multiple zoom-in operations. After each zoom-in operation is performed, the camera sends a new preview image to the hardware abstraction layer for detection until the identification of the two-dimensional code in the continuous M frames of preview images starting from a certain frame of new preview image is detected, the two-dimensional code is in the preset position, the size meets the preset size, and the content of the two-dimensional code can be detected in the continuous M frames of preview images.
[0142] If the hardware abstraction layer can recognize the continuous M frames of preview images, it can be considered that the continuous M frames of preview images are stable.
[0143] Exemplarily, the hardware abstraction layer does not detect the identification of the two-dimensional code in the Nth preview image obtained, or the size of the identification of the two-dimensional code in the Nth preview image does not conform to the preset size, where N is a positive integer greater than or equal to 1. In order to improve the success rate of two-dimensional code recognition, the hardware abstraction layer can send the above adjustment message to the camera, and obtain the (N+1)th preview image to the (N+M)th preview image after the zooming operation. If the identification of the two-dimensional code in the preset position and conforming to the preset size can be detected in the (N+1)th preview image to the (N+M)th preview image, and the content of the two-dimensional code can be detected in the (N+1)th preview image to the (N+M)th preview image, the hardware abstraction layer can consider that the continuous and stable M preview images have been obtained.
[0144] In S616, the hardware abstraction layer sends the continuous and stable M preview images to the application. Correspondingly, the application receives the continuous and stable M preview images.
[0145] In S617, the application uses a two-dimensional code content recognition algorithm to recognize the content of the two-dimensional code in the continuous and stable M preview images, obtains the valid information of the two-dimensional code, and completes the two-dimensional code scanning.
[0146] Exemplarily, when the code scanning is successful, the application can display a green dot on the two-dimensional code image to respond to the successful code scanning, and jump to a recognition success interface. In this case, the valid information of the two-dimensional code can be considered to be obtained.
[0147] Optionally, in S611, in addition to triggering the calling of the two-dimensional code detection algorithm to detect the preview image when the focusing distance meets the distance condition, the hardware abstraction layer can also trigger the calling of the two-dimensional code detection algorithm to detect the preview image when the time length of recognizing the two-dimensional code meets the time length condition.
[0148] Exemplarily, the time length condition can be a preset time length, for example, 3 seconds. When the time length of recognizing the two-dimensional code is greater than or equal to the preset time length, the hardware abstraction layer can consider that the current is a two-dimensional code recognition difficult scene, so as to pre-identify the preview image.
[0149] In the embodiments of the present application, the hardware abstraction layer can perceive the two-dimensional code scanning operation of the application based on the activity name of the two-dimensional code. When it is detected that the current is a long-distance code scanning scene, the hardware abstraction layer can perform pre-recognition of the two-dimensional code by calling the two-dimensional code detection algorithm. When the obtained preview image cannot meet the detection condition, the hardware abstraction layer can instruct the camera to perform a zooming operation to obtain a clearer preview image. This is conducive to improving the success rate of the application recognizing the two-dimensional code in the long-distance scene, thereby improving the user experience of using the terminal device.
[0150] It should be understood that the embodiments of the present application make improvements on the system side of the terminal device compared with the existing application scanning process (such as the method 100 described above), and specifically include the following points:
[0151] 1. In the existing application scanning process, the scanning operation of the application on the two-dimensional code is not perceived by the system of the terminal device. In the embodiments of the present application, the Android runtime and the hardware abstraction layer can perceive the scanning operation of the application on the two-dimensional code.
[0152] 2. In the existing application scanning process, the terminal device detects the identifier of the two-dimensional code through the application. In the embodiments of the present application, the terminal device detects the identifier of the two-dimensional code by calling the two-dimensional code detection algorithm in the hardware abstraction layer.
[0153] 3. In the existing application scanning process, the application of the terminal device needs to continuously detect until the identifier of the two-dimensional code is detected, or the terminal device is brought close to the two-dimensional code to detect the identifier of the two-dimensional code. In the embodiments of the present application, when the identifier of the two-dimensional code is not detected, or the size of the identifier of the two-dimensional code in the preview image does not meet the preset size, the terminal device can not be close to the two-dimensional code, and the hardware abstraction layer of the terminal device can instruct the camera to perform a zoom-in operation until M consecutive stable preview images meeting the condition are obtained.
[0154] It should be understood that the size of the serial number of the above processes does not mean the order of execution, and the execution order of each process should be determined according to its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0155] The above describes in detail the two-dimensional code recognition method according to the embodiments of the present application. Figures 2 to 6 , and the two-dimensional code recognition device according to the embodiments of the present application will be described in detail in combination with Figure 7 and Figure 8 .
[0156] Figure 7 A schematic block diagram of a two-dimensional code recognition device 700 provided by the embodiments of the present application is shown, which includes an acquisition module 710 and a processing module 720.
[0157] The obtaining module 710 is configured to obtain a first preview image of the two-dimensional code based on a first focusing distance, the first focusing distance being greater than or equal to a preset threshold. The processing module 720 is configured to, if an identifier of the two-dimensional code is not detected from the first preview image, or if a size of the identifier of the two-dimensional code in the first preview image does not conform to a preset size, adjust the focusing distance until a second preview image of the two-dimensional code is obtained, the second preview image including content of the two-dimensional code, the identifier of the two-dimensional code being at a preset position of the second preview image, and the size of the identifier of the two-dimensional code conforming to the preset size; and perform content recognition on the two-dimensional code based on the second preview image.
[0158] Optionally, the second preview image is a plurality of continuous images.
[0159] Optionally, the obtaining module 710 is configured to obtain a preview request, the preview request being used to start the camera to obtain a preview image. The processing module 720 is configured to start the camera to focus based on the preview request, and determine the first focusing distance.
[0160] Optionally, the processing module 720 is configured to display a scanning interface, and determine a preview view frame in the scanning interface, the preview view frame being used to display the two-dimensional code; and start the camera to focus in the preview view frame based on the preview request, and determine the first focusing distance.
[0161] Optionally, the obtaining module 710 is configured to obtain an activity name of the scanning interface. The processing module 720 is configured to determine, according to the activity name of the scanning interface, whether the scanning interface is a two-dimensional code scanning interface; and determine, in a case where the scanning interface is the two-dimensional code scanning interface, that the first focusing distance is greater than or equal to the preset threshold.
[0162] Optionally, the processing module 720 is configured to adjust the first focusing distance by a preset step to obtain a second focusing distance. The obtaining module 710 is configured to obtain a candidate preview image of the two-dimensional code based on the second focusing distance; and obtain the candidate preview image of the two-dimensional code based on the second focusing distance obtained by each adjustment, until an identifier of the two-dimensional code is detected from the obtained candidate preview image, and the candidate preview image includes content of the two-dimensional code, the candidate preview image being determined as the second preview image. The identifier of the two-dimensional code is at a preset position of the candidate preview image, and the size of the identifier of the two-dimensional code conforms to the preset size.
[0163] In an optional example, the apparatus 700 can be specifically a terminal device in the above-described embodiments, or the functions of the terminal device in the above-described embodiments can be integrated in the apparatus 700. The above-described functions can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-described functions. The apparatus 700 can be used to execute the respective processes and / or steps corresponding to the terminal device in the above-described method embodiments.
[0164] It should be understood that the apparatus 700 herein is embodied in the form of functional modules. The term "module" herein can refer to an application specific integrated circuit (ASIC), an electronic circuit, a processor (shared, dedicated or group) and memory that execute one or more software or firmware programs, a combinational logic circuit, and / or other suitable components that provide the described functionality. In the embodiments of the present application, Figure 7 The apparatus 700 in the above-described embodiments can also be a chip or a chip system, for example, a system on chip (SoC).
[0165] Figure 8 Another apparatus 800 for recognizing a two-dimensional code is shown in the schematic block diagram. The apparatus 800 includes a processor 810, a transceiver 820 and a memory 830. The processor 810, the transceiver 820 and the memory 830 communicate with each other through internal connection paths. The memory 830 is configured to store instructions, and the processor 810 is configured to execute the instructions stored in the memory 830 to control the transceiver 820 to transmit and / or receive signals.
[0166] It should be understood that the apparatus 800 can be specifically a terminal device in the above-described embodiments, or the functions of the terminal device in the above-described embodiments can be integrated in the apparatus 800, and the apparatus 800 can be used to execute the respective steps and / or processes corresponding to the terminal device in the above-described method embodiments. Alternatively, the memory 830 can include a read-only memory and a random access memory, and provide instructions and data to the processor. A part of the memory can also include a non-volatile random access memory. For example, the memory can also store device type information. The processor 810 can be used to execute the instructions stored in the memory, and when the processor executes the instructions, the processor can execute the respective steps and / or processes corresponding to the terminal device in the above-described method embodiments.
[0167] It should be understood that, in the embodiments of the present application, the processor 810 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.
[0168] Those skilled in the art can clearly understand that the modules and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0169] Those skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working processes of the above-described system, device and module can refer to the corresponding processes in the foregoing method embodiments, which will not be repeated here.
[0170] In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the above-described device embodiments are only schematic, for example, the division of the modules is only a logical function division, and actual implementation can have another division manner, for example, a plurality of modules or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the shown or discussed modules can be indirect coupling or communication connection through some interfaces, devices or modules, and can be electrical, mechanical or other forms.
[0171] The modules described as separate components can or can not be physically separated, and the components shown as modules can or can not be physical modules, i.e. can be located in one place, or can be distributed to a plurality of network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the present embodiment.
[0172] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically, or two or more modules can be integrated into one module.
[0173] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the parts of the technical solutions that essentially contribute to the prior art or the parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.
[0174] The above is only a specific implementation of the present application, but the protection scope of the embodiments of the present application is not limited to this. Any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the embodiments of the present application, which should be covered within the protection scope of the embodiments of the present application. Therefore, the protection scope of the embodiments of the present application should be subject to the protection scope of the claims.
Claims
1. A method of recognizing a two-dimensional code, characterized by, The application is applied to a terminal device with a camera, a terminal device hardware abstraction layer, and the method comprises the following steps: obtaining a first preview image of a two-dimensional code based on a first focusing distance; determining whether the first focusing distance is greater than or equal to a preset threshold through the hardware abstraction layer; if the first focusing distance is greater than or equal to the preset threshold, the hardware abstraction layer calls a two-dimensional code detection algorithm to detect the first preview image; if the identification of the two-dimensional code is not detected from the first preview image, or if the size of the identification of the two-dimensional code in the first preview image does not meet the preset size, the hardware abstraction layer sends an adjustment message to the camera, the adjustment message being used to instruct the camera to adjust the focusing distance by a preset step size until a second preview image of the two-dimensional code is obtained, the second preview image including the content of the two-dimensional code, the identification of the two-dimensional code being at a preset position of the second preview image, and the size of the identification of the two-dimensional code meeting the preset size; the focusing distance being a scanning distance between the terminal device and the two-dimensional code; performing content recognition on the two-dimensional code based on the second preview image.
2. The method of claim 1, wherein, The second preview image is a plurality of continuous images.
3. The method of claim 1, wherein, Before the step of obtaining the first preview image of the two-dimensional code based on the first focusing distance, the method further comprises the following steps: obtaining a preview request, the preview request being used to start the camera to obtain a preview image; starting the camera to focus based on the preview request, and determining the first focusing distance.
4. The method of claim 3, wherein, Before the step of starting the camera to focus based on the preview request and determining the first focusing distance, the method further comprises the following steps: displaying a scanning interface, and determining a preview view frame in the scanning interface, the preview view frame being used to display the two-dimensional code; the step of starting the camera to focus based on the preview request and determining the first focusing distance comprises the following step: starting the camera to focus in the preview view frame based on the preview request, and determining the first focusing distance.
5. The method of claim 4, wherein, After the step of displaying the scanning interface, the method further comprises the following steps: obtaining an activity name of the scanning interface; determining whether the scanning interface is a two-dimensional code scanning interface according to the activity name of the scanning interface; After the step of determining the first focusing distance, the method further comprises the following step: if the scanning interface is the two-dimensional code scanning interface, determining that the first focusing distance is greater than or equal to the preset threshold.
6. The method according to any one of claims 1-5, characterized in that, the step of adjusting the focusing distance until the second preview image is obtained comprises the following steps: adjusting the first focusing distance by the preset step size to obtain a second focusing distance; obtaining a candidate preview image of the two-dimensional code based on the second focusing distance obtained each time until the identification of the two-dimensional code is detected from the obtained candidate preview image, and the candidate preview image includes the content of the two-dimensional code, the candidate preview image being determined as the second preview image; wherein the identification of the two-dimensional code is at a preset position of the candidate preview image, and the size of the identification of the two-dimensional code meets the preset size.
7. An identification device of a two-dimensional code, characterized by comprising: The application further provides a terminal device comprising a module for executing the method. The application further provides a computer program product comprising a computer program for executing the method.
8. An identification device of a two-dimensional code, characterized by comprising: comprising: a processor coupled with a memory for storing a computer program which, when invoked by the processor, causes the apparatus to perform the method of any of claims 1-6.
9. A computer-readable storage medium, characterized in that, a computer program for storing which, when run on a computer, causes the computer to perform the method of any of claims 1-6.
10. A computer program product, characterised in that, a computer program product comprising computer program code which, when run on a computer, causes the computer to implement the method of any of claims 1-6.
Citation Information
Patent Citations
Two-dimensional code recognition method and apparatus
CN107122693A
Live broadcasting picture focal length adjustment method, storage device and terminal
CN107948509A
Method and device for identifying two-dimensional code, terminal equipment and storage medium
CN109598162A