Code scanning method and electronic equipment

By operating the camera module and the ranging module in parallel in electronic devices, and directly adjusting the focal length and motor position, the problem of long focus and zoom time in traditional technology is solved, and the efficiency of scanning code recognition is improved.

CN119136050APending Publication Date: 2024-12-13HONOR DEVICE CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410996775.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2022-09-26
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

When traditional electronic devices identify target barcodes, they need to focus and zoom, resulting in slow recognition speed and long time.

Method used

By controlling the distance measurement module in parallel while turning on the camera module, the target movement parameters of the camera module are determined based on the distance measured by the distance measurement module, and the focus and motor position are directly adjusted to shorten the focus and zoom time.

Benefits of technology

It significantly shortens the process time of scanning code recognition, improves the efficiency of scanning code, and avoids recognition failure caused by too long focusing time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119136050A_ABST
    Figure CN119136050A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code scanning method which is applied to electronic equipment, the electronic equipment comprises a distance measuring module and a camera module, and the method comprises the following steps: after a first operation of a user is received, the electronic equipment starts a code scanning application in response to the first operation. And the electronic device receives a second operation of the user on the code scanning application, starts the camera module in response to the second operation, and controls the distance measurement module to measure the distance between the electronic device and the target barcode. Based on the distance between the electronic device and the target bar code, target movement parameters of the camera module are determined, and the target movement parameters comprise a target focal length when the camera module recognizes the target bar code and a target movement position of a motor located in the camera module when the camera module recognizes the target bar code. And identifying the target bar code based on the target movement parameter. According to the invention, the distance measuring module can be controlled in parallel to measure distance while the camera module is started, so that the time for the camera module to shoot the target bar code to focus and zoom is shortened, and the code scanning efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This case is a divisional application. The application number of the original application is 202211176547.8, and the original application date is September 26, 2022. The entire contents of the original application are incorporated into this application by reference. Technical Field

[0002] The embodiments of the present application relate to the field of terminal technology, and in particular to a code scanning method and an electronic device. Background Art

[0003] With the development of technology, barcodes (such as QR codes and barcodes) are everywhere in our lives. Barcodes can help us quickly complete payments, web logins, information acquisition, anti-counterfeiting and traceability, etc.

[0004] In traditional technology, when an electronic device recognizes a target barcode, it usually uses a camera module to capture a frame of the target barcode. Then, the electronic device controls the camera module to focus based on the image. After the camera module focuses, the electronic device identifies whether there is a target barcode in the focused image. If so, it automatically zooms until the target barcode is clear. Then, the clear target barcode is identified and the target page is jumped.

[0005] However, focusing and zooming will consume a certain amount of time, resulting in a slow speed for the electronic device to recognize the target barcode. Summary of the invention

[0006] The embodiment of the present application provides a code scanning method and an electronic device. When a user uses the electronic device, the time for the camera module to shoot a target barcode for focusing and zooming can be shortened, thereby shortening the process of code scanning and recognition and improving the efficiency of code scanning.

[0007] In a first aspect, an embodiment of the present application provides a code scanning method, which is applied to an electronic device, the electronic device including a ranging module and a camera module, the method comprising: receiving a first operation of a user. In response to the first operation, the electronic device starts a code scanning application. The electronic device receives a second operation of the user. In response to the second operation, the electronic device turns on the camera module and controls the ranging module to measure the distance between the electronic device and the target barcode. The electronic device determines the target movement parameters of the camera module based on the distance between the electronic device and the target barcode, the target movement parameters including the target focal length when the camera module identifies the target barcode, and the target movement position of the motor in the camera module when the camera module identifies the target barcode. The electronic device identifies the target barcode based on the target movement parameters.

[0008] In the embodiment of the present application, the distance measuring module is controlled to measure the distance at the same time as the camera module is turned on, without having to wait for the camera module to be turned on before starting the distance measuring module to measure the distance. This can shorten the time it takes for the camera module to focus and zoom on the target barcode, thereby shortening the process of scanning and identifying the barcode and improving the efficiency of scanning.

[0009] In one possible implementation, before the electronic device turns on the camera module and controls the ranging module to measure the distance between the electronic device and the target barcode, the method also includes: obtaining the package name of the code scanning application and the number of the camera module; based on the package name of the code scanning application, the code scanning application whitelist, the camera module number and the whitelist of the camera module number, determining that the electronic device is in a code scanning scenario.

[0010] In an embodiment of the present application, whether the electronic device is in a code scanning scenario is determined based on the package name of the code scanning application and the number of the camera module, which can avoid abnormal code scanning startup caused by misoperation in a non-code scanning scenario.

[0011] In one possible implementation, determining that the electronic device is in a code scanning scenario includes: if the package name of the code scanning application is in a preset code scanning application whitelist, and the camera module number is in the whitelist of camera module numbers, the electronic device is in the code scanning scenario.

[0012] In the embodiment of the present application, when two conditions are met together, it can be determined that the electronic device is in a code scanning scenario to avoid abnormal code scanning caused by misoperation.

[0013] In a possible implementation, the distance measurement module includes a time-of-flight TOF lens module; controlling the distance measurement module to measure the distance between the electronic device and the target barcode includes: the electronic device controls the TOF lens module to measure the distance between the electronic device and the target barcode.

[0014] In the embodiment of the present application, the TOF lens module can be used to obtain the distance between the electronic device and the target barcode even in poor ambient light conditions, thereby providing a data basis for subsequently determining the target movement parameters of the camera module based on the distance.

[0015] In one possible implementation, the target movement parameters of the camera module are determined based on the distance between the electronic device and the target barcode, including: based on a first corresponding relationship and the distance between the electronic device and the target barcode, determining the target movement position of the motor when the camera module identifies the target barcode, the first corresponding relationship being the corresponding relationship between the motor position parameters and the shooting distance.

[0016] The embodiment of the present application can directly and accurately determine the optimal position of the focus motor when the camera module is in clear focus, and then when scanning and shooting the code subsequently, the focus motor can be adjusted to the optimal position first, and then the target barcode can be photographed to directly obtain a clearly focused target barcode image, thereby shortening the focusing time.

[0017] In one possible implementation, the target movement parameters of the camera module are determined based on the distance between the electronic device and the target barcode, and the method also includes: determining the target focal length of the camera module when identifying the target barcode based on a second corresponding relationship and the distance between the electronic device and the target barcode, wherein the second corresponding relationship is the corresponding relationship between the zoom ratio and the shooting distance.

[0018] The embodiments of the present application can directly and accurately determine the target focal length of the camera module when zooming in to obtain a relatively clear and appropriately sized target barcode. That is to say, before shooting the target barcode, the target focal length can be determined, so that when shooting the target barcode, the camera module can directly obtain an enlarged or reduced image of the target barcode, so that the electronic device can quickly identify the target barcode.

[0019] In a possible implementation, the electronic device determines the target movement parameters of the camera module based on the distance between the electronic device and the target barcode, and also includes: determining the target focal length based on the distance between the electronic device and the target barcode and a preset object distance.

[0020] The embodiment of the present application can directly determine the target focal length of the camera module when zooming in to obtain a relatively clear and appropriately sized target barcode, so that when the camera module shoots the target barcode, it can directly obtain an enlarged or reduced image of the target barcode, so that the electronic device can quickly identify the target barcode.

[0021] In a possible implementation, the preset object distance includes a first object distance and a second object distance, and the first object distance is less than the second object distance. The electronic device determines the target movement parameters of the camera module based on the distance between the electronic device and the target barcode, including: if the distance between the electronic device and the target barcode is less than the first object distance, the first focal length is used as the target focal length. If the distance between the electronic device and the target barcode is greater than or equal to the first object distance and less than the second object distance, the second focal length is used as the target focal length. If the distance between the electronic device and the target barcode is greater than the second object distance, the third focal length is used as the target focal length, and the second focal length is greater than the first focal length and less than the third focal length.

[0022] The embodiment of the present application can determine the corresponding preset different target focal lengths according to the measured distance to adapt to the target focal lengths corresponding to different object distances to achieve a better zoom effect, so that the electronic device can quickly identify the target barcode.

[0023] In one possible implementation, the electronic device identifies the target barcode based on the target movement parameters, including: the electronic device controls the camera module to adjust the initial focal length to the target focal length, and after adjusting the motor from the initial position to the target movement position, controls the camera module to collect the target barcode; the electronic device identifies the target barcode.

[0024] In the embodiment of the present application, the focusing and zooming processes are omitted, so as to avoid as much as possible the situation where the QR code cannot be recognized due to the focusing time being too long or the distance between the target barcode and the terminal being too long and the image of the target barcode being taken being too small.

[0025] In a second aspect, an embodiment of the present application provides a code scanning device, which is applied to an electronic device, and the electronic device includes a distance measurement module and a camera module. The code scanning device includes: a first operation receiving module, which is used to receive a first operation of a user. A first response module, which is used to start a code scanning application by the electronic device in response to the first operation. A second operation receiving module, which is used to receive a second operation of the user. A second response module, which is used to turn on the camera module by the electronic device in response to the second operation, and control the distance measurement module to measure the distance between the electronic device and the target barcode. A first determination module, which is used to determine the target movement parameters of the camera module based on the distance between the electronic device and the target barcode, and the target movement parameters include the target focal length when the camera module recognizes the target barcode, and the target movement position of the motor in the camera module when the camera module recognizes the target barcode. An identification module, which is used to identify the target barcode based on the target movement parameters.

[0026] The barcode scanning device provided in the embodiment of the present application controls the distance measuring module to measure the distance in parallel while turning on the camera module, without having to wait for the camera module to be turned on before starting the distance measuring module to measure the distance. This can shorten the time it takes for the camera module to focus and zoom on the target barcode, thereby shortening the process of barcode scanning and recognition and improving the efficiency of barcode scanning.

[0027] In a third aspect, an embodiment of the present application provides an electronic device, the electronic device comprising: a processor, a ranging module and a camera module. The processor is used to call a computer program in a memory to execute some or all steps of the code scanning method in the first aspect and various possible implementations of the first aspect.

[0028] In a fourth aspect, the present application provides a computer storage medium, which stores instructions. When the instructions are executed on a computer, the computer executes part or all of the steps of the code scanning method in the first aspect and various possible implementations of the first aspect.

[0029] In a fifth aspect, the present application provides a computer program product, which, when running on a computer, enables the computer to execute part or all of the steps of the code scanning method in the first aspect and various possible implementation methods of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0031] Figure 1 A schematic diagram showing the hardware structure of an electronic device according to an embodiment of the present application;

[0032] Figure 2 A scene diagram for identifying a two-dimensional code shown in an embodiment of the present application;

[0033] Figure 3 A schematic diagram of the appearance of an electronic device shown in an embodiment of the present application;

[0034] Figure 4 It is the target barcode page image obtained by the traditional barcode scanning method;

[0035] Figure 5 A schematic diagram of a traffic application QR code shown in an embodiment of the present application;

[0036] Figure 6 A schematic diagram of the appearance of another electronic device in a folded state shown in an embodiment of the present application;

[0037] Figure 7 This is a schematic diagram of the appearance of another electronic device in an unfolded state shown in an embodiment of the present application;

[0038] Figure 8 A schematic diagram of a code scanning application interface shown in an embodiment of the present application;

[0039] Fig. 9 is a software structure block diagram of an electronic device shown in an embodiment of the present application;

[0040] Fig.10 This is a flowchart of a code scanning method according to an embodiment of the present application;

[0041] Fig.11 A schematic diagram of obtaining a first operation shown in an embodiment of the present application;

[0042] Fig.12 A schematic diagram of obtaining a second operation shown in an embodiment of the present application;

[0043] Fig.13A schematic diagram of an electronic device measuring the distance of a target barcode shown in an embodiment of the present application;

[0044] Fig.14 A schematic diagram of motor position parameters in a camera module shown in an embodiment of the present application;

[0045] Fig.15 A schematic diagram of a code scanning device shown in an embodiment of the present application;

[0046] Fig.16 A schematic diagram of another electronic device shown in an embodiment of the present application;

[0047] Fig.17 A schematic diagram of a computer storage medium corresponding to an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION

[0048] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present application, the technical solutions in the embodiments of the present application are described in detail below in conjunction with the accompanying drawings.

[0049] The terms used in the following embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to be used as limitations on the embodiments of the present application. As used in the specification and the appended claims of the embodiments of the present application, the singular expressions "one", "a kind of", "described", "above", "the" and "this" are intended to also include plural expressions, unless there is a clear contrary indication in its context. It should also be understood that although the terms first, second, etc. may be used to describe a certain class of objects in the following embodiments, the objects should not be limited to these terms. These terms are only used to distinguish the specific objects of the class of objects. For example, the terms first, second, etc. may be used to describe the acquisition module in the following embodiments, but the acquisition module should not be limited to these terms. These terms are only used to distinguish different acquisition modules. The same is true for other classes of objects that may be described in the following embodiments using the terms first, second, etc., and will not be repeated here.

[0050] Figure 1 A schematic diagram of the hardware structure of an electronic device shown in an embodiment of the present application.

[0051] It should be noted that the electronic device 100 of the embodiment of the present application can be a mobile phone, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) device, a virtual reality (VR) device, an artificial intelligence (AI) device, a wearable device, a vehicle-mounted device, a smart home device and / or a smart city device, etc. The embodiment of the present application does not impose any special restrictions on the specific type of the electronic device 100.

[0052] Reference Figure 1 As shown, exemplarily, the electronic device 100 may include a processor 101, a memory 102, a wireless communication module 103, a mobile communication module 104, an antenna 103A, an antenna 104A, a power switch 105, a sensor module 106, a focus motor 107, a camera 108, a display screen 109, etc. Among them, the sensor module 106 may include a gyroscope sensor 106A, an acceleration sensor 106B, an ambient light sensor 106C, an image sensor 106D, a distance sensor 106E, etc. Among them, the wireless communication module 103 may include a WLAN communication module, a Bluetooth communication module, etc. The above multiple parts can transmit data through a bus.

[0053] The processor 101 may include one or more processing units. Different processing units may be independent devices or integrated into one or more processors. In some examples, the processor 110 may include, but is not limited to, at least one of an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and a neural-network processing unit (NPU).

[0054] The memory 102 may be used to store computer executable program codes, and the executable program codes may include instructions. The processor 101 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the memory 102. The memory 102 may include a program storage area and a data storage area. In a specific implementation, the memory 902 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more disk storage devices, flash memory devices, or other non-volatile solid-state storage devices.

[0055] The wireless communication function of the electronic device 100 can be implemented through the antenna 103A, the antenna 104A, the mobile communication module 104, the wireless communication module 103, the modem processor and the baseband processor.

[0056] Antenna 103A and antenna 104A can be used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of the antennas.

[0057] The mobile communication module 104 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 can include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves through the antenna 104A, and filter, amplify, etc. the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 104 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 104A.

[0058] The modulation and demodulation processor may include a modulator and a demodulator. The modulator is used to modulate the low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is transmitted to the application processor. The application processor outputs a sound signal through an audio device, or displays an image or video through the display screen 109.

[0059] The wireless communication module 103 can provide wireless communication solutions including wireless local area networks (WLAN), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 103 receives electromagnetic waves via the antenna 103A, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 101. The wireless communication module 103 can also receive the signal to be sent from the processor 101, modulate the frequency of the signal, amplify it, and convert it into electromagnetic waves for radiation through the antenna 103A.

[0060] The power switch 105 may be used to control the supply of power to the electronic device 100 .

[0061] The gyro sensor 106A can be used to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., x, y, and z axes) can be determined by the gyro sensor 106A. The gyro sensor 106A can be used for anti-shake shooting. For example, when the shutter is pressed, the gyro sensor 106A detects the angle of the electronic device 100 shaking, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to offset the shaking of the electronic device 100 through reverse movement to achieve anti-shake. The gyro sensor 106A can also be used for navigation and somatosensory game scenes.

[0062] The acceleration sensor 106B can detect the magnitude of the acceleration of the electronic device 100 in various directions (generally three axes). When the electronic device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the electronic device 100. For example, the acceleration sensor 106B can be applied to applications such as horizontal and vertical screen switching and pedometers.

[0063] The ambient light sensor 106C is used to sense the brightness of the ambient light. The electronic device 100 can adaptively adjust the brightness of the display screen 109 according to the perceived brightness of the ambient light. The ambient light sensor 106C can also be used to automatically adjust the white balance when taking pictures. The image sensor 106D, also known as a photosensitive element, can utilize the photoelectric conversion function of the photoelectric device to convert the light image on the photosensitive surface into an electrical signal that is proportional to the light image. The image sensor can be a charge coupled device (CCD) sensor or a complementary metal oxide semiconductor (CMOS) sensor.

[0064] The distance sensor 106E can be used to measure the distance. The electronic device 100 can measure the distance by infrared or laser. In some shooting scenarios, the electronic device 100 can use the distance sensor 106E to measure the distance to achieve fast focusing.

[0065] The focus motor 107 can be used for fast focusing. The electronic device 100 can control the movement of the lens through the focus motor 107 to achieve automatic focusing.

[0066] The electronic device 100 can realize the shooting function through the ISP, the camera 108, the video codec, the GPU, the display screen 109 and the application processor.

[0067] The ISP is used to process the data fed back by the camera module 108. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera sensor through the lens. The light signal is converted into an electrical signal, and the camera sensor transmits the electrical signal to the ISP for processing and converts it into an image visible to the naked eye. The ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. The ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, the ISP can be set in the camera module 108.

[0068] The camera module 108 can be used to capture still images or videos. The object generates an optical image through the lens and projects it onto the image sensor. The image sensor can convert the optical signal into an electrical signal, and then transmit the electrical signal to the ISP to convert it into a digital image signal. The ISP can output 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.

[0069] The video codec is used to compress or decompress digital images. The electronic device 100 may support one or more video codecs. In this way, the electronic device 100 can open or save pictures or videos in multiple coding formats.

[0070] The electronic device 100 can realize the display function through a GPU, a display screen 109, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 109 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 101 may include one or more GPUs, which execute program instructions to generate or change display information.

[0071] The display screen 109 is used to display images, videos, etc. The display screen 109 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light emitting diode or an active-matrix organic light emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 109, where N is a positive integer greater than 1.

[0072] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0073] For example, Figure 2 A scene diagram for identifying a two-dimensional code shown in an embodiment of the present application. Figure 3 This is a schematic diagram of the appearance of an electronic device 100 shown in an embodiment of the present application. Figure 2 As shown, in Figure 2In the illustrated scenario, there is a target barcode 201 and an electronic device 100. Among them, the electronic device 100 may include a page 210 displaying application icons. Among them, the page 210 may include multiple application icons (for example, a code scanning application icon 211, a setting application icon 212, a payment application icon 213, a communication application icon 214, etc.). Optionally, the top of the page 210 on which the application icons are placed also displays a status bar, which may include information such as a strength indicator of the communication signal, a power value, and time. Further optionally, there may be a tray (dock) area below the page 210, and the dock area may include one or more tray icons (for example, a dialing application icon 215, a message application icon 216, a shooting application icon 217, etc.), and one or more tray icons in the dock area may remain displayed when the page is switched.

[0074] In the embodiment of the present application, the target barcode may include but is not limited to any one of a one-dimensional barcode, a two-dimensional barcode, and a three-dimensional barcode. The target barcode may use a number of geometric shapes corresponding to binary to represent textual numerical information. The barcode scanning process may be interpreted as the process from when the electronic device 100 receives a barcode scanning input for a barcode scanning application to when the barcode in the image captured by the camera module is parsed to obtain the information represented by the barcode.

[0075] Figure 4 This is the target barcode page image obtained by the traditional barcode scanning method. Figure 4 As shown, after the electronic device 100 receives a scan code input request for a scan code application, in response to the user's scan code operation, the camera module of the electronic device 100 acquires a frame of initial image. Then, based on the initial image, the electronic device 100 can drive the focus motor to oscillate and converge in an anti-phase focusing manner to determine the optimal motor drive position. The electronic device 100 achieves focusing by rotating the focus motor to the optimal motor drive position, and determines whether there is a QR code in the initial image after focusing is completed. If a QR code exists, zooming is performed to obtain a clearer target barcode image. Then, recognition is performed based on the target barcode image, and jumps to the following example. Figure 5 Schematic diagram of the transportation application QR code shown.

[0076] In the above-mentioned traditional barcode scanning usage scenario, the camera module in the electronic device 100 is required to first capture an initial image of the target barcode, and then focus according to the parameter information of the initial image. However, since the target barcode is too far away from the electronic device 100, the captured initial image is small, which increases the difficulty of focusing and the time required for QR code recognition. In addition, due to the long focusing time, the electronic device 100 may believe that there is no QR code in the code scanning interface, and thus the zoom function cannot be triggered, resulting in failure to recognize the QR code.

[0077] In order to solve the above problems, an embodiment of the present application provides a method for scanning a code. After receiving an input instruction for a code scanning application, the electronic device 100 can control the distance measurement module to measure the distance between the electronic device 100 and the target barcode, and at the same time, control the camera module for collecting the target barcode to be turned on. Before the camera module is fully started, the electronic device 100 can calculate the target movement parameters that need to be configured for the camera module based on the distance between the electronic device and the target barcode. Then, after controlling the camera module to configure the target movement parameters, the target barcode is photographed and collected. The electronic device 100 identifies the target barcode in the collected image.

[0078] Compared with the traditional technology, after the camera module shoots a frame of image, the reverse focusing method based on the image oscillates and converges until the focus is completed, and then the target barcode in the focused image is identified. This application does not need to find the target moving position, but is based on the distance measurement module to quickly calculate the target moving position, so that the camera module is configured according to the target moving position, and directly shoots a clear target barcode, which can greatly improve the focusing speed and shorten the process of scanning and identifying the code, and improve the efficiency of scanning. And it is also possible to determine the target moving parameters related to zoom based on the distance measured by the distance measurement module, so that the target barcode can be quickly identified in the case of fast focusing during the scanning process. At the same time, try to avoid focusing failure caused by too long focusing time, or the failure of zooming due to the target barcode being too far away, resulting in the inability to identify the barcode, and then triggering the manual zooming, resulting in a long time to identify the target barcode.

[0079] The following describes the code scanning scenario provided in the embodiments of the present application.

[0080] Reference Figure 2 As shown, the electronic device may receive a user input (such as a single click) for the code scanning application icon 211, and in response to the input, the electronic device obtains the code scanning parameter information of the code scanning application and sends it to the code scanning scene determination module to determine whether the current scene is a code scanning scene.

[0081] When it is determined that the electronic device is in a code scanning scenario, control Figure 3 The corresponding camera module 31 in the electronic device is turned on, and controls the distance measuring module 32 to measure the distance between the target barcode 201 and the electronic device. When using the code scanning method of the embodiment of the present application, the camera module 31 and the distance measuring module 32 shoot in the same direction.

[0082] Figure 6 FIG. 1 is a schematic diagram of the appearance of another electronic device in a folded state shown in an embodiment of the present application. Figure 6As shown, for example, if the electronic device is a folding screen mobile phone, the distance measuring module 32 can be arranged on the back side of the A screen component on the electronic device, and the camera module 31 is arranged on the back side of the B screen component. When the folding screen mobile phone is in the folded state, the screen of the A screen component is in contact with the screen of the B screen component, and the shooting direction a of the distance measuring module is opposite to the shooting direction b of the camera module.

[0083] Figure 7 FIG. 1 is a schematic diagram of the appearance of another electronic device in an unfolded state shown in an embodiment of the present application. Figure 7 As shown, when the foldable screen mobile phone is in the unfolded state, the screen of the A screen component and the screen of the B screen component are located in the same extension direction. At this time, the ranging module 32 and the camera module 31 have the same shooting direction. Among them, the ranging module 32 can include any one of a TOF lens module, an infrared laser rangefinder, a binocular vision ranging module, etc., which is not limited here.

[0084] Generally speaking, in Figure 7 In the electronic device shown, the distance measuring module and the camera module have the same shooting direction, and the electronic device of the embodiment of the present application can recognize the target barcode. Figure 6 In the electronic device shown, since the shooting direction of the distance measuring module is opposite to the shooting direction of the camera module, the electronic device of the embodiment of the present application cannot recognize the target barcode.

[0085] Figure 8 This is a schematic diagram of a code scanning application interface shown in an embodiment of the present application. Figure 4-Figure 8 As shown, after the electronic device obtains the distance between the target barcode 201 and the electronic device, the target movement parameter of the camera module can be determined. For example, after the lens in the camera module is controlled to move to the target movement position, the electronic device controls the camera module to shoot the target barcode, and obtains the following Figure 8 The barcode scanning application interface shown includes a clear target barcode.

[0086] It should be noted that, since the motor position parameters and zoom ratio for clear focus have been determined based on the distance between the target barcode and the electronic device, the camera module can directly obtain the following information when shooting the target barcode: Figure 8 The display interface shown in FIG. 1 shows a zoomed and clear QR code directly in the display area of ​​the electronic device. In the traditional code scanning method, the electronic device needs to shoot the target barcode and obtain the following information: Figure 4The initial image in the display interface of the electronic device shown, obviously, the initial image only occupies a small area in the center of the display area, therefore, it is necessary to repeatedly oscillate and converge to determine the optimal motor drive position based on the initial image taken, and then achieve focus, and after the focus is completed, zoom the initial image to obtain the zoomed image. Obviously, the code scanning method of the embodiment of the present application can shorten the time of zooming and focusing, and thus can quickly realize the code scanning function.

[0087] Fig. 9 It is a software structure block diagram of an electronic device shown in an embodiment of the present application. The method can be applied to electronic devices. The layered architecture divides the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. Taking the Android system as an example, in some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the Android runtime (Android runtime) and the system library, and the kernel layer.

[0088] The application layer may include a series of application packages. Fig. 9 As shown, the application package may include applications such as camera, gallery, call, navigation, Bluetooth, music, video, short message, etc.

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

[0090] like Fig. 9 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.

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

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

[0093] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.

[0094] The phone manager is used to provide communication functions for electronic devices, such as the management of call status (including answering, hanging up, etc.).

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

[0096] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.

[0097] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.

[0098] The core library consists of two parts: one is the function that the Java language needs to call, and the other is the core library of the system. The system can include Android, IOS, Hongmeng, etc., which are not limited here.

[0099] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection. In an embodiment of the present application, the application layer is used to receive the user's second operation and determine whether the electronic device is in a code scanning scenario. It is also used to display the recognition result of the target barcode.

[0100] The system layer includes multiple functional modules. For example: surface manager, media libraries, 3D graphics processing library (for example: OpenGL ES), 2D graphics engine (for example: SGL), etc. In the embodiment of the present application, it is used to receive a first operation of the user and start the code scanning application in response to the first operation. When the code scanning scene is determined, the ranging module is controlled to measure the distance between the electronic device and the target barcode, and the camera module is turned on. And based on the distance between the electronic device and the target barcode, the target movement parameter of the camera module is determined. It is also used to identify the target barcode after acquiring the image taken by the camera module.

[0101] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.

[0102] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0103] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0104] A 2D graphics engine is a drawing engine for 2D drawings.

[0105] The kernel layer is a layer between hardware and software. The kernel layer includes at least a display driver, a camera driver, an audio driver, and a sensor driver. In the embodiment of the present application, the kernel layer is used to control the camera driver to work according to the target movement parameters determined by the system layer, and control the camera module to shoot the target barcode.

[0106] Fig. 9 The software system shown involves a program for the code scanning method (such as a core library), an application module (such as a notification manager) and an application framework that provide the code scanning method, as well as a WLAN service, and a kernel and underlying layer that provide WLAN capabilities and basic communication protocols.

[0107] The code scanning scenario shown above is only one of the application scenarios of the code scanning method in the embodiment of the present application in actual application. The code scanning scenario in the embodiment of the present application can also be applied to scenarios for scanning codes in different scenarios such as payment, web page login, etc., and is not limited here.

[0108] In order to better understand the code scanning method provided by this application, the specific implementation process and algorithm are introduced from the implementation level below.

[0109] Fig.10 Flowchart of the code scanning method shown in the embodiment of the present application. It should be noted that the code scanning method in the embodiment of the present application is applicable to an electronic device equipped with a code scanning application, and including a ranging module and a camera module for collecting target barcodes. The present application can be applicable to payment scenarios in real life when users make payments, scenarios where health codes are scanned when entering different places, scenarios where parking lots are self-serviced, and scenarios where tally clerks scan codes when entering and recording goods, etc., without limitation here.

[0110] In the specific implementation process, the code scanning method shown in this application includes steps S101-S106:

[0111] S101, the electronic device receives a first operation from a user.

[0112] The first operation is an operation in which a user triggers the running of an application based on the display interface of the electronic device. The operation of triggering the application may be a user triggering the application by a key selection, a touch selection, a voice selection, etc., which is not limited here. Fig.11 As shown, the user clicks on the payment application on the display interface.

[0113] S102, in response to the first operation, the electronic device starts a code scanning application.

[0114] Specifically, after receiving the first operation of the user, in response to the first operation, the electronic device starts the code scanning application and jumps to the application display interface. Fig.12 The application display interface may include multiple functional modules.

[0115] S103: The electronic device receives a second operation by the user.

[0116] The second operation is triggered by the user based on the application interface to scan the second operation of the code. The second operation of scanning the code can be triggered by the user through key selection, touch selection, voice selection, etc.

[0117] For example, the user can click on Fig.12 The scan function module shown in , and then the second operation of the electronic device user.

[0118] S104, in response to the second operation, the electronic device turns on the camera module and controls the distance measurement module to measure the distance between the electronic device and the target barcode.

[0119] Specifically, the electronic device receives an input from a user to turn on the code scanning function (for example, Figure 2 After the second operation of the code scanning application icon in the code scanning application, the code scanning application can send the parameter information of the code scanning application to the code scanning scene determination module of the hardware abstraction layer through the camera module function interface of the application framework layer. The code scanning scene determination module obtains the scene parameter information of the code scanning application, and then obtains the preset parameter list stored in the memory. The electronic device can then determine whether the parameter information of the code scanning application exists in the preset parameter list, and if the parameter information of the code scanning application exists in the preset parameter list, determine that the electronic device is in the code scanning scene.

[0120] It should be noted that the scene parameter information of the code scanning application may include the package name of the code scanning application, the name of the active component, the calling camera module number, etc., which are not limited here. Among them, the package name in the embodiment of the present application is the unique identifier of the application, and one package name represents one application. For example, the package name is com.wechat.mm. The electronic device may include multiple camera modules, including a front camera module, a rear camera module, a wide-angle camera module, etc., and each camera module corresponds to a number.

[0121] The preset parameter list stores the package names of all applications that provide the code scanning function and a white list of all camera module numbers that can implement the code scanning function.

[0122] As an optional implementation, before the electronic device turns on the camera module in step S104 and controls the distance measuring module to measure the distance between the electronic device and the target barcode, the code scanning method further includes:

[0123] S1042, obtaining the package name of the code scanning application and the number of the camera module.

[0124] S1044, based on the package name of the code scanning application, the preset code scanning application whitelist, the number of the camera module and the whitelist of camera module numbers, determine whether the electronic device is in a code scanning scenario.

[0125] Specifically, after receiving the user's code scanning input, the package name of the corresponding code scanning application and the number of the camera module can be obtained, and then the electronic device can obtain the preset code scanning application whitelist and the camera module number whitelist stored in the memory. The electronic device scans the preset code scanning application whitelist, and then it can be determined whether the package name of the code scanning application exists in the preset code scanning application whitelist. The electronic device compares the obtained camera module number with the whitelist of camera module numbers to determine whether the camera module number exists in the whitelist of camera module numbers. If the package name of the code scanning application is in the preset code scanning application whitelist and the camera module number is in the whitelist of camera module numbers, it is determined that the electronic device is in the code scanning scene.

[0126] For example, when the package name of the corresponding code scanning application is com.WeChat.mm, and the camera module is a rear camera, its number is camera ID-01. The preset code scanning application whitelist may include: com.WeChat.mm; com.alipay.mm; com.tencent.mm; com.honorpay.mm, etc. And the whitelist of camera module numbers may include: camera ID-01, camera ID-02, camera ID-03. Among them, camera ID-02 can correspond to a wide-angle camera module, and camera ID-03 corresponds to a large aperture camera module. At this time, the package name of the code scanning application exists in the preset code scanning application whitelist, and the camera module number corresponds to the whitelist of camera module numbers, then it can be determined that the electronic device is in a code scanning scene.

[0127] It should be noted that if the package name of the code scanning application is in the preset code scanning application whitelist, but the camera module number does not correspond to the camera module number whitelist, the electronic device is not in the code scanning scene. If the camera module number corresponds to the camera module number whitelist, and the package name of the code scanning application is not in the preset code scanning application whitelist, the electronic device is not in the code scanning scene. When the electronic device is not in the code scanning scene, the step of turning on the camera module and controlling the ranging module to perform ranging is not executed.

[0128] In an embodiment of the present application, by comparing the package name of the code scanning application with a preset whitelist of code scanning applications, and comparing the number of the camera module with a whitelist of camera module numbers, when it is determined that the code scanning application can scan codes and can use the preset camera module for scanning codes, the electronic device is considered to be in a code scanning scenario to perform subsequent code scanning tasks.

[0129] As an optional implementation method, after determining that the electronic device processes the barcode scanning scenario, the camera module can be turned on and the distance measurement module can be controlled to measure the distance between the electronic device and the target barcode.

[0130] Specifically, when the electronic device is determined to be in a code scanning scenario, it can control the camera module to start up and configure the initial lens parameter information corresponding to the code scanning application to the camera module. While the electronic device controls the camera module to start up, the electronic device controls the distance measurement module to measure the distance between the electronic device and the target barcode.

[0131] For example, Fig.13 This is a schematic diagram of an electronic device measuring the distance of a target barcode shown in an embodiment of the present application. Fig.13As shown, taking the distance measurement module 32 as a time of flight (TOF) lens module as an example, the electronic device can control the TOF lens module to measure the distance d between the electronic device and the target barcode in the shooting direction c of the camera module 31 .

[0132] It should be noted that the distance measurement principle of the TOF lens module is to continuously send modulated high-frequency infrared light pulses to the target through the TOF lens module, and then use the sensor to receive the light returned from the object, and obtain the distance of the target object by detecting the flight (round-trip) time of the light pulse. Since TOF distance measurement is not affected by ambient light, it can obtain the distance d between the electronic device and the target barcode even in poor ambient light conditions, and thus provide a data basis for the subsequent determination of the target movement parameters of the camera module based on the distance.

[0133] S105, the electronic device determines a target movement parameter of the camera module based on the distance between the electronic device and the target barcode.

[0134] The target movement parameters include the target focal length when the camera module recognizes the target barcode, and the target movement position of the motor in the camera module when the camera module recognizes the target barcode. The motor drive in the camera module can be instructed to rotate to the target movement position (motor drive code value).

[0135] Specifically, after the electronic device obtains the distance d between the electronic device and the target barcode, the code value corresponding to the distance d between the electronic device and the target barcode measured by the ranging module can be determined based on the correspondence between the motor drive value (also called code value) of the motor in the camera module and the shooting distance.

[0136] As an optional implementation, the target movement parameter may include the target movement position of the motor. The specific steps of an embodiment of step 105 include:

[0137] S1052, obtaining motor position parameters and shooting distance corresponding to the camera module.

[0138] The motor position parameter is the position scale value of the camera drive motor, which is used to reflect the position of the lens in the camera module. It should be noted that the camera drive motor can be rotated to the corresponding position scale value according to the motor position parameter to achieve the movement of the lens in the camera module. The shooting distance is the object distance preset by the camera module.

[0139] Specifically, the electronic device obtains the motor position parameters and shooting distances corresponding to the camera modules stored in advance from the memory. The motor position parameters and shooting distances corresponding to different camera modules may be the same or different, and are not limited here.

[0140] S1054, based on the motor position parameter, the shooting distance, and the distance between the electronic device and the target barcode, determine the target moving position of the motor when the camera module recognizes the target barcode.

[0141] Specifically, after obtaining the motor position parameters and shooting distance, the correspondence between the motor position parameters and the shooting distance can be determined, and then the proportional relationship between the distance between the electronic device and the target barcode and the shooting distance can be determined. Based on the correspondence and proportional relationship, the target moving position of the motor when the camera module corresponding to the distance between the electronic device and the target barcode recognizes the target barcode can be determined.

[0142] In an embodiment of the present application, by determining the correspondence between the motor position parameters in the camera module and the shooting distance that are pre-stored and stored therein, the target movement position of the motor can be determined by further bringing the distance between the electronic device and the target barcode into the correspondence, and the optimal position of the motor in the camera module when the camera module is in clear focus can be directly and accurately determined. Then, when scanning and shooting the code subsequently, the motor can be adjusted to the optimal position, and then when shooting the target barcode, a clearly focused target barcode image can be directly obtained.

[0143] As an optional implementation, the specific steps of an embodiment of step S1054 include:

[0144] S1054a, obtaining a first corresponding relationship between the motor position parameter and the shooting distance.

[0145] S1054b, the distance between the electronic device and the target barcode, determines the target moving position of the motor when the camera module recognizes the target barcode.

[0146] Fig.14 FIG. 1 is a schematic diagram of motor position parameters in a camera module shown in an embodiment of the present application. Fig.14 As shown, exemplarily, the motor position parameter of the focus motor in the camera module can be set to a minimum value of 100code and a maximum value of 900code, and the shooting distance can be set to a minimum value of 5cm and a maximum value of 5m. Among them, if the motor position parameter is 100code, at this time, the lens A can be located at the near focus, corresponding to a shooting distance of 5cm. If the motor position parameter is 900code, at this time, the lens A is located at the far focus, corresponding to a shooting distance of 5m. 100code-900code and 5cm-5m can be divided into a one-to-one linear relationship according to a preset step size. When the distance between the acquired electronic device and the target barcode is 2m, it can be determined that 2 / (5+500)=0.396, and then (900-100)*0.396+100=416.8. The target moving position of the motor is determined to be 416.8code.

[0147] It should be noted that the motor position parameters can generally be set to 0-1023 code. However, since the motor position parameters corresponding to the nearest point (near focus) and the farthest point (far focus) of the lens position parameters cannot be completely pushed to 0 code and 1023 code, the motor position parameters of the near focus position are usually 100 code, and the motor position parameters of the far focus position are 900 code.

[0148] Generally speaking, if the current motor position parameter is 100 code, the image captured is too large, and the camera motor can be further controlled to move to 0 code. If the current motor position parameter is 900 code, if the image captured is still too small, the camera motor can be further driven to move to 1023 code, and there is no restriction here.

[0149] The above setting of the motor position parameter is only a feasible embodiment, and the setting of the motor position parameter can also be adaptively set according to specific circumstances, which is not limited here. In addition, the relationship between the motor position parameter and the shooting distance can also be nonlinear, which is not limited here.

[0150] In an embodiment of the present application, by determining a first correspondence between a motor position parameter and a shooting distance, the target moving position of the motor is determined based on the first correspondence and the distance. Since the target moving position of the focusing motor can be directly calculated based on the first linear relationship and the distance between the electronic device and the target barcode, the electronic device can control the lens of the camera module to move to a target moving position at which clear focus can be achieved.

[0151] Compared with the traditional technology in which the camera module gradually determines the target moving position of the motor with clear focus through reverse focusing in an oscillating convergence manner, the embodiment of the present application shortens the time for determining the target moving position of the motor, thereby improving the focusing speed, so that the target barcode can be quickly identified under fast focusing during the scanning process.

[0152] The embodiment corresponding to the above steps S1052-S1054 determines the target movement position of the motor during the focusing process. In order to enable the electronic device to recognize the target barcode when the focusing is completed, the target barcode can also be zoomed on the basis of the focusing. As another optional implementation, the target movement parameter includes the target focal length. The electronic device determines the target movement parameter of the camera module based on the distance between the electronic device and the target barcode, and also includes:

[0153] S1056, obtaining a preset zoom ratio corresponding to the camera module.

[0154] The preset zoom ratio is a zoom ratio corresponding to a shooting distance in a camera module pre-stored in a memory. The preset zoom ratios corresponding to different camera modules may be the same or different. The preset zoom ratio may also be a zoom ratio corresponding to a motor position parameter in the camera module. The preset zoom ratio may also be a preset fixed zoom ratio, which is not limited here.

[0155] For example, refer to Fig.14 As shown, the preset zoom ratio of the camera module can correspond to the shooting distance. For example, if the shooting distance is 5cm-5m, if the shooting distance is 5cm, the corresponding preset zoom ratio is 1.7 times, and if the shooting distance is 5m, the corresponding preset zoom ratio is 2 times.

[0156] As another example, refer to Fig.14 As shown, if the preset zoom ratio corresponds to the motor position parameter in the camera module, for example, when the shooting distance is 5cm, the preset zoom ratio can be set to 1.7 times, and when the shooting distance is 5m, the preset zoom ratio can be set to 2 times.

[0157] S1058, determining a target focal length when the camera module recognizes the target barcode based on a preset zoom ratio, a shooting distance, and a distance between the electronic device and the target barcode.

[0158] Specifically, after obtaining the preset zoom ratio and shooting distance, the linear relationship between the preset zoom ratio and the shooting distance can be determined, and then the proportional relationship between the distance between the electronic device and the target barcode and the shooting distance can be determined. Based on the linear relationship and the proportional relationship, the target moving position of the motor when the camera module corresponding to the distance between the electronic device and the target barcode recognizes the target barcode is determined.

[0159] It should be noted that the relationship between the preset zoom ratio and the shooting distance may also be non-linear, which is not limited here.

[0160] In the embodiment of the present application, by determining the correspondence between the zoom ratio and the shooting distance pre-stored and stored in the camera module, the distance between the electronic device and the target barcode can be further brought into the correspondence to determine the target focal length when the camera module identifies the target barcode, and the target barcode with clear focus and appropriate size of the camera module can be directly and accurately determined. Compared with the traditional technology, the focus is automatically adjusted after the first frame image is focused, or when the automatic zoom is not possible, the focused image needs to be manually zoomed, the electronic device of the embodiment of the present application can adjust the zoom ratio to the target focal length, and when shooting the target barcode, directly obtain the image after the target barcode is enlarged or reduced, so that the electronic device can quickly identify the target barcode, shortening the time for the electronic device to identify the target barcode.

[0161] As one of the optional implementations, the specific steps of an embodiment of step S1058 include:

[0162] S1058a, obtaining a second corresponding relationship between a preset zoom ratio and a shooting distance.

[0163] S1058b, based on the second corresponding relationship and the distance between the electronic device and the target barcode, determine the target focal length when the camera module recognizes the target barcode.

[0164] For example, Fig.12 As shown, the shooting distance in the camera module is set to 5cm-5m, and the preset zoom ratio is 1.5x-2x. Among them, the shooting distance of 5cm corresponds to the preset zoom ratio of 1.5x. The shooting distance of 5m corresponds to the preset zoom ratio of 2x. 5cm-5m and 1.5x-2x can be divided into a one-to-one linear relationship according to the preset step size. When the distance between the acquired electronic device and the target barcode is 2m, it can be determined that 2 / (5+500)=0.396, and then (2-1.5)*0.396+1.5=1.698. It is determined that the target focal length when the camera module recognizes the target barcode is 1.698 times.

[0165] In this embodiment, by determining the second corresponding relationship between the preset zoom ratio and the shooting distance, since the target focal length of the camera module can be directly calculated according to the second corresponding relationship and the distance between the electronic device and the target barcode, the target barcode can be directly photographed by the camera module according to the target focal length, and the target barcode image can be directly obtained after being enlarged or reduced so that the electronic device can quickly identify it. Compared with the traditional technology, it is necessary to focus first, identify the target barcode when the focus is clear, and then zoom when the target barcode is identified. There is no need to zoom based on the focus result, and the target barcode of the appropriate size can be directly photographed, and the situation where the target barcode cannot be recognized due to the target barcode being too small is avoided as much as possible.

[0166] In another optional embodiment, the specific steps of an embodiment of step S1068 include:

[0167] The target focal length is determined based on the distance between the electronic device and the target barcode and the preset object distance.

[0168] For example, the preset object distance can be a fixed object distance value, for example, the maximum shooting distance is 5m. If the distance between the electronic device and the target barcode and the preset object distance are less than 5m, the target focal length is determined to be the preset focal length, that is, the preset 1.5 times focal length.

[0169] By way of example, the preset object distance may include a first object distance and a second object distance, wherein the first object distance is smaller than the second object distance.

[0170] At this time, step 105 further includes:

[0171] Step 1055a: if the distance between the electronic device and the target barcode is less than the first object distance, the first focal length is used as the target focal length.

[0172] Step 1055b: If the distance between the electronic device and the target barcode is greater than or equal to the first object distance and less than the second object distance, the second focal length is used as the target focal length.

[0173] Step 1055c: if the distance between the electronic device and the target barcode is greater than the second object distance, the third focal length is used as the target focal length, and the second focal length is greater than the first focal length and less than the third focal length.

[0174] The first focal length, the second focal length and the third focal length are pre-stored default focal lengths, that is, default zoom ratios. The first focal length, the second focal length and the third focal length have different focal length values, and the first focal length is less than the second focal length and less than the third focal length.

[0175] For example, if the preset first object distance is 2m and the second object distance is 4m. At this time, if the distance between the electronic device and the target barcode is less than 2m, the first focal length, i.e., 1x focal length, is selected. If the distance between the electronic device and the target barcode is between 2m-4m, the second focal length, i.e., 1.5x focal length, can be selected. If the distance between the electronic device and the target barcode is greater than 4m, the third focal length, i.e., 2x focal length, is selected.

[0176] In an embodiment of the present application, by comparing the distance between the electronic device and the target barcode with the preset object distance, the corresponding preset different target focal lengths are determined to adapt to the target focal lengths corresponding to different object distances, thereby achieving a better zoom effect, so that the electronic device can quickly identify the target barcode.

[0177] S106, the electronic device identifies the target barcode based on the target movement parameters.

[0178] Specifically, when the electronic device determines the target movement parameters of the camera module, the camera module can be configured according to the target movement parameters, and then when the configuration is completed, the camera module is controlled to shoot the target barcode. Figure 8 After scanning the target barcode image shown in the figure, the target barcode in the image can be recognized and the page can be jumped to the following Figure 4 The ride page shown.

[0179] As an achievable implementation method, the specific steps of an embodiment of step S106 include:

[0180] S1062, the electronic device controls the camera module to adjust the initial focal length to the target focal length, and adjusts the motor from the initial position to the target moving position, and then controls the camera module to collect the target barcode.

[0181] S1064, the electronic device identifies the target barcode.

[0182] Specifically, the electronic device controls the camera module to adjust the initial focal length to the target focal length based on the target movement position and target focal length of the motor in the target movement parameter, and controls the motor in the camera module to rotate to the target movement position. Then the electronic device controls the camera module to shoot the target barcode, and an image of the target barcode with clear focus and enlarged or reduced to a suitable size according to a preset zoom ratio can be obtained. The electronic device recognizes the target barcode, and after successful recognition, jumps to the corresponding application page.

[0183] It should be noted that, in one example, it generally takes 200-300 milliseconds to turn on the camera module. However, the ranging module measures the distance between the electronic device and the target barcode, and the electronic device generally takes 100 milliseconds to calculate the target movement parameters. Compared with the traditional technology of determining the target movement parameters (for example, the process of motor oscillation convergence to determine the focus parameters and determine the zoom parameters), the time required is approximately 600-700 milliseconds. This significantly shortens the time to determine the target movement parameters, thereby shortening the scanning time.

[0184] In this embodiment, the electronic device can move the lens in the camera module to the target specified position according to the target moving position and the target focal length of the motor, and then capture a clear image of the target barcode with a suitable size, so as to identify the target barcode, which can shorten the time of finding the target moving position of the motor by the oscillation convergence method in the traditional technology, and at the same time avoid the situation where the two-dimensional code cannot be recognized due to the long focusing time or the long distance between the target barcode and the terminal. In addition, the embodiment of the present application captures the target barcode only after determining that the lens group of the camera module has moved to the target specified position, which is different from the traditional technology of first capturing a frame of image and then determining the clear focus position based on the image, which can reduce the loss of camera module performance.

[0185] In an embodiment of the present application, after the electronic device receives a first operation from a user, in response to the first operation, the electronic device starts a code scanning application. The electronic device receives a second operation from the user, in response to the second operation, the electronic device turns on the camera module, and controls the distance measurement module to measure the distance between the electronic device and the target barcode. The electronic device determines the target movement parameters of the camera module based on the distance between the electronic device and the target barcode, and the target movement parameters include the target focal length when the camera module identifies the target barcode, and the target movement position of the motor in the camera module when the camera module identifies the target barcode. The electronic device identifies the target barcode based on the target movement parameters. The distance measurement module can be controlled to measure the distance in parallel while the camera module is turned on, without having to wait for the camera module to be turned on before starting the distance measurement module for distance measurement, which can shorten the time for the camera module to shoot the target barcode for focusing and zooming, thereby shortening the process of code scanning and recognition, and improving the efficiency of code scanning.

[0186] Based on the same inventive concept, the embodiment of the present application also provides a code scanning device for implementing the code scanning method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more code scanning device embodiments provided below can refer to the limitations of the code scanning method above, and will not be repeated here.

[0187] Fig.15 The following is a schematic diagram of a code scanning device shown in an embodiment of the present application. In a feasible embodiment, the code scanning device is applied to an electronic device, and the electronic device includes a distance measurement module and a camera module. The code scanning device includes:

[0188] A first operation receiving module 151, configured to receive a first operation from a user;

[0189] The first response module 152 is used for starting the code scanning application by the electronic device in response to the first operation;

[0190] The second operation receiving module 153 is used to receive a second operation of the user;

[0191] The second response module 154 is used to respond to the second operation, the electronic device turns on the camera module, and controls the distance measurement module to measure the distance between the electronic device and the target barcode;

[0192] A first determination module 155 is used to determine a target movement parameter of the camera module based on the distance between the electronic device and the target barcode, the target movement parameter including a target focal length when the camera module recognizes the target barcode, and a target movement position of a motor in the camera module when the camera module recognizes the target barcode;

[0193] The recognition module 156 is used to recognize the target barcode based on the target movement parameters.

[0194] The specific limitations in the embodiments of the code scanning device of the present application can be found in the above-mentioned limitations on the code scanning method, which will not be repeated here.

[0195] In one possible implementation, the code scanning device further includes:

[0196] The first acquisition module 157 is used to obtain the package name of the code scanning application and the serial number of the camera module;

[0197] The scene determination module 158 is used to determine whether the electronic device is in a code scanning scene based on the package name of the code scanning application, the code scanning application whitelist, the camera module number and the camera module number whitelist.

[0198] In one achievable manner, the scene determination module 158 is specifically used to determine that if the package name of the code scanning application is in a preset code scanning application whitelist, and the camera module number is in the whitelist of camera module numbers, the electronic device is in a code scanning scene.

[0199] In one possible implementation, the distance measurement module includes a time-of-flight TOF lens module; the second response module 154 includes:

[0200] The distance measuring unit is used to control the TOF lens module to measure the distance between the electronic device and the target barcode.

[0201] In one practicable manner, the first determining module 155 includes:

[0202] The motor target movement position determination unit is used to determine the motor target movement position when the camera module recognizes the target barcode based on the first corresponding relationship and the distance between the electronic device and the target barcode. The first corresponding relationship is the corresponding relationship between the motor position parameter and the shooting distance.

[0203] In one practicable manner, the first determining module 155 includes:

[0204] The first target focal length determination unit is used to determine the target focal length when the camera module recognizes the target barcode based on the second corresponding relationship and the distance between the electronic device and the target barcode. The second corresponding relationship is the corresponding relationship between the zoom ratio and the shooting distance.

[0205] In one practicable manner, the first determining module 155 further includes:

[0206] The second target focal length determining unit is used to determine the target focal length based on the distance between the electronic device and the target barcode and a preset object distance.

[0207] In one achievable manner, the preset object distance includes a first object distance and a second object distance, the first object distance is smaller than the second object distance, and the second target focal length determination unit is specifically used to use the first focal length as the target focal length if the distance between the electronic device and the target barcode is smaller than the first object distance; use the second focal length as the target focal length if the distance between the electronic device and the target barcode is greater than or equal to the first object distance and smaller than the second object distance; use the third focal length as the target focal length if the distance between the electronic device and the target barcode is greater than the second object distance, and the second focal length is greater than the first focal length and smaller than the third focal length.

[0208] In one implementation, the identification module 156 includes:

[0209] The adjustment unit is used to control the camera module to adjust the initial focal length to the target focal length, and after adjusting the motor from the initial position to the target moving position, control the camera module to collect the target barcode;

[0210] The recognition unit is used to recognize the target barcode.

[0211] The specific limitations in the embodiments of the code scanning device of the present application can be found in the above-mentioned limitations on the code scanning method, which will not be repeated here.

[0212] Fig.16 This is another schematic diagram of an electronic device shown in an embodiment of the present application. In a feasible embodiment, the electronic device is Fig.16 The hardware structure shown implements the corresponding functions, such as Fig.16 As shown, the electronic device includes a processor 1401 and a memory 1402, wherein the memory stores computer program instructions. When the computer program instructions are executed by the processor 1401, the electronic device executes the steps of the method in any one of the above embodiments.

[0213] For specific implementation, see Fig.17 , Fig.17 A schematic diagram of a computer storage medium corresponding to an electronic device shown in an embodiment of the present application. Among them, the computer storage medium 1501 set in the electronic device can store a program, and when the program is executed, some or all of the steps in each embodiment of the code scanning method can be implemented. The storage medium in any device can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.

[0214] One or more of the above modules or units can be implemented by software, hardware or a combination of the two. When any of the above modules or units is implemented by software, the software exists in the form of computer program instructions and is stored in a memory, and the processor can be used to execute the program instructions and implement the above method flow. The processor may include but is not limited to at least one of the following: a central processing unit (CPU), a microprocessor, a digital signal processor (DSP), a microcontroller unit (MCU), or an artificial intelligence processor and other types of computing devices that run software, each of which may include one or more cores for executing software instructions to perform operations or processing. The processor may be built into an SoC (system on chip) or an application specific integrated circuit (ASIC), or it may be an independent semiconductor chip. In addition to the core used to execute software instructions for operations or processing in the processor, it may further include necessary hardware accelerators, such as field programmable gate arrays (FPGA), PLDs (programmable logic devices), or logic circuits that implement dedicated logic operations.

[0215] When the above modules or units are implemented in hardware, the hardware can be any one or any combination of a CPU, a microprocessor, a DSP, an MCU, an artificial intelligence processor, an ASIC, a SoC, an FPGA, a PLD, a dedicated digital circuit, a hardware accelerator or a non-integrated discrete device, which can run the necessary software or not rely on the software to execute the above method flow.

[0216] When the above modules or units are implemented using software, they can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, a computer, a server, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server, or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.

[0217] It should be understood that in various embodiments of the present application, the size of the serial number of each process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment.

[0218] It should be understood that the technical solutions shown in this application include but are not limited to application to Android systems, and may also be applied to Hongmeng or others.

[0219] Each part of this specification is described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment part.

[0220] The specific implementation methods described above further illustrate the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above description is only the specific implementation methods of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solutions of the present application should be included in the scope of protection of the present application.

Claims

1. A code scanning method, characterized in that: The method is applied to an electronic device, the electronic device includes a distance measurement module and a camera module, and the method includes: The electronic device receives a first operation from a user; In response to the first operation, the electronic device starts a code scanning application; The electronic device receives a second operation of the user on the code scanning application; In response to the second operation, the electronic device turns on the camera module and controls the distance measurement module to measure the distance between the electronic device and the target barcode; The electronic device determines the target movement parameters of the camera module based on the distance between the electronic device and the target barcode, the target movement parameters including the target focal length when the camera module recognizes the target barcode, and the target movement position of the motor in the camera module when the camera module recognizes the target barcode; The electronic device identifies the target barcode based on the target movement parameter.

2. The method according to claim 1, characterized in that Before the electronic device turns on the camera module and controls the distance measurement module to measure the distance between the electronic device and the target barcode, the method further includes: Obtain the package name of the code scanning application and the serial number of the camera module; Based on the package name of the code scanning application, the code scanning application whitelist, the number of the camera module and the whitelist of camera module numbers, it is determined that the electronic device is in a code scanning scenario.

3. The method according to claim 2, characterized in that The determining that the electronic device is in a code scanning scenario includes: If the package name of the code scanning application is in the preset code scanning application whitelist, and the number of the camera module is in the whitelist of the camera module numbers, the electronic device is in the code scanning scenario.

4. The method according to any one of claims 1 to 3, characterized in that: The ranging module includes a time-of-flight TOF lens module; The controlling the distance measuring module to measure the distance between the electronic device and the target barcode includes: The electronic device controls the TOF lens module to measure the distance between the electronic device and the target barcode.

5. The method according to any one of claims 1 to 4, characterized in that: The electronic device determines the target movement parameter of the camera module based on the distance between the electronic device and the target barcode, including: Based on a first corresponding relationship and a distance between the electronic device and the target barcode, a target moving position of the motor when the camera module recognizes the target barcode is determined, wherein the first corresponding relationship is a corresponding relationship between the motor position parameter and the shooting distance.

6. The method according to any one of claims 1 to 5, characterized in that: The electronic device determines the target movement parameter of the camera module based on the distance between the electronic device and the target barcode, and further includes: Based on a second corresponding relationship and a distance between the electronic device and the target barcode, a target focal length when the camera module recognizes the target barcode is determined, wherein the second corresponding relationship is a corresponding relationship between a zoom ratio and the shooting distance.

7. The method according to any one of claims 1 to 5, characterized in that: The electronic device determines the target movement parameter of the camera module based on the distance between the electronic device and the target barcode, and further includes: The target focal length is determined based on the distance between the electronic device and the target barcode and a preset object distance.

8. The method according to any one of claims 1 to 7, characterized in that: The preset object distance includes a first object distance and a second object distance, and the first object distance is smaller than the second object distance; the electronic device determines the target movement parameter of the camera module based on the distance between the electronic device and the target barcode, including: If the distance between the electronic device and the target barcode is less than the first object distance, the first focal length is used as the target focal length; If the distance between the electronic device and the target barcode is greater than or equal to the first object distance and less than the second object distance, the second focal length is used as the target focal length; If the distance between the electronic device and the target barcode is greater than the second object distance, the third focal length is used as the target focal length, and the second focal length is greater than the first focal length and less than the third focal length.

9. The method according to any one of claims 1 to 8, characterized in that: The electronic device identifies the target barcode based on the target movement parameter, including: The electronic device controls the camera module to adjust the initial focal length to the target focal length, and after adjusting the motor from the initial position to the target moving position, controls the camera module to capture the target barcode; The electronic device identifies the target barcode.

10. The method according to any one of claims 1 to 9, characterized in that: The second operation is a code scanning operation triggered by a user based on an application program interface of the code scanning application.

11. An electronic device, characterized in that: The electronic device comprises: a processor, a distance measurement module and a camera module, wherein the processor is used to call a computer program in a memory to execute the method according to any one of claims 1 to 10.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Laser range finding type barcode scanning device and method

    CN106682558A

  • Barcode decoding method and device for carrying out ranging and automatic focusing through laser

    CN108241813A

  • Graphics barcode scanning method, device, mobile terminal and storage medium

    CN109214225A

  • Code scanning method and device

    CN113919382A

  • Code reader

    JP2005182518A