Focusing method and device, electronic equipment and storage medium

By determining the initial focus area in the preview image and judging its flatness, the problem of difficulty in accurately focusing when shooting in a flat area in the prior art is solved, and the applicability of the imaging effect and focus method are improved.

CN120017960APending Publication Date: 2025-05-16BEIJING XIAOMI MOBILE SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311520175.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-11-15
Publication Date
2025-05-16

AI Technical Summary

Technical Problem

Existing autofocus technology is difficult to accurately find the focus when shooting flat areas, resulting in difficult imaging clarity.

Method used

The focus position is determined by determining the initial focus area in the preview image and determining whether it is a flat area based on the statistical results of the pixel values ​​of the pixel points in each sub-region.

Benefits of technology

The imaging effect in different shooting scenes is improved, and the applicability and accuracy of the focus method is enhanced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120017960A_ABST
    Figure CN120017960A_ABST
Patent Text Reader

Abstract

The invention relates to a focusing method and device, electronic equipment and a storage medium. The method comprises the following steps: determining an initial focusing area in a preview image; wherein the initial focusing area comprises a plurality of sub-areas; determining whether each sub-region is a flat region or not according to a statistical result of the pixel values of the pixel points in each sub-region; wherein the concentration degree of the pixel value distribution of each pixel point in the flat area is greater than the concentration degree of the pixel value distribution of each pixel point in the non-flat area; determining whether the initial focusing area is a flat area or not according to the result of whether each sub-area is the flat area or not; and determining a focusing position based on the initial focusing area and a result indicating whether the initial focusing area is a flat area. According to the scheme, the focusing imaging effect can be improved when the shooting scene is flat.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of imaging technology, and in particular to a focusing method and device, an electronic device, and a storage medium. Background Art

[0002] Nowadays, for electronic devices such as mobile phones, cameras, tablets, and wearable devices, functions such as taking photos and recording videos have become the core needs of users when purchasing electronic devices, among which the clarity of the image has attracted much attention. Usually, the clarity of the image is improved through autofocus technologies such as Phase Detection Auto Focus (PDAF), Continuous Auto Focus (CAF), and Time-of-Flight (TOF) focus. Among them, TOF focus relies on laser sensors to find the focus of a flat area at a short distance in low light through laser focus; PDAF and CAF algorithms need to determine the phase difference (PD) or focus value (FV) through the grayscale difference between pixels in the region of interest (ROI) of the image, and then guide the focus based on the phase difference or clarity.

[0003] However, when the captured image includes flat areas such as the sky, walls, and smooth surfaces, the PD and FV values ​​calculated by the PDAF and CAF algorithms are often less reliable due to the lack of details in the flat areas. For devices without TOF focus or when shooting flat scenes at a long distance, out-of-focus conditions will still occur. The existing autofocus technology cannot find the focal point well, resulting in difficulty in meeting the image clarity requirements. Summary of the invention

[0004] The present invention provides a focusing method and device, an electronic device, and a storage medium.

[0005] According to a first aspect of an embodiment of the present disclosure, there is provided a focusing method, comprising:

[0006] Determine an initial focus area in the preview image; wherein the initial focus area includes a plurality of sub-areas;

[0007] Determine whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region; wherein the concentration degree of the pixel value distribution of each pixel in the flat region is greater than the concentration degree of the pixel value distribution of each pixel in the non-flat region;

[0008] Determining whether the initial focus area is a flat area according to the result of whether each sub-area is a flat area;

[0009] A focus position is determined based on the initial focus area and a result of whether the initial focus area is a flat area.

[0010] In some embodiments, determining whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region includes:

[0011] Dividing each sub-region respectively to obtain a plurality of sub-blocks corresponding to each sub-region; wherein each sub-block includes a plurality of pixel points;

[0012] For each sub-region, statistics are performed on the pixel values ​​of the pixels in each sub-block in the sub-region, and whether the sub-region is a flat region is determined according to the statistical results of each sub-block.

[0013] In some embodiments, for each sub-region, counting pixel values ​​of pixels in each sub-block in the sub-region, and determining whether the sub-region is a flat region according to the statistical results of each sub-block, includes:

[0014] For each sub-region, according to the statistical results of each sub-block in the sub-region, determine the standard deviation of the pixel value distribution of the pixel points in the sub-region;

[0015] According to the standard deviation corresponding to the sub-region, it is determined whether the sub-region is a flat region.

[0016] In some embodiments, the pixel value of the pixel point includes pixel values ​​of different color channels; and determining the standard deviation of the pixel value distribution of the pixel point in the sub-region according to the statistical results of each sub-block in the sub-region includes:

[0017] For each sub-block in the sub-region, determining first pixel means of different color channels in the sub-block according to pixel values ​​of each pixel point in the sub-block;

[0018] Determine second pixel means of different color channels in the sub-region according to the pixel values ​​of each pixel point in the sub-region in different color channels;

[0019] The standard deviation corresponding to the sub-region is determined according to the first pixel means of different color channels in each sub-block of the sub-region and the second pixel means of different color channels in the sub-region.

[0020] In some embodiments, determining the standard deviation corresponding to the sub-region according to the first pixel means of different color channels in each sub-block of the sub-region and the second pixel means of different color channels in the sub-region includes:

[0021] Determine the maximum first pixel mean and the minimum first pixel mean of each color channel of the sub-region according to the first pixel means of different color channels in each sub-block of the sub-region;

[0022] For each color channel, determine a standard deviation of the sub-region in the color channel according to the maximum first pixel mean, the minimum first pixel mean, and the second pixel mean of the sub-region in the color channel;

[0023] According to the standard deviation of the sub-region in each color channel, the standard deviation corresponding to the sub-region is determined.

[0024] In some embodiments, determining the standard deviation corresponding to the sub-region according to the standard deviation of the sub-region in each color channel includes:

[0025] The mean of the standard deviations of the sub-regions in each color channel is determined as the standard deviation corresponding to the sub-region.

[0026] In some embodiments, determining whether the initial focus area is a flat area according to the result of whether each sub-area is a flat area includes:

[0027] Count the number of flat areas in each sub-area;

[0028] When the number is greater than a first preset number threshold, it is determined that the initial focus area is a flat area.

[0029] In some embodiments, determining the focus position based on the initial focus area and whether the initial focus area is a flat area includes:

[0030] When the initial focus area is a flat area, expanding the initial focus area;

[0031] The focus position is determined based on the expanded initial focus area.

[0032] In some embodiments, the preview image includes multiple frames, and the initial focus area in each frame of the preview image is consistent; when the initial focus area is a flat area, expanding the initial focus area includes:

[0033] When the initial focus area in the preview image of the frames meeting the second preset number threshold is a flat area, the initial focus area is expanded.

[0034] In some embodiments, when the initial focus area is a flat area, expanding the initial focus area includes:

[0035] When the initial focus area is a flat area, the width of the initial focus area is weighted using a preset first weighting coefficient and the height of the initial focus area is weighted using a preset second weighting coefficient with the initial focus area as the center to obtain an expanded initial focus area.

[0036] In some embodiments, the method further comprises:

[0037] Determining a confidence level of phase difference focusing based on the initial focusing area;

[0038] The step of determining whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region comprises:

[0039] When the confidence level is less than a preset confidence threshold, whether each sub-region is a flat region is determined according to statistical results of pixel values ​​of pixels in each sub-region.

[0040] According to a second aspect of an embodiment of the present disclosure, there is provided a focusing device, comprising:

[0041] A first determination module, configured to determine an initial focus area in the preview image; wherein the initial focus area includes a plurality of sub-areas;

[0042] A second determination module is used to determine whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region; wherein the concentration degree of the pixel value distribution of each pixel in the flat region is greater than the concentration degree of the pixel value distribution of each pixel in the non-flat region;

[0043] A third determination module, configured to determine whether the initial focus area is a flat area according to the result of whether each sub-area is a flat area;

[0044] A focusing module is used to determine a focus position based on the initial focusing area and whether the initial focusing area is a flat area.

[0045] In some embodiments, the second determination module is used to divide each sub-region separately to obtain multiple sub-blocks corresponding to each sub-region; wherein each sub-block includes multiple pixel points; for each sub-region, the pixel values ​​of the pixel points in each sub-block in the sub-region are counted, and whether the sub-region is a flat area is determined based on the statistical results of each sub-block.

[0046] In some embodiments, the second determination module is used to determine, for each sub-region, the standard deviation of the pixel value distribution of the pixel points in the sub-region according to the statistical results of each sub-block in the sub-region; and determine whether the sub-region is a flat region according to the standard deviation corresponding to the sub-region.

[0047] In some embodiments, the pixel value of the pixel point includes pixel values ​​of different color channels; the second determination module is used to determine, for each sub-block in the sub-block, a first pixel mean of different color channels in the sub-block according to the pixel values ​​of each pixel point in the sub-block; determine a second pixel mean of different color channels in the sub-block according to the pixel values ​​of each pixel point in the sub-block in different color channels; determine the standard deviation corresponding to the sub-block according to the first pixel mean of different color channels in each sub-block of the sub-block and the second pixel mean of different color channels in the sub-block.

[0048] In some embodiments, the second determination module is used to determine the maximum first pixel mean and the minimum first pixel mean of the sub-region in each color channel according to the first pixel means of different color channels in each sub-block of the sub-region; for each color channel, determine the standard deviation of the sub-region in the color channel according to the maximum first pixel mean, the minimum first pixel mean, and the second pixel mean of the sub-region in the color channel; determine the standard deviation corresponding to the sub-region according to the standard deviation of the sub-region in each color channel.

[0049] In some embodiments, the second determination module is used to determine the mean of the standard deviations of the sub-regions in each color channel as the standard deviation corresponding to the sub-region.

[0050] In some embodiments, the third determination module is used to count the number of flat areas in each sub-area; when the number is greater than a first preset number threshold, determine that the initial focus area is a flat area.

[0051] In some embodiments, the focusing module is used to expand the initial focusing area when the initial focusing area is a flat area; and determine the in-focus position based on the expanded initial focusing area.

[0052] In some embodiments, the preview image includes multiple frames, and the initial focus area in each preview image is consistent; the focus module is used to expand the initial focus area when the initial focus area in the preview image of the frames that meet the second preset number threshold is a flat area.

[0053] In some embodiments, the focusing module is used to, when the initial focusing area is a flat area, weight the width of the initial focusing area using a preset first weighting coefficient and weight the height of the initial focusing area using a preset second weighting coefficient with the initial focusing area as the center, to obtain an expanded initial focusing area.

[0054] In some embodiments, the apparatus further comprises:

[0055] A fourth determination module, used to determine the confidence of phase difference focusing based on the initial focusing area;

[0056] The second determination module is used to determine whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixel points in each sub-region when the confidence level is less than a preset confidence threshold.

[0057] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, including:

[0058] A processor; a memory for storing processor-executable instructions; wherein the processor is configured to execute the method as described in the first aspect above.

[0059] According to a fourth aspect of an embodiment of the present disclosure, there is provided a storage medium, including:

[0060] When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the method as described in the first aspect above.

[0061] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:

[0062] On the one hand, compared with the method of determining the shooting scene of the preview image based on the scene recognition algorithm in the related art, and determining whether the preview image is flat based on the shooting scene, which is affected by the scene recognition accuracy and limited applicable scenes, the focusing device of the embodiment of the present disclosure determines whether each sub-region is a flat region based on the statistical results of the pixel values ​​of the pixel points in each sub-region of the initial focus region, and then determines whether the initial focus region is a flat region based on the result of whether each sub-region is a flat region, while improving the accuracy of determining whether the initial focus region is a flat region, it has a high generalization ability applicable to different shooting scenes. On the other hand, compared with the method of directly pushing the lens motor to the hyperfocal distance when the preview image is flat in the related art, which is coupled with the influence of the mechanical displacement parameters of the lens motor, and the focusing effect of the near-focus flat scene based on the hyperfocal distance is poor, the embodiment of the present disclosure determines the focus position when the focus is clear based on the result of whether the initial focus region is a flat region and the initial focus region, improves the matching degree of the focus position with the result of whether the initial focus region is a flat region and the initial focus region, thereby improving the matching degree of the focus position with the shooting scene, and has a good imaging effect in different shooting scenes.

[0063] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0065] Figure 1 An example of a focusing method process shown in an embodiment of the present disclosure Figure 1 .

[0066] Figure 2 This is an example diagram of initial focus area division shown in an embodiment of the present disclosure.

[0067] Figure 3 This is an example diagram of statistical results corresponding to different sub-regions shown in an embodiment of the present disclosure.

[0068] Figure 4 This is an example diagram of standard deviations corresponding to different sub-regions shown in an embodiment of the present disclosure.

[0069] Figure 5 This is an example diagram showing a comparison of an initial focus area before and after expansion, shown in an embodiment of the present disclosure.

[0070] Figure 6 An example of a focusing method process shown in an embodiment of the present disclosure Figure 2 .

[0071] Figure 7 is a diagram of a focusing device shown in an embodiment of the present disclosure.

[0072] Figure 8 It is a block diagram of an electronic device shown in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0073] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0074] In the related technology, a scene recognition algorithm is used to identify image scenes, and in image scenes such as sky scenes, smooth wall scenes, smooth object surface scenes, etc., the lens motor is directly pushed to the hyperfocal distance at the current shooting angle; or when the confidence of the aforementioned PDAF focus is low, switch to CAF focus, and when the FV curve is a flat curve, the lens motor is directly pushed to the hyperfocal distance at the current shooting angle.

[0075] However, the above scheme has the following problems: (1) The above scheme still cannot find the focal point well for the near-focus flat area; (2) The hyperfocal position of the lens module is coupled with the influence of factors such as the mechanical displacement parameters of the lens motor, and the accuracy of the hyperfocal position is low; (3) The flat area depends on the accuracy of the scene recognition algorithm, and the accuracy and ability to generalize to different scenes are weak.

[0076] In this regard, an embodiment of the present disclosure provides a focusing method, the execution subject of which may be a focusing device. For example, the focusing method may be executed by a terminal device or a server or other electronic device including an image acquisition component, wherein the terminal device may be a mobile phone, a camera, a tablet computer, a vehicle-mounted device, a wearable device, etc. If the execution subject is a server or other electronic device, after the terminal device including the image acquisition component obtains a preview image, it sends it to the server or other electronic device, so that the server or other electronic device determines the focus position based on the preview image, and can also feed back the focus position to the terminal device to guide imaging. In some possible implementations, the focusing method may be implemented by a processor calling computer-readable instructions stored in a memory.

[0077] Figure 1 This is an example of a focusing method process shown in an embodiment of the present disclosure. Figure 1 ,Depend on Figure 1 It can be seen that the following steps are included:

[0078] S11, determining an initial focus area in the preview image; wherein the initial focus area includes a plurality of sub-areas;

[0079] S12, determining whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region; wherein the concentration degree of the pixel value distribution of each pixel in the flat region is greater than the concentration degree of the pixel value distribution of each pixel in the non-flat region;

[0080] S13, determining whether the initial focus area is a flat area according to the result of whether each sub-area is a flat area;

[0081] S14: Determine a focus position based on the initial focus area and a result of whether the initial focus area is a flat area.

[0082] In step S11, the focusing device determines an initial focusing area in the preview image, for example, taking the 1 / 3 central area of ​​the preview image as the initial focusing area; or using a target detection algorithm, a foreground detection algorithm, etc., taking areas such as face areas, human body areas, and foreground areas as the initial focusing areas, etc., which are not limited in the embodiments of the present disclosure.

[0083] The initial focus area of ​​the embodiment of the present disclosure includes multiple sub-areas, which may be multiple sub-areas obtained after sliding a sliding window of a preset size in the initial focus area, or multiple sub-areas obtained after dividing the initial focus area based on a preset number of areas, or multiple sub-areas obtained by using the method of dividing areas in the aforementioned autofocus algorithm, etc.; each sub-area in the initial focus area of ​​the embodiment of the present disclosure includes multiple pixel points.

[0084] In step S12, the focusing device determines whether each sub-region is a flat region based on the statistical results of the pixel values ​​of the pixels in each sub-region; in some embodiments, the focusing device determines the difference between the pixel values ​​of the pixels in each sub-region, and determines that the sub-region is a flat region when the sum of the differences between the pixel values ​​of the pixels is less than a preset pixel difference threshold; and determines that the sub-region is a non-flat region when the sum of the differences between the pixel values ​​of the pixels is greater than or equal to the preset pixel difference threshold. If the preview image is a grayscale image, the pixel value of the pixel is a grayscale value; if the preview image is a color image, the pixel value of the pixel includes pixel values ​​of different color channels, such as a red channel (R), a green channel (G), and a blue channel (B).

[0085] In some embodiments, the focusing device processes the pixel values ​​of the pixel points in each sub-area based on the standard deviation formula to obtain the standard deviation corresponding to each sub-area, and determines the sub-area whose standard deviation is less than a preset standard deviation threshold as a flat area, and determines the sub-area whose standard deviation is greater than or equal to the preset standard deviation threshold as a non-flat area.

[0086] It can be understood that the pixel value distribution of each pixel point in the flat area of ​​the embodiment of the present disclosure is relatively concentrated, that is, the concentration degree of the pixel value distribution of each pixel point in the flat area is greater than the concentration degree of the pixel value distribution of each pixel point in the non-flat area.

[0087] In step S13, the focusing device determines whether the initial focusing area is a flat area according to the result of whether each sub-area is a flat area; in some embodiments, the focusing device counts the number of flat areas in each sub-area, and when the number is greater than a preset number threshold, determines that the initial focusing area is a flat area; when the number is less than or equal to the preset number threshold, determines that the initial focusing area is a non-flat area. Through this solution, the convenience of determining whether the initial focusing area is a flat area based on the result of whether each sub-area is a flat area can be improved.

[0088] In some embodiments, the focusing device counts the size of the flat area of ​​the adjacent sub-area in the initial focusing area, calculates the proportion of the size in the size of the initial focusing area, and determines that the initial focusing area is a flat area when the proportion is greater than a preset proportion threshold; when the proportion is less than or equal to the preset proportion threshold, the initial focusing area is determined to be a non-flat area.

[0089] In step S14, the focusing device determines the focus position based on the initial focus area and whether the initial focus area is a flat area; wherein the focus position represents the lens position when the focus is clear. In some embodiments, if the initial focus area is a flat area, the focusing device can expand the initial focus area, such as expanding the initial focus area in a preset direction (such as the x direction), or expanding the initial focus area in all directions (such as the x direction and the y direction), and based on the expanded initial focus area, the focus position is determined using the aforementioned PDAF algorithm, CAF algorithm, or other autofocus technology.

[0090] In some embodiments, if the initial focus area is a flat area, the focusing device can use a PDAF algorithm, a CAF algorithm, etc. to determine the initial focus position, and then use a calibrated preset focal length error to correct the initial focus position to obtain the final focus position; wherein the calibrated preset focal length error can be obtained based on multiple experimental fittings of multiple flat area samples.

[0091] In some embodiments, if the initial focus area is a flat area, the focusing device can use the PDAF algorithm, CAF algorithm, etc. to determine the initial focus position, and then use the correspondence between the number of preset flat sub-areas and the focal length error to determine the target focal length error corresponding to the number of flat sub-areas in the initial focus area, and use the target focal length error to correct the initial focus position to obtain the final focus position; wherein, the correspondence between the number of preset flat sub-areas and the focal length error can be obtained by performing multiple experimental fittings on initial focus area samples including different numbers of flat sub-areas.

[0092] In some embodiments, if the initial focus area is a non-flat area, the focusing device can directly process the initial focus area using a PDAF algorithm, a CAF algorithm, etc., and determine the focus position based on the PD value or FV value obtained after the processing.

[0093] It can be understood that, on the one hand, compared with the method in the related art of determining the shooting scene of the preview image based on the scene recognition algorithm and determining whether the preview image is flat based on the shooting scene, which will be affected by the scene recognition accuracy and limited applicable scenes, the focusing device of the embodiment of the present disclosure determines whether each sub-region is a flat area based on the statistical results of the pixel values ​​of the pixel points in each sub-region in the initial focus area, and then determines whether the initial focus area is a flat area based on the results of whether each sub-region is a flat area. While improving the accuracy of determining whether the initial focus area is a flat area, it has a high generalization ability applicable to different shooting scenes. On the other hand, compared with the method in the related art of directly pushing the lens motor to the hyperfocal distance when the preview image is flat, which couples influences such as the mechanical displacement parameters of the lens motor and the poor focusing effect on near-focus flat scenes based on the hyperfocal distance, the embodiment of the present disclosure determines the focus position when the focus is clear based on the result of whether the initial focus area is a flat area and the initial focus area, improves the matching degree of the focus position with the result of whether the initial focus area is a flat area and the initial focus area, thereby improving the matching degree of the focus position with the shooting scene, and has better imaging effects in different shooting scenes.

[0094] In some embodiments, determining whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region includes:

[0095] Dividing each sub-region respectively to obtain a plurality of sub-blocks corresponding to each sub-region; wherein each sub-block includes a plurality of pixel points;

[0096] For each sub-region, statistics are performed on the pixel values ​​of the pixels in each sub-block in the sub-region, and whether the sub-region is a flat region is determined according to the statistical results of each sub-block.

[0097] In the embodiment of the present disclosure, the focusing device divides each sub-area using a sliding window or based on a preset number of areas, or obtains multiple sub-blocks corresponding to each sub-area using the block division method in the automatic white balance algorithm; wherein each sub-block includes multiple pixel points.

[0098] Figure 2 is an example diagram of initial focus area division shown in an embodiment of the present disclosure, Figure 2 In the figure, the larger squares in the image marked by L1 correspond to the sub-areas in the aforementioned initial focus area; the smaller squares in the image marked by L2 are the divided sub-blocks; the image marked by L3 shows that each sub-area in the initial focus area in the image includes multiple divided sub-blocks; wherein each sub-block includes multiple pixel points.

[0099] In the embodiment of the present disclosure, after obtaining multiple sub-blocks corresponding to each sub-region, the focusing device counts the pixel values ​​of the pixels in each sub-block in the sub-region for each sub-region, and determines whether the sub-region is a flat region based on the statistical results of each sub-block; in some embodiments, the focusing device counts the sum of the pixel values ​​of the pixels in each sub-block for multiple sub-blocks in each sub-region, and determines the difference between the sums of the pixel values ​​corresponding to each sub-block; when the difference between the sums of the pixel values ​​is less than a preset pixel difference threshold, it indicates that the display contents of the sub-blocks in the sub-region are similar, thereby determining that the sub-region is a flat region; when the difference between the sums of the pixel values ​​is greater than or equal to the preset pixel difference threshold, it indicates that the display contents of the sub-blocks in the sub-region are relatively different, thereby determining that the sub-region is a non-flat region.

[0100] In some embodiments, the focusing device counts the sum of pixel values ​​of pixel points in each sub-block for multiple sub-blocks in each sub-region, and then determines the number of adjacent sub-blocks whose sum of pixel values ​​has a difference less than a preset pixel difference threshold. When the number of adjacent sub-blocks is greater than the preset number threshold, the area of ​​adjacent sub-blocks with similar displayed contents in the sub-region is larger, thereby determining that the sub-region is a flat region. When the number of adjacent sub-blocks is less than or equal to the preset number threshold, the area of ​​adjacent sub-blocks with similar displayed contents in the sub-region is smaller, thereby determining that the sub-region is a non-flat region.

[0101] It can be understood that the focusing device of the embodiment of the present disclosure determines whether a sub-region is a flat area based on the statistical results of the pixel values ​​of the pixel points in each sub-block in the sub-region, and can accurately judge the degree of differentiation between the sub-blocks in the sub-region, thereby improving the accuracy of determining whether a sub-region is a flat area based on the statistical results of the pixel values ​​of the pixel points in the sub-blocks.

[0102] In some embodiments, for each sub-region, counting pixel values ​​of pixels in each sub-block in the sub-region, and determining whether the sub-region is a flat region according to the statistical results of each sub-block, includes:

[0103] For each sub-region, according to the statistical results of each sub-block in the sub-region, determine the standard deviation of the pixel value distribution of the pixel points in the sub-region;

[0104] According to the standard deviation corresponding to the sub-region, it is determined whether the sub-region is a flat region.

[0105] In the embodiment of the present disclosure, the focusing device determines the standard deviation of the pixel value distribution of the pixels in each sub-region according to the statistical results of each sub-block in each sub-region, and determines whether each sub-region is a flat region according to the standard deviation corresponding to each sub-region. In some embodiments, the focusing device determines the pixel mean of the pixels in the sub-block according to the pixel value of each pixel in the sub-block for each sub-block, and determines the standard deviation corresponding to the sub-block based on the pixel mean and the pixel value of each pixel in the sub-block using a preset standard deviation equation, and determines the mean of the standard deviations corresponding to each sub-block as the standard deviation of the pixel value distribution of the pixels in the sub-region.

[0106] In some embodiments, the focusing device determines, for each sub-block, a pixel mean of the pixels in the sub-block according to the pixel values ​​of each pixel in the sub-block, and determines, based on the pixel values ​​of each pixel, a maximum pixel mean in the difference between the pixel value in the sub-block and the pixel mean; wherein the maximum pixel mean is negatively correlated with the concentration of the pixel distribution; thereby, the maximum value of the maximum pixel means corresponding to each sub-block represents the standard deviation corresponding to the sub-region, or the weighted result of the maximum value of the maximum pixel means corresponding to each sub-block represents the standard deviation corresponding to the sub-region.

[0107] After determining the standard deviation corresponding to the sub-region, the focusing device of the embodiment of the present disclosure determines that the sub-region is a flat region when the standard deviation corresponding to the sub-region is less than a preset standard deviation threshold; and determines that the sub-region is a non-flat region when the standard deviation corresponding to the sub-region is greater than or equal to the preset standard deviation threshold, which can be expressed by the following formulas (1) and (2):

[0108] Flat:AverStdRGB_i <FlatStdThr; (1)

[0109] No-Flat:AverStdRGB_i>=FlatStdThr; (2)

[0110] Among them, AverStdRGB_i represents the standard deviation corresponding to the sub-region, and FlatStdThr represents the preset standard deviation threshold.

[0111] It can be understood that, on the one hand, the standard deviation corresponding to the sub-region can accurately characterize the concentration of the pixel value distribution in the sub-region. If the standard deviation corresponding to the sub-region is small, it characterizes that the content of the sub-region is flat (such as the sky, a smooth desktop, etc.); if the standard deviation corresponding to the sub-region is large, it characterizes that the content of the sub-region is not flat. Therefore, the accuracy of determining the standard deviation corresponding to the sub-region based on the statistical results of each sub-block in the sub-region is high in the embodiment of the present disclosure, and then the accuracy of determining whether the sub-region is a flat region based on the standard deviation corresponding to the sub-region is high. On the other hand, the embodiment of the present disclosure can use the standard deviation threshold as a debugging parameter, and adjust the strictness of determining whether the sub-region is a flat region by adjusting the preset standard deviation threshold based on the actual shooting scene, which has the advantage of high flexibility.

[0112] In some embodiments, the pixel value of the pixel point includes pixel values ​​of different color channels; and determining the standard deviation of the pixel value distribution of the pixel point in the sub-region according to the statistical results of each sub-block in the sub-region includes:

[0113] For each sub-block in the sub-region, determining first pixel means of different color channels in the sub-block according to pixel values ​​of each pixel point in the sub-block;

[0114] Determine second pixel means of different color channels in the sub-region according to the pixel values ​​of each pixel point in the sub-region in different color channels;

[0115] The standard deviation corresponding to the sub-region is determined according to the first pixel means of different color channels in each sub-block of the sub-region and the second pixel means of different color channels in the sub-region.

[0116] In the embodiment of the present disclosure, the pixel value of the pixel point includes the pixel value of different color channels, such as the RGB value of the pixel point. The focusing device of the embodiment of the present disclosure determines the first pixel mean values ​​of different color channels in the sub-block according to the pixel value of each pixel point in the sub-block for each sub-block in the sub-region, wherein the first pixel mean values ​​of different color channels are such as the pixel mean value of the red channel, the pixel mean value of the green channel, the pixel mean value of the blue channel, etc. corresponding to the sub-block.

[0117] The focusing device of the disclosed embodiment determines the second pixel means of different color channels in the sub-region according to the pixel values ​​of each pixel in the sub-region in different color channels, for example, determines the pixel mean of each pixel in the sub-region in the red channel, the pixel mean of each pixel in the sub-region in the green channel, and the pixel mean of each pixel in the sub-region in the blue channel; or determines the average value of the pixel means of the red channel corresponding to each sub-block as the second pixel mean of the red channel in the sub-region, determines the average value of the pixel means of the green channel corresponding to each sub-block as the second pixel mean of the green channel in the sub-region, determines the average value of the pixel means of the blue channel corresponding to each sub-block as the second pixel mean of the blue channel in the sub-region, etc.

[0118] After determining the first pixel means of different color channels in each sub-block of the sub-region and the second pixel means of different color channels in the sub-region, the focusing device of the embodiment of the present disclosure determines the standard deviation corresponding to the sub-region according to the first pixel means of different color channels in each sub-block of the sub-region and the second pixel means of different color channels in the sub-region; for example, the standard deviation corresponding to the first pixel mean and the second pixel mean is determined by using the correspondence between the preset first pixel mean, the second pixel mean and the standard deviation obtained based on multiple fittings of historical experiments; or, the first pixel mean and the second pixel mean are calculated using a preset standard deviation equation obtained based on multiple fittings of historical experiments to obtain the standard deviation corresponding to the sub-region.

[0119] It can be understood that compared to determining the standard deviation corresponding to the sub-region based only on the pixel value of the pixel points in the sub-block in one color channel or only on the grayscale value of the pixel points, the embodiment of the present disclosure determines the standard deviation corresponding to the sub-region based on the pixel values ​​of the pixel points in different color channels that include more valid pixel information, which can improve the accuracy of determining the standard deviation corresponding to the sub-region.

[0120] In some embodiments, determining the standard deviation corresponding to the sub-region according to the first pixel means of different color channels in each sub-block of the sub-region and the second pixel means of different color channels in the sub-region includes:

[0121] Determine the maximum first pixel mean and the minimum first pixel mean of each color channel of the sub-region according to the first pixel means of different color channels in each sub-block of the sub-region;

[0122] For each color channel, determine the standard deviation of the sub-region in the color channel according to the maximum pixel mean, the minimum pixel mean, and the second pixel mean of the sub-region in the color channel;

[0123] According to the standard deviation of the sub-region in each color channel, the standard deviation corresponding to the sub-region is determined.

[0124] In the embodiment of the present disclosure, the focusing device determines, for each color channel, the maximum first pixel mean as the maximum first pixel mean corresponding to the sub-region, and the minimum first pixel mean as the minimum first pixel mean corresponding to the sub-region according to the first pixel mean of the color channel in each sub-block of the sub-region;

[0125] The focusing device determines the standard deviation of the sub-region in the color channel according to the maximum first pixel mean, the minimum first pixel mean, and the second pixel mean of the sub-region in the color channel; for example, based on a preset standard deviation formula, the initial standard deviation is determined based on the second pixel mean corresponding to the sub-region; based on the correspondence between the preset maximum first pixel mean, the minimum first pixel mean and the standard deviation correction value, the standard deviation correction value corresponding to the sub-region is determined, and the initial standard deviation is corrected using the standard deviation correction value to obtain the standard deviation of the sub-region in the color channel; or based on a preset sub-region standard deviation equation obtained by fitting multiple historical experiments, the maximum first pixel mean, the minimum first pixel mean, and the second pixel mean are calculated to obtain the standard deviation corresponding to the sub-region.

[0126] It can be understood that since the maximum first pixel mean and the minimum first pixel mean can characterize the size of the pixel value distribution range, determining the initial standard deviation based on the second pixel mean corresponding to the sub-region can characterize the degree of distribution concentration. Therefore, the embodiment of the present disclosure determines the standard deviation of the sub-region in the color channel based on the maximum first pixel mean, the minimum first pixel mean, and the second pixel mean, and combines the size of the pixel value distribution range and the distribution concentration, so the accuracy of determining the standard deviation of the sub-region in the color channel is higher.

[0127] Figure 3 This is an example diagram of statistical results corresponding to different sub-regions shown in an embodiment of the present disclosure. Figure 3 In the figure, the first column shows different flat sub-regions and different non-flat sub-regions, where the large area in the center of the pear in the image is considered a flat area, and the edge area of ​​the pear is considered a non-flat area. The second column shows different color channels, including the red channel (R), the green channel (G), and the blue channel (B). The third to sixth columns respectively show the second pixel mean (Mean), the minimum first pixel mean (Min), the maximum first pixel mean (Max), and the standard deviation (Std) of the sub-region in different color channels. As can be seen from the above figure, the pixel values ​​of the pixels in the flat sub-region are distributed more concentratedly, and the corresponding standard deviation is smaller; the pixel values ​​of the pixels in the non-flat sub-region are distributed more dispersedly, and the corresponding standard deviation is larger.

[0128] After determining the standard deviation of the sub-region in different color channels, the focusing device of the embodiment of the present disclosure determines the standard deviation corresponding to the sub-region according to the standard deviation of the sub-region in each color channel; in some embodiments, the mean of the standard deviation of the sub-region in each color channel is determined as the standard deviation corresponding to the sub-region, which can be expressed by the following formula (3):

[0129]

[0130] Among them, AverStdRGB_i represents the standard deviation of the sub-region in the initial focus area, StdR_i represents the standard deviation of the sub-region in the red channel, StdG_i represents the standard deviation of the sub-region in the green channel, and StdB_i represents the standard deviation of the sub-region in the blue channel. Through this solution, the convenience of determining the standard deviation corresponding to the sub-region can be improved.

[0131] based on Figure 3 The statistical results corresponding to the sub-regions shown are obtained Figure 4 An example graph of standard deviation corresponding to a different sub-region is shown; Figure 4 In , the standard deviation corresponding to the sub-region is calculated based on the above formula (3).

[0132] In some embodiments, the focusing device may also pre-set a weighted value for the red channel, a weighted value for the green channel, and a weighted value for the blue channel based on the human eye's visual perception of the red, green, and blue phases, thereby determining the sum of the weighted value of the red channel weighted by the standard deviation of the red channel, the weighted value of the green channel weighted by the standard deviation of the green channel, and the weighted value of the blue channel weighted by the standard deviation of the blue channel as the standard deviation corresponding to the sub-area.

[0133] In some embodiments, determining whether the initial focus area is a flat area according to the result of whether each sub-area is a flat area includes:

[0134] Count the number of flat areas in each sub-area;

[0135] When the number is greater than a first preset number threshold, it is determined that the initial focus area is a flat area.

[0136] In the embodiment of the present disclosure, after determining whether each sub-region is a flat region according to the statistical result of the pixel values ​​of the pixel points in each sub-region, the focusing device counts the number of flat regions in each sub-region, and determines that the initial focus region is a flat region when the number is greater than a first preset number threshold; and determines that the initial focus region is a non-flat region when the number is less than or equal to the first preset number threshold. Through this solution, the convenience of determining whether the initial focus region is a flat region can be improved.

[0137] In some embodiments, determining the focus position based on the initial focus area and whether the initial focus area is a flat area includes:

[0138] When the initial focus area is a flat area, expanding the initial focus area;

[0139] The focus position is determined based on the expanded initial focus area.

[0140] In the embodiment of the present disclosure, when the initial focus area of ​​the focusing device is a flat area, the effect of guiding the focus only based on the pixel values ​​of the pixels in the initial focus area is poor. In this regard, when the initial focus area is a flat area, the focusing device expands the initial focus area, such as expanding the initial focus area in a preset direction (such as the x direction), or expanding the initial focus area in all directions (such as the x direction and the y direction), and based on the expanded initial focus area, the focus position is determined using the aforementioned PDAF algorithm, CAF algorithm, etc.

[0141] It can be understood that when the initial focus area is a flat area, the initial focus area is expanded so that the expanded initial focus area includes more pixel information, which helps to improve the accuracy of determining the focus position based on the expanded initial focus area.

[0142] In some embodiments, the preview image includes multiple frames, and the initial focus area in each frame of the preview image is consistent; when the initial focus area is a flat area, expanding the initial focus area includes:

[0143] When the initial focus area in the preview image of the frames meeting the second preset number threshold is a flat area, the initial focus area is expanded.

[0144] In the embodiment of the present disclosure, the preview image includes multiple frames, such as the preview image includes multiple captured frames, or multiple image frames in a video stream, etc.; wherein the initial focus area in each frame of the preview image is consistent.

[0145] The focusing device of the disclosed embodiment uses the aforementioned method to respectively determine whether the initial focus area in each frame preview image is a flat area, and when the initial focus area in the preview image of the frames that meet the second preset number threshold is a flat area, the initial focus area is expanded, and the focus position is determined based on the pixel values ​​of the pixel points in the expanded initial focus area in any frame preview image.

[0146] Exemplarily, the preview image includes three consecutive frames of images. If the second preset number threshold is 3, then when the initial focus areas in the three consecutive frames of images are all flat areas, the initial focus area is expanded, and the focus position is determined based on the pixel values ​​of the pixel points in the expanded initial focus area in the last frame of the preview image, thereby improving the real-time focusing.

[0147] It can be seen from the above that the condition for expanding the initial focus area in the embodiment of the present disclosure can be expressed by the following expression (4):

[0148] FlatGridNum>GridNum*FlatGridRatio&&FlatFrameCnt>FlatCntThr; (4)

[0149] Among them, FlatGridNum represents the number of sub-areas that are flat areas in the initial focus area in the preview image frame (such as the last previewed frame), GridNum represents the total number of sub-areas in the initial focus area, FlatGridRatio is a preset ratio (such as 50%); GridNum*FlatGridRatio corresponds to the aforementioned first preset quantity threshold, FlatFrameCnt represents the number of frames in which the initial focus area in multiple frames of preview images is a flat area, and FlatCntThr corresponds to the aforementioned second preset quantity threshold.

[0150] It can be understood that, through the scheme provided by the embodiments of the present disclosure, the first preset number threshold, the second preset number threshold or the aforementioned preset ratio can be used as debugging parameters. By adjusting the above parameters based on the actual shooting scene, the conditions for determining whether the initial focus area needs to be expanded are adjusted, thereby expanding the adjustment space while making the switching of the expanded initial focus area to guide the focus smoother.

[0151] In some embodiments, when the initial focus area is a flat area, expanding the initial focus area includes:

[0152] When the initial focus area is a flat area, the width of the initial focus area is weighted using a preset first weighting coefficient and the height of the initial focus area is weighted using a preset second weighting coefficient with the initial focus area as the center to obtain an expanded initial focus area.

[0153] In the embodiment of the present disclosure, when the initial focus area is a flat area, the focus area is centered on the initial focus area, and the width and height of the initial focus area are weighted by using the preset first weighting coefficient and the second preset weighting coefficient to obtain an expanded initial focus area, wherein the weighted width and height can be expressed by the following formulas (5) and (6), respectively:

[0154] Width=FlatExtWidth*OriWidth; (5)

[0155] Height=FlatExtHeight*OriHeight; (6)

[0156] Among them, Width represents the width of the initial focus area after extension, FlatExtWidth corresponds to the first weighting coefficient, and OriWidth represents the width of the initial focus area before extension; Height represents the height of the initial focus area after extension, FlatExtHeight corresponds to the second weighting coefficient, and OriHeight represents the height of the initial focus area before extension.

[0157] Figure 5 This is an example diagram showing a comparison of an initial focus area before and after expansion according to an embodiment of the present disclosure. Figure 5 In the figure, L4 identifies the initial focus area before expansion in the image, and L5 identifies the initial focus area after expansion with the initial focus area as the center in the image.

[0158] It is understandable that focusing based on the initial focus area in the image usually has a better effect, but the initial focus area of ​​the platform has less effective pixel information. Therefore, the embodiment of the present disclosure expands the initial focus area with the initial focus area as the center, so that the expanded initial focus area includes more effective pixel information (such as Figure 5 The initial focus area marked by L5 in the figure includes the edge of the pear), which can further improve the effect of guiding focus based on the expanded initial focus area.

[0159] In some embodiments, the method further comprises:

[0160] Determining a confidence level of phase difference focusing based on the initial focusing area;

[0161] The step of determining whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region comprises:

[0162] When the confidence level is less than a preset confidence threshold, whether each sub-region is a flat region is determined according to statistical results of pixel values ​​of pixels in each sub-region.

[0163] In the disclosed embodiment, the focusing device determines the confidence of phase difference focusing based on the initial focusing area based on the aforementioned PDAF algorithm, CAF algorithm and other autofocus algorithms, and enters the focusing process for the flat area when the confidence is less than the preset confidence threshold, determines whether each sub-area is a flat area based on the statistical results of the pixel values ​​of the pixels in each sub-area, determines whether the initial focusing area is a flat area based on the result of whether each sub-area is a flat area, and then determines the focus position based on the initial focusing area and the result of whether the initial focusing area is a flat area. Through this scheme, when the confidence is greater than or equal to the preset confidence threshold, that is, when the effect of focusing based on the aforementioned autofocus algorithm is better, the autofocus algorithm is directly used for focusing; when the confidence is less than the preset confidence threshold, the focusing process for the flat area is entered, thereby improving the purposefulness and necessity of running the focusing process for the flat area.

[0164] Figure 6 This is an example of a focusing method process shown in an embodiment of the present disclosure. Figure 2 ,Depend on Figure 6 It can be seen that the following steps are included:

[0165] S201, determine whether the confidence is less than a preset confidence threshold; if so, execute step S202; if not, execute step S211.

[0166] In the embodiment of the present disclosure, the focusing device determines the confidence of the phase difference focusing based on the initial focus area in the preview image based on the automatic focus algorithm such as the PDAF algorithm and the CAF algorithm, and determines whether the confidence is less than a preset confidence threshold; if the confidence is less than the preset confidence threshold, execute step S202; if the confidence is greater than or equal to the preset confidence threshold, execute step S211, and use the automatic focus algorithm to guide the focusing based on the initial focus area.

[0167] S202, counting the pixel value of each sub-block in each sub-area of ​​the initial focus area;

[0168] In the embodiment of the present disclosure, when the confidence of focusing guidance based on the initial focus area is less than a preset confidence threshold, the focusing device counts the pixel values ​​of each sub-block in each sub-area in the initial focus area. For example, each sub-area in the initial focus area is divided respectively to obtain sub-blocks corresponding to each sub-area; for each sub-block in the sub-area, according to the pixel values ​​of each pixel point in the sub-block in different color channels, the first pixel mean of different color channels in the sub-block is determined; and according to the pixel values ​​of each pixel point in the sub-area in different color channels, the second pixel mean of different color channels in the sub-area is determined; wherein the different color channels include red channel, green channel, and blue channel.

[0169] S203, calculating the standard deviation of each sub-region in different color channels;

[0170] In the embodiment of the present disclosure, the focusing device determines the standard deviation corresponding to the sub-region according to the first pixel means of different color channels in each sub-block of the sub-region and the second pixel means of different color channels in the sub-region. Exemplarily, according to the first pixel means of different color channels in each sub-block of the sub-region, the maximum first pixel mean and the minimum first pixel mean of the sub-region in each color channel are determined, and for each color channel, according to the maximum first pixel mean, the minimum first pixel mean, and the second pixel mean of the sub-region in the color channel, the standard deviation of the sub-region in the color channel is determined; thereby, according to the standard deviation of the sub-region in each color channel, the standard deviation corresponding to the sub-region is determined.

[0171] S204, calculating the standard deviation corresponding to each sub-region;

[0172] In the embodiment of the present disclosure, the mean of the standard deviations of the sub-regions in each color channel is determined as the standard deviation corresponding to each sub-region.

[0173] S205, determining whether the standard deviation corresponding to the sub-region is less than a preset standard deviation threshold; if so, executing step S206; if not, executing step S211;

[0174] In the embodiment of the present disclosure, it is determined whether the standard deviation corresponding to the sub-region is less than a preset standard deviation threshold. If the standard deviation corresponding to the sub-region is less than the preset standard deviation threshold, it indicates that the pixel value distribution of the pixels in the sub-region is relatively concentrated, and step S206 is executed; if the standard deviation corresponding to the sub-region is greater than or equal to the preset standard deviation threshold, it indicates that the pixel value distribution of the pixels in the sub-region is relatively dispersed, and step S211 is executed to use the autofocus algorithm to guide focusing based on the initial focus area.

[0175] S206, the sub-region is a flat region;

[0176] In the embodiment of the present disclosure, the standard deviation corresponding to the sub-region is smaller than a preset standard deviation threshold, indicating that the pixel values ​​of the pixels in the sub-region are distributed more concentratedly, and the sub-region is determined to be a flat region.

[0177] S207, counting the number of flat sub-areas in the initial focus area;

[0178] In the embodiment of the present disclosure, the focusing device counts the number of sub-areas that are flat areas in the initial focusing area;

[0179] S208: Whether the initial focus area in the preview image of the frames that meet the second preset number threshold is a flat area; if so, execute step S209; if not, execute step S211;

[0180] In the embodiment of the present disclosure, the preview image includes multiple frames, and the initial focus area in each preview image frame is consistent; when the initial focus area in the preview image that meets the second preset number threshold frame is a flat area, for example, the initial focus areas in the three consecutive frames are all flat areas, step S209 is executed; when the initial focus area in the preview image that does not meet the second preset number threshold frame is a flat area, step S211 is executed to use the autofocus algorithm to guide focusing based on the initial focus area.

[0181] S209, expanding the initial focus area;

[0182] In an embodiment of the present disclosure, when the initial focus area in the preview image that meets the second preset number threshold frames is a flat area, the initial focus area is expanded. For example, with the initial focus area as the center, the width of the initial focus area is weighted using a preset first weighting coefficient, and the height of the initial focus area is weighted using a preset second weighting coefficient to obtain an expanded initial focus area.

[0183] S210, guiding focus based on the expanded initial focus area;

[0184] In the embodiment of the present disclosure, the focusing device guides the focusing based on the expanded initial focus area based on the automatic focus algorithm such as the PDAF algorithm and the CAF algorithm. Since the expanded initial focus area includes more pixel information, the solution provided by the embodiment of the present disclosure has a better focusing imaging effect when the preview image includes a flat area scene.

[0185] Figure 7 is a diagram of a focusing device shown in an embodiment of the present disclosure, comprising Figure 7 It is known that, including:

[0186] A first determination module 701 is used to determine an initial focus area in a preview image; wherein the initial focus area includes a plurality of sub-areas;

[0187] The second determination module 702 is used to determine whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region; wherein the concentration degree of the pixel value distribution of each pixel in the flat region is greater than the concentration degree of the pixel value distribution of each pixel in the non-flat region;

[0188] A third determination module 703, configured to determine whether the initial focus area is a flat area according to the result of whether each sub-area is a flat area;

[0189] The focusing module 704 is configured to determine a focus position based on the initial focusing area and whether the initial focusing area is a flat area.

[0190] In some embodiments, the second determination module 702 is used to divide each sub-region separately to obtain multiple sub-blocks corresponding to each sub-region; wherein each sub-block includes multiple pixel points; for each sub-region, the pixel values ​​of the pixel points in each sub-block in the sub-region are counted, and whether the sub-region is a flat area is determined based on the statistical results of each sub-block.

[0191] In some embodiments, the second determination module 702 is used to determine, for each sub-region, the standard deviation of the pixel value distribution of the pixel points in the sub-region according to the statistical results of each sub-block in the sub-region; and determine whether the sub-region is a flat region according to the standard deviation corresponding to the sub-region.

[0192] In some embodiments, the pixel value of the pixel point includes pixel values ​​of different color channels; the second determination module 702 is used to determine, for each sub-block in the sub-block, a first pixel mean of different color channels in the sub-block according to the pixel values ​​of each pixel point in the sub-block; determine a second pixel mean of different color channels in the sub-block according to the pixel values ​​of each pixel point in the sub-block in different color channels; determine the standard deviation corresponding to the sub-block according to the first pixel mean of different color channels in each sub-block of the sub-block and the second pixel mean of different color channels in the sub-block.

[0193] In some embodiments, the second determination module 702 is used to determine the maximum first pixel mean and the minimum first pixel mean of the sub-region in each color channel according to the first pixel means of different color channels in each sub-block of the sub-region; for each color channel, determine the standard deviation of the sub-region in the color channel according to the maximum first pixel mean, the minimum first pixel mean, and the second pixel mean of the sub-region in the color channel; determine the standard deviation corresponding to the sub-region according to the standard deviation of the sub-region in each color channel.

[0194] In some embodiments, the second determination module 702 is used to determine the mean of the standard deviations of the sub-regions in each color channel as the standard deviation corresponding to the sub-region.

[0195] In some embodiments, the third determination module 703 is used to count the number of flat areas in each sub-area; when the number is greater than a first preset number threshold, determine that the initial focus area is a flat area.

[0196] In some embodiments, the focusing module 704 is configured to expand the initial focusing area when the initial focusing area is a flat area; and determine the in-focus position based on the expanded initial focusing area.

[0197] In some embodiments, the preview image includes multiple frames, and the initial focus area in each preview image frame is consistent; the focus module 704 is used to expand the initial focus area when the initial focus area in the preview image that meets the second preset number threshold frames is a flat area.

[0198] In some embodiments, the focusing module 704 is used to, when the initial focusing area is a flat area, weight the width of the initial focusing area using a preset first weighting coefficient and weight the height of the initial focusing area using a preset second weighting coefficient with the initial focusing area as the center, to obtain an expanded initial focusing area.

[0199] In some embodiments, the apparatus further comprises:

[0200] A fourth determination module, used to determine the confidence of phase difference focusing based on the initial focusing area;

[0201] The second determination module 702 is used to determine whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region when the confidence level is less than a preset confidence threshold.

[0202] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0203] Figure 8 8 is a block diagram of an electronic device 800 shown in an embodiment of the present disclosure. For example, the electronic device 800 may be a mobile phone, a mobile computer, etc.

[0204] Reference Figure 8 , the electronic device 800 may include one or more of the following components: a processing component 802 , a memory 804 , a power component 806 , a multimedia component 808 , an audio component 810 , an input / output (I / O) interface 812 , a sensor component 814 , and a communication component 816 .

[0205] The processing component 802 generally controls the overall operation of the electronic device 800, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.

[0206] The memory 804 is configured to store various types of data to support operations on the electronic device 800. Examples of such data include instructions for any application or method operating on the electronic device 800, contact data, phone book data, messages, pictures, videos, etc. The memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0207] The power supply component 806 provides power to the various components of the electronic device 800. The power supply component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 800.

[0208] The multimedia component 808 includes a screen that provides an output interface between the electronic device 800 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front camera and / or a rear camera. When the electronic device 800 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

[0209] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC), and when the electronic device 800 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 804 or sent via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.

[0210] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: home button, volume button, start button, and lock button.

[0211] The sensor assembly 814 includes one or more sensors for providing various aspects of status assessment for the electronic device 800. For example, the sensor assembly 814 can detect the open / closed state of the electronic device 800, the relative positioning of the components, such as the display and keypad of the electronic device 800, and the sensor assembly 814 can also detect the position change of the electronic device 800 or a component of the electronic device 800, the presence or absence of contact between the user and the electronic device 800, the orientation or acceleration / deceleration of the electronic device 800, and the temperature change of the electronic device 800. The sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0212] The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices. The electronic device 800 can access a wireless network based on a communication standard, such as Wi-Fi, 4G or 5G, or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0213] In an exemplary embodiment, the electronic device 800 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.

[0214] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 804 including instructions, and the instructions can be executed by a processor 820 of an electronic device 800 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0215] A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to perform the aforementioned focusing method.

[0216] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims above.

[0217] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A focusing method, characterized in that: The method comprises: Determine an initial focus area in the preview image; wherein the initial focus area includes a plurality of sub-areas; Determine whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region; wherein the concentration degree of the pixel value distribution of each pixel in the flat region is greater than the concentration degree of the pixel value distribution of each pixel in the non-flat region; Determining whether the initial focus area is a flat area according to the result of whether each sub-area is a flat area; A focus position is determined based on the initial focus area and a result of whether the initial focus area is a flat area.

2. The method according to claim 1, characterized in that The step of determining whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region comprises: Dividing each sub-region separately to obtain a plurality of sub-blocks corresponding to each sub-region; wherein each sub-block includes a plurality of pixel points; For each sub-region, statistics are performed on the pixel values ​​of the pixels in each sub-block in the sub-region, and whether the sub-region is a flat region is determined according to the statistical results of each sub-block.

3. The method according to claim 2, characterized in that For each sub-region, counting pixel values ​​of pixels in each sub-block in the sub-region, and determining whether the sub-region is a flat region according to the statistical results of each sub-block, includes: For each sub-region, according to the statistical results of each sub-block in the sub-region, determine the standard deviation of the pixel value distribution of the pixel points in the sub-region; According to the standard deviation corresponding to the sub-region, it is determined whether the sub-region is a flat region.

4. The method according to claim 3, characterized in that: The pixel value of the pixel point includes pixel values ​​of different color channels; and determining the standard deviation of the pixel value distribution of the pixel point in the sub-region according to the statistical results of each sub-block in the sub-region includes: For each sub-block in the sub-region, determining first pixel means of different color channels in the sub-block according to pixel values ​​of each pixel point in the sub-block; Determine second pixel means of different color channels in the sub-region according to the pixel values ​​of each pixel point in the sub-region in different color channels; The standard deviation corresponding to the sub-region is determined according to the first pixel means of different color channels in each sub-block of the sub-region and the second pixel means of different color channels in the sub-region.

5. The method according to claim 4, characterized in that The determining the standard deviation corresponding to the sub-region according to the first pixel means of different color channels in each sub-block of the sub-region and the second pixel means of different color channels in the sub-region comprises: Determine the maximum first pixel mean and the minimum first pixel mean of each color channel of the sub-region according to the first pixel means of different color channels in each sub-block of the sub-region; For each color channel, determine a standard deviation of the sub-region in the color channel according to the maximum first pixel mean, the minimum first pixel mean, and the second pixel mean of the sub-region in the color channel; According to the standard deviation of the sub-region in each color channel, the standard deviation corresponding to the sub-region is determined.

6. The method according to claim 5, characterized in that Determining the standard deviation corresponding to the sub-region according to the standard deviation of each color channel of the sub-region includes: The mean of the standard deviations of the sub-regions in each color channel is determined as the standard deviation corresponding to the sub-region.

7. The method according to claim 1, characterized in that The determining whether the initial focus area is a flat area according to the result of whether each sub-area is a flat area includes: Count the number of flat areas in each sub-area; When the number is greater than a first preset number threshold, it is determined that the initial focus area is a flat area.

8. The method according to claim 1, characterized in that The determining of the focus position based on the initial focus area and a result of whether the initial focus area is a flat area includes: When the initial focus area is a flat area, expanding the initial focus area; The focus position is determined based on the expanded initial focus area.

9. The method according to claim 8, characterized in that The preview image includes multiple frames, and the initial focus area in each preview image frame is consistent; When the initial focus area is a flat area, expanding the initial focus area includes: When the initial focus area in the preview image of the frames meeting the second preset number threshold is a flat area, the initial focus area is expanded.

10. The method according to claim 8, characterized in that When the initial focus area is a flat area, expanding the initial focus area includes: When the initial focus area is a flat area, the width of the initial focus area is weighted using a preset first weighting coefficient and the height of the initial focus area is weighted using a preset second weighting coefficient with the initial focus area as the center to obtain an expanded initial focus area.

11. The method according to claim 1, characterized in that: The method further comprises: Determining a confidence level of phase difference focusing based on the initial focusing area; The step of determining whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region comprises: When the confidence level is less than a preset confidence threshold, whether each sub-region is a flat region is determined according to statistical results of pixel values ​​of pixels in each sub-region.

12. A focusing device, characterized in that: The device comprises: A first determination module, configured to determine an initial focus area in the preview image; wherein the initial focus area includes a plurality of sub-areas; A second determination module is used to determine whether each sub-region is a flat region according to the statistical results of the pixel values ​​of the pixels in each sub-region; wherein the concentration degree of the pixel value distribution of each pixel in the flat region is greater than the concentration degree of the pixel value distribution of each pixel in the non-flat region; A third determination module, configured to determine whether the initial focus area is a flat area according to the result of whether each sub-area is a flat area; A focusing module is used to determine a focus position based on the initial focusing area and whether the initial focusing area is a flat area.

13. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to execute the method as claimed in any one of claims 1 to 11.

14. A computer-readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the method as claimed in any one of claims 1 to 11.