Method for improving auto-focus performance
By obtaining image edge contour values, the performance of AutoFocus is optimized using the Sobel operator and variance calculation, solving the problems of long autofocus time and large memory usage, and achieving faster focusing speed and lower resource consumption.
Patent Information
- Application Number
- CN202410948209.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2026-01-16
AI Technical Summary
Existing AutoFocus technology suffers from long autofocus time and high memory usage.
The method of obtaining image edge contour values is adopted. Edge information is extracted by the Sobel operator, and the variance is calculated to determine the image sharpness. The optimization step S2 is to multiply by a coefficient N to obtain the sharpness value, specifically np.var(sobelx) + np.var(sobely)) * N, where N is usually 100, replacing the steps of calculating gradient magnitude and median in the original method.
It improves AutoFocus performance, reduces computational load, lowers CPU utilization and memory usage, and enhances speed and resource utilization efficiency.
Smart Images

Figure CN121357415A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of intelligent video processing technology, and specifically relates to a method for improving the performance of autofocus. Background Technology
[0002] In existing technology, AutoFocus, or automatic focusing, is a function of camera lenses that allows the camera lens to automatically focus on the subject without manual focusing, thereby producing a clear photo—that is, finding the clearest image in a set of pictures.
[0003] There are many existing AutoFocus technologies. This method uses the method of obtaining the image edge contour value as the standard for judging the image sharpness.
[0004] However, the existing technology has drawbacks such as long autofocus time and large memory usage. Summary of the Invention
[0005] To address the aforementioned issues, the purpose of this application is to improve the performance of AutoFoucs.
[0006] Specifically, the present invention provides a method for improving the performance of autofocus, the method comprising the following steps:
[0007] S1, Sobel operator extracts edge values:
[0008] The image edge information is extracted using the cv2.Soble() command, represented as follows:
[0009] sobelx=cv2.Sobel(img,cv2.CV_32F,1,0)
[0010] sobely=cv2.Sobel(img,cv2.CV_32F,0,1);
[0011] S2. Calculate the variance to obtain the sharpness value:
[0012] af=(np.var(sobelx)+np.var(sobely))*N
[0013] Here, np.var is a function to calculate the variance. The formula is the sum of the variances of Sobelx and Sobely, multiplied by a coefficient N. Since the value after variance calculation is small, it is multiplied by a coefficient. N can be changed according to the specific scene. The obtained af is the image sharpness value.
[0014] The pixel values obtained after processing by the Sobel operator are relatively scattered, so variance can be used as a criterion for evaluation, since variance is a measure of the dispersion of a random variable or a set of data.
[0015] Most importantly, after extensive testing in real-world scenarios, the optimized method can replace the original method. If N is 100, then the result is magnified 100 times.
[0016] The method described uses the acquisition of image edge contour values as a standard for judging image clarity.
[0017] The method described above obtains the image sharpness value based on the premise that the sharper the image, the more obvious the edge information.
[0018] Therefore, the advantage of this application is that it improves performance while achieving better results than previous methods. In terms of performance, the optimized method has a larger difference between the peak and the trough, making it easier to find the peak. In terms of performance, the amount of computation is reduced, so CPU utilization and memory usage will be reduced, which is reflected in increased speed and reduced resource usage. Attached Figure Description
[0019] The accompanying drawings, which are provided to further illustrate the invention and form part of this application, are not intended to limit the scope of the invention.
[0020] Figure 1 This is a schematic diagram of the blurry original input image without the Sobel operation.
[0021] Figure 2 yes Figure 1 The Sobely results are shown in the Sobely results display diagram.
[0022] Figure 3 yes Figure 1 The Sobel results are displayed in the Sobelx results chart.
[0023] Figure 4 This is a clear illustration of the original input image without Sobel operations, and Figure 1 Make a comparison.
[0024] Figure 5 yes Figure 4 The Sobely results are shown in the Sobely results display diagram.
[0025] Figure 6 yes Figure 4 The Sobel results are displayed in the Sobelx results chart.
[0026] Figure 7 This is a diagram comparing the sharpness value curves of the original method and the optimized scheme.
[0027] Figure 8 This is a flowchart illustrating the method. Detailed Implementation
[0028] To better understand the technical content and advantages of the present invention, the present invention will now be described in further detail with reference to the accompanying drawings.
[0029] This invention relates to a method for improving the performance of AutoFocus autofocus, specifically by increasing speed and reducing resource usage, such as CPU and memory. This application involves obtaining the sharpness value of an image by acquiring its edge values, using these as a criterion for judging image sharpness. This method is based on the premise that the sharper the image, the more obvious the edge information. This application is an optimized method for extracting AutoFocus sharpness values, using Python code.
[0030] First, let's understand the process of obtaining sharpness values in the original AutoFoucs, including:
[0031] S1, Sobel operator extracts edge values.
[0032] The image edge information is extracted using the cv2.Soble() command, represented as follows:
[0033] sobelx=cv2.Sobel(img,cv2.CV_32F,1,0)
[0034] sobely=cv2.Sobel(img,cv2.CV_32F,0,1);
[0035] Sobel's results show that... Figures 1 to 6 As shown, Figure 1 and Figure 4 It is an input image. Figure 2 and Figure 3 for Figure 1 The Sobel results are shown in the image. Figure 5 and Figure 6 for Figure 4 The Sobel results are shown in the figure; specifically, Figure 1 For the input blurry image, Figure 2 for Figure 1 The image shows the results of Sobel edge detection, where edge information in the y-direction is extracted. Figure 3 for Figure 1 The image shows the results of edge information extracted in the x-direction after Sobel edge detection. Figure 4 To input a clear image, Figure 5 for Figure 4The image shows the results of Sobel edge detection, where edge information in the y-direction is extracted. Figure 6 for Figure 4 The image shows the results of edge information extracted in the x-direction after Sobel edge detection.
[0036] S2, Calculate the gradient magnitude
[0037] Gmag=np.sqrt(sobelx*sobelx+sobely*sobely);
[0038] S3, Find the median after removing zero values.
[0039] Gmag = Gmag.flatten()
[0040] Gmag = Gmag[Gmag! = 0]
[0041] ortanca_deger=np.median(Gmag);
[0042] S4, Set a threshold filter and sum the results.
[0043] ortanca_deger3=ortanca_deger*self.x#x=10Gmag=Gmag[Gmag>ortanca_deger3]
[0044] af = np.sum(Gmag).
[0045] The steps of the method for improving AutoFocus performance in this application are as follows: Figure 8 As shown, it includes:
[0046] The S1.Sobel operator extracts edge values;
[0047] The image edge information is extracted using the cv2.Soble() command, represented as follows:
[0048] sobelx=cv2.Sobel(img,cv2.CV_32F,1,0)
[0049] sobely=cv2.Sobel(img,cv2.CV_32F,0,1);
[0050] S2. Calculate the variance to obtain the sharpness value:
[0051] The pixel values obtained after processing by the Sobel operator are relatively scattered, so variance can be used as a criterion for evaluation, since variance is a measure of the dispersion of a random variable or a set of data.
[0052] Of course, the most important thing is that, after extensive testing in real-world scenarios, the optimized method can replace the original method. Figure 7 This is the test result for one of the scenarios;
[0053] af=(np.var(sobelx)+np.var(sobely))*100.
[0054] np.var is a function to calculate the variance. The formula is the sum of the variances of sobelx and sobely, multiplied by 100. The resulting af value is the image sharpness value.
[0055] The optimization solution is to replace steps S2 to S4 in the original process with variance. The variance of the results of step S1, sobelx and sobely, is multiplied by 100 to obtain the image sharpness value. The reason for multiplying by 100 is to compare the value with the original solution. Since the value after variance calculation is small, it is magnified by 100 times. Here, 100 can be changed according to the specific scenario.
[0056] Comparison of sharpness curves between the original method and the optimized scheme, for example Figure 7 As shown, the upper curve represents the sharpness curve of the original method, and the lower curve represents the sharpness value curve after optimization. The horizontal axis represents the image code, and the vertical axis represents the corresponding sharpness value of the image. The image corresponding to the highest point is the sharpest, and it becomes increasingly blurry towards both sides. In terms of effect, from... Figure 7 It can be seen that the optimized method has a larger difference between the peak value and the trough value, making it easier to find the peak value. The optimized solution has a larger difference between the peak value and the trough value than the original solution, which is an advantage over the original solution.
[0057] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, various modifications and variations can be made to the embodiments of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for improving AutoFocus performance, characterized by, The method comprises the following steps: S1, the edge value is extracted by a sobel operator: The picture edge information is extracted by a cv2.Soble() instruction, which is expressed as: sobelx = cv2.Sobel(img, cv2.CV_32F, 1, 0) sobely = cv2.Sobel(img, cv2.CV_32F, 0, 1); S2. The variance is obtained, and the definition value is obtained: af = (np.var(sobelx) + np.var(sobely)) * N np.var is a function for calculating variance, the formula is the sum of the variances of sobelx and sobely, and then multiplied by a coefficient N. Since the value after doing the variance is small, it is multiplied by a coefficient. N can be changed according to the specific scene. The obtained af is the definition value of the picture. The pixel value distribution obtained after the Sobel operator processing is relatively scattered, so the variance is used as the evaluation standard, because the variance is a measure of the dispersion degree of random variables or a group of data.
2. The method of claim 1, wherein, The N is 100, and the magnification is 100 times.
3. The method of claim 1, wherein, The method used in the method is to obtain the edge contour value of the image as the standard for judging the definition of the picture.
4. The method of claim 1, wherein the AutoFocus performance is improved by, The method for obtaining the definition value of the picture adopts the premise that the more clear the picture is, the more obvious the edge information is.