A code scanning method and electronic device
By selectively collecting recognition frame images in electronic devices based on ambient light brightness and image quality, the problem of slow recognition code recognition in the existing technology is solved, and the code scanning efficiency and user experience are improved.
Patent Information
- Application Number
- CN202211124961.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-15
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2042-09-15
AI Technical Summary
In existing code scanning technology, differences in device load, memory, lighting environment, and image quality lead to slow identification code recognition, affecting user experience.
By collecting and identifying recognition frame images in electronic devices only when the ambient light brightness is greater than or equal to the threshold, and discarding recognition frame images with poor brightness or clarity, the number of invalid recognition frames is reduced and recognition efficiency is improved.
It improves the efficiency of QR code scanning recognition, reduces the waste of device computing resources, and improves the user's QR code scanning experience.
Smart Images

Figure CN116739014B
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal technology, and in particular to a code scanning method and electronic device. Background Art
[0002] With the popularization of smart terminals and the development and widespread application of image recognition technology, the application of code scanning scenarios has become more and more extensive. For example, when making payment transactions through payment applications, you need to scan the payment code / receipt code, when adding friends through social applications, you need to scan the personal QR code, and when entering and leaving a specific place, you need to scan the health code / pass code, etc.
[0003] Among them, the scanning speed is a factor that affects the user's scanning experience. At present, the scanning speed of the scanning image collected by the camera is slow, which makes it difficult for users to scan the code and affects the user experience.
[0004] There is currently no effective solution to the problem of slow scanning speed. Summary of the invention
[0005] The embodiments of the present application provide a code scanning method and an electronic device, which can reduce the number of invalid recognition frame images recognized by the electronic device, thereby reducing the number of threads created for recognition frame images, the memory space occupied by the recognition process, and the recognition time, thereby improving the recognition efficiency.
[0006] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0007] In a first aspect, the present application provides a code scanning method, which can be applied to an electronic device, wherein the electronic device includes a camera, and the method includes: the electronic device displays a code scanning interface. Then, an identification frame image and a preview frame image are obtained, and the identification frame image and the preview frame image are obtained by processing the code scanning image captured by the camera. The electronic device displays the preview frame image on the code scanning interface. If the ambient light brightness of the identification frame image is greater than or equal to a threshold value, the electronic device performs code scanning on the identification frame image to determine the code scanning recognition result.
[0008] In the present application, the electronic device does not recognize the recognition frame images collected when the ambient light brightness is less than the preset value, and only recognizes the recognition frame images collected when the ambient light brightness is greater than the preset value, so the number of recognition frame images required to be recognized is smaller. And compared to the solution that does not discard the recognition frame images, the invalid recognition frame images discarded by the present application, that is, the recognition frame images that cannot recognize the identification code are discarded. Therefore, the present application will not only not increase the scanning time, but also avoid the problem of wasting equipment computing resources and reducing the scanning speed due to the target application's recognition of invalid frames, thereby improving the scanning efficiency.
[0009] In addition, the electronic device only selectively recognizes the recognition frame images, and the number of preview frame images displayed on the code scanning interface is consistent with the scanned code images captured by the camera, so as not to affect the normal preview of the images captured by the camera on the code scanning interface. In other words, discarding the recognition frame images will not be visually perceived by the user, and the preview frame images displayed on the code scanning interface will not affect the user's viewing experience due to frame drops. Therefore, this application can reduce the number of recognition frame images to be recognized by the target application without affecting the normal preview of the images captured by the camera on the code scanning interface, so as to reduce the number of threads created for the recognition frame images, the memory space occupied by the recognition process, and the recognition time, thereby improving the recognition efficiency.
[0010] In a possible design method of the first aspect, if the ambient light brightness of the recognition frame image is greater than or equal to the threshold, the recognition frame image is scanned for code recognition, including: if the ambient light brightness of the recognition frame image is greater than or equal to the threshold, and the exposure convergence operation and focus convergence operation of the camera are completed, then the recognition frame image is scanned for code recognition.
[0011] In addition, the method also includes: if the ambient light brightness of the recognition frame image is greater than or equal to a threshold, and the exposure convergence operation or focus convergence operation of the camera is detected, then deleting the recognition frame image obtained by the camera based on the scanned code image during the exposure convergence operation or the focus convergence operation, wherein the deleted recognition frame image is not used for scanned code recognition.
[0012] In this design mode, the electronic device deletes the recognition frame image obtained from the scanned code image during the camera exposure convergence process or the focus convergence process, so that the recognition frame image obtained during the camera exposure process or the convergence process can be scanned and recognized without scanning the code, so as to reduce the number of invalid recognition frame images with poor brightness and poor clarity. Specifically, when the camera is in the automatic exposure convergence state, the acquired scanned code image will have the problem of underexposure or overexposure, resulting in poor brightness of the recognition frame image obtained from the scanned code image, which makes it difficult to scan the code. If the electronic device scans and recognizes the recognition frame image with poor brightness, it will not only waste the computing power resources of the device, but also reduce the scanning speed. Therefore, the recognition frame image with poor brightness is discarded in this design mode, which improves the recognition efficiency. Similarly, when the camera is in the automatic focus convergence state, the camera automatically adjusts the focal length, and the focal length does not reach the target value during the adjustment process. The clarity of the scanned code image acquired during the focal length adjustment process is poor, so the clarity of the recognition frame image obtained from the scanned code image is also poor, which makes it difficult to scan the code. Based on this, the electronic device discards the recognition frame image with poor clarity, which improves the recognition efficiency.
[0013] In a possible design method of the first aspect, if the ambient light brightness of the recognition frame image is greater than or equal to the threshold, the recognition frame image is scanned for code recognition, including: if the ambient light brightness of the recognition frame image is greater than or equal to the threshold, the recognition frame image includes an identification code and the size of the identification code is increased, the recognition frame image corresponding to the identification code with the increased size is scanned for code recognition.
[0014] In this design, the electronic device scans the recognition frame image for code recognition only when the recognition frame image includes the recognition code and the size of the recognition code increases. This can reduce the number of recognition frames to be recognized, thereby improving recognition efficiency.
[0015] In a possible design method of the first aspect, if the ambient light brightness of the recognition frame image is greater than or equal to the threshold, the recognition frame image is scanned for recognition, including: if the ambient light brightness of the recognition frame image is greater than or equal to the threshold, and an image zoom operation performed on the scanning interface is detected, then after the image zoom operation is performed, the recognition frame image obtained according to the scanning image is scanned for recognition.
[0016] In this design, the electronic device detects an image zoom operation, wherein the image zoom operation indicates that the user adjusts the display size of the identification code. Then the size of the adjusted identification code is larger, and the image quality of the identification frame image is better. Therefore, the probability of successful recognition after the identification frame image is recognized is greater, and the recognition efficiency is higher.
[0017] In a possible design of the first aspect, before performing code scanning and recognition on the recognition frame image obtained according to the code scanning image after the above-mentioned image magnification operation is performed, the method further includes: determining that the recognition frame image includes an recognition code.
[0018] In a possible design of the first aspect, before displaying the code scanning interface, the method further includes: starting the target application. If the ambient light brightness of the recognition frame image is greater than or equal to the threshold, scanning the recognition frame image for code recognition includes: if the ambient light brightness of the recognition frame image is greater than or equal to the threshold and the application identifier of the target application is a preset identifier, scanning the recognition frame image for code recognition.
[0019] Among them, the preset identifier can be pre-set to distinguish target applications that do not need interval frame dropping. When the application identifier is a preset identifier, it means that the target application only recognizes the latest recognition frame image after each thread recognition ends, which is equivalent to reducing the number of recognition frame images that the application needs to recognize. For target applications with preset identifiers, the electronic device does not delete the recognition frame image to avoid the problem of slowing down the scanning speed caused by deleting too many recognition frame images.
[0020] In a possible design method of the first aspect, if the ambient light brightness of the recognition frame image is greater than or equal to the threshold, the recognition frame image is scanned for recognition, including: if the ambient light brightness of the recognition frame image is greater than or equal to the threshold, the recognition frame image does not include the recognition code, and a drag operation of the preview frame image is detected in the scanning interface, then the recognition frame image obtained by processing the same scanning image as the preview frame image is scanned for recognition.
[0021] In this design method, when the operation of dragging the image is detected, the identification frame image is not deleted, that is, the identification frame image after the dragging operation is performed is scanned for identification. Specifically, during the scanning process, when the scanning interface does not include the identification code, on the one hand, the user can adjust the shooting angle of the camera or enlarge the image in the scanning interface to realize the identification code in the scanning interface. In addition, the user can also adjust the position of the identification code in the scanning interface by dragging the image as described in this design method. When the target application detects the operation of dragging the image, it means that there is a high possibility that the identification code is included in the scanning interface after the operation. Therefore, the continuous identification frame images collected by the camera after the operation are identified to avoid missing the identification frame image and causing the scanning time to be too long, thereby improving the scanning efficiency.
[0022] In a possible design of the first aspect, the method further includes: acquiring a metadata frame, wherein the metadata frame includes acquisition parameters for processing a scanned code image to obtain an identification frame image. Acquiring a light intensity parameter from the acquisition parameter, and determining the ambient light brightness of the identification frame image according to the light intensity parameter.
[0023] In this design, the ambient light brightness is represented by the illumination intensity parameter, and the illumination intensity parameter includes: Luxindex. For example, the ambient light brightness is the reciprocal of Luxindex, that is, 1 / Luxindex. The larger the value of Luxindex, the smaller the ambient light brightness, and the darker the light of the code scanning scene; the smaller the value of Luxindex, the larger the ambient light brightness, and the brighter the light of the code scanning scene. Based on this, the electronic device can obtain the illumination intensity parameter from the metadata frame, so as to determine the ambient light brightness of the recognition frame image and the preview frame image obtained by processing the code scanning image relative to the metadata frame, and determine the quality of the lighting environment according to the ambient light brightness. In the case of poor lighting environment, code scanning recognition is not performed; in the case of good lighting environment, code scanning recognition is performed. Thereby reducing the recognition of invalid recognition frame images obtained in the case of poor lighting environment, so as to improve the efficiency of code scanning.
[0024] In a possible design of the first aspect, the method further includes: if the ambient light brightness of the recognition frame image is less than a threshold value, or if the exposure convergence operation or focus convergence operation of the camera is detected when the ambient light brightness of the recognition frame image is greater than or equal to the threshold value, or if the size of the identification code in the recognition frame image is less than or equal to a preset size when the ambient light brightness of the recognition frame image is greater than or equal to the threshold value, or if the recognition frame image does not include the identification code when the ambient light brightness of the recognition frame image is greater than or equal to the threshold value, then a frame loss flag is set for the recognition frame image. If the ambient light brightness of the recognition frame image is greater than or equal to the threshold value, the recognition frame image is scanned for identification, including: scanning the recognition frame image that does not include a frame loss flag, wherein the ambient light brightness of the recognition frame image that does not include a frame loss flag is greater than or equal to the threshold value.
[0025] In this design, the electronic device sets a frame loss flag for the recognition frame image to be deleted to indicate that the recognition frame image is not used for code scanning recognition. In this way, the electronic device can perform code scanning processing on the recognition frame image that does not contain the frame loss flag to reduce the number of recognition frame images.
[0026] In a possible design manner of the first aspect, the setting of a frame loss flag for the identification frame image includes: setting a frame loss flag for at least one identification frame image in each preset frame loss period.
[0027] In this design, the electronic device uses an interval frame dropping strategy to set a frame dropping flag for the recognition frame image. That is, T is a frame dropping cycle, and N frames of recognition frame images are discarded in each frame dropping cycle. Then, according to the frame dropping strategy, the electronic device will set a frame dropping flag for the N frames of recognition frame images in the frame dropping cycle T.
[0028] In some embodiments, the electronic device may set a frame loss flag for all identified frame images that meet the above frame loss conditions.
[0029] In other embodiments, the electronic device may set a frame loss flag for the first M frame identification frame images that meet the above frame loss conditions.
[0030] Through different frame dropping strategies, electronic devices can selectively delete invalid recognition frame images to achieve the beneficial effect of fast code scanning.
[0031] In a second aspect, the present application provides an electronic device, the electronic device comprising: a memory and one or more processors; the memory and the processor are coupled. The memory is used to store computer program code, the computer program code includes computer instructions; when the computer instructions are executed by the processor, the electronic device executes the method described in the first aspect and any possible design thereof.
[0032] In a third aspect, the present application provides a computer-readable storage medium, which may include computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the method as in the first aspect and its possible design methods.
[0033] In a fourth aspect, the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the method of the first aspect and possible design methods thereof.
[0034] It can be understood that the electronic device of the second aspect, the computer storage medium of the third aspect, and the computer program product of the fourth aspect provided above are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 A schematic diagram of the code scanning and recognition principles of two types of applications provided in the embodiments of the present application;
[0036] Figure 2 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;
[0037] Figure 3 A software structure block diagram of an electronic device provided in an embodiment of the present application;
[0038] Figure 4 A schematic diagram of a set of code scanning scenarios provided in an embodiment of the present application;
[0039] Figure 5 Another set of code scanning scenario schematic diagrams provided for an embodiment of the present application;
[0040] Figure 6 An interactive diagram of a code scanning method provided in an embodiment of the present application;
[0041] Fig. 6A A schematic diagram of an operation of opening a camera provided in an embodiment of the present application;
[0042] Figure 6B A schematic diagram of another operation of opening a camera provided in an embodiment of the present application;
[0043] Fig. 7A An interactive diagram of another code scanning method provided in an embodiment of the present application;
[0044] Figure 7B A schematic diagram of the effect corresponding to another code scanning method provided in an embodiment of the present application;
[0045] Figure 8A schematic diagram of the effect corresponding to another code scanning method provided in an embodiment of the present application;
[0046] Fig. 9 An interactive diagram of another code scanning method provided in an embodiment of the present application;
[0047] Fig.10 A schematic diagram of the effect corresponding to another code scanning method provided in an embodiment of the present application;
[0048] Fig.11 An interactive diagram of another code scanning method provided in an embodiment of the present application;
[0049] Fig.12 A schematic diagram of the effect corresponding to another code scanning method provided in an embodiment of the present application;
[0050] Fig.13 A flowchart corresponding to a code scanning method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this embodiment, unless otherwise specified, "plurality" means two or more.
[0052] At present, although the application of code scanning scenarios is becoming more and more widespread, the recognition speed of the identification code is affected due to differences in factors such as device load, memory, lighting environment and image quality.
[0053] For example: when using the same application to scan the same identification code, the recognition speed is slow when the device load pressure is high, the available memory capacity is small, the environment is dark, and the identification code image is small; while the recognition speed is fast when the device load pressure is low, the available memory capacity is large, the light is bright, and the identification code image is large. In the above scenario with fast recognition speed, the time of the scanning process perceived by the user is short, so the user's scanning experience is good; once the device is in the above scenario with slow recognition speed, the time of the scanning process perceived by the user will be longer, so the user's scanning experience is poor. However, the current scanning technology cannot quickly identify the identification code when the device is in a scenario with slow recognition speed, which brings the problem of difficulty in scanning to the user.
[0054] In addition, the scanning speed is also affected by the differences in the scanning and recognition principles of the application. The following is an explanation of the scanning and recognition process of two types of applications with different recognition algorithms.
[0055] Figure 1Schematic diagram of the code scanning recognition principle of two types of applications provided in the embodiment of this application. Figure 1 As shown in FIG. 1 , the first type of application recognizes each recognition frame (also called recognition frame image), so the recognition speed is slow. Specifically, Figure 1 As shown in (a), after the device runs the first type of application, the camera returns 30fps (Frames Per Second) to the abstract layer, that is, after the camera is started, it returns a frame of data every 33ms (millisecond), including a preview frame (also called a preview frame image, Figure 1 The preview frame is used to display on the code scanning interface, and the identification frame is used to obtain the information of the identification code. In the abstract layer, the identification frame is stored in a cache so that the identification frame can be processed before being rendered to the screen. The first type of application creates a thread for each identification frame returned to the algorithm processing module 101 of the first type of application to identify the information of the identification frame, and each thread is mutually exclusive to ensure serial execution between threads. Figure 1 In (a), when the first thread 102 identifies the 0th identification frame, although the 1st identification frame has been returned to the algorithm processing module 101 of the first type of application, the second thread 103 needs to wait until the first thread 102 finishes identifying the 0th identification frame before it can start identifying the 1st identification frame. In other words, when the first thread 102 identifies the 0th identification frame, the first thread 102 occupies the mutex lock, and the second thread 103 is locked (also called lock) at this time, and cannot perform the identification operation. It is not until the first thread 102 finishes identifying the 0th identification frame that the second thread 103 occupies the mutex lock and starts to identify the 1st identification frame (also called process).
[0056] The second type of application recognizes the latest frame after each thread recognizes the frame, so the recognition speed is fast. Figure 1 As shown in (b), after the device runs the second type of application, the camera also returns a frame of data every 33ms, including a preview frame and a recognition frame. However, after the algorithm processing module 101 of the second type of application completes the recognition of a recognition frame, if no recognition code is recognized, a thread is created to capture the latest recognition frame returned to the algorithm processing module 101, and recognize the latest recognition frame. Figure 1 In (b), when the third thread 104 identifies the 0th identification frame, although the 1st identification frame has been returned to the algorithm processing module 101 of the second type of application, the algorithm processing module 101 waits for the third thread 104 to complete the identification of the 0th identification frame before creating the fourth thread 105. Then the algorithm processing module 101 grabs the latest identification frame for the fourth thread 105, that is, Figure 1The second identification frame shown in (b) is returned to the algorithm processing module 101, and the fourth thread 105 starts to identify the second identification frame. That is, although the algorithm processing module 101 receives two identification frames when creating the fourth thread 105, the second type of application does not identify each identification frame, but captures the latest identification frame to identify whether there is an identification code.
[0057] In the description of the recognition process of the first and second types of applications mentioned above, the first type of application recognizes each recognition frame, so there are at least two problems with using the first type of application to scan the code. First, a large number of threads are created, which occupies a large amount of memory space. In scenarios where the device load pressure is high and the available memory capacity is small, the computing resources allocated to the threads are insufficient, so the recognition speed is affected, which in turn affects the speed at which users scan the code. Second, the first type of application will recognize image frames collected under poor lighting conditions and image quality, which not only fails to recognize the identification code, but also wastes thread resources and memory space.
[0058] Although the second type of application only recognizes some recognition frames, it also starts processing from the first recognition frame captured by the camera. In the case of poor lighting environment and image quality, the second type of application will also perform a large number of invalid recognitions, resulting in a waste of device computing resources.
[0059] In order to reduce the number of invalid recognition frames recognized by the device, an embodiment of the present application provides a code scanning method that can be applied to electronic devices. When the electronic device scans the code in a scene with poor lighting environment and image quality, it only recognizes a part of the recognition frames collected by the camera in the above scene, thereby reducing the number of threads created for the recognition frame, the memory space occupied by the recognition process, and the recognition time, thereby improving the recognition efficiency.
[0060] Exemplarily, the electronic device in the embodiments of the present application may be a mobile phone, a tablet computer, a desktop, a laptop, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, an augmented reality (AR) or virtual reality (VR) device, etc., which supports a camera function. The embodiments of the present application do not impose any special restrictions on the specific form of the electronic device.
[0061] Before describing in detail the code scanning method provided in the embodiment of the present application, the structure of the electronic device is first introduced here.
[0062] Figure 2 The hardware structure diagram of an electronic device provided in an embodiment of the present application is shown in FIG. Figure 2As shown, taking the electronic device as a mobile phone 200 as an example, the mobile phone 200 may include a processor 210, an external memory interface 220, an internal memory 221, a universal serial bus (USB) interface 230, a charging management module 240, a power management module 241, a battery 242, an antenna 1, an antenna 2, a mobile communication module 250, a wireless communication module 260, an audio module 270, a speaker 270A, a receiver 270B, a microphone 270C, an earphone interface 270D, a sensor module 280, a touch sensor 280A, an ambient light sensor 280B, a button 290, a motor 291, an indicator 292, a camera 293, a display screen 294, and a subscriber identification module (SIM) card interface 295, etc.
[0063] It is to be understood that the structure shown in this embodiment does not constitute a specific limitation on the mobile phone 200. In other embodiments, the mobile phone 200 may include more or fewer components than shown in the figure, or combine some components, or separate 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.
[0064] The processor 210 may include one or more processing units, for example, the processor 210 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0065] The controller may be the nerve center and command center of the mobile phone 200. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0066] A memory may also be provided in the processor 210 for storing instructions and data. In some embodiments, the memory in the processor 210 is a cache memory. The memory may store instructions or data that the processor 210 has just used or cyclically used. If the processor 210 needs to use the instruction or data again, it may be directly called from the memory. Repeated access is avoided, and the waiting time of the processor 210 is reduced, thereby improving the efficiency of the system. In some embodiments of the present application, the memory may store an executable program for identifying the lighting environment and image magnification operations, as well as user data, application data, etc. generated by performing the above operations.
[0067] The wireless communication function of the mobile phone 200 can be implemented through the antenna 1, the antenna 2, the mobile communication module 250, the wireless communication module 260, the modem processor and the baseband processor. In some embodiments of the present application, the mobile phone 200 can send a signal to start the target application, a signal to call the camera driver, etc. through the above-mentioned wireless communication module 260. After recognizing the identification code, the mobile phone 200 can also perform corresponding operations according to the recognized identification code through the above-mentioned mobile communication module 250 or the above-mentioned wireless communication module 260, such as opening a certain web page or sending an unlocking instruction to a shared vehicle.
[0068] The touch sensor 280A is also called a "touch device". The touch sensor 280A can be arranged on the display screen 294, and the touch sensor 280A and the display screen 294 form a touch screen, also called a "touch screen". The touch sensor 280A is used to detect a touch operation acting on or near it. The touch sensor 280A can pass the detected touch operation to the application processor to determine the type of touch event. The visual output related to the touch operation can be provided through the display screen 294. In some embodiments, the touch sensor 280A can be arranged on the surface of the mobile phone 200, which is different from the position of the display screen 294. In an embodiment of the present application, the mobile phone 200 can detect the touch operation of the user acting on the icon of the target application through the touch sensor 280A, and in response to the touch operation, the mobile phone 200 starts the target application. In some embodiments of the present application, the mobile phone 200 can detect the user performing an image zoom operation in the code scanning preview interface through the touch sensor 280A. In response to the image zoom operation, the mobile phone 200 ends the operation of identifying a partial recognition frame and starts to recognize all the recognition frames collected by the camera 293 since the image zoom operation is performed frame by frame.
[0069] The ambient light sensor 280B is used to sense the ambient light brightness (also known as the lighting environment). In some embodiments of the present application, the mobile phone 200 determines whether to perform identification code recognition processing on the currently collected recognition frame based on the ambient light brightness. Specifically, if the ambient light brightness is less than the threshold, it means that the lighting environment is dark, and the mobile phone 200 does not process the recognition frame collected under the ambient light brightness; if the ambient light brightness is greater than or equal to the threshold, it means that the lighting environment is bright, and the mobile phone 200 processes the recognition frame collected under the ambient light brightness. In this way, the mobile phone 200 can effectively avoid the problem of wasting device computing resources caused by processing invalid recognition frames in scenes with poor lighting environments, thereby improving recognition efficiency.
[0070] The mobile phone 200 implements the display function through a GPU, a display screen 294, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 294 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 210 may include one or more GPUs, which execute program instructions to generate or change display information.
[0071] The display screen 294 is used to display images, videos, etc. The display screen 294 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.
[0072] The mobile phone 200 can realize the shooting function through the ISP, the camera 293, the video codec, the GPU, the display screen 294 and the APP processor.
[0073] The ISP is used to process the data fed back by the camera 293. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal. The camera photosensitive element transmits the electrical signal to the ISP for processing, and the electrical signal is converted into an image visible to the naked eye, where the image can be an image including an identification code or an image not including an identification code. 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 293.
[0074] The camera 293 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the mobile phone 200 may include 1 or N cameras 293, where N is a positive integer greater than 1.
[0075] In the embodiment of the present application, the mobile phone 200 can obtain preview frames, identification frames, and metadata frames through the camera 293. Specifically, the camera captures the scanned code image, which is also called raw data. The ISP converts the raw data into YUV data (also called brightness, chroma, and saturation diagram), and outputs one channel of YUV data as one preview stream and one preview frame according to the needs of the target application, and simultaneously outputs a metadata frame for each frame of YUV data, which is used to describe the light intensity, autofocus parameters, auto exposure parameters, auto white balance parameters, etc. of the YUV data.
[0076] Figure 3 A software structure block diagram of an electronic device provided in an embodiment of the present application. The software system of the electronic device can adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to illustrate the software structure of the mobile phone 200.
[0077] like Figure 3As shown, the layered architecture can divide the software into several layers, and each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely the application layer (referred to as application layer) 310, the application framework layer (referred to as framework layer) 320, the hardware abstract layer (hardwareabstract layer, HAL) layer 330, and the kernel layer (Kernel, also known as the driver layer). It should be noted that in the embodiment of the present application, the kernel layer is used to provide simple access to the hardware logic, and the functional actions that embody the hardware access logic (such as the frame skipping recognition logic described in detail in the method embodiment below) are placed in the HAL layer, and the HAL layer can communicate directly with the camera of the hardware layer without passing through the kernel layer, so the kernel layer is in Figure 3 Not shown.
[0078] The application layer (Application) 310 may include a series of application packages, such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and desktop launcher.
[0079] In the embodiment of the present application, the application layer 310 may include a camera system application (also referred to as a camera application) 311. The operation of the camera application 311, for example, taking photos, recording videos, etc., requires the use of a camera.
[0080] In the embodiment of the present application, the application layer 310 may also include other applications (also called third-party applications) 312 that need to use the camera. TM QR code scanning function, Alipay TM Scan code function, TikTok TM The code scanning function of the other third-party application 312 may be WeChat. TM , Alipay TM ,Tik Tok TM And other applications.
[0081] like Figure 3 As shown, the camera application 311 and the third-party application 312 can be used to display the preview image (also called preview frame) reported by the bottom layer in the preview interface. Among them, the mobile phone 200 can include multiple cameras, each of which can be used to capture the preview frame. For the convenience of explanation, the camera that appears below is understood to be the camera that currently captures the preview frame.
[0082] In an embodiment of the present application, the application layer 310 can instruct the HAL layer 330 to start the camera according to the user operation. The application layer 310 can also instruct the HAL layer 330 to perform a zoom operation on the image captured by the camera according to the user operation, or instruct the HAL layer 330 to start / turn off the flashlight function.
[0083] The framework layer 320 provides an application programming interface (API) and a programming framework for the application layer 310. The framework layer 320 includes some predefined functions. Figure 3 As shown, the framework layer 320 may provide a camera API, such as CameraAPI (API 1|API 2) 321 and a camera service (CameraService) 322 .
[0084] Among them, CameraAPI (API 1|API 2) 321 serves as an interface for the bottom layer (such as HAL layer 330) to interact with the application layer 310. Specifically, CameraAPI (API 1|API 2) 321 can receive a request from the upper layer (such as the application layer 310) to open a specified camera, and process the request through the camera service 322. In the embodiment of the present application, the camera service 322 then opens the corresponding camera through the HAL layer 330, and obtains the preview frame, recognition frame, metadata frame, etc. reported by the camera through the HAL layer 330.
[0085] In the embodiment of the present application, the camera service 322 can be used to obtain a strategy for discarding the recognition frame according to a request from the application layer 310 and / or according to the recognition frame reported from the lower layer (such as the HAL layer 330). For example, the strategy for discarding the recognition frame includes: the camera service 322 receives the recognition frame reported by the HAL layer 330, wherein the state of discarding (which can be understood as deleting) the recognition frame without recognition is error (error refers to an exception that the application does not have to handle), the camera service 322 determines the state of the recognition frame, if the state of the recognition frame is error, the camera service 322 does not return the recognition frame to the application; if the state of the recognition frame is not error, such as the recognition frame is not set to a state, the camera service 322 returns the recognition frame to the application layer 310 for recognition processing.
[0086] The HAL layer 330 is used to connect the framework layer 320 and the kernel layer. For example, the HAL layer 330 can transmit data between the framework layer 320 and the kernel layer. Of course, the HAL layer 330 can also process the data from the bottom layer (i.e., the kernel layer) and then transmit it to the framework layer 320. In the embodiment of the present application, the HAL layer 330 can process the preview frame, recognition frame, and metadata frame reported by the camera of the hardware layer, and return the recognition frame and the preview frame to the camera service 322.
[0087] like Figure 3 As shown, the HAL layer 330 may include a HAL interface definition language (HIDL) interface 331, a camera hardware abstraction layer (Camera Provider) 332, and a HAL interface. The camera hardware abstraction layer 332 provides a standard HIDL interface to the upper layer (such as the camera service 322) for calling, and maintains normal communication with the upper layer. In addition, the camera hardware abstraction layer 332 controls the camera downward through a standard HAL interface, such as HAL3.0, and obtains data such as preview frames, recognition frames, metadata frames, etc. reported by the camera.
[0088] In the embodiment of the present application, the camera hardware abstraction layer 332 can report the acquired preview frame and the identification frame of the setting status to the upper layer (such as the camera service 322).
[0089] In an embodiment of the present application, the camera hardware abstraction layer 332 includes a camera driver. Different from the camera driver in the kernel layer, the camera driver in the camera hardware abstraction layer 332 is used to set the status of the recognition frame reported by the camera according to the lighting environment and image quality, and report the recognition frame with the set status together with the preview frame to the camera service 322.
[0090] The code scanning method provided in the embodiment of the present application can be implemented in a mobile phone 200 having the above-mentioned hardware structure and software structure.
[0091] The following is an example of the workflow of the software and hardware of the mobile phone 200 in combination with the code scanning scenario.
[0092] When the touch sensor 280A receives a touch operation, the corresponding hardware interrupt is sent to the kernel layer. The kernel layer processes the touch operation into an original input event (including touch coordinates, timestamp of the touch operation, and other information). The original input event is stored in the kernel layer. The framework layer 320 obtains the original input event from the kernel layer and identifies the control corresponding to the input event. Taking the touch operation as a touch single-click operation, and the control corresponding to the single-click operation is a control that implements the code scanning function on the interface of the third-party application 312 as an example, the third-party application 312 calls the camera service 322 of the framework layer 320, and then calls the camera driver through the camera service 322, and starts the camera 293 through the camera driver to collect the code scanning image, and processes the code scanning route into a preview frame and an identification frame. Then the camera 293 reports the preview frame, the identification frame, and the metadata frame to the camera driver of the HAL layer 330. The camera driver sets a frame loss flag (also known as status error, error or status) for the recognition frame reported by the camera 293 according to the lighting environment or image quality, and reports the recognition frame with the frame loss flag set together with the preview frame to the camera service 322. The camera service 322 receives the recognition frame reported by the HAL layer 330, determines whether to return the recognition frame to the third-party application 312 according to whether the recognition frame has a frame loss flag, and returns the preview frame at the same time. The third-party application 312 displays the preview frame in the preview box and processes the information in the recognition frame at the same time. If the identification code is recognized, the third-party application 312 issues a command to turn off the camera, the camera stops collecting data, and the third-party application 312 instructs the mobile phone 200 to perform corresponding operations according to the recognized identification code, such as opening a web page or sending an unlock command to a shared vehicle.
[0093] Figure 4 A schematic diagram of a group of code scanning scenarios provided by an embodiment of the present application is shown. Figure 4 As shown in (a), when the user performs a code scanning operation under poor lighting conditions, the camera 293 reports the recognition frame, preview frame, and metadata frame to the camera driver. The camera driver determines that the ambient light brightness is poor lighting conditions based on the metadata frame, and the camera driver sets the status of the recognition frame to error, and reports it together with the preview frame to the camera service. The camera service determines not to report the recognition frame to the third-party application based on the error status of the recognition frame, so the camera service only reports the preview frame to the third-party application. The third-party application displays the preview frame in the preview interface. Since the third-party application did not receive the recognition frame, no recognition processing was performed, so no invalid recognition was performed. As shown Figure 4As shown in (b), the user turns on the flashlight function of the mobile phone. At this time, the brightness of the framing environment increases, and the corresponding camera driver recognizes that the ambient light brightness is good according to the metadata frame. The camera driver does not set an error for the recognition frame, but uploads the recognition frame and the preview frame to the camera service. The camera service determines that the recognition frame needs to be reported to the third-party application based on the fact that no error is set for the recognition frame, so the camera service reports the recognition frame and the preview frame to the third-party application. The third-party application displays the preview frame on the preview interface and performs recognition processing on the recognition frame until the identification code is recognized. In this scenario, the third-party application only recognizes the recognition frames collected in the scene with good lighting conditions, thereby greatly reducing the number of invalid recognition frames (i.e., recognition frames with poor lighting conditions) that need to be recognized, thereby reducing the number of threads created for the recognition frames, the memory space occupied by the recognition process, and the recognition time, thereby improving the recognition efficiency.
[0094] Figure 5 Another set of code scanning scenarios provided by the embodiment of the present application is shown. Figure 5 As shown in (a), the user performs a code scanning operation, but the identification code displayed in the preview interface is small, which means that the size of the identification code in the image captured by the camera is too small and the image quality is poor. Therefore, the camera driver marks the status of the identification frame by not marking the identification frame at intervals of one identification frame and marking two consecutive identification frames with an error status. Correspondingly, the camera service adopts a frame-dropping strategy of discarding two identification frames and reporting one identification frame to the third-party application. Figure 5 As shown in (b), when the user performs an image zoom operation, the third-party application sends an image zoom request to the camera driver. The camera driver stops marking the status of the recognition frame, and directly uploads the recognition frame and preview frame to the camera service, which is then returned to the third-party application by the camera service. The third-party application performs recognition processing on continuous recognition frames. In this scenario, the third-party application first performs frame skipping recognition on the recognition frame to avoid recognizing recognition frames with poor image quality and wasting computing resources. After detecting that the user performs an image zoom operation, the camera driver confirms that the image quality has improved (the recognition code in the image changes from a small size to a large size), and stops marking the status of the recognition frame. The third-party application performs continuous frame recognition on the preview frame. Based on this, the third-party application only continuously recognizes the recognition frames collected in the scene with good image quality, thereby greatly reducing the number of invalid recognition frames (i.e., recognition frames with poor image quality) that need to be recognized, thereby reducing the number of threads created for the recognition frame, the memory occupied by the recognition process, and the recognition time, thereby improving the recognition efficiency.
[0095] In the following, we will combine Figure 6 The method flow chart shown is used to introduce in detail a code scanning method provided in an embodiment of the present application.
[0096] S601: In response to the user opening the camera, the target application displays a code scanning interface and sends a request to the camera service to start the camera.
[0097] Before S601, the target application may receive an operation of opening the camera by the user, wherein the target application may be a camera application or a third-party application.
[0098] In some embodiments, the operation of opening the camera includes triggering the mobile phone to run a camera application in the background. Fig. 6A After clicking the icon 602a in the mobile phone main interface 601a shown in (a), the code scanning interface 603a is entered.
[0099] Alternatively, the operation of opening the camera includes triggering the mobile phone to use the camera to start the code scanning function when the third-party application is running in the background. TM For example, the function of using the camera can be Figure 6B The operation of clicking the "Scan 602b" icon in the third-party application main interface 601b shown in (a) of FIG. The mobile phone detects the operation, activates the scanning function of the third-party application, and the mobile phone displays Figure 6B The code scanning interface 603b is shown in (b).
[0100] In other embodiments, the operation of opening the camera includes switching the shooting mode. The camera application or the camera used in the third-party application may provide multiple shooting modes, such as shooting, recording, panoramic, code scanning, object recognition, etc. For example, the operation of opening the camera is to switch the shooting mode of the camera application to the code scanning mode. Fig. 6A By selecting the scan code 604a icon on the main interface of the camera application shown in (b), the camera application can switch to the scan code mode. The icon 602a is the application icon of the camera application, and the scan code 604a is the function icon of the scan code function in the camera application.
[0101] After the application receives the above-mentioned user's operation to turn on the camera, the application can call the camera interface (such as the open Camera interface) to request to start the camera, that is, send a request to start the camera to the camera service. Among them, the request to start the camera carries functional parameters for indicating the camera type and shooting mode, so that the bottom layer can be clearly instructed to start the corresponding camera to meet the needs of the corresponding function. In some embodiments, the request to start the camera also includes an application identifier, which is used by the camera driver to determine whether the application that starts the camera is a preset target application.
[0102] S602: In response to receiving the request to start the camera, the camera service sends a request to call the camera driver to the camera driver.
[0103] Before S602 , the camera service may receive a request to start the camera from the target application.
[0104] In this embodiment, after receiving the request to start the camera, the camera service sends a message to call the camera driver to the underlying camera driver to instruct the camera driver to drive the camera to start.
[0105] S603: In response to receiving the request to call the camera driver, the camera driver starts the camera and obtains the metadata frame, the recognition frame and the preview frame.
[0106] Before S603 , the camera driver may receive a request for invoking the camera driver from the camera service.
[0107] In this embodiment, after receiving the request to call the camera driver, the camera driver can control the camera to turn on. After the camera is turned on, it can continuously collect scanned images, process the scanned images into recognition frames and preview frames, and output metadata frames. Among them, the preview image in the scanned code interface can be realized by the camera reporting the preview frame to the upper layer; the scanned code recognition result (also called recognition result) can be realized by recognizing the recognition code.
[0108] S604: The camera reports the metadata frame, the identification frame and the preview frame to the camera driver.
[0109] It should be noted that in actual applications, the camera reports the metadata stream, recognition stream and preview stream to the camera driver. This step takes a frame of metadata, recognition image and preview image captured by the camera at a certain moment as an example. The captured frame of metadata is the metadata frame, the frame of recognition image is the recognition frame, and the frame of preview image is the preview frame.
[0110] The metadata frame is used to describe the value of the image captured by the camera at the above-mentioned moment. For example, the metadata frame includes frame rate, image size, encoding, color bit depth, ambient light brightness, etc. The recognition frame and the preview frame are both image data (equivalent to the aforementioned YUV data). The image data can be displayed on the display screen of the mobile phone, or can be used for recognition processing to obtain the identification code in the image data. The value of the image data can be obtained from the metadata frame that describes the camera acquisition parameters at the image data acquisition timestamp. For example, the mobile phone can determine the lighting environment (also known as ambient light brightness) when the camera captures the preview frame and the recognition frame based on the light intensity in the metadata frame.
[0111] Among them, metadata frames, recognition frames and preview frames are all cached in the memory block so that the recognition frames or preview frames can be processed before being rendered to the screen. Therefore, metadata frames, recognition frames and preview frames will occupy memory space, which will affect the recognition speed when the available memory capacity is small.
[0112] The above S601 to S604 can be processed according to the process of starting the camera to collect raw data and reporting the preview image, recognition image and metadata in the prior art, and no redundant description is given here.
[0113] S605: The camera driver identifies the ambient light brightness according to the metadata frame.
[0114] In this embodiment, the ambient light brightness and illumination intensity parameters are represented, and the illumination intensity parameters include: Luxindex (also known as illumination intensity, or illumination for short). For example, the ambient light brightness is the reciprocal of Luxindex, i.e., 1 / Luxindex. The larger the value of Luxindex, the smaller the ambient light brightness, and the darker the light in the code scanning scene. The smaller the value of Luxindex, the larger the ambient light brightness, and the brighter the light in the code scanning scene.
[0115] The camera driver can obtain the light intensity from the metadata frame to determine the ambient light brightness of the recognition frame and the preview frame obtained by processing the scanned image relative to the metadata frame, wherein the ambient light brightness is used to determine the quality of the lighting environment.
[0116] S606: The camera driver determines that the ambient light brightness of the metadata frame is less than a threshold value, and sets a frame loss flag for the recognition frame collected at the same timestamp as the metadata frame.
[0117] The ambient light brightness of the metadata frame is less than the threshold, indicating that the lighting environment of the recognition frame and the preview frame is a dark scene. In this case, the camera driver sets a frame drop flag for the recognition frame collected at the same timestamp as the metadata frame to instruct the upper-layer camera service to discard the recognition frame. The recognition frame discarded by the camera service will not be recognized by the upper-layer target application, so the upper-layer target application does not need to allocate threads for invalid frames to recognize the QR code in the invalid frame, thus avoiding the waste of device computing resources due to a large number of invalid recognitions.
[0118] Furthermore, the frame loss flag may be the status of the identification frame, for example, if the status is error, it indicates that the frame identification frame is an invalid identification frame that needs to be discarded. If the status is not error, for example, the status is empty (NULL) or the status is not set, it indicates that the frame identification frame is an identification frame that needs to be identified. It should be understood that the benefit of the camera driver setting the frame loss flag for the invalid identification frame is that the upper-layer camera service can determine whether to upload the identification frame to the target application based on the frame loss flag. Therefore, in some embodiments, the identification frame flag may also be a pair of identifiers representing different meanings, such as (Y / N), (1 / 0), etc., wherein the frame loss flag may be N, or 0, and the flag for not losing a frame is Y, 1.
[0119] S607: The camera driver reports the recognition frame and the preview frame to the camera service.
[0120] The reported recognition frames include recognition frames with frame loss flags and recognition frames without frame loss flags. That is, the recognition frames obtained by the camera service are images obtained after the camera driver analyzes and processes the ambient light brightness. Therefore, after receiving the recognition frames, the camera service can detect whether the recognition frames are marked, that is, execute S608.
[0121] S608: The camera service detects whether the recognition frame is marked, and returns the preview frame and the recognition frame without the mark to the target application.
[0122] Based on the foregoing, it can be known that the preview frame is used to display on the code scanning interface, and the identification frame is used to obtain the information of the identification code. In other words, whether there is frame loss in the preview frame is perceptible to the user, while whether there is frame loss in the identification frame will not affect the user's code scanning experience. Therefore, when scanning the code in a dark environment, the number of preview frames uploaded by the camera service to the target application in this embodiment is consistent with the number of preview frames reported by the camera, and the number of uploaded identification frames is less than the number of identification frames reported by the camera, thereby reducing the number of identification frames to be identified by the target application without affecting the normal preview of the image captured by the camera in the code scanning interface, thereby reducing the number of threads created for the identification frame, the memory space occupied by the identification process, and the identification time, thereby improving the recognition efficiency.
[0123] In some embodiments, the camera service detecting whether the recognition frame is marked includes: the camera service detecting whether the state of the recognition frame is error, if the state of the recognition frame is error, indicating that the recognition frame is marked, then returning the recognition frame without error to the target application.
[0124] In some other embodiments, the camera service detects whether the recognition frame is marked, including: the camera service detects whether the recognition frame is marked "N (or 0)", if the recognition frame is marked "N (or 0)", it means that the recognition frame is marked. If the recognition frame is not marked "N (or 0)", such as the recognition frame is marked as "Y (or 1)", it means that the recognition frame is not marked. Then the camera service returns the recognition frame without the mark "N (or 0)" to the target application.
[0125] After the camera service returns the preview frame and the identification frame without the mark, the target application receives the preview frame and the identification frame without the mark, and then the target application executes S609 to realize the recognition of the two-dimensional code.
[0126] S609: The target application displays a preview frame on the code scanning interface, recognizes the recognition frame, and determines a recognition result.
[0127] In S609, if the recognition result of the current frame is that the QR code is not recognized, the target application continues to receive the preview frame of the next frame and the recognition frame of the next frame without the mark, and recognizes the recognition frame of the next frame to determine whether the QR code is recognized. When the target application recognizes the QR code from the recognition frame, the target application sends a request to the camera service to turn off the camera. Exemplarily, the target application calls the camera interface (such as the close Camera interface) to request to turn off the camera, so as to send a request to the camera service to turn off the camera. After receiving the request to turn off the camera, the camera service transmits the request to turn off the camera to the lower layer, turns off the corresponding camera, and finally stops the preview in the code scanning interface.
[0128] In summary, when the method of this embodiment is used to scan a code in a dark environment, the camera driver can set a frame loss flag for the recognition frame collected in the dark environment, so that the camera service can discard the recognition frame, so that the recognition frame reported to the target application by the camera service does not include the invalid recognition frame recognized in the dark environment. In this way, the problem of wasting device computing resources and reducing the scanning speed due to the recognition of invalid frames by the target application can be avoided, thereby improving the scanning efficiency.
[0129] Above Figure 6 In the embodiment shown, only the recognition frames whose ambient light brightness is greater than or equal to the threshold are recognized. In the actual code scanning scenario, when the user scans the code in a dark environment, the camera will automatically expose and focus to make the brightness and clarity of the acquired image tend to be normal. During the automatic exposure and autofocus process of the camera, the ambient light brightness value may be greater than or equal to the threshold, but the target application still cannot recognize the QR code from the recognition frame. However, in response to this situation, the above embodiment reports the recognition frame to the target application for recognition, resulting in the target application making a large number of invalid frames for recognition, resulting in a waste of device computing resources.
[0130] Based on this, the present application embodiment also provides another scanning method, which can be Figure 6 On the basis of the illustrated embodiment, the recognition of invalid frames by the target application is effectively reduced, thereby improving the scanning speed.
[0131] Reference Fig. 7A After S606, the code scanning method provided in the embodiment of the present application may include:
[0132] S701: The camera driver determines that the ambient light brightness of the metadata frame is greater than or equal to a threshold, and obtains a first convergence result of automatic exposure and a second convergence result of automatic focus from the metadata frame.
[0133] Based on the above, we know that the camera uses automatic exposure to make the brightness of the photographed object normal. During the automatic exposure process, the camera's aperture, shutter, sensitivity (International Standards Organization, ISO) and other parameters are gradually adjusted, that is, the camera's aperture, shutter, ISO and other parameters have a certain adjustment time, which is called the adjustment process. During the adjustment process, the camera's automatic exposure is in a convergence state, and when the adjustment is completed, the camera's aperture, shutter, ISO and other parameters remain unchanged, so the automatic exposure is in a convergence end state.
[0134] Similarly, the camera uses autofocus to make the image of the object clear. During the camera exposure process, the brightness of the object changes from dark to bright, so the camera uses autofocus to make the image taken by the camera clear from blurry. During the process of adjusting the focus of the camera, the focus has not reached the target value, so the autofocus is in a convergence state. When the camera finishes adjusting the focus, the focus reaches the target value, so the autofocus is in a convergence end state.
[0135] Based on this, the metadata frame is also used to provide camera parameters (also called camera parameters) so that the camera driver can determine a first convergence result of automatic exposure and a second convergence result of automatic focus.
[0136] In some embodiments, the camera parameters include: AEdone, AFdone. Among them, AE is also called autoexposure, and AEdone indicates that the autoexposure is in a convergence end state. AF is also called auto focus, and AFdone indicates that the autofocus is in a convergence end state. That is, in this embodiment, the camera driver determines that the ambient light brightness of the metadata frame is greater than or equal to the threshold, and obtains AEdone and AFdone from the metadata frame. If AEdone is obtained, it indicates that the autoexposure is in a convergence end state. If AFdone is obtained, it indicates that the autofocus is in a focusing end state. Therefore, the camera driver can determine the first convergence result of the autoexposure and the second convergence result of the autofocus by whether AEdone and AFdone are recognized.
[0137] In other embodiments, the camera parameters include the camera's aperture, shutter, ISO, focal length, etc. The camera driver obtains the camera parameters of at least two metadata frames, and determines whether the automatic exposure or automatic focus is in a convergence state by judging whether the camera parameters have changed, that is, determining a first convergence result of the automatic exposure and a second convergence result of the automatic focus.
[0138] S702: The camera driver determines that the automatic exposure and / or the automatic focus is in a convergence state according to the first convergence result and the second convergence result, and sets a frame loss flag for the identification frame collected at the same timestamp as the metadata frame according to the frame loss strategy.
[0139] Regarding the setting method of the frame loss flag, reference may be made to the introduction of the frame loss flag in S606 above, and no redundant description will be given here.
[0140] The following focuses on the frame loss strategy of this embodiment.
[0141] During the camera's automatic exposure and autofocus process, the ambient light brightness value may be greater than or equal to the threshold, but the target application may still be unable to recognize the QR code from the recognition frame. Therefore, recognizing the recognition frames collected during the automatic exposure and autofocus process will not only result in the inability to recognize the QR code from invalid frames, but also occupy thread resources. Based on this, the recognition frames collected during the automatic exposure and autofocus process are discarded to reduce the number of threads created for the recognition frames, the memory space occupied by the recognition process, and the recognition time, thereby improving the recognition efficiency.
[0142] It should be understood that discarding any one or more recognition frames in the process of automatic exposure and automatic focusing of the camera can achieve the beneficial effect of reducing the number of threads created for the recognition frames. In this embodiment, three frame discarding strategies are proposed.
[0143] First, the frame dropping strategy includes discarding all recognition frames acquired when the auto-exposure and / or auto-focus are in a convergence state.
[0144] Then, according to the frame drop strategy, the camera driver sets a frame drop flag for the recognition frame in which the auto exposure and / or auto focus are in a convergence state.
[0145] Secondly, the frame dropping strategy includes: taking T as a frame dropping period, and dropping N identification frames in each frame dropping period.
[0146] Then according to the frame loss strategy, the camera driver sets a frame loss flag for the N frame identification frames within the frame loss period T.
[0147] Exemplarily, T is 3 frames, and N is 2, that is, two recognition frames are discarded out of every three recognition frames, and only one recognition frame is retained for target application recognition.
[0148] For example, the frame dropping strategy includes: every time a frame is identified, two consecutive frames of identification are discarded, and the cycle continues.
[0149] Third, the frame dropping strategy includes: identifying frames of the first M frames acquired when the auto exposure and / or auto focus are in a convergence state. For example, M is 3, 6, 10, 15, 20, etc.
[0150] Then, according to the frame drop strategy, the camera driver sets a frame drop flag for the first M frames in which the auto exposure and / or auto focus are in a convergence state.
[0151] S703: The camera driver determines that both the automatic exposure and the automatic focus are in a convergence end state according to the first convergence result and the second convergence result, and ends setting a frame loss flag for the recognition frame according to the frame loss strategy.
[0152] The fact that both the auto-exposure and the auto-focus are in the convergence completion state may be that the camera parameters in the metadata frame include AEdone and AFdone. Alternatively, the fact that both the auto-exposure and the auto-focus are in the convergence completion state may be that the camera parameters in the metadata frame remain unchanged compared to the previous frame.
[0153] It should be understood that during the code scanning process, the camera driver may terminate the operation of setting the frame loss flag for the recognition frame according to the frame loss strategy for multiple times. Each termination operation may be referred to as "the camera driver terminates the operation of setting the frame loss flag for the recognition frame according to the frame loss strategy".
[0154] In some embodiments, the camera driver stops setting the frame loss flag for the recognition frame according to the frame loss strategy, so that the camera driver no longer sets the frame loss flag for all subsequent recognition frames received. Then the camera driver only performs the operation of stopping setting the frame loss flag for the recognition frame according to the frame loss strategy once.
[0155] In other embodiments, after the camera driver finishes setting the frame loss flag for the recognition frame according to the frame loss strategy, the camera driver no longer sets the frame loss flag for the recognition frame received subsequently. Until the recognition frame meets the preset conditions, the camera driver continues to set the frame loss flag for the recognition frame received subsequently, for example, the preset conditions include: Luxindex is less than the threshold. Exemplarily, the user scans the code in a dark environment. When the user starts the flashlight function of the mobile phone, Luxindex is greater than or equal to the threshold, the camera automatically exposes and automatically focuses. During the automatic exposure and automatic focus process, the camera driver sets the frame loss flag for the recognition frame according to the frame loss strategy. When both the automatic exposure and the automatic focus are in the convergence end state, the camera driver ends setting the frame loss flag for the recognition frame according to the frame loss strategy. If the user accidentally touches the mobile phone and causes the flashlight function to be turned off, and the Luxindex rises to greater than the preset value, the camera driver continues to set the frame loss flag for the recognition frame corresponding to the Luxindex greater than the preset value. That is to say, in this scenario, the frame dropping process executed by the camera driver is: first discard all recognition frames whose Luxindex is greater than the preset value; then discard the recognition frames according to the frame dropping strategy (such as discarding two consecutive recognition frames every other recognition frame); then end the frame dropping after the automatic exposure and automatic focus are completed; finally, when the Luxindex rises to a value greater than the preset value, continue to discard all recognition frames whose Luxindex is greater than the preset value.
[0156] After the camera driver sets the frame drop flag for the recognition frame, it uploads the recognition frame and the preview frame to the camera service so that the camera service can perform the frame drop operation according to the frame drop flag. The frame drop operation performed by the camera service can refer to the description of S607 above. Based on this, after the mobile phone executes S703, it executes the above S607.
[0157] In summary, by adopting the method of this embodiment, the camera driver can not only set a frame loss flag for the recognition frame corresponding to the ambient light brightness being less than the threshold, but also set a frame loss flag for the recognition frame in the convergence state when the ambient light brightness is greater than or equal to the threshold. This can reduce the number of recognition frames uploaded by the camera service to the target application, thereby reducing the number of threads created by the target application for the recognition frames, the memory space occupied by the recognition process, and the recognition time, thereby improving the recognition efficiency.
[0158] For example, Figure 7B As shown, after adopting the method of this embodiment, when scanning the code in a dark environment, all the multiple recognition frames collected by the camera in the scene where the screen brightness is dark (i.e., the Luxindex is large) are discarded; when the screen brightness becomes brighter (i.e., the Luxindex is small), during the process of automatic exposure and automatic focus of the camera, the camera driver identifies two recognition frames to be discarded at intervals of one frame. When the camera ends automatic exposure and automatic focus, the camera driver no longer identifies the recognition frames. In this way, the number of recognition frames recognized by the target application is much smaller than the number of recognition frames collected by the camera, so the recognition speed is fast, the time-consuming scanning process that the user can perceive is short, and the user's scanning experience is good.
[0159] In the aforementioned Figure 6 In the illustrated embodiment, after the camera is started, the metadata frame does not need any processing by the hardware, while the preview frame and the recognition frame need to be processed by the hardware. For example, the hardware needs to perform processing such as cropping and beautification on the image, so the metadata frame has three more frames than the recognition frame.
[0160] Based on this, after the camera driver obtains the metadata frame, it discards the first three data frames and starts to identify the ambient light brightness of each metadata frame from the fourth data frame. Then, the camera driver determines the metadata information of the first identification frame according to the ambient light brightness in the fourth metadata frame. That is, in this embodiment, the i-th identification frame corresponds to the i+3-th metadata frame. The camera driver obtains the metadata information corresponding to the identification frame according to the corresponding relationship, so as to determine the ambient light brightness.
[0161] For example, Figure 8As shown, after adopting the method of this embodiment, the first three metadata frames are discarded, and metadata information such as Luxindex is obtained from the fourth metadata frame, and the ambient light brightness is determined according to the metadata information. The ambient light brightness of the first six recognition frames is less than the threshold, so the recognition frames are discarded. From the seventh frame, it is detected based on the metadata frame that the camera is in the AE convergence state or the AF convergence state, so the interval frame is dropped. When it is detected based on the metadata frame that the camera ends the AE convergence and AF convergence, the interval frame dropping is stopped, and each recognition frame is uploaded to the target application.
[0162] In another scenario, the image quality captured by the camera when the mobile phone scans the code is poor, for example, the size of the identification code in the image is too small, or the scanning posture is tilted, causing the identification code area in the image to become a non-rectangular area, affecting the image quality.
[0163] Based on this, the present application embodiment also provides another scanning method, which can be Figure 6 Based on the embodiments, the recognition time when scanning a code is effectively reduced when the image quality is poor.
[0164] Reference Fig. 9 After S606, the code scanning method provided in the embodiment of the present application may include:
[0165] S901: The camera driver determines that the ambient light brightness of the metadata frame is greater than or equal to a threshold, and sets a frame loss flag for the recognition frame collected at the same timestamp as the metadata frame according to a frame loss strategy.
[0166] The frame loss strategy may refer to the introduction of the frame loss strategy in S702 above, and will not be described here in detail.
[0167] In some embodiments, the frame loss strategy in S901 and the frame loss strategy in S702 are two different strategies. For example, in S702, the frame loss flag is set for the identification frame by using the interval frame loss method, and in S901, the frame loss flag is set for all identification frames.
[0168] In some other embodiments, the frame loss strategy in S901 and the frame loss strategy in S702 are two identical strategies. For example, both S702 and S901 use an interval frame loss method to set a frame loss flag for the identification frame.
[0169] S902: The target application sends a request to end frame loss to the camera driver in response to the image zoom-in operation performed on the code scanning interface.
[0170] Before S902, the target application may receive an image zoom-in operation performed by the user on the code scanning interface, wherein the image zoom-in operation may be a double-click operation or a two-finger swipe operation.
[0171] In some embodiments, the image magnification operation includes the user double-clicking the image in the code scanning box of the code scanning interface. For example, after double-clicking the image in the code scanning box, the image is magnified and displayed in the code scanning box.
[0172] In other embodiments, the image zoom operation includes the user performing a two-finger swipe operation on the code scanning interface. In this embodiment, the user's thumb and index finger touch the touch screen at the same time, forming two touch points, one of which moves in a first direction and the other moves in a second direction, and the first direction and the second direction are opposite. The target application determines that the user performs a two-finger swipe operation based on the touch trajectory of the touch points, and then the target application sends a request to the camera driver to end frame loss.
[0173] In this step, the user performs an image zoom operation to shorten the shooting distance and magnify the photographed object, so that the objects in the recognition frame and the preview frame are magnified, thereby improving the image quality. Therefore, in response to the image zoom operation, the target application sends a request to end frame drop to the camera driver to end the frame drop processing of the recognition frame when the image quality is good, thereby avoiding the problem of long scanning time caused by discarding valid recognition frames.
[0174] In some embodiments, before receiving an image zoom operation performed by a user in a code scanning interface, the camera driver may determine whether the identification frame includes an identification code. If the identification frame includes an identification code, the camera driver confirms that the image zoom operation performed by the user is used to enlarge the size of the identification code.
[0175] In some embodiments, S902 may be replaced by S902a.
[0176] S902a: In response to the image dragging operation performed on the code scanning interface, the target application sends a request to the camera driver to end frame dropping.
[0177] Before S902a, the preview frame image displayed on the code scanning interface does not include the identification code. After S902a is executed, the preview frame image displayed on the code scanning interface includes the identification code.
[0178] Specifically, during the code scanning process, when the code scanning interface does not include the identification code, the user can adjust the camera shooting angle to realize the identification code in the code scanning interface. In addition, the user can also adjust the position of the identification code in the code scanning interface by dragging the image.
[0179] Based on this, when the target application detects the operation of dragging the image, it means that there is a high possibility that the identification code is included in the code scanning interface after the operation. Therefore, the continuous identification frames collected by the camera after the operation are identified to avoid missing the identification frames and causing the scanning time to be too long.
[0180] In some other embodiments, S902 may be replaced by S902b.
[0181] S902b: The target application sends a request to end frame loss to the camera driver in response to the image zoom-out operation performed on the code scanning interface.
[0182] Before S902b, the preview frame image displayed in the code scanning interface does not include the complete identification code. After S902b is executed, the image in the code scanning interface is reduced, so the identification code is completely displayed in the code scanning interface. Then, when the target application detects the image reduction operation, it means that the identification code can be completely displayed in the code scanning interface after the operation. Therefore, the continuous identification frames collected by the camera after the operation are identified to avoid missing the identification frames and causing the code scanning time to be too long.
[0183] S903: In response to receiving the request to end frame loss, the camera driver ends setting the frame loss flag for the identification frame according to the frame loss strategy.
[0184] Before S903 , the camera driver may receive a request from the target application to end frame dropping.
[0185] In this embodiment, after the camera driver receives the request to end frame loss, it can end the setting of the frame loss flag for the recognition frame, so the recognition frame uploaded by the camera driver to the camera service is the recognition frame without the frame loss flag set. After the camera service receives the recognition frame, it uploads it to the target application for recognition. Among them, the operation performed by the camera service can refer to the description of S607 above. Based on this, after the mobile phone executes S903, it executes the above S607.
[0186] To summarize, by adopting the method of this embodiment, the camera driver can set a frame drop flag for the recognition frames collected when the image quality is poor, so as to reduce the number of recognition frames uploaded by the camera service to the target application, and end the frame drop operation on the recognition frames when the image quality is good, thereby avoiding the problem of long scanning time caused by discarding valid recognition frames.
[0187] For example, Fig.10 As shown, after adopting the method of this embodiment, when the camera driver obtains the recognition frame, the camera driver sets a frame loss flag for two consecutive recognition frames every frame. When receiving the user's image zoom operation, the camera driver no longer discards the recognition frame. In this way, in the case of poor image quality, the number of recognition frames recognized by the target application is much smaller than the number of recognition frames collected by the camera, so the recognition speed is fast, the time spent on the scanning process that the user can perceive is short, and the user's scanning experience is good.
[0188] In the above embodiments, the frame dropping operation in the code scanning process is mainly explained from the perspective of lighting environment and image quality. In actual implementation, the code scanning recognition principles adopted by different applications are different. For example, the second type of application introduced above only recognizes the latest frame after each thread recognition ends, which is equivalent to reducing the number of recognition frames that the application needs to recognize. Therefore, for this type of application, the embodiment of this application also provides a code scanning method, which can be seen in Fig.11 , the frame loss strategy can be determined according to the application type through S1101-S1102, S603-S606, S1103 and S607-S608.
[0189] S1101: In response to the user opening the camera, the target application displays a code scanning interface and sends a request to start the camera and an application identifier to the camera service.
[0190] Different from S601, in this step, the target application also uploads an application identifier to the camera service to distinguish the type of application program. For example, the application identifier is used to distinguish the first type of application from the second type of application.
[0191] S1102: In response to receiving the request to start the camera, the camera service sends a request to call the camera driver and an application identifier to the camera driver.
[0192] For an introduction to this step, please refer to the description of S602 above.
[0193] In addition, the camera service also sends the application identifier sent by the target application to the camera driver, so that the camera driver determines whether to set a frame loss flag for the continuous multiple-frame recognition frames according to the application identifier.
[0194] After the mobile phone executes S1102, it may execute S602-S606 above, thereby setting a frame loss flag for the recognition frame whose ambient light brightness is less than the threshold, and then the mobile phone executes S1103.
[0195] S1103: In response to the acquired application identifier being a non-target identifier, the camera driver ends setting a frame loss flag for the continuous multiple identification frames when determining that the ambient light brightness of the metadata frame is greater than or equal to a threshold.
[0196] The non-target identifier is used to indicate the second type of application in the above text, and the target identifier is used to indicate the first type of application in the above text.
[0197] Among them, the non-target identifier is also called the preset identifier. The non-target identifier can be set in advance to distinguish target applications that do not require interval frame loss. When the application identifier is a non-target identifier, it means that the target application only recognizes the latest frame after the recognition of each thread ends, which is equivalent to reducing the number of recognition frames that the application needs to recognize. Therefore, for the second type of application, the camera driver ends the frame loss flag for multiple consecutive frames to avoid the problem of slowing down the scanning speed caused by discarding too many recognition frames, thereby improving the recognition speed of the target application for the recognition code in a dark environment without reducing the scanning speed. The camera driver then reports the recognition frame and the preview frame to the camera driver so that the camera driver can perform frame loss processing according to the frame loss flag of the recognition frame. Based on this, after S1103, the mobile phone executes S607-S609 in the previous text to complete the scanning process.
[0198] For example, Fig.12 As shown, after adopting the method of this embodiment, when scanning the code in a dark environment, all the multiple recognition frames collected by the camera in the scene where the screen brightness is dark (i.e., the Luxindex is large) are discarded; when the screen brightness becomes brighter (i.e., the Luxindex is small), the camera driver determines whether the target application is a non-target application. If it is a non-target application, the camera driver directly reports all subsequent recognition frames to the camera service, and the camera service reports the recognition frames to the target application for recognition. In this way, when the user uses the second type of application to scan the code, the camera driver will not discard too many recognition frames, thereby increasing the recognition speed of the target application for the recognition code in a dark environment without reducing the scanning speed. Therefore, the recognition speed is fast, the time-consuming scanning process that the user can perceive is short, and the user's scanning experience is good.
[0199] In some embodiments, the application identifier can also distinguish between the third category of applications and the fourth category of applications, where the third category of applications uses the preview stream as the real-time preview screen and the video stream for identifying the identification code. In other words, the third category of applications only sends down one stream configuration, and the preview stream is used for both displaying on the code scanning interface and obtaining the identification code information. The fourth category of applications sends down two stream configurations, with the preview stream as the video stream for the real-time preview screen and the identification stream as the identification stream for identifying the identification code.
[0200] The target application sends an application identifier to the code scanning service, so that the underlying camera service determines whether the target application only sends down one stream configuration. If it is determined that only one stream configuration is sent down, the camera driver sets a frame loss flag for the preview stream. The camera service will copy one preview stream, upload one preview stream to the target application, and discard the preview frames with the frame loss flag set in the other preview stream, and then upload them to the target application. In this way, this embodiment can avoid the problem that the code scanning interface cannot display the preview frame normally after the preview stream is lost due to the target application only sending down one stream configuration, thereby reducing the number of preview frames to be recognized by the target application without affecting the normal preview of the image captured by the camera in the code scanning interface.
[0201] To facilitate the understanding of the various embodiments in the foregoing, a complete process example is used below to illustrate the present application scheme and its effects. Fig.13 This is a flowchart of a code scanning method in a specific example of this application.
[0202] Reference Fig.13 The code scanning method provided in the embodiment of the present application may include:
[0203] S1301. Start the camera service: When the mobile phone is turned on, the camera service will be started, or, after the camera service is started, the camera service will be automatically restarted.
[0204] S1302, open the camera: Among them, opening the camera application, entering the camera function in the third-party application, and switching the shooting mode can trigger the opening of the camera and entering the code scanning function. It should be understood that opening the camera means opening the camera and entering the code scanning interface.
[0205] S1303, connecting to the camera, can also be understood as a request to start the camera: after receiving the user's operation to turn on the camera, the target program can send a request to start the camera and an application identifier to the camera service, where the application identifier is used to distinguish the type of the target application.
[0206] S1304, collect metadata frames, identification frames, and preview frames; after receiving the request to call the camera driver, the camera driver can control the camera to turn on. After the camera is turned on, it can continuously collect raw data, process the raw data to obtain YUV data, and divide the YUV data into two video streams, one video stream provides identification frames, and the other video stream provides preview frames, and at the same time report the metadata frame of the YUV data.
[0207] S1305, identifying ambient light brightness; the camera driver may obtain light intensity from the metadata frame, thereby determining the lighting environment of the recognition frame and the preview frame.
[0208] S1306, whether it is less than the threshold; if the ambient light brightness of the metadata frame is less than the threshold, it means that the lighting environment of the recognition frame and the preview frame is a dark scene, then the camera driver sets a frame drop flag for the recognition frame collected at the same timestamp as the metadata frame to instruct the upper-layer camera service to discard the recognition frame. If the ambient light brightness is greater than or equal to the threshold, it means that the lighting environment is bright, then the camera driver does not set a frame drop flag for the recognition frame corresponding to the metadata frame, and directly uploads the recognition frame to the camera service to instruct the camera service to upload the recognition frame collected under the ambient light brightness to the target application for recognition processing.
[0209] S1307, whether it is a target identifier; if the application identifier is a target identifier, it means that the target application is the first type of application mentioned above, and it is necessary to perform frame drop processing on the recognition frames after the lighting environment is bright. If the application identifier is a non-target identifier, it means that the target application is the second type of application mentioned above, and the recognition frames after the lighting environment is bright are continuously recognized and processed.
[0210] S1308: Is it in the convergence state? If AE or AF is in the convergence state, it means that the exposure or focus is in the process of adjustment. If AE and AF are not in the convergence state, it means AEdone and AFdone.
[0211] S1308a: Is it an image zoom-in operation? When receiving an image zoom-in operation from the user, the camera driver no longer discards the recognition frame.
[0212] S1309, interval frame dropping: performing interval frame dropping on the recognition frames collected by the camera in the AE convergence state and the AF convergence state.
[0213] S1310: No processing; no intermittent frame dropping, and each identification frame is uploaded to the target application.
[0214] S1311, reporting the identification frame and the preview frame; wherein the preview frame is used to be displayed on the code scanning interface, and the identification frame is used to obtain the information of the identification code.
[0215] S1312, displaying the preview frame; wherein, discarding the recognition frame will not affect the normal display of the preview frame on the code scanning interface, and thus will not affect the normal preview of the image captured by the camera on the code scanning interface.
[0216] S1313, determining the recognition result; recognizing the recognition frame reported by the framework layer at the application layer, and jumping to the interface corresponding to the recognition result.
[0217] It can be seen that the above Fig.13 The complete example shown can reduce the number of invalid recognition frames recognized by the application layer by discarding the recognition frames at the abstract layer, thereby reducing the number of threads created for recognition frames, the memory space occupied by the recognition process, and the recognition time, thereby improving the recognition efficiency.
[0218] Some other embodiments of the present application provide an electronic device, which may include: the above-mentioned display screen (such as a touch screen), a memory and one or more processors. The display screen, the memory and the processor are coupled. The memory is used to store computer program code, and the computer program code includes computer instructions. When the processor executes the computer instructions, the electronic device can execute the various functions or steps executed by the mobile phone in the above-mentioned method embodiment. The structure of the electronic device can refer to Figure 2 The structure of the mobile phone 200 is shown.
[0219] An embodiment of the present application also provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed on the above-mentioned electronic device, the electronic device executes each function or step executed by the mobile phone in the above-mentioned method embodiment.
[0220] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute each function or step executed by the mobile phone in the above method embodiment.
[0221] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0222] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0223] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0224] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0225] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0226] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. A code scanning method, characterized in that: Applied to an electronic device, the electronic device including a camera, the method comprising: Start the target application; Display the code scanning interface; Acquire an identification frame image and a preview frame image, wherein the identification frame image and the preview frame image are obtained by processing the scanned code image captured by the camera; Displaying the preview frame image on the code scanning interface; If the ambient light brightness of the recognition frame image is greater than or equal to the threshold, scanning the recognition frame image to determine the scanning recognition result; Wherein, if the ambient light brightness of the recognition frame image is greater than or equal to a threshold, scanning the recognition frame image for code recognition includes: If the ambient light brightness of the recognition frame image is greater than or equal to the threshold, and the application identifier of the target application is a preset identifier, then a frame drop flag is not set for the recognition frame image and subsequent recognition frame images; the frame drop flag is used to indicate discarding the recognition frame image; the preset identifier is used to indicate a second type of application; after the second type of application recognizes a frame of recognition frame image, if no identification code is recognized, the latest frame of recognition frame image is recognized, and a frame drop flag is set for the recognition frame images between the recognized frame image and the latest frame of recognition frame image; The exposure convergence operation and the focus convergence operation of the camera are completed, and the recognition frame image is scanned for code recognition.
2. The method according to claim 1, characterized in that The method further comprises: If the ambient light brightness of the recognition frame image is greater than or equal to the threshold, and the exposure convergence operation or the focus convergence operation of the camera is detected, the recognition frame image obtained by the camera based on the scanned code image during the execution of the exposure convergence operation or the focus convergence operation is deleted, wherein the deleted recognition frame image is not used for scanned code recognition.
3. The method according to claim 1, characterized in that If the ambient light brightness of the recognition frame image is greater than or equal to a threshold, scanning the recognition frame image for code recognition includes: If the ambient light brightness of the recognition frame image is greater than or equal to a threshold, the recognition frame image includes an identification code and the size of the identification code is increased, the recognition frame image corresponding to the identification code with the increased size is scanned for identification.
4. The method according to claim 1 or 3, characterized in that If the ambient light brightness of the recognition frame image is greater than or equal to a threshold, scanning the recognition frame image for code recognition includes: If the ambient light brightness of the recognition frame image is greater than or equal to a threshold value, and an image zoom operation performed on the code scanning interface is detected, code scanning recognition is performed on the recognition frame image obtained based on the code scanning image after the image zoom operation is performed.
5. The method according to claim 4, characterized in that Before performing code scanning and recognition on the recognition frame image obtained according to the code scanning image after performing the image magnification operation, the method further includes: It is determined that the identification frame image includes an identification code.
6. The method according to claim 1, wherein If the ambient light brightness of the recognition frame image is greater than or equal to a threshold, scanning the recognition frame image for code recognition includes: If the ambient light brightness of the recognition frame image is greater than or equal to a threshold, the recognition frame image does not include an identification code, and a drag operation of the preview frame image is detected on the code scanning interface, the recognition frame image obtained by processing the same code scanning image as the preview frame image is scanned for code recognition.
7. The method according to any one of claims 1 to 3, characterized in that The method further comprises: Acquire a metadata frame, wherein the metadata frame includes acquisition parameters for processing the scanned code image to obtain the recognition frame image; A light intensity parameter is obtained from the acquisition parameter, and the ambient light brightness of the recognition frame image is determined according to the light intensity parameter.
8. The method according to any one of claims 1 to 3, characterized in that The method further includes: if the ambient light brightness of the recognition frame image is less than a threshold, or detecting the exposure convergence operation or focus convergence operation of the camera when the ambient light brightness of the recognition frame image is greater than or equal to a threshold, or when the ambient light brightness of the recognition frame image is greater than or equal to a threshold, the size of the recognition code in the recognition frame image is less than or equal to a preset size, or when the ambient light brightness of the recognition frame image is greater than or equal to a threshold, the recognition frame image does not include the recognition code, Then setting a frame loss flag for the identified frame image; If the ambient light brightness of the recognition frame image is greater than or equal to a threshold, scanning the recognition frame image for code recognition includes: Scanning and identifying the recognition frame image that does not include the frame loss mark, wherein the ambient light brightness of the recognition frame image that does not include the frame loss mark is greater than or equal to a threshold.
9. The method according to claim 8, characterized in that The step of setting a frame loss flag for the identified frame image includes: The frame loss flag is set for at least one frame of the identification frame image in each preset frame loss period.
10. An electronic device, characterized in that: include: A memory and one or more processors; the memory and the processor are coupled; the memory is used to store computer program code, the computer program code including computer instructions; When the processor executes the computer instructions, the electronic device performs the method according to any one of claims 1 to 9.
11. A computer-readable storage medium, characterized in that The method comprises computer instructions, which, when executed on an electronic device, cause the electronic device to execute the method according to any one of claims 1 to 9.
Citation Information
Cited By
Code scanning method and electronic device
EP4439382A1
Code scanning method and electronic device
WO2024055817A1
