Focusing method and electronic device

By adjusting the focus position during shooting to match the size of the face detection frame, the instability of autofocus in environments with moving subjects or low signal-to-noise ratio is solved, improving image clarity and focus stability.

CN119854631BActive Publication Date: 2026-01-23HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311322106.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-11
Publication Date
2026-01-23
Estimated Expiration
2043-10-11

AI Technical Summary

Technical Problem

In existing technologies, autofocus is prone to instability when shooting moving subjects or in low signal-to-noise ratio environments, resulting in low image sharpness.

Method used

By obtaining the focus position and the size of the face detection box, the matching relationship is determined, and the focus position is adjusted to ensure stability. The focus position at the previous focus moment is used as a reference to reduce the frequency of focus position changes.

Benefits of technology

It improves image clarity when shooting moving portraits or in low signal-to-noise ratio environments, and enhances focus stability and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119854631B_ABST
    Figure CN119854631B_ABST
Patent Text Reader

Abstract

The application relates to the field of image processing, in particular to a focusing method and an electronic device. The focusing method is applied to an electronic device, and the electronic device comprises a camera device. The method comprises the following steps: performing optimization processing on a focusing position calculated by an automatic focusing function of the electronic device; in the case that the calculated focusing position and the size of a face detection frame do not match, discarding the focusing position and continuing to use the previous focusing position. Through the method in the embodiment of the application, the wrong and inaccurate focusing position data can be filtered out according to the size change of the face detection frame, stable focusing is realized, and therefore the definition of a photographed image is effectively improved, and the user experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of image processing, and in particular to a focusing method and an electronic device. BACKGROUND

[0002] Auto Focus is a way of using the principle of light reflection of an object, receiving the reflected light by a sensor on a camera, and driving an electric focusing device (such as a focusing motor) to focus through calculation and processing. Currently, electronic devices with photographing functions usually have an auto focus function.

[0003] However, when photographing a moving person or in a case where the signal-to-noise ratio of the environment is low, the focusing result of the auto focus function is prone to instability, resulting in low clarity of the photographed image, thereby affecting the user experience. SUMMARY

[0004] The present application provides a focusing method and an electronic device, which solves the problem of unstable focusing in the prior art.

[0005] To achieve the above-mentioned purpose, the present application adopts the following technical solutions:

[0006] In a first aspect, a focusing method is provided, applied to an electronic device, the electronic device comprising a camera device, and the method comprising:

[0007] obtaining a first focusing position and a first size of a first detection frame, wherein the first focusing position is a calculated relative distance between a sensor and a lens module of the camera device after auto focusing at a first time, and the first detection frame is a detection frame obtained by performing face detection on a preview image in a viewfinder frame corresponding to the first time;

[0008] if the first focusing position and the first size do not match, adjusting a focusing position of the camera device to a second focusing position, so that the camera device focuses according to the second focusing position at the first time, wherein the second focusing position is a focusing position used by the camera device to focus at a second time, and the second time is a previous focusing time of the first time.

[0009] In the present application, after obtaining the first focusing position and the first size of the first detection frame, it can be determined whether the first focusing position and the first size match. If the first focusing position and the first size match, the camera device is controlled to focus according to the first focusing position at the first time. If the first focusing position and the first size do not match, the step of adjusting the focusing position of the camera device to the second focusing position is performed.

[0010] It can be understood that the focusing method adopted at the second time can be the same as the focusing method adopted at the first time.

[0011] For the first focusing time, in an implementation manner, the imaging device can be caused to focus according to the first focusing position at the first focusing time, where the first focusing position is the relative distance between the sensor and the lens module of the imaging device after automatic focusing at the first focusing time. In this implementation manner, the result of automatic focusing at the first focusing time is used for focusing, and the result of automatic focusing is not adjusted.

[0012] For the first focusing time, in another implementation manner, the result of automatic focusing at the first focusing time can also be adjusted, and the imaging device can be caused to focus according to the adjusted focusing position at the first focusing time. Specifically, if the first focusing position matches the third size of the third detection frame, the imaging device is caused to focus according to the first focusing position at the first focusing time; if the first focusing position does not match the third size, the focusing position of the imaging device is adjusted to a focusing position matching the third size, and the imaging device is caused to focus according to the focusing position matching the third size at the first focusing time. The third detection frame is a detection frame obtained by performing face detection on the preview image in the viewfinder frame corresponding to the first focusing time. Compared with the above implementation manner, the focusing position at the first focusing time is also adjusted in this implementation manner, so that the preview image obtained at the first focusing time is clear.

[0013] In some related technologies, the imaging device usually focuses according to the first focusing position, in other words, the imaging device focuses by using the focusing position calculated by the automatic focusing function of the electronic device. In the present application, after the first focusing position is obtained, the focusing position of the imaging device needs to be adaptively adjusted according to the matching relationship between the first focusing position and the first size, and focusing is performed according to the adjusted focusing position (second focusing position) at the first time. In other words, the focusing method of the present application is equivalent to an optimization process of the focusing position calculated by the automatic focusing function of the electronic device.

[0014] In the application embodiment, in the case that the size of the detection frame is inconsistent, the first focusing position is abandoned, and the previous focusing position is followed. In this way, the frequency of change of the focusing position can be effectively reduced, the focusing stability is ensured, and thus the clarity of the captured image is improved.

[0015] In an implementation form of the first aspect, the method further comprises:

[0016] obtaining a second size of a second detection frame, wherein the second detection frame is a detection frame obtained by performing face detection on a preview image in a viewfinder frame corresponding to a second time point;

[0017] if the first size and the second size are inconsistent, determining whether the first focusing position and the first size are matched.

[0018] if the first size and the second size are consistent, controlling the camera device to focus according to the second focusing position at the first time point.

[0019] Taking a rectangular frame as an example, the first size includes a first width value and a first height value, and the second size includes a second width value and a second height value.

[0020] Taking an elliptical frame as an example, the first size includes a first major axis diameter and a first minor axis diameter, and the second size includes a second major axis diameter and a second minor axis diameter.

[0021] Since the detection frame meets the principle of near large and far small, in the application embodiment, whether the shooting distance between the photographed user and the lens changes is determined by judging whether the size of the detection frame is consistent. If the first size and the second size are inconsistent, it indicates that the shooting distance between the photographed user and the lens changes at the first time point and the second time point, and then the focusing position is adjusted. If the first size and the second size are consistent, it indicates that the shooting distance between the photographed user and the lens does not change at the first time point and the second time point, and then the first focusing position does not need to be adjusted, and the focusing is performed by using the focusing position adjusted at the previous time point (the second time point) (the second focusing position). In this way, the calculation time of the algorithm can be effectively reduced, and the focusing efficiency is improved.

[0022] In an implementation form of the first aspect, the detection frame is a rectangular frame, the first size comprises a first width value and a first height value, the second size comprises a second width value and a second height value, and the method further comprises:

[0023] if the first width value is consistent with the second width value and / or the first height value is consistent with the second height value, it is determined that the first size and the second size are consistent;

[0024] if the first width value is inconsistent with the second width value and the first height value is inconsistent with the second height value, it is determined that the first size and the second size are inconsistent.

[0025] In the embodiments of the present application, if the sizes of two edges of the detection frame are changed, it is considered that the first size and the second size are inconsistent; and if the size of one edge of the detection frame is not changed, it is considered that the first size and the second size are consistent. Through the determination of the consistency of the first size and the second size in the above implementation form, whether the distance between the photographed user and the lens is changed can be determined more accurately, which is beneficial to the stability of subsequent focusing.

[0026] It should be noted that if the detection frame is of other shapes, the implementation form of determining whether the first size and the second size are consistent is the same as that of the above implementation form of the rectangular frame, that is, when each size in the first size and the second size is changed, it is determined that the first size and the second size are inconsistent; and if any size in the first size and the second size is not changed, it is determined that the first size and the second size are consistent. Details are not repeated here.

[0027] In an implementation form of the first aspect, the determination of whether the first focusing position and the first size match comprises:

[0028] determining a preset threshold value according to the first size and the second size;

[0029] if the first focusing position exceeds the preset threshold value, it is determined that the first focusing position and the first size do not match;

[0030] if the first focusing position does not exceed the preset threshold value, it is determined that the first focusing position and the first size match.

[0031] In an implementation form of the first aspect, the detection frame is a rectangular frame, the first size comprises a first width value and a first height value, the second size comprises a second width value and a second height value; and the determination of the preset threshold value according to the first size and the second size comprises:

[0032] calculate a first variation between the first width value and the second width value, and a second variation between the first height value and the second height value;

[0033] obtain relationship data between a size value of a target edge and a focus position, wherein the target edge is an edge corresponding to a target variation in the first detection frame, and the target variation is a minimum value of the first variation and the second variation;

[0034] determine the preset threshold according to the relationship data.

[0035] For example, if the first variation is less than the second variation, the target variation is the first variation, and the target edge is the width edge; if the first variation is greater than the second variation, the target variation is the second variation, and the target edge is the height edge.

[0036] For example, when the target edge is the width edge, the target focus position corresponding to the first width value is found from the relationship data between the width edge and the focus position. When the target edge is the height edge, the target focus position corresponding to the first height value is found from the relationship data between the height edge and the focus position.

[0037] By the above implementation manner, the preset threshold of the focus position is determined according to the relationship data corresponding to the edge with the minimum variation in the detection frame, which can accurately reflect the change of the distance between the user being photographed and the lens, improve the reliability of the judgment result, and thus improve the accuracy of the subsequent focus position.

[0038] In some implementation manners, the relationship data between the size value of each edge of the detection frame and the focus position can be calibrated in advance, and the relationship data is stored in the electronic device (for example, in the storage medium of the electronic device), and the corresponding relationship data can be called when needed.

[0039] In other implementation manners, the relationship data can be continuously updated as the user uses. For example, in some application scenarios, if the focus is performed by the focusing method of the embodiments of the present application, the preview image cannot still be guaranteed to be clear, and the user can manually focus. In this case, the electronic device can record the focus position of the user's manual focusing, associate the focus position with the size of the current face detection frame, and adjust the existing relationship data according to the association relationship, so as to update the relationship data. With the continuous updating of the relationship data, the focusing stability of the focusing method of the embodiments of the present application will be higher and higher.

[0040] It should be noted that the focusing method provided by the embodiments of the present application can be processed for each image frame, or processed once every preset number of image frames.

[0041] In a second aspect, a chip system is provided, the chip system comprising a processor coupled with a memory, the processor executing a computer program stored in the memory to implement the method according to any one of the first aspect.

[0042] In a third aspect, an electronic device is provided, the electronic device comprising a processor configured to execute a computer program stored in a memory to cause the electronic device to implement the method according to any one of the first aspect.

[0043] In a fourth aspect, a computer-readable storage medium is provided, the computer-readable storage medium storing a computer program, the computer program being executed by one or more processors to implement the method according to any one of the first aspect.

[0044] In a fifth aspect, a computer program product is provided, the computer program product, when executed on an electronic device, causing the electronic device to implement the method according to any one of the first aspect. BRIEF DESCRIPTION OF DRAWINGS

[0045] Figure 1 FIG. 1 is a structural schematic diagram of an electronic device provided by an embodiment of the present application;

[0046] Figure 2 FIG. 2 is a software structure block diagram of the electronic device 100 of the embodiment of the present application;

[0047] Figure 3 FIG. 3 is a schematic diagram of an imaging principle provided by the embodiment of the present application;

[0048] Figure 4 FIG. 4 is a schematic diagram of a moving portrait shooting scene provided by the embodiment of the present application;

[0049] Figure 5 FIG. 5 is a flow schematic diagram of a focusing method provided by the embodiment of the present application;

[0050] Figure 6 FIG. 6 is a flow schematic diagram of a focusing method provided by another embodiment of the present application;

[0051] Figure 7 FIG. 7 is a schematic diagram of a first detection frame and a second detection frame provided by the embodiment of the present application;

[0052] Figure 8 FIG. 8 is a schematic diagram of a calibration image provided by the embodiment of the present application;

[0053] Figure 9 FIG. 9 is a schematic diagram of a linear relationship between a high side of a detection frame and a focusing position;

[0054] Figure 10 FIG. 10 is a diagram of a preset threshold value varying with the size of a detection frame provided by the embodiment of the present application;

[0055] Figure 11 is a contrast diagram of the focusing position provided by the embodiment of the present application. DETAILED DESCRIPTION

[0056] In the following description, for the purposes of explanation and not limitation, specific details are set forth, such as particular sequences of steps, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application can be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known methods, techniques, etc. are omitted so as not to obscure the description of the present application.

[0057] It should be understood that the term "comprising" when used in the specification and claims of this application indicates the presence of the described features, integers, steps, operations, elements, and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.

[0058] It should also be understood that, in the embodiments of the present application, "one or more" means one, two, or more than two; "and / or" describes the association relationship of the associated objects, which means that there can be three relationships; for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone, where A and B can be singular or plural. The character " / " generally represents an "or" relationship between the associated objects before and after it.

[0059] In addition, in the description of the specification and the appended claims of the present application, the terms "first", "second", "third", "fourth", etc. are only used to distinguish the description, and cannot be understood as indicating or implying relative importance.

[0060] In the present application, the reference to "one embodiment" or "some embodiments" and the like means that the specific features, structures or characteristics described in connection with the embodiment are included in one or more embodiments of the present application. Therefore, the statements "in one embodiment", "in some embodiments", "in other some embodiments", "in other some embodiments" and the like appearing in different places in the specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized. The terms "include", "contain", "have" and their variants mean "including but not limited to", unless otherwise specifically emphasized.

[0061] The focusing method provided in the embodiments of the present application can be applied to an electronic device with a photographing function. The electronic device comprises a camera, and the electronic device realizes the photographing function through the camera. The electronic device in the embodiments of the present application can also be referred to as a terminal device, a terminal, a user equipment (UE) or a user terminal, etc. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a handheld computer, a wearable device (such as a smart watch, a smart bracelet, etc.), a notebook computer, a palm computer, a personal computer, a smart home device (such as a television, etc.), a smart screen, a game console, a mobile Internet device (MID), a point of sale (POS), an augmented reality (AR) device, a virtual reality (VR) device, a camera, a video camera, etc. The embodiments of the present application do not specially limit the specific form of the electronic device. For the convenience of description, the following embodiments are described by taking a mobile phone as an example.

[0062] Exemplarily, referring to Figure 1 , it is a structural schematic diagram of the electronic device provided in the embodiments of the present application.

[0063] As shown in Figure 1 , the electronic device 100 can comprise a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 140A, a battery 140B, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a loudspeaker 170A, a receiver 170B, a microphone 170C, a headset interface 170D, a sensor module 180, a key 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 can comprise a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0064] The processor 110 can comprise one or more processing units, wherein different processing units can be independent devices or can be integrated in one or more processors.

[0065] The processor 110 can also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory can hold instructions or data that the processor 110 has just used or is using repeatedly. If the processor 110 needs to use the instructions or data again, it can call them directly from the memory. This avoids repeated access and reduces the waiting time of the processor 110, thus improving the efficiency of the system.

[0066] In some embodiments, the processor 110 is configured to execute a computer program stored in the memory to implement the focusing method provided in the embodiments of the present application.

[0067] The electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor, etc. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 can include one or more GPUs that execute program instructions to generate or change display information.

[0068] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Miniled, a MicroLed, a Micro-OLED, a quantum dot light emitting diode (QLED), etc. In some embodiments, the electronic device 100 can include 1 or N display screens 194, N being a positive integer greater than 1. In some embodiments, the electronic device 100 displays a user interface, such as a shooting interface of a camera application, through the display screen 194.

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

[0070] The camera 193 is used to capture still images or videos. In some embodiments, the electronic device 100 can include 1 or N cameras 193, N being a positive integer greater than 1.

[0071] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 performs various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. For example, the processor 110 performs a photographing function of the electronic device 100 and an auto-focusing function in a photographing process by running the instructions stored in the internal memory 121. The internal memory 121 can include a program storage area and a data storage area. The program storage area can store an operating system, at least one application program required by a function, and the like. The data storage area can store data created during use of the electronic device 100 (such as interface information corresponding to a user interface, and the like), and the like. In addition, the internal memory 121 can include a high-speed random access memory, and can further include a non-volatile memory such as at least one of a magnetic disk storage device, a flash memory device, a universal flash storage (UFS), and the like.

[0072] The pressure sensor 180A is used to sense a pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be disposed on the display screen 194. There are many types of pressure sensors 180A, such as a resistive pressure sensor, an inductive pressure sensor, a capacitive pressure sensor, and the like. The capacitive pressure sensor can include at least two parallel plates with conductive material. When a force is applied to the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure according to the change in capacitance. When a touch operation is applied to the display screen 194, the electronic device 100 detects the intensity of the touch operation according to the pressure sensor 180A. The electronic device 100 can also calculate the position of the touch according to the detection signal of the pressure sensor 180A.

[0073] The touch sensor 180K, also referred to as a "touch panel". The touch sensor 180K can be disposed on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also referred to as a "touch panel". The touch sensor 180K is used to detect a touch operation applied thereto or in the vicinity thereof. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event. For example, when a touch operation is applied to an icon of a camera application, an instruction to open the camera application is executed. For another example, when a touch operation is applied to a certain position within a viewfinder in a photographing interface of the camera application, an instruction to perform auto-focusing is executed. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be disposed on the surface of the electronic device 100, which is different from the position where the display screen 194 is located.

[0074] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.

[0075] Understandable, Figure 1 The illustrated structures of the electronic device 100 are merely structural examples, showing some modules related to the focusing method described in the embodiments of this application. The structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0076] In addition, an operating system runs on top of the aforementioned components. Examples include iOS, Android (an open-source operating system), and Windows. Applications can be installed and run on this operating system.

[0077] The operating system of electronic device 100 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This application embodiment uses the layered architecture Android system as an example to exemplify the software structure of electronic device 100.

[0078] Figure 2 This is a software structure block diagram of the electronic device 100 according to an embodiment of this application.

[0079] A layered architecture divides software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the system libraries and Android runtime, and the kernel layer.

[0080] The application layer can include a series of application packages. For example... Figure 2 As shown, the application package can include applications such as camera, gallery, calendar, call, map, e-book, shopping, Bluetooth, music, video, and SMS. For example, a camera application can include an autofocus function; when a user takes a portrait photo using the camera application, the electronic device uses the autofocus function to focus on the face as the subject.

[0081] The application framework layer provides an application programming interface (API) and a programming framework for the applications of the application layer. The application framework layer includes some pre-defined functions. As shown in Figure 2 The application framework layer can include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.

[0082] In the embodiments of the present application, the application framework layer can include a camera access interface, wherein the camera access interface is configured to provide an application programming interface and a programming framework for a camera application.

[0083] The Android runtime includes a core library and a virtual machine. The Android runtime is responsible for the scheduling and management of the Android system. The core library includes two parts: one part is the function functions required by the java language to call, and the other part is the core library of the Android. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the java files of the application layer and the application framework layer into binary files. The virtual machine is configured to perform the management of the object life cycle, the management of the stack, the management of the thread, the management of the security and the exception, and the garbage collection.

[0084] The system library can include a plurality of functional modules. For example: a surface manager, media libraries, a three-dimensional graphics processing library (for example: OpenGL ES), a 2D graphics engine (for example: SGL), and the like.

[0085] The kernel layer is a layer between hardware and software. The kernel layer at least includes a display driver, a camera driver, an audio driver, and a sensor driver. The camera driver is configured to drive the camera to collect images.

[0086] The focusing method provided in the embodiments of the present application will be described below in combination with the above hardware structure and software structure.

[0087] For the convenience of understanding, the concepts related to the embodiments of the present application will be introduced first.

[0088] Focusing, also called focusing or focusing, refers to adjusting the relative distance (image distance) between the sensor and the lens by moving the position of the sensor (such as a CMOS image sensor) or the lens module (such as some floating lenses) of the camera, so as to achieve the purpose of clear imaging.

[0089] For example, referring to Figure 3 is a schematic diagram of the imaging principle provided in the embodiments of the present application. As shown in Figure 3As shown in FIG. 1, AB represents a photographed object, A'B' represents an image of AB, CD represents a lens, u represents an object distance (a distance between the photographed object AB and a lens optical center O), v represents an image distance (a distance between the lens optical center O and the image A'B'), and f represents a focal distance (a distance between a focal point F and the lens optical center O).

[0090] As shown in FIG. 2, the triangle ABO and the triangle A'B'O are similar triangles, and thus AB:A'B' = u:v, that is, A'B' = v x AB / u. Because the relationship between the image distance, the object distance, and the focal distance is 1 / u + 1 / v = 1 / f, the following relationship A'B' = v x AB / f - AB exists. Figure 3

[0091] As can be seen from the above relationship, in the case that the focal distance f is fixed and AB is unchanged, as the lens module moves (moves along the straight line on which BB' is located), the image A'B' and the image distance v are in a linear relationship. That is, the larger the image distance v is, the larger the image A'B' is; the smaller the image distance v is, the smaller the image A'B' is. Generally, the lens is installed at the position of the focusing motor, and the lens position / focusing motor position and the image distance v and the object distance u are also in a linear relationship, that is, the closer the lens position / focusing motor position is to the photographed object, the larger the image distance v is and the smaller the object distance is; the farther the lens position / focusing motor position is from the photographed object, the smaller the image distance v is and the larger the object distance is.

[0092] The image distance is adjusted by moving the lens module, so that the image perceived by the sensor is clear. When the imaging is clear, that is, the focusing is completed. In the embodiments of the present application, the relative distance (image distance) between the sensor and the lens when the focusing is completed is referred to as a focusing position or a focusing position.

[0093] It should be noted that the above example is a focusing mode by moving the lens module, and the principle of a focusing mode by moving the sensor is similar, which will not be described here. The difference between the two is that the focusing mode by moving the lens module changes the image distance and the object distance at the same time, while the focusing mode by moving the sensor only changes the image distance.

[0094] At present, electronic devices with a shooting function have an automatic focusing function. Auto Focus is a way of using the principle of light reflection of an object, receiving the reflected light by a sensor on a camera, and driving an electric focusing device (such as a focusing motor) to focus through calculation and processing. Taking a mobile phone as an example, when a user takes an object through a camera application on the mobile phone, the camera application can automatically focus on the photographed object through a focusing algorithm to ensure that the image of the photographed picture is clear.

[0095] ​The auto-focusing includes phase focusing and contrast focusing. The phase focusing refers to measuring the phase difference of light passing through the lens by using phase detection pixels on the camera sensor, so as to calculate the distance and position of the object and automatically adjust the position of the lens. The contrast focusing refers to measuring the sharpness of the object by detecting the contrast difference between regions in the scene, so as to automatically adjust the position of the lens. Compared with the two ways, the phase focusing way is usually faster and is suitable for shooting moving objects. The contrast focusing way is more accurate and is suitable for shooting static objects or close-up shooting.

[0096] In some application scenarios, the shooting of moving objects may be unstable. For example, when shooting a moving portrait, since the person is in a moving state, the detected face region does not match the actual face region, resulting in unstable focusing and a pull focus situation. The pull focus refers to changing the position of the lens module while pressing the shutter, thereby producing a radial exposure effect.

[0097] For example, referring to Figure 4 , which is a schematic diagram of a moving portrait shooting scenario provided by an embodiment of the present application. As shown in Figure 4 , the user interface 40 of the camera application is shown in (a), in which the position of the face detection frame 401 in the viewfinder matches the actual face region. Since face detection has a certain hysteresis, as the shooting object moves, the face detection frame may not be able to "keep up" with the movement of the shooting object. As shown in Figure 4 , the user interface 41 of the camera application is shown in (b), in which the position of the face detection frame 402 in the viewfinder does not match the actual face region.

[0098] In the application scenario shown in Figure 4 , since the face detection frame does not match the actual face region, the focusing subject may change, such as taking part of the background as the focusing subject, which results in inaccurate focusing and a pull focus situation, thereby affecting the sharpness of the portrait shooting.

[0099] In other application scenarios, the signal-to-noise ratio of the shooting environment is low, such as shooting a portrait in backlight or shooting a portrait in night scene. In this application scenario, the phase focusing way may detect more error data, for example, taking part of the background pixels as the pixels of the face region, resulting in inaccurate distance and position of the calculated face, and further resulting in unstable focusing and affecting the sharpness of the portrait shooting.

[0100] Based on this, the embodiment of the present application provides a focusing method. Through the method in the embodiment of the present application, the wrong and inaccurate focusing position data can be filtered out according to the size change of the face detection frame, stable focusing is realized, and thus the definition of the photographed image is effectively improved, and the user experience is improved.

[0101] Referring to Figure 5 , a flowchart of the focusing method provided by the embodiment of the present application is shown. As an example but not limitation, as shown in Figure 5 , the focusing method can include the following steps:

[0102] S501, a first focusing position and a first size of a first detection frame are acquired.

[0103] The first focusing position is the relative distance between the sensor and the lens module of the camera device after automatic focusing at a first time, and the first detection frame is the detection frame obtained by performing face detection on a preview image in a viewfinder frame corresponding to the first time.

[0104] In the embodiment of the present application, the first focusing position can be a focusing position calculated by the automatic focusing function (automatic focusing algorithm) of the electronic device. For example, when the electronic device is a camera, the focusing position can be calculated by the automatic focusing function of the camera. For another example, when the electronic device is a mobile phone, the focusing position can be calculated by the automatic focusing function of the camera application in the mobile phone.

[0105] In the embodiment of the present application, the face detection algorithm can be used to perform face detection processing on the preview image to obtain the detection frame. In the embodiment of the present application, the face detection algorithm used and the way of obtaining the detection frame are not limited.

[0106] The size of the detection frame is used to represent the size of the detection frame. In some implementations, the detection frame can be a rectangular frame, and accordingly, the size of the detection frame includes the size value of the width side and the size value of the height side. In other implementations, the detection frame can also be an oval frame, and accordingly, the size of the detection frame includes the size value of the long axis diameter and the short axis diameter (or the long axis radius and the short axis radius). Of course, the detection frame can also be other shapes, and accordingly, the size of the detection frame includes the size value used to represent the size of the detection frame. In the embodiment of the present application, the shape of the detection frame is not limited.

[0107] S502, if the first focusing position and the first size do not match, the focusing position of the camera device is adjusted to a second focusing position, so that the camera device focuses according to the second focusing position at the first time.

[0108] In the embodiments of the present application, after S501, it can be determined whether the first focus position and the first size match. If the first focus position and the first size match, the camera device is controlled to focus according to the first focus position at the first time. If the first focus position and the first size do not match, S502 is performed.

[0109] In an implementation, if the first focus position and the first size do not match, a focus position matching the first size can be calculated, and the focus position of the camera device is adjusted to the calculated focus position matching the first size, so that the camera device focuses according to the focus position matching the first size at the first time. However, compared with the method in S502, this implementation needs to recalculate a new focus position as long as the first focus position and the first size do not match, and the calculation frequency is high, which can easily affect the focus efficiency. In addition, in the case that the face detection frame is not accurate and the size of the detection frame changes continuously, the focus result obtained by this implementation also changes continuously, which can still affect the focus stability.

[0110] The second focus position is a focus position used by the camera device to focus at a second time, and the second time is a previous focus time of the first time. It can be understood that the focus method used at the second time can be the same as the focus method used at the first time. Specifically, a third focus position and a second size of a second detection frame are obtained. If the third focus position and the second size do not match, the focus position of the camera device is adjusted to a fourth focus position, i.e., the second focus position is the fourth focus position. If the third focus position and the second size match, the second focus position is the third focus position. The third focus position is a calculated relative distance between a sensor and a lens module of the camera device after automatic focusing at the second time. The second detection frame is a detection frame obtained by performing face detection on a preview image in a viewfinder frame corresponding to the second time. The fourth focus position is a focus position used by the camera device to focus at a third time, and the third time is a previous focus time of the second time. The same applies to the subsequent.

[0111] For the first focus time, in an implementation, the camera device can be caused to focus according to a first focus position at the first focus time. The first focus position is a calculated relative distance between a sensor and a lens module of the camera device after automatic focusing at the first focus time. In this implementation, the result of automatic focusing at the first focus time is used for focusing, and the result of automatic focusing is not adjusted.

[0112] For the first focusing moment, in another implementation manner, the result of the automatic focusing of the first focusing moment can also be adjusted, and the camera device is caused to focus according to the adjusted focusing position at the first focusing moment. Specifically: if the first focusing position matches the third size of the third detection frame, the camera device is caused to focus according to the first focusing position at the first focusing moment; if the first focusing position does not match the third size, the focusing position of the camera device is adjusted to a focusing position matching the third size, and the camera device is caused to focus according to the focusing position matching the third size at the first focusing moment. The third detection frame is a detection frame obtained by performing face detection on a preview image in a viewfinder frame corresponding to the first focusing moment. Compared with the above implementation manner, the focusing position of the first focusing moment is also adjusted in this implementation manner, so that the preview image obtained from the first focusing moment is clear.

[0113] In some related technologies, the camera device usually focuses according to the first focusing position, in other words, the camera device focuses according to the focusing position calculated by the automatic focusing function of the electronic device. In the present application, after obtaining the first focusing position, the focusing position of the camera device needs to be adaptively adjusted according to the matching relationship between the first focusing position and the first size, and focusing is performed according to the adjusted focusing position (second focusing position) at the first time. In other words, the focusing method of the present application is equivalent to an optimization process of the focusing position calculated by the automatic focusing function of the electronic device.

[0114] In the application scenarios such as sports portrait shooting or low signal-to-noise ratio of the shooting environment, compared with the focusing method in the related art, the focusing method in the present application can cause the focusing position to change frequently and be unstable. Since the face detection frame satisfies the principle of near large and far small, the focusing position does not match the size of the face detection frame, which is equivalent to the focusing position not matching the shooting distance (the distance between the photographed object and the camera device). In the focusing method in the present application, in the case where the focusing position does not match the size of the face detection frame, the focusing position is discarded, and the previous focusing position is followed. In this way, the frequency of change of the focusing position can be effectively reduced, the stability of focusing is ensured, and the clarity of the photographed image is improved.

[0115] In some embodiments, referring to Figure 6 is a flowchart of a focusing method provided by another embodiment of the present application. As an example but not limitation, as shown in Figure 6 , the method can include the following steps:

[0116] S601, obtaining a first focusing position and a first size of a first detection frame.

[0117] Step S601 is the same as step S501, and details are referable to the description in the embodiment of S501, which will not be repeated here.

[0118] S602, a second size of a second detection frame is acquired.

[0119] The second detection frame is a detection frame obtained by performing face detection on a preview image in a viewfinder frame corresponding to a second moment, and the second moment is a previous focusing moment of the first moment.

[0120] The manner of acquiring the second detection frame is the same as that of acquiring the first detection frame, and details are referable to the description of the manner of acquiring the first detection frame in the embodiment of S501, which will not be repeated here.

[0121] S603, it is judged whether the first size and the second size are consistent.

[0122] Taking the detection frame as a rectangular frame as an example, the first size includes a first width value and a first height value, and the second size includes a second width value and a second height value.

[0123] In some implementations, step S603 can include:

[0124] If the first width value is consistent with the second width value, and the first height value is consistent with the second height value, it is determined that the first size and the second size are consistent; otherwise, it is determined that the first size and the second size are inconsistent.

[0125] In this implementation, it is considered that the first size and the second size are consistent as long as the size of any one side of the detection frame changes.

[0126] Referring to Figure 7 is a schematic diagram of the first detection frame and the second detection frame provided by the embodiment of the present application.

[0127] In one case, the distance between the user being photographed and the lens does not change, but the user's face posture changes. As shown in (a) of Figure 7 , the face in the first detection frame 71 is a front face, and the face in the second detection frame 72 is a side face. In this case, the width value of the detection frame changes. Specifically, the height values of the first detection frame 71 and the second detection frame 72 are the same, both being a1; the width values of the first detection frame 71 and the second detection frame 72 are different, the first width value of the first detection frame 71 is b1, and the second width value of the second detection frame 72 is b2. As shown in (b) of Figure 7As shown in (b) of FIG. 7, the face in the first detection frame 71 is a front face, and the face in the second detection frame 73 is a head-up state. In this case, the length value of the detection frame changes. Specifically, the height values of the first detection frame 71 and the second detection frame 73 are different, the first height value of the first detection frame 71 is a1, and the second height value of the second detection frame 73 is a2; the width values of the first detection frame 71 and the second detection frame 73 are the same, and are both b1.

[0128] In another case, the distance between the photographed user and the lens changes. As shown in (c) of FIG. 7, the face in the first detection frame 71 is a front face, and the face in the second detection frame 74 is also a front face. However, the face corresponding to the second detection frame 74 is farther away from the lens position, so the height value and the width value of the first detection frame 71 and the second detection frame 74 change. Specifically, the first height value of the first detection frame 71 is a1, and the second height value of the second detection frame 74 is a2; the first width value of the first detection frame 71 is b1, and the second width value of the second detection frame 74 is b2. Figure 7 As shown in (b) of FIG. 7, the face in the first detection frame 71 is a front face, and the face in the second detection frame 73 is a head-up state. In this case, the length value of the detection frame changes. Specifically, the height values of the first detection frame 71 and the second detection frame 73 are different, the first height value of the first detection frame 71 is a1, and the second height value of the second detection frame 73 is a2; the width values of the first detection frame 71 and the second detection frame 73 are the same, and are both b1.

[0129] Figure 7 As can be seen from the examples, when the height value and the width value of the detection frame change, it indicates that the distance between the photographed user and the lens changes; if either the height value or the width value of the detection frame does not change, it indicates that the distance between the photographed user and the lens does not change, and it may only be a change in the face posture.

[0130] Therefore, if the above implementation manner is used, the case where the distance between the photographed user and the lens does not change may be misjudged as the distance between the photographed user and the lens changes, thereby affecting the stability of subsequent focusing.

[0131] To solve the above problem, in some other implementation manners, the step S603 can include:

[0132] If the first width value and the second width value are consistent, and / or the first height value and the second height value are consistent, it is determined that the first size and the second size are consistent.

[0133] If the first width value and the second width value are inconsistent, and the first height value and the second height value are inconsistent, it is determined that the first size and the second size are inconsistent.

[0134] Specifically, the first width value and the second width value being consistent can mean that the first width value and the second width value are the same; or the first width value and the second width value can differ by less than a first preset value. Similarly, the first height value and the second height value being consistent can mean that the first height value and the second height value are the same; or the first height value and the second height value can differ by less than a second preset value.

[0135] ​In the implementation manner, the sizes of the two sides of the detection frame are changed, and it is considered that the first size and the second size are inconsistent; as long as the size of one side of the detection frame is not changed, it is considered that the first size and the second size are consistent. Through the consistency of the first size and the second size in the implementation manner, whether the distance between the photographed user and the lens changes can be accurately judged, and the stability of subsequent focusing is beneficial.

[0136] Similarly, if the detection frame is an oval frame, the first size can include a first long-axis diameter and a first short-axis diameter, and the second size can include a second long-axis diameter and a second short-axis diameter. The implementation manner of S603 can include:

[0137] If the first long-axis diameter and the second long-axis diameter are consistent, and / or the first short-axis diameter and the second short-axis diameter are consistent, it is determined that the first size and the second size are consistent.

[0138] If the first long-axis diameter and the second long-axis diameter are inconsistent, and the first short-axis diameter and the second short-axis diameter are inconsistent, it is determined that the first size and the second size are inconsistent.

[0139] The first long-axis diameter and the second long-axis diameter being consistent can mean that the first long-axis diameter and the second long-axis diameter are the same, or that the difference between the first long-axis diameter and the second long-axis diameter is less than a first preset value. Similarly, the first short-axis diameter and the second short-axis diameter being consistent can mean that the first short-axis diameter and the second short-axis diameter are the same, or that the difference between the first short-axis diameter and the second short-axis diameter is less than a second preset value.

[0140] It should be noted that if the detection frame is of other shapes, the implementation manner of step S603 is the same as the implementation manner of the above-mentioned rectangular frame or oval frame, that is, when each size in the first size and the second size changes, it is determined that the first size and the second size are inconsistent; if any size in the first size and the second size does not change, it is determined that the first size and the second size are consistent. Herein, no further description is given.

[0141] S604, if the first size and the second size are inconsistent, it is determined whether the first focusing position and the first size are matched.

[0142] In some implementation manners, step S604 can include:

[0143] A preset threshold value is determined according to the second size; if the first focusing position exceeds the preset threshold value, it is determined that the first focusing position and the first size are not matched; if the first focusing position does not exceed the preset threshold value, it is determined that the first focusing position and the first size are matched.

[0144] Taking a rectangular detection frame as an example, the method for determining the preset threshold based on the second dimension includes: obtaining the relationship data between the height or width dimension and the focus position; and determining the preset threshold based on the relationship data.

[0145] The data relating the height dimension to the focus position includes the focus position corresponding to different height dimension values. Similarly, the data relating the width dimension to the focus position includes the focus position corresponding to different width dimension values.

[0146] like Figure 7 As shown, in some cases, the width of the detection frame remains unchanged while the height changes. In this case, using the relationship data corresponding to the height to determine the preset threshold is equivalent to determining that the size of the detection frame has changed. In other cases, the width of the detection frame changes while the height remains unchanged. In this case, using the relationship data corresponding to the width to determine the preset threshold is equivalent to determining that the size of the detection frame has changed. Neither of these two situations can accurately reflect the change in distance between the user being photographed and the lens, resulting in poor reliability of the judgment result and thus affecting the accuracy of the focus position.

[0147] To address the aforementioned problem, in some other implementations, step S604 may include:

[0148] A preset threshold is determined based on the first and second dimensions;

[0149] If the first focus position exceeds the preset threshold, it is determined that the first focus position and the first size do not match.

[0150] If the first focus position does not exceed the preset threshold, it is determined that the first focus position and the first size match.

[0151] Taking a rectangular detection frame as an example, the method for determining the preset threshold based on the first size and the second size includes: calculating the first change between the first width value and the second width value, and the second change between the first height value and the second height value; obtaining the relationship data between the size value of the target side and the focus position, and determining the preset threshold based on the relationship data.

[0152] Wherein, the target edge is the edge corresponding to the target change amount in the first detection frame, and the target change amount is the minimum value between the first change amount and the second change amount. For example, if the first change amount is less than the second change amount, then the target change amount is the first change amount, and the target edge is the width edge; if the first change amount is greater than the second change amount, then the target change amount is the second change amount, and the target edge is the height edge.

[0153] By the above implementation manner, the preset threshold of the focusing position is determined according to the relationship data corresponding to the edge pair with the least change in the detection frame, which can accurately reflect the change of the distance between the photographed user and the lens, improve the reliability of the judgment result, and thus improve the accuracy of the subsequent focusing position.

[0154] In some implementation manners, the relationship data between the size value of each edge of the detection frame and the focusing position can be calibrated in advance, and the relationship data is stored in the electronic device (for example, in the storage medium of the electronic device). When S604 is performed, the corresponding relationship data is called.

[0155] For example, referring to Figure 8 is a schematic diagram of calibrating an image provided by an embodiment of the present application. As shown in Figure 8 , in the calibration process, the photographed object and the lens are kept at different shooting distances. At each shooting distance, the electronic device performs focusing to make the preview image in the viewfinder clear, and obtains the size of the detection frame and the focusing position after focusing is completed. After the calibration is completed, the relationship data is generated according to the size of the detection frame and the focusing position corresponding to each shooting distance. As shown in the following table:

[0156]

[0157] The value of the focusing position is a value calculated by the algorithm of the automatic focusing function. The corresponding current value is obtained by digital-to-analog conversion of the value, and the focusing motor is driven according to the current value to adjust the focusing position of the camera device.

[0158] According to the data in the above table, the linear relationship between the height edge of the detection frame and the focusing position, and the linear relationship between the width edge of the detection frame and the focusing position can be fitted. As shown in Figure 9 , the linear relationship between the height edge of the detection frame and the focusing position, according to which the focusing position corresponding to any size value of the height edge of the detection frame can be calculated.

[0159] In other implementation manners, the relationship data can be continuously updated as the user uses. For example, in some application scenarios, if the focusing is still not guaranteed to be clear after the focusing is performed by the focusing method of the present application, the user can manually focus. In this case, the electronic device can record the focusing position of the user's manual focusing, associate the focusing position with the size of the current face detection frame, and adjust the existing relationship data according to the association relationship, thereby updating the relationship data. With the continuous updating of the relationship data, the focusing stability of the focusing method of the present application will be higher and higher.

[0160] After acquiring the relational data, the method for determining the preset threshold based on the relational data between the target edge size value and the focus position includes: finding the target focus position corresponding to the target edge size value in the first dimension from the relational data, and determining the preset threshold based on the target focus position.

[0161] For example, when the target edge is the wide edge, the target focus position corresponding to the first width value is found from the relationship data between the wide edge and the focus position. When the target edge is the tall edge, the target focus position corresponding to the first height value is found from the relationship data between the tall edge and the focus position.

[0162] The preset threshold can be determined by using the target focus position as the preset threshold, or by adding / subtracting a certain value from the target focus position as the preset threshold.

[0163] See Figure 10 This is a graph showing the change of the preset threshold as a function of the detection frame size, as provided in the embodiments of this application. Figure 10 As shown, curve 101 represents the change in the size of the detection frame, and curve 102 represents the change in the preset threshold. As the size of the detection frame changes, the determined preset threshold also changes. Figure 9 It can be seen that the size of the detection frame has an inverse linear relationship with the preset threshold, therefore from Figure 10 It can be seen that as the size of the detection frame increases, the preset threshold decreases, which means that as the distance between the user being photographed and the lens decreases, the lens module moves closer to the sensor; conversely, as the size of the detection frame decreases, the preset threshold increases, which means that as the distance between the user being photographed and the lens increases, the lens module moves further away from the sensor. This is consistent with... Figure 3 The imaging principle is shown.

[0164] S605, if the first focus position and the first size do not match, the focus position of the camera device is adjusted to the second focus position so that the camera device focuses according to the second focus position at the first moment.

[0165] S606, if the first focus position and the first size match, control the camera device to focus according to the first focus position at the first moment.

[0166] Step S605 is the same as step S502 above, and can be found in the description in the embodiment of S502.

[0167] S607, if the first size and the second size are the same, control the camera device to focus according to the second focus position at the first moment.

[0168] Since the detection frame conforms to the principle of near large and far small, in the embodiment of the application, whether the shooting distance between the photographed user and the lens changes is determined by judging whether the sizes of the detection frames are consistent; if the first size is inconsistent with the second size, it indicates that the shooting distance between the photographed user and the lens changes at the first moment and the second moment, and then the focusing position is adjusted; if the first size is consistent with the second size, it indicates that the shooting distance between the photographed user and the lens does not change at the first moment and the second moment, and then the first focusing position does not need to be adjusted, and the focusing position (the second focusing position) adjusted at the previous moment (the second moment) can be used for focusing. In this way, the calculation time of the algorithm can be effectively reduced, and the focusing efficiency is improved.

[0169] For example, referring to Figure 11 , which is a comparison diagram of the focusing position provided by the embodiment of the application. As Figure 11 indicated, if the scheme in the related art (for example, the curve 111 in Figure 11 ) is used, that is, the focusing position is focused by using the result of automatic focusing, the change frequency of the focusing position is high, and the change amplitude is large, which leads to unstable focusing. If the focusing method of the embodiment of the application (for example, the curve 112 in Figure 11 ) is used, the focusing position that does not match the size of the current detection frame is discarded, and the focusing position that matches the size of the detection frame is used for focusing, which effectively reduces the change frequency and the change amplitude of the focusing position, thereby effectively improving the stability of the focusing.

[0170] It should be noted that the focusing method provided by the embodiment of the application can be processed for each image frame, or can be processed once every preset number of image frames. The two methods are only different in processing frequency, and the focusing method is essentially the same, therefore, both methods are within the protection scope of the embodiment of the application.

[0171] It should be understood that the size of the serial number of each step in the above embodiment does not mean the order of execution, the execution order of each process should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiment of the application.

[0172] The embodiment of the application further provides a computer readable storage medium, the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the steps in each of the method embodiments.

[0173] The embodiment of the application further provides a computer program product, when the computer program product runs on an electronic device, the electronic device can implement the steps in each of the method embodiments.

[0174] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the present application can implement all or part of the processes in the above-mentioned embodiment methods through a computer program to instruct related hardware to complete. The computer program can be stored in a computer readable storage medium, and the computer program can implement the steps of each method embodiment described above when executed by a processor. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or some intermediate forms. The computer readable medium can at least include any entity or device capable of carrying the computer program code to the first device, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium. For example, U disk, mobile hard disk, magnetic disk or optical disk, etc. In some jurisdictions, according to legislation and patent practice, the computer readable medium can not be an electrical carrier signal and a telecommunication signal.

[0175] The embodiments of the present application also provide a chip system, which includes a processor coupled with a memory. The processor executes a computer program stored in the memory to implement the steps of any method embodiment of the present application. The chip system can be a single chip or a chip module composed of multiple chips.

[0176] In the above embodiments, the description of each embodiment has its own focus. The parts not described or recorded in detail in a certain embodiment can be referred to the relevant description of other embodiments.

[0177] Those skilled in the art can appreciate that the units and method steps of the examples described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application. Finally, it should be noted that: the above description is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or replacements within the technical scope disclosed in the present application should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A focusing method, characterized in that, Applied to an electronic device, the electronic device including a camera device, the method includes: The first focus position and the first size of the first detection frame are obtained, wherein the first focus position is the calculated relative distance between the sensor and the lens module after the camera device performs autofocus at the first moment, and the first detection frame is the detection frame obtained by performing face detection on the preview image in the viewfinder corresponding to the first moment. Determine whether the first focus position and the first size match; If the first focus position and the first size do not match, the focus position of the camera device is adjusted to the second focus position so that the camera device focuses according to the second focus position at the first moment, wherein the second focus position is the focus position used by the camera device to focus at the second moment, and the second moment is the previous focus moment of the first moment. The step of determining whether the first focus position and the first size match includes: Obtain the second size of the second detection box, wherein the second detection box is a detection box obtained by performing face detection on the preview image in the viewfinder corresponding to the second time point; A preset threshold is determined based on the first size and the second size; If the first focus position exceeds the preset threshold, it is determined that the first focus position and the first size do not match. If the first focus position does not exceed the preset threshold, then the first focus position and the first size are determined to match.

2. The method according to claim 1, characterized in that, The method further includes: Obtain the second size of the second detection box, wherein the second detection box is a detection box obtained by performing face detection on the preview image in the viewfinder corresponding to the second time point; If the first size and the second size are inconsistent, then determine whether the first focus position and the first size match.

3. The method according to claim 2, characterized in that, After obtaining the second size of the second detection box, the method further includes: If the first size and the second size are the same, then the camera device is controlled to focus according to the second focus position at the first moment.

4. The method according to claim 2 or 3, characterized in that, The first dimension includes a first width value and a first height value, the second dimension includes a second width value and a second height value, and the method further includes: If the first width value is the same as the second width value, and / or the first height value is the same as the second height value, then the first dimension and the second dimension are determined to be the same; If the first width value is inconsistent with the second width value, and the first height value is inconsistent with the second height value, then it is determined that the first size and the second size are inconsistent.

5. The method according to claim 1, characterized in that, The first dimension includes a first width value and a first height value, and the second dimension includes a second width value and a second height value; The step of determining the preset threshold based on the first size and the second size includes: Calculate a first change between the first width value and the second width value, and a second change between the first height value and the second height value; Obtain the relationship data between the size value of the target edge and the focus position, wherein the target edge is the edge corresponding to the target change amount in the first detection frame, and the target change amount is the minimum value between the first change amount and the second change amount; The preset threshold is determined based on the relationship data.

6. The method according to claim 1, characterized in that, The method further includes: If the first focus position matches the first size, then the camera device is controlled to focus according to the first focus position at the first moment.

7. A chip system, characterized in that, The chip system includes a processor coupled to a memory, the processor executing a computer program stored in the memory to implement the method as described in any one of claims 1 to 6.

8. An electronic device, characterized in that, The electronic device includes a processor for running a computer program stored in a memory to enable the electronic device to perform the method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by one or more processors, implements the method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Camera focusing method and system, and electronic device

    CN106170064A

  • Focusing control method and device, electronic equipment and computer readable storage medium

    CN110650288A