Focus value calculation method and device, electronic equipment and storage medium

By using RAW images and compressed brightness information to calculate image edge information in the camera, the problem of low focus accuracy in cameras in dark light environments is solved, and high-precision focus value calculation and focus effect are achieved.

CN120050516APending Publication Date: 2025-05-27INTELLINDUST INFORMATION TECH (SHENZHEN) CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510196710.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-21
Publication Date
2025-05-27

AI Technical Summary

Technical Problem

In dark light environments, it is difficult for the camera to achieve accurate focus because the received light signal is weak, resulting in a significant decrease in the accuracy of focal value calculation.

Method used

By acquiring the RAW image collected by the camera, compressing its brightness information, calculating the image edge information, and calculating the focus value based on the image edge information and image width and height. This method uses the original detail information in the RAW image to reduce the impact of brightness changes on the image edge information, thereby improving the accuracy of focal value calculation.

Benefits of technology

High-precision focus of the camera in dark light environments is achieved, and high-precision image edge information is calculated using RAW images and compressed brightness information, thereby obtaining high-precision focus value.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120050516A_ABST
    Figure CN120050516A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a focus value calculation method and device, electronic equipment and a storage medium, and relates to the technical field of cameras, and the method comprises the steps: obtaining a RAW image collected by a camera; compressing brightness information of the RAW image to obtain a first image; image edge information of the first image is calculated, and the image edge information comprises gradients of pixel values of pixel points in the first image in the horizontal direction and the vertical direction; and calculating a focus value according to the image edge information and the image width and height of the first image. By using the RAW image and compressing the brightness information of the RAW image, the high-precision image edge information can be calculated, and then the high-precision focus value can be calculated according to the high-precision image edge information and the image width and height of the first image, so that a subsequent camera can realize precise focusing in a dark light environment according to the focus value.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of cameras, and particularly to a method, device, electronic device and storage medium for calculating a focus value. Background Art

[0002] In the technical field of cameras, the accurate calculation of the focus value (FV, Focus Value) is the key to obtaining high-quality images. In good lighting conditions, the camera can rely on bright light signals to accurately determine the detailed information of the objects in the image, and can calculate the accurate focus value accordingly. Then, when the camera adjusts its focal length according to the focus value, accurate focusing can be achieved, and clear photos can be taken.

[0003] However, in low-light environments, such as night shooting or low-light source scenes, the light signals received by the camera are weak, and the detailed information of the photographed object cannot be accurately determined according to these light signals, resulting in a significant decrease in the accuracy of the focus value calculation, and it is difficult for the camera to achieve accurate focusing. Summary of the Invention

[0004] The purpose of the embodiments of the present invention is to provide a method, device, electronic device and storage medium for calculating a focus value, so as to improve the accuracy of calculating the focus value, and facilitate the camera to achieve accurate focusing in low-light environments. The specific technical solutions are as follows:

[0005] In the first aspect of the embodiments of the present invention, a method for calculating a focus value is provided, and the method includes:

[0006] Obtain a RAW image collected by the camera;

[0007] Compress the luminance information of the RAW image to obtain a first image;

[0008] Calculate the image edge information of the first image, where the image edge information includes: the gradients of the pixel values of the pixel points in the first image in the horizontal and vertical directions;

[0009] Calculate the focus value according to the image edge information and the image width and height of the first image.

[0010] In an embodiment of the present invention, before compressing the luminance information of the RAW image, the method further includes:

[0011] Perform noise reduction processing on the RAW image to obtain a RAW image after noise reduction processing;

[0012] The compression of the luminance information of the RAW image includes:

[0013] Compress the luminance information of the RAW image after noise reduction processing.

[0014] In one embodiment of the present invention, compressing the luminance information of the RAW image to obtain a first image includes:

[0015] Updating the pixel value of each pixel point in the RAW image to the nth power of the pixel value of the pixel point to obtain a first image, where the value range of n is (0, 1).

[0016] In one embodiment of the present invention, before calculating the image edge information of the first image, the method further includes:

[0017] Setting the pixel value of the pixel point in the first image whose pixel value is higher than a preset threshold to 0 to obtain a first image after light source filtering;

[0018] Calculating the image edge information of the first image includes:

[0019] Calculating the image edge information of the first image after light source filtering.

[0020] In one embodiment of the present invention, calculating the focus value according to the image edge information and the image width and height of the first image includes:

[0021] Calculating the focus value FV according to the image edge information and the image width and height of the first image according to the following expression:

[0022]

[0023] where sobel_x is the gradient of the pixel value of the pixel point in the first image in the horizontal direction, sobel_y is the gradient of the pixel value of the pixel point in the first image in the vertical direction, w is the width of the first image, and h is the height of the first image.

[0024] In one embodiment of the present invention, after calculating the focus value, the method further includes:

[0025] Adjusting the focal length of the camera according to the focus value and the focal length when the camera captures the RAW image.

[0026] In the second aspect of the embodiments of the present invention, a focus value calculation device is further provided. The device includes:

[0027] A RAW image acquisition module for acquiring a RAW image captured by a camera;

[0028] A first image obtaining module for compressing the luminance information of the RAW image to obtain a first image;

[0029] An image edge information calculation module for calculating the image edge information of the first image, where the image edge information includes: the gradients of the pixel values of the pixel points in the first image in the horizontal and vertical directions;

[0030] A focus value calculation module for calculating a focus value according to the image edge information and the width and height of the first image.

[0031] In one embodiment of the present invention, the device further includes:

[0032] A RAW image noise reduction module for performing noise reduction processing on the RAW image to obtain a noise-reduced RAW image;

[0033] The first image obtaining module is specifically configured to compress the luminance information of the noise-reduced RAW image.

[0034] In one embodiment of the present invention, the first image obtaining module is specifically configured to update the pixel value of each pixel point in the RAW image to the nth power of the pixel value of the pixel point to obtain a first image, where the value range of n is (0, 1).

[0035] In one embodiment of the present invention, the device further includes:

[0036] A light source filtering module for setting the pixel values of the pixel points in the first image whose pixel values are higher than a preset threshold to 0 to obtain a first image after light source filtering;

[0037] The image edge information calculation module is specifically configured to calculate the image edge information of the first image after light source filtering.

[0038] In one embodiment of the present invention, the focus value calculation module is specifically configured to calculate a focus value FV according to the following expression based on the image edge information and the width and height of the first image:

[0039]

[0040] where sobel_x is the gradient of the pixel value of the pixel point in the first image in the horizontal direction, sobel_y is the gradient of the pixel value of the pixel point in the first image in the vertical direction, w is the width of the first image, and h is the height of the first image.

[0041] In one embodiment of the present invention, the device further includes:

[0042] A focal length adjustment module for adjusting the focal length of the camera according to the focus value and the focal length when the camera captures the RAW image.

[0043] In a third aspect of an embodiment of the present invention, there is further provided an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0044] Memory, used to store computer programs;

[0045] The processor is used to implement any method step described in the first aspect when executing the program stored in the memory.

[0046] In a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, any method step described in the first aspect is implemented.

[0047] Beneficial effects of the embodiments of the present invention:

[0048] In the solution provided by the embodiment of the present invention, since the RAW image calculated based on the RAW image contains more original image detail information compared to the RGB image after image signal processing when calculating the focus value, these more original image detail information can make the subsequently calculated image edge information more accurate. In addition, the brightness information of the RAW image is compressed before calculating the image edge information, which can minimize the impact of brightness changes on the subsequent calculation of the image edge information and improve the accuracy of the calculated image edge information. Therefore, by using the brightness information of the RAW image and the compressed RAW image, high-precision image edge information can be calculated, and then a high-precision focus value can be calculated based on the high-precision image edge information and the image width and height of the first image, so that the subsequent camera can achieve accurate focus in a dark light environment based on the focus value.

[0049] Of course, it is not necessary to achieve all of the advantages described above at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other embodiments can also be obtained based on these drawings.

[0051] Figure 1 A schematic diagram of a flow chart of a focus value calculation method provided by an embodiment of the present invention;

[0052] Figure 2 A schematic diagram of a specific flow chart of a focus value calculation method provided by an embodiment of the present invention;

[0053] Figure 3 Another specific flowchart of the focus value calculation method provided by the embodiment of the present invention;

[0054] Figure 4 Still another specific flowchart of the focus value calculation method provided by the embodiment of the present invention;

[0055] Figure 5 Schematic diagrams of five RAW images with different sharpness levels collected in a low-light environment;

[0056] Figure 6 Based on a focus value calculation method provided by the embodiment of the present invention, the Figure 5 Schematic diagrams of the focus values of the five RAW images with different sharpness levels therein;

[0057] Figure 7 Schematic diagram of the structure of a focus value calculation device provided by the embodiment of the present invention;

[0058] Figure 8 Schematic diagram of the structure of an electronic device provided by the embodiment of the present invention. Specific embodiments

[0059] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art based on this application belong to the scope of protection of the present invention.

[0060] In order to improve the accuracy of calculating the focus value so that the camera can achieve accurate focusing in a low-light environment, the embodiments of the present invention provide a focus value calculation method, device, electronic device, computer-readable storage medium, and computer program product. First, the focus value calculation method provided by the embodiments of the present invention will be introduced below.

[0061] A focus value calculation method provided by the embodiments of the present invention can be applied to any electronic device that needs to calculate the focus value. For example, it can be the camera itself or terminal devices such as mobile phones and computers connected to the camera. There is no specific limitation here. For the sake of clear description, it is hereinafter referred to as an electronic device.

[0062] As Figure 1 shown, Figure 1 Schematic flowchart of a focus value calculation method provided by the embodiments of the present invention. The above focus value calculation method may include:

[0063] S101: Obtain the RAW image collected by the camera.

[0064] S102: compressing brightness information of the RAW image to obtain a first image.

[0065] S103: Calculate image edge information of the first image.

[0066] The image edge information includes: the gradients of the pixel values ​​of the pixels in the first image in the horizontal and vertical directions.

[0067] S104: Calculate a focus value according to the image edge information and the image width and height of the first image.

[0068] In the solution provided by the embodiment of the present invention, since the focus value is calculated based on the RAW image, the RAW image contains more original image detail information compared to the RGB image after image signal processing, and these more original image detail information can make the subsequently calculated image edge information more accurate. In addition, the brightness information of the RAW image is compressed before calculating the image edge information, which can minimize the impact of brightness changes on the subsequent calculation of the image edge information and improve the accuracy of the calculated image edge information. Therefore, by using the brightness information of the RAW image and the compressed RAW image, high-precision image edge information can be calculated, and then a high-precision focus value can be calculated based on the high-precision image edge information and the image width and height of the first image, so that the subsequent camera can achieve accurate focus in a dark environment based on the focus value.

[0069] When it is necessary to calculate the focus value of an image captured by a camera, the electronic device can obtain a RAW image captured by the camera, wherein the RAW image is an original image that has not been processed by ISP (Image Signal Processing), and the original image contains more original image detail information than an RGB image processed by ISP.

[0070] When the camera is capturing images, the ambient lighting of the scene in which the camera is located may change, thereby causing the overall brightness of the image captured by the camera to change. In order to minimize the impact of brightness changes on subsequent calculation of image edge information, after obtaining the RAW image, the electronic device can obtain a first image by compressing the brightness information of the RAW image. The specific implementation method of compressing the brightness information of the RAW image is described in subsequent embodiments and will not be described in detail here.

[0071] After obtaining the first image, the electronic device may calculate the gradients of the pixel values ​​of the pixels in the first image in the horizontal and vertical directions as the image edge information of the first image.

[0072] In a possible implementation, the electronic device can calculate the image edge information of the first image by using a Sobel operator with a convolution kernel size of 5*5. Among them, the convolution kernel parameters of 5*5 can be shown as follows:

[0073]

[0074] Among them, x is the convolution kernel used to calculate the gradient of the pixel value of the pixel point in the first image in the horizontal direction, and y is the convolution kernel used to calculate the gradient of the pixel value of the pixel point in the first image in the vertical direction.

[0075] By calculating the convolution of the above two convolution kernels, the electronic device can respectively obtain the gradients of the pixel values of the pixel points in the first image in the horizontal and vertical directions.

[0076] Of course, the above convolution kernel size of 5*5 is only an example. The electronic device can use convolution kernels of various sizes to calculate the above image edge information, such as 3*3, 5*5, 7*7, etc. The embodiment of the present application does not specifically limit the size of the convolution kernel.

[0077] In another possible implementation, the electronic device can also calculate the above image edge information by using Fourier transform. Specifically: First, the electronic device can perform Fourier transform on the first image, convert the first image from the spatial domain to the frequency domain to obtain a spectrogram, and use a preset high-pass filter to filter out low-frequency components and retain high-frequency components. Second, the electronic device can apply the high-pass filter to the spectrogram to obtain a filtered spectrogram that only contains high-frequency components. Finally, the electronic device performs inverse Fourier transform on the filtered spectrogram to convert the image from the frequency domain back to the spatial domain to obtain the image edge information of the first image.

[0078] After the electronic device obtains the edge information of the first image, it can calculate the FV value according to the image edge information and the image width and height of the first image.

[0079] In a possible implementation, the electronic device can calculate the focus value FV according to the image edge information and the image width and height of the first image according to the following expression:

[0080]

[0081] Among them, sobel_x is the gradient of the pixel value of the pixel point in the edge information in the horizontal direction, sobel_y is the gradient of the pixel value of the pixel point in the edge information in the vertical direction, w is the width of the first image, and h is the height of the first image.

[0082] When calculating the focus value according to the solution provided in the embodiment of the present invention, since the focus value is calculated based on the RAW image, the RAW image contains more original image detail information compared to the RGB image that has undergone image signal processing. These additional original image detail information can make the subsequent calculated image edge information more accurate. In addition, before calculating the image edge information, the brightness information of the RAW image is compressed, which can minimize the impact of brightness changes on the subsequent calculation of the image edge information and improve the accuracy of calculating the image edge information. Therefore, by using the RAW image and compressing the brightness information of the RAW image, high-precision image edge information can be calculated, and then a highly accurate focus value can be calculated based on the high-precision image edge information and the image width and height of the first image, so that the subsequent camera can achieve accurate focusing in low-light environments according to this focus value.

[0083] As an implementation manner of the embodiment of the present invention, as Figure 2 shown, before the electronic device executes the above step S102, it can also execute step S201:

[0084] S201: Perform noise reduction processing on the RAW image to obtain a noise-reduced RAW image.

[0085] Correspondingly, when the electronic device executes step S102, it can be specifically implemented through step S202:

[0086] S202: Compress the brightness information of the noise-reduced RAW image to obtain a first image.

[0087] There are various methods for the electronic device to perform noise reduction processing on the RAW image, such as mean filtering, median filtering, deep learning noise reduction, etc. The specific manner of noise reduction processing is not limited in the embodiments of the present application.

[0088] In a possible implementation manner, the electronic device can use a 7×7 mean filter to perform noise reduction processing on the above RAW image, that is, create a 7×7 matrix, traverse each pixel point in the RAW image, align the center of the 7×7 matrix with this pixel, add the gray values of the 49 pixel points included in the matrix, then divide by 49 to obtain an average value, and replace the gray value of the corresponding pixel point in the original RAW image with the above average value. In this implementation manner, because the window of the 7×7 mean filter is relatively large and can include more pixel points for average calculation, the impact of noise on the RAW image can be effectively reduced.

[0089] In another possible implementation, the electronic device can use a median filter of size 5*5 to perform noise reduction on the above RAW image, that is, create a window of size 5*5. This window can be square, circular, cross-shaped, etc. Sort the pixel values of the pixel points within the above window and take the median as the new pixel value of the central pixel point. In this implementation, noise reduction is performed by using the median filter method, which can protect the image edges while reducing noise, and has a good effect on removing salt-and-pepper noise.

[0090] In the solution provided by the embodiments of the present invention, before compressing the luminance information of the RAW image, the electronic device can also perform noise reduction on the RAW image, which can effectively reduce the impact of noise on the RAW image. When subsequently compressing the luminance information, compared with directly compressing the luminance information of the RAW image, the details of the luminance information in different exposure regions of the RAW image after compression noise reduction are retained, and the luminance information can be smoother and more natural when finally output, thereby improving the overall quality and visual effect of the RAW image, and further improving the accuracy of subsequent focus value calculation.

[0091] As an implementation of the embodiments of the present invention, the electronic device can compress the luminance information of the RAW image by the following method:

[0092] The electronic device can update the pixel value of each pixel point in the RAW image to the nth power of the pixel value of that pixel point to obtain a first image, where the value range of n is (0, 1).

[0093] The specific value of n can be determined according to the shooting data of the camera. For example, when the data of the RAW image captured by the camera is 10 bits, n can be 0.5. When n is 0.5, when the electronic device updates the pixel value in the above manner, it can be specifically implemented through the following expression:

[0094] y = x 0.5 ;

[0095] where x is the original pixel value of the pixel point, and y is the updated pixel value of the pixel point. When the original pixel value of the pixel point is 100, the pixel value of the pixel point can be updated to 10 through the above expression.

[0096] Through the above exponential transformation, the pixel value of each pixel point in the RAW image can be reduced, which can well compress the luminance information of the image, and at the same time will not have too much impact on the relative relationship between the pixel values of each pixel point, thereby reducing the impact of the luminance change of the image on calculating the image edge information of the image.

[0097] In addition, the electronic device can also perform processing such as linear transformation or logarithmic transformation on the pixel values of each pixel point in the RAW image to compress the luminance information of the RAW image, which is not specifically limited herein.

[0098] In the solution provided by the embodiment of the present invention, the electronic device can first compress the luminance information of the RAW image without greatly affecting the relative relationship between the pixel values of each pixel point, thereby reducing the influence of the luminance change of the image on calculating the image edge information of the image, and further effectively reducing the influence of the luminance change on the subsequent calculation of the FV, which can improve the accuracy of the subsequent focus value calculation.

[0099] As an implementation manner of the embodiment of the present invention, as Figure 3 shown, before calculating the image edge information of the first image, the electronic device can also execute step S301:

[0100] S301: Set the pixel values of the pixel points in the first image whose pixel values are higher than the preset threshold to 0 to obtain the first image after light source filtering.

[0101] Correspondingly, when the electronic device executes step S103, it can be specifically implemented through step S302:

[0102] S302: Calculate the image edge information of the first image after light source filtering.

[0103] Since it is easy to have a poor focusing situation in a low-light environment, a large light spot will be formed in the light source area at this time. The light spot will provide more information details in the subsequent calculation of the focus value, resulting in a deviation in the calculation of the focus value. Therefore, it is necessary to filter the light source and then calculate the image edge information.

[0104] For light source filtering, a possible implementation manner is to set a threshold according to the RAW image data captured by the camera. Then, for the first image, the electronic device can set the pixel values of the pixel points in the image whose pixel values are higher than the preset threshold to 0 to obtain the first image after light source filtering.

[0105] For example, when the RAW image data captured by the electronic device is 10 bits, the maximum pixel value of its pixel points is 2 10-1 = 1023, that is, the value range of the pixel values of the pixel points is [0, 1023]. Then, the pixel points with pixel values greater than 700 can be recognized as the pixel points corresponding to the light source area.

[0106] Continuing with the above formula y = x 0.5Example of compressing the luminance information of a RAW image. For a pixel in the first image, its pixel value is compressed to the 0.5th power of the original pixel value. Therefore, when determining whether a pixel in the first image is a pixel corresponding to a light source area, the value used should also be updated to the 0.5th power of the original value accordingly. That is, the above preset threshold can be set to 700 0.5 . Then, for the first image, the electronic device can set the pixel values of the pixels in the first image whose pixel values are higher than 700 0.5 to 0, so as to turn the light source area in the first image black, obtain the first image after light source filtering, and then calculate the image edge information of the first image after light source filtering, so as to remove the image edge information introduced by the light source area in the first image.

[0107] In the solution provided by the embodiments of the present invention, before calculating the image edge information, the electronic device can first filter out the light source area in the first image by setting the pixel values of the pixels whose pixel values are higher than the preset threshold to 0, and then calculate the image edge information based on the first image after light source filtering, realizing the removal of the image edge information introduced by the light source area in the first image, thereby effectively avoiding the influence of the light source area on the subsequent calculation of the focus value and ensuring the accuracy of the subsequent calculation of the focus value.

[0108] As an implementation manner of the embodiments of the present invention, as Figure 4 shown, after the electronic device executes the above step S104, it can also execute step 401:

[0109] S401: Adjust the focal length of the camera according to the focus value and the focal length when the camera captures the RAW image.

[0110] After the electronic device obtains the focus value of the first image through the above steps S101 - S104, it can determine the difference between the focus value of the first image and the preset focus value, and then calculate the target focal length that the camera needs to adjust according to this difference and the focal length when the camera captures the RAW image. Finally, the focal length of the camera can be adjusted to the above target focal length through the focusing motor of the camera.

[0111] In addition, after the focal length of the camera is adjusted to the above target focal length, the electronic device can also obtain a new RAW image again, repeat the focus value calculation method provided by the embodiments of the present invention, calculate the focus value of the new RAW image, and then judge whether to fine-tune the focal length of the camera according to the difference between this focus value and the preset focus value, so as to ensure that a clear image is captured.

[0112] In the solution provided by the embodiment of the present invention, after the electronic device calculates the focus value, it can adjust the focal length of the camera according to the focus value and the focal length when the camera captures the RAW image, so that the camera can complete focusing and capture a clear image. Moreover, the calculation complexity of the above focus value calculation method is relatively low, and the electronic device can quickly calculate the focus value of the image captured by the camera, so that the camera can achieve rapid focusing based on the calculated focus value.

[0113] See Figure 5 and Figure 6 , Figure 5 is a schematic diagram of five RAW images with different sharpness levels captured in a low-light environment. Figure 6 is a focus value linear graph of the focus values of the five RAW images with different sharpness levels in Figure 5 calculated based on a focus value method provided by an embodiment of the present invention.

[0114] As Figure 5 shown, the five images are five RAW images with different sharpness levels captured by the electronic device in a low-light environment. Among the above five RAW images, the first RAW image has the lowest sharpness, the second RAW image is the clearest, the sharpness of the third RAW image is second only to the second RAW image, the sharpness of the fourth RAW image is lower than that of the third RAW image, and the sharpness of the fifth RAW image is lower than that of the fourth RAW image.

[0115] The focus values of the five RAW images with different sharpness levels in Figure 5 calculated by the focus value calculation method provided by the embodiment of the present invention are as Figure 6 shown. Figure 5 Among them, the focus value corresponding to the clearest RAW image is the highest, the focus value corresponding to the least clear RAW image is the lowest, and the sharpness of the remaining three RAW images also corresponds to the Figure 6 sorting of the last three values in

[0116] Corresponding to the above focus value calculation method, see Figure 7 , an embodiment of the present invention provides a structural schematic diagram of a focus value calculation device, and the device includes:

[0117] A RAW image acquisition module 701, configured to acquire a RAW image captured by the camera;

[0118] A first image obtaining module 702, configured to compress the luminance information of the RAW image to obtain a first image;

[0119] The image edge information calculation module 703 is used to calculate the image edge information of the first image, wherein the image edge information includes: the gradient of the pixel value of the pixel point in the first image in the horizontal and vertical directions;

[0120] The focus value calculation module 704 is used to calculate the focus value according to the image edge information and the image width and height of the first image.

[0121] In the solution provided by the embodiment of the present invention, since the focus value is calculated based on the RAW image, the RAW image contains more original image detail information compared to the RGB image after image signal processing, and these more original image detail information can make the subsequently calculated image edge information more accurate. In addition, the brightness information of the RAW image is compressed before calculating the image edge information, which can minimize the impact of brightness changes on the subsequent calculation of the image edge information and improve the accuracy of the calculated image edge information. Therefore, by using the brightness information of the RAW image and the compressed RAW image, high-precision image edge information can be calculated, and then a high-precision focus value can be calculated based on the high-precision image edge information and the image width and height of the first image, so that the subsequent camera can achieve accurate focus in a dark environment based on the focus value.

[0122] In one embodiment of the present invention, the focus value calculation device further includes:

[0123] A RAW image noise reduction device is used to perform noise reduction processing on the RAW image to obtain a RAW image after noise reduction processing;

[0124] The first image obtaining module 702 is specifically used to compress the brightness information of the RAW image after the noise reduction process.

[0125] In one embodiment of the present invention, the first image obtaining module 702 is specifically used to update the pixel value of each pixel in the RAW image to the nth power of the pixel value of the pixel to obtain the first image, where the value range of n is (0,1).

[0126] In one embodiment of the present invention, the focus value calculation device further includes:

[0127] A light source filtering module, used to set the pixel values ​​of the pixels in the first image whose pixel values ​​are higher than a preset threshold to 0, so as to obtain the first image after light source filtering;

[0128] The image edge information calculation module 703 is specifically used to calculate the image edge information of the first image after light source filtering.

[0129] In one embodiment of the present invention, the above-mentioned focus value calculation module 704 is specifically configured to calculate the focus value FV according to the following expression based on the image edge information and the width and height of the first image:

[0130]

[0131] where sobel_x is the gradient of the pixel value of the pixel point in the first image in the horizontal direction, sobel_y is the gradient of the pixel value of the pixel point in the first image in the vertical direction, w is the width of the first image, and h is the height of the first image.

[0132] In one embodiment of the present invention, the above-mentioned focus value calculation device further includes:

[0133] A focal length adjustment module, configured to adjust the focal length of the camera according to the focus value and the focal length when the camera captures a RAW image.

[0134] An embodiment of the present invention further provides an electronic device, as Figure 8 shown, including a processor 801, a communication interface 802, a memory 803, and a communication bus 804. Among them, the processor 801, the communication interface 802, and the memory 803 complete mutual communication through the communication bus 804.

[0135] The memory 803 is used to store a computer program;

[0136] The processor 801, when executing the program stored on the memory 803, implements the focus value calculation method provided in any of the above embodiments.

[0137] The communication bus mentioned in the above electronic device may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of simplicity, only a thick line is shown in the figure, but it does not mean that there is only one bus or one type of bus.

[0138] The communication interface is used for communication between the above electronic device and other devices.

[0139] The memory may include a Random Access Memory (RAM), and may also include a Non-Volatile Memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located far from the aforementioned processor.

[0140] The above-mentioned processor may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0141] In another embodiment provided by the present invention, there is also provided a computer-readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the steps of any of the above-mentioned focus value calculation methods are implemented.

[0142] In another embodiment provided by the present invention, there is also provided a computer program product containing instructions, which when running on a computer, causes the computer to execute any of the focus value calculation methods in the above-mentioned embodiments.

[0143] In the above-mentioned embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present invention are generated in whole or in part. The computer may be a general-purpose computer, a dedicated computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, Digital Subscriber Line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be accessed by a computer, or a data storage device such as a server or data center that includes one or more integrated available media. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a Solid State Disk (SSD)).

[0144] It should be noted that in this text, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the said element.

[0145] Each embodiment in this specification is described in a related manner. For the same or similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the embodiments of the device, electronic device, computer-readable storage medium and computer program product, since they are basically similar to the method embodiments, the description is relatively simple, and reference can be made to the partial description of the method embodiments for the relevant parts.

[0146] The above are only the preferred embodiments of the present invention and are not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are all included in the protection scope of the present invention.

Claims

1. A focus value calculation method, characterized in that: The method comprises: Get the RAW image captured by the camera; Compressing the brightness information of the RAW image to obtain a first image; Calculating image edge information of the first image, wherein the image edge information includes: gradients of pixel values ​​of pixel points in the first image in horizontal and vertical directions; A focus value is calculated according to the image edge information and the image width and height of the first image.

2. The method according to claim 1, characterized in that: Before compressing the brightness information of the RAW image, the method further includes: Performing noise reduction processing on the RAW image to obtain a RAW image after noise reduction processing; The compressing the brightness information of the RAW image comprises: The brightness information of the RAW image after the noise reduction process is compressed.

3. The method according to claim 1, characterized in that The compressing the brightness information of the RAW image to obtain a first image includes: The pixel value of each pixel in the RAW image is updated to the nth power of the pixel value of the pixel to obtain a first image, wherein the value range of n is (0, 1).

4. The method according to claim 1, characterized in that: Before calculating the image edge information of the first image, the method further includes: Setting the pixel values ​​of the pixels in the first image whose pixel values ​​are higher than a preset threshold to 0 to obtain the first image after light source filtering; The calculating the image edge information of the first image comprises: Image edge information of the first image after the light source filtering is calculated.

5. The method according to claim 1, characterized in that The calculating the focus value according to the image edge information and the image width and height of the first image includes: The focus value FV is calculated according to the image edge information and the image width and height of the first image according to the following expression: Among them, sobel_x is the gradient of the pixel value of the pixel point in the first image in the horizontal direction, sobel_y is the gradient of the pixel value of the pixel point in the first image in the vertical direction, w is the width of the first image, and h is the height of the first image.

6. The method according to any one of claims 1 to 5, characterized in that: After calculating the focus value, the method further includes: The focal length of the camera is adjusted according to the focus value and the focal length of the camera when acquiring the RAW image.

7. A focus value calculation device, characterized in that: The device comprises: RAW image acquisition module, used to obtain the RAW image collected by the camera; A first image obtaining module, used for compressing the brightness information of the RAW image to obtain a first image; An image edge information calculation module, used to calculate the image edge information of the first image, wherein the image edge information includes: the gradient of the pixel value of the pixel point in the first image in the horizontal and vertical directions; A focus value calculation module is used to calculate a focus value according to the image edge information and the image width and height of the first image.

8. The device according to claim 7, characterized in that The device also includes: A RAW image noise reduction module, used to perform noise reduction processing on the RAW image to obtain a RAW image after noise reduction processing; The first image obtaining module is specifically used to compress the brightness information of the RAW image after the noise reduction processing.

9. The device according to claim 7, characterized in that The first image obtaining module is specifically used to update the pixel value of each pixel in the RAW image to the nth power of the pixel value of the pixel to obtain a first image, wherein the value range of n is (0, 1).

10. The device according to claim 7, characterized in that The device also includes: A light source filtering module, used to set the pixel values ​​of the pixels in the first image whose pixel values ​​are higher than a preset threshold to 0, so as to obtain the first image after light source filtering; The image edge information calculation module is specifically used to calculate the image edge information of the first image after the light source is filtered.

11. The device according to claim 7, characterized in that The focus value calculation module is specifically used to calculate the focus value FV according to the image edge information and the image width and height of the first image according to the following expression: Among them, sobel_x is the gradient of the pixel value of the pixel point in the first image in the horizontal direction, sobel_y is the gradient of the pixel value of the pixel point in the first image in the vertical direction, w is the width of the first image, and h is the height of the first image.

12. The device according to any one of claims 7 to 11, characterized in that: The device also includes: A focal length adjustment module is used to adjust the focal length of the camera according to the focus value and the focal length of the camera when acquiring the RAW image.

13. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 6 when executing a program stored in a memory.

14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 6 are implemented.