Camera focal length control method based on image processing

By real-time capture and multi-scale decomposition of images, extracting multi-scale features and inputting focal length prediction models, the problems of adaptability and low processing efficiency of focal length control in the prior art are solved, and high accuracy and real-time in complex scenarios are achieved Sexual image adjustment.

CN119299857APending Publication Date: 2025-01-10NANJING ZHENGTU INFORMATION TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411443266.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-16
Publication Date
2025-01-10

AI Technical Summary

Technical Problem

The existing camera focal length control methods lack adaptability, low processing efficiency, incomplete feature extraction, weak model generalization ability, and difficult to achieve fast and accurate focal length adjustment in complex and changeable target scenarios, affecting image clarity and real-time performance. .

Method used

By capturing the target scene image in real time, decomposing it into image layers of different scales, extracting edge gradients, texture information and high-frequency components, forming multi-scale feature vectors, inputting the pre-trained focal length prediction model for adjustment, using Laplace pyramid and Qualcomm Filtering and other methods perform image decomposition and feature extraction, and combine machine learning algorithms to build a focal length prediction model.

Benefits of technology

It significantly improves the accuracy and robustness of focal length control, reduces the computing burden, improves real-time performance, and can respond quickly under different lighting conditions and scene complexity to ensure image clarity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119299857A_ABST
    Figure CN119299857A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image analysis, and discloses a camera focal length control method based on image processing, and the method comprises the steps: capturing a target scene image in real time through a camera, and decomposing the target scene image into image layers of different scales, so as to comprehensively analyze image features of different resolutions and detail degrees. According to the method, multi-scale features such as edge gradient, texture information and high-frequency component are extracted from each image layer, and feature fusion is carried out to form a multi-scale feature vector; and inputting the vector into a pre-trained focal length prediction model to predict the focal length required for achieving the optimal definition. According to the prediction result, the focal length of the camera is adjusted, and the image is captured again after adjustment. The method improves the adaptability, accuracy and real-time performance of focal length control, and is suitable for various scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image analysis, and in particular to a camera focus control method based on image processing. Background Art

[0002] In modern photography and machine vision applications, camera focus control is one of the key technologies to achieve high-quality image capture. Traditional camera focus adjustment methods mostly rely on manual operation or are based on simple image clarity evaluation algorithms. These methods may perform well in static or preset environments, but when faced with complex and changing target scenes, they often cannot quickly and accurately achieve automatic focus adjustment, resulting in insufficient clarity of the captured image, affecting subsequent image analysis and application. The main defects in the existing technology include:

[0003] Lack of adaptability: Traditional methods often rely on fixed parameters or preset rules to adjust the focal length, which makes it difficult to adapt to changes in lighting conditions, target distances, and scene complexity.

[0004] Low processing efficiency: Some existing technologies require complex processing of full-resolution images when adjusting the focus, which not only increases the computational burden, but also prolongs the time for focus adjustment, affecting real-time performance.

[0005] Incomplete feature extraction: Traditional methods may only consider a single feature of the image (such as edge clarity) and ignore the multi-scale features of the image, such as edge gradients, texture information, and high-frequency components, which limits the accuracy and robustness of focus adjustment.

[0006] Weak model generalization ability: Some learning-based focal length control methods have poor generalization ability for new scenarios in practical applications due to limited training data or unreasonable model design, making them difficult to promote to a wide range of usage scenarios. Summary of the invention

[0007] The purpose of the present invention is to provide a camera focus control method based on image processing to solve the problems raised in the above background technology.

[0008] To achieve the above object, the present invention provides the following technical solution: a camera focus control method based on image processing, the method comprising:

[0009] Capturing images of target scenes in real time through a camera;

[0010] Decompose the captured image into image layers of different scales, each layer representing a different resolution and level of detail;

[0011] Extract image features for each image layer, including edge gradient, texture information and high-frequency components of the image;

[0012] The features extracted from image layers of different scales are fused to form a multi-scale feature vector;

[0013] The fused multi-scale feature vector is input into a pre-trained focal length prediction model to predict the focal length required for the captured image to achieve optimal clarity;

[0014] The focal length of the camera is adjusted according to the prediction result of the focal length prediction model; after the focal length is adjusted, the image of the target scene is recaptured.

[0015] Preferably, the image is decomposed into image layers of different scales using a Laplace pyramid analysis method, and the specific steps include:

[0016] Step 1: Perform Gaussian filtering on the captured image to smooth the image and remove high-frequency noise in preparation for building a Gaussian pyramid;

[0017] Step 2: Downsample the filtered image by deleting all even rows and columns to obtain a low-resolution image with half the size as the first layer of the Gaussian pyramid;

[0018] Step 3: Repeat steps 1 and 2, and perform Gaussian filtering and downsampling on the downsampled image again until the preset number of layers is reached or the image size is smaller than the preset value, and a complete Gaussian pyramid is constructed;

[0019] Step 4: Starting from the top layer of the Gaussian pyramid, upsample each layer of the image by doubling the image size in each direction and filling the newly added rows and columns with zeros;

[0020] Step 5: Perform Gaussian filtering on the upsampled image to estimate the approximate value of the newly added pixels to obtain the upsampled and filtered image;

[0021] Step 6: Use the original image of the corresponding layer in the Gaussian pyramid to subtract the upsampled and filtered image obtained in step 5, calculate the difference, and obtain the image of the corresponding layer in the Laplacian pyramid;

[0022] Step 7: Repeat steps 4 to 6 until all layers in the Gaussian pyramid are processed and a complete Laplacian pyramid is constructed;

[0023] Step 8: Output each layer of the image in the Laplacian pyramid as an image layer of different scales, each layer representing a different resolution and level of detail.

[0024] Preferably, for each image layer after preprocessing, a Sobel edge gradient operator is used to calculate the edge gradient intensity and direction of each pixel in the image;

[0025] According to the calculation result of the edge gradient operator, an edge gradient map of each image layer is generated; and non-maximum suppression processing is performed on the edge gradient map;

[0026] The processed edge gradient map is used as the edge gradient feature representation of the image layer.

[0027] Preferably, a gray level co-occurrence matrix algorithm is selected to extract texture features from each image layer, and the texture features of each image layer are calculated according to the algorithm, including roughness, contrast and directionality of the texture;

[0028] The calculated texture features are sorted to form a texture feature vector for each image layer;

[0029] The texture feature vector of each image layer is used as the texture feature representation of the image layer.

[0030] Preferably, a high-pass filtering-based high-frequency component extraction method is selected to perform filtering processing on each image layer to separate the high-frequency components in the image; the high-pass filtering function is:

[0031]

[0032] Among them, H(u,v) represents the high-pass filter function, D(u,v) is the distance from the point (u,v) to the center of the frequency rectangle, and D0 is the cutoff frequency;

[0033] The image layer is transformed from the spatial domain to the frequency domain using a two-dimensional discrete Fourier transform (DFT). The transformation formula is:

[0034] F(u,v)=DFT{f(x,y)}

[0035] Where DFT{} means performing a two-dimensional discrete Fourier transform on the image in the brackets. f(x,y) is the pixel value of the image in the spatial domain, and F(u,v) is the frequency domain representation after the transform;

[0036] In the frequency domain, the high-pass filter function H(u,v) is multiplied by the frequency domain representation F(u,v) of the image layer to extract the high-frequency components:

[0037] G(u,v)=H(u,v)·F(u,v)

[0038] Among them, G(u,v) is the frequency domain representation after filtering;

[0039] Use the two-dimensional inverse discrete Fourier transform IDFT to convert the filtered frequency domain representation G(u,v) back to the spatial domain to obtain the representation of the high-frequency component in the spatial domain;

[0040] The extracted high-frequency components are normalized and encoded, and the encoded high-frequency feature representation is output as the high-frequency component feature of the image layer.

[0041] Preferably, the step of obtaining the focal length prediction model includes:

[0042] S1: Collect a training dataset containing images captured by the camera at different focal lengths and their corresponding optimal focal length labels;

[0043] S2: Perform multi-scale decomposition on each image to obtain image layers with different resolutions and levels of detail;

[0044] S3: extract image features for each image layer, including edge gradient, texture information and high-frequency components;

[0045] S4: Fuse the features extracted from image layers at different scales to form a multi-scale feature vector;

[0046] S5: Use a machine learning algorithm to build a focal length prediction model with multi-scale feature vectors as input parameters and the corresponding optimal focal length label as output;

[0047] S6: Use the training data set to train the constructed focal length prediction model to obtain a trained focal length prediction model.

[0048] Preferably, a linear regression model is selected to construct a focal length prediction model, and the algorithm formula of the model is:

[0049] y=β0+β1x1+β2x2+...+β n x n +∈

[0050] Among them, y is the target variable, representing the optimal focal length of the camera, x1, x2, ..., x n is the input variable, representing the multi-scale feature vector extracted from the image, β0 is the intercept term, β1, β2, ..., β n is the regression coefficient, ∈ is the error term;

[0051] Initialize the model parameters for each feature x in the linear regression model i The corresponding parameter β i Assign an initial value, which is set to a random number close to 0, and also assign an initial value to the intercept term β0;

[0052] Using the data in the training set, the parameters of the linear regression model are continuously updated iteratively through the gradient descent algorithm to minimize the loss function value between the true focal length value and the predicted focal length value;

[0053] In each iteration, the values ​​of the model parameters are adjusted according to the gradient information of the loss function to the model parameters until the loss function converges or reaches the preset number of iterations.

[0054] Preferably, the performance of the focal length prediction model is evaluated using precision and recall; the precision represents the proportion of samples whose actual focal length values ​​also fall within the range among all samples predicted by the model as positive samples; the positive samples are samples whose predicted focal length values ​​fall within a specified range; the recall represents the proportion of samples whose actual focal length values ​​fall within a specific range that are correctly predicted by the model as falling within the range.

[0055] Compared with the prior art, the present invention has the following beneficial effects:

[0056] The present invention achieves comprehensive analysis of different resolutions and levels of detail by capturing images of the target scene in real time and decomposing them into image layers of different scales. This method can adaptively cope with changes in different lighting conditions, target distances, and scene complexity, significantly improving the accuracy and robustness of focus control.

[0057] By extracting features from image layers of different scales separately, rather than performing complex processing on full-resolution images, the present invention effectively reduces the computational burden, shortens the time for focus adjustment, and improves real-time performance. This enables the camera to respond and adjust focus more quickly in a dynamic environment to capture clear images. The present invention comprehensively considers the multi-scale features of the image, including edge gradients, texture information, and high-frequency components, rather than relying solely on a single feature. This comprehensive feature extraction method improves the accuracy and robustness of focus adjustment, allowing the camera to capture high-quality images in a variety of scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] Figure 1 This is an overall step diagram of the camera focus control method based on image processing according to the present invention;

[0059] Figure 2 A diagram showing the steps of decomposing an image into layers of different scales using the Laplacian pyramid analysis method;

[0060] Figure 3 A step diagram of a high-frequency component extraction method for high-pass filtering;

[0061] Figure 4 Training flowchart for the focal length prediction model. DETAILED DESCRIPTION

[0062] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0063] See also Figure 1-4 The present invention provides a technical solution: a camera focus control method based on image processing, the specific steps are as follows:

[0064] Image capture: First, the image of the target scene is captured in real time through the camera to obtain the basis of the current scene visual information and provide raw data for subsequent image processing and focal length adjustment.

[0065] Image decomposition: Decompose the captured image into image layers of different scales. This decomposition process can use multi-scale analysis techniques, such as pyramid decomposition or Laplacian pyramid, where each layer represents a different resolution and level of detail. The purpose of decomposition is to be able to extract image features from multiple scales and improve the accuracy and robustness of focus adjustment.

[0066] Feature extraction: Extract image features for each image layer. The extracted features include but are not limited to the edge gradient, texture information and high-frequency components of the image. The edge gradient reflects the contour and detail changes of the object in the image, the texture information provides the structure and pattern of the image surface, and the high-frequency component reveals the richness of the image details. The combination of these features can more comprehensively describe the quality of the image and provide rich information for focus adjustment.

[0067] Feature fusion: The features extracted from image layers of different scales are fused to form a multi-scale feature vector. The fusion can be done in a simple splicing manner or in a more complex weighted fusion or feature fusion technology in deep learning. The fused feature vector contains image information extracted from multiple scales, providing a comprehensive input for focal length prediction.

[0068] Focal length prediction: The fused multi-scale feature vector is input into a pre-trained focal length prediction model. This model can be a regression model based on machine learning or deep learning, which is used to predict the focal length required to capture the image to achieve optimal clarity. The model training process should cover a variety of lighting conditions, target distances, and scene complexities to improve its generalization ability.

[0069] Focus adjustment: The focus of the camera is adjusted according to the prediction results of the focus prediction model. The adjustment process can be continuous or step-by-step, depending on the hardware performance of the camera and the accuracy requirements of the focus adjustment.

[0070] Image recapture: After the focus adjustment, recapture the image of the target scene. This step is to verify the effect of the focus adjustment and make further adjustments as needed. If the image clarity meets the expectations, the focus adjustment process ends; otherwise, the above steps can be repeated for iterative optimization.

[0071] This outbreak is further described below in conjunction with Examples 1 to 3:

[0072] Embodiment 1:

[0073] The present invention uses the Laplace pyramid analysis method to decompose the image into image layers of different scales. The Laplace pyramid analysis method can decompose the original image into image layers of multiple scales, each layer representing a different resolution and degree of detail. This multi-scale analysis method makes subsequent image processing and focal length adjustment more precise and accurate. The Laplace pyramid analysis method constructs a Gaussian pyramid through Gaussian filtering and downsampling, and then calculates the Laplace pyramid through upsampling and filtering. This calculation method is relatively efficient because it avoids complex processing on full-resolution images, thereby reducing the computational burden and improving the processing speed. The specific implementation steps are as follows:

[0074] Step 1: Gaussian filter the captured image. Use a Gaussian filter to smooth the original image to remove high-frequency noise in the image and prepare for the construction of a Gaussian pyramid. The selection of the Gaussian filter should take into account the size and standard deviation of the filter to ensure that the filtering effect meets the needs of subsequent processing.

[0075] Step 2: Downsample the filtered image. Reduce the size of the image by half by removing all even rows and columns in the image to obtain a low-resolution image. This low-resolution image will serve as the first layer of the Gaussian pyramid.

[0076] Step 3: Repeat steps 1 and 2 to build a complete Gaussian pyramid. Perform Gaussian filtering and downsampling again on each downsampled image until the preset number of layers is reached or the image size is smaller than the preset value. Each layer represents a different resolution and level of detail.

[0077] Step 4: Starting from the top layer of the Gaussian pyramid, upsample each layer of the image. The upsampled image is obtained by doubling the image size in each direction and filling the newly added rows and columns with 0.

[0078] Step 5: Gaussian filter the upsampled image. Use the same Gaussian filter as in step 1 to filter the upsampled image to estimate the approximate value of the newly added pixels. In this way, the upsampled and filtered image is obtained.

[0079] Step 6: Calculate the image of the corresponding layer in the Laplacian pyramid. Use the original image of the corresponding layer in the Gaussian pyramid to subtract the upsampled and filtered image obtained in step 5 to calculate the difference. This difference image represents the image of the corresponding layer in the Laplacian pyramid, which contains the image details at that scale.

[0080] Step 7: Repeat steps 4 to 6 to construct a complete Laplacian pyramid. Upsample, filter, and interpolate each layer of the Gaussian pyramid until all layers are processed. In this way, a complete Laplacian pyramid is obtained, which contains the detailed information of the original image at different scales.

[0081] Step 8: Output each layer of the Laplacian pyramid. Output each layer of the Laplacian pyramid as an image layer of different scales, each layer represents a different resolution and level of detail. These image layers of different scales can be used for subsequent image processing and focal length adjustment.

[0082] Suppose there is a 1024x1024 original image, and you want to decompose it into three scales of image layers. First, perform Gaussian filtering and downsampling on the original image to obtain a 512x512 first-layer image. Then, perform Gaussian filtering and downsampling on the first-layer image again to obtain a 256x256 second-layer image. Next, perform upsampling, filtering, and difference calculation on the second-layer image to obtain the Laplacian image of the first layer. Similarly, perform upsampling, filtering, and difference calculation on the first-layer image to obtain the Laplacian image of the original image. Finally, three scales of image layers are obtained: the Laplacian image of the original image, the Laplacian image of the first layer, and the second layer image (as the image layer with the lowest resolution). These image layers of different scales can be used for subsequent image processing and focal length adjustment.

[0083] After image preprocessing, the Sobel edge gradient operator is used to perform edge detection on each image layer and generate an edge gradient map. The specific implementation steps are as follows:

[0084] Step 1: For each image layer after preprocessing, the Sobel edge gradient operator is used to calculate the edge gradient strength and direction of each pixel in the image. The Sobel operator is an algorithm for edge detection, which can detect edges by calculating the approximate value of the first-order derivative of the image grayscale. Specifically, for each pixel in the image, the Sobel operator is used to perform convolution in its horizontal and vertical directions to obtain the gradient values ​​of the pixel in the x direction and y direction, and then the edge gradient strength and direction are calculated based on these two gradient values.

[0085] Step 2: Generate an edge gradient map for each image layer based on the calculation results of the edge gradient operator. The edge gradient map is an image of the same size as the original image, in which each pixel value represents the edge gradient intensity of the corresponding pixel in the original image. Through the edge gradient map, the edge information in the image can be intuitively seen.

[0086] Step 3: Perform non-maximum suppression on the edge gradient map. Non-maximum suppression is a commonly used post-processing step for edge detection. It can remove non-maximum points in the edge gradient map to obtain clearer edge lines. Specifically, for each pixel in the edge gradient map, its gradient strength is compared with the gradient strength of the eight neighboring pixels around it. If the gradient strength of the pixel is not the largest, it is set to 0.

[0087] Step 4: Use the processed edge gradient map as the edge gradient feature representation of the image layer. After non-maximum suppression, each pixel in the edge gradient map represents the edge gradient feature of the corresponding position in the original image. These features can be used for subsequent image processing and focus adjustment tasks.

[0088] The gray level co-occurrence matrix algorithm is used to extract texture features from each image layer after preprocessing. The specific implementation steps are as follows:

[0089] Step 1: Select the gray level co-occurrence matrix algorithm to extract texture features for each image layer. The gray level co-occurrence matrix is ​​a statistical method that describes texture features by analyzing the spatial relationship of pixel gray levels in an image.

[0090] Step 2: Calculate the texture features of each image layer according to the gray level co-occurrence matrix algorithm, including the roughness, contrast and directionality of the texture. Roughness reflects the fineness or roughness of the texture, contrast reflects the clarity of the texture, and directionality reflects the main direction of the texture.

[0091] Step 2.1: Calculate the roughness. Roughness is measured by the uneven distribution of elements in the gray-level co-occurrence matrix. Specifically, the entropy or energy of the gray-level co-occurrence matrix can be calculated to characterize the roughness. Step 2.2: Calculate the contrast. The contrast is measured by the difference in the values ​​of the elements in the gray-level co-occurrence matrix. Specifically, the contrast or variance of the gray-level co-occurrence matrix can be calculated to characterize the contrast. Step 2.3: Calculate the directionality. Directionality is measured by the difference in the distribution of elements in the gray-level co-occurrence matrix in different directions. Specifically, the moment of inertia or correlation of the gray-level co-occurrence matrix in different directions can be calculated to characterize the directionality.

[0092] Step 3: Arrange the calculated texture features to form a texture feature vector for each image layer. A texture feature vector is a vector containing multiple texture features and is used to describe the texture characteristics of an image layer.

[0093] Step 4: Use the texture feature vector of each image layer as the texture feature representation of the image layer. In this way, each image layer can use its corresponding texture feature vector to represent its texture characteristics, which is convenient for subsequent image processing and focus adjustment tasks.

[0094] The gray-level co-occurrence matrix algorithm can fully describe the texture features of the image layer, including roughness, contrast, and directionality. These features together constitute a complete description of the image texture, providing rich information for subsequent image processing and focus adjustment.

[0095] Embodiment 2:

[0096] A high-pass filtering-based high-frequency component extraction method is used to filter each preprocessed image layer to separate the high-frequency components in the image. The specific implementation steps include:

[0097] Step 1: Define the high-pass filter function H(u,v), which is a key component in the frequency domain and is used to extract high-frequency information of the image.

[0098]

[0099] Among them, H(u,v) represents the high-pass filter function, D(u,v) represents the distance from the point (u,v) to the center of the frequency rectangle, and D0 is the set cutoff frequency.

[0100] Step 2: Use two-dimensional discrete Fourier transform (DFT) to transform the image layer from the spatial domain to the frequency domain. The transformation formula is:

[0101] F(u,v)=DFT{f(x,y)}

[0102] Among them, f(x,y) is the pixel value of the image in the spatial domain, and F(u,v) is the transformed frequency domain representation. The purpose of this step is to convert the image from the spatial domain to the frequency domain for subsequent filtering processing.

[0103] Step 3: In the frequency domain, multiply the high-pass filter function H(u,v) by the frequency domain representation F(u,v) of the image layer to extract the high-frequency components. The specific operation is:

[0104] G(u,v)=H(u,v)F(u,v)

[0105] Among them, G(u,v) is the frequency domain representation after filtering. This step implements high-pass filtering and extracts the high-frequency components in the image.

[0106] Step 4: Use the two-dimensional inverse discrete Fourier transform (IDFT) to transform the filtered frequency domain representation G(u,v) back to the spatial domain to obtain the representation of the high-frequency component in the spatial domain. The inverse transform formula is:

[0107] IDFT{G(u,v)}=g(x,y)

[0108] Among them, g(x,y) is the representation of the high-frequency component in the spatial domain. This step converts the filtered frequency domain representation back to the spatial domain for subsequent processing and feature extraction.

[0109] Step 5: Normalize and encode the extracted high-frequency components. Normalization encoding is to map the pixel values ​​of the high-frequency components into a uniform range for subsequent feature representation and comparison.

[0110] Step 6: The encoded high-frequency feature representation is output as the high-frequency component feature of the image layer. This step completes the extraction and representation of the high-frequency component features, and provides important feature information for subsequent image processing and focus adjustment tasks.

[0111] Suppose there is a preprocessed image layer with a size of 1024x1024. First, define the high-pass filter function H(u,v) and set the cutoff frequency D0. Then, use the two-dimensional discrete Fourier transform to convert the image layer from the spatial domain to the frequency domain to obtain the frequency domain representation F(u,v). Next, multiply the high-pass filter function H(u,v) by F(u,v) in the frequency domain to extract the high-frequency component and obtain the filtered frequency domain representation G(u,v). Finally, use the two-dimensional inverse discrete Fourier transform to convert G(u,v) back to the spatial domain to obtain the representation g(x,y) of the high-frequency component in the spatial domain. After normalizing and encoding g(x,y), it is output as the high-frequency component feature of the image layer. In this way, the high-frequency information of the image layer can be effectively extracted and utilized.

[0112] Embodiment 3:

[0113] The steps to obtain the focal length prediction model include:

[0114] Step S1: Collect a training dataset. This dataset contains images captured by the camera at different focal lengths and their corresponding optimal focal length labels. These data will be used to train the focal length prediction model so that it can learn the relationship between image features and optimal focal length.

[0115] Step S2: Perform multi-scale decomposition on each image. Through this step, image layers with different resolutions and levels of detail are obtained. Multi-scale decomposition helps to extract features of the image at different scales, thereby improving the accuracy of focal length prediction.

[0116] Step S3: Extract image features for each image layer. These features include edge gradient, texture information and high-frequency components. Edge gradient can describe the edge information in the image, texture information can reflect the texture characteristics of the image, and high-frequency components can capture the detail information in the image. These features together constitute the multi-scale feature representation of the image.

[0117] Step S4: Fuse the features extracted from image layers of different scales. By fusing features of different scales, a multi-scale feature vector is formed. This step aims to integrate information at different scales and provide comprehensive feature input for subsequent focal length prediction.

[0118] Step S5: Use a machine learning algorithm to build a focal length prediction model. Select a linear regression model as the prediction model, and its algorithm formula is:

[0119] y=β0+β1x1+β2x2+...+β n x n +∈

[0120] Among them, y is the target variable, representing the optimal focal length of the camera, x1, x2, ..., x n is the input variable, representing the multi-scale feature vector extracted from the image, β0 is the intercept term, β1, β2, ..., β n is the regression coefficient and ∈ is the error term.

[0121] Step S6: Use the training data to perform model training. The specific steps include:

[0122] S601, initializing model parameters: Before training begins, the model training submodule initializes each model parameter (including the intercept term β0 and regression coefficients β1, β2, β3, β4, β5, β6, β7, β8, β9, β10, β11, β12, β13, β14, β15, β16, β17, β18, β19, β20, n ) is assigned a random initial value close to 0. These initial values ​​will serve as the starting point for the gradient descent algorithm.

[0123] S602, calculate the predicted value: in each iteration, use the current model parameters and the input data in the training set to calculate the predicted value according to the linear regression formula.

[0124] S603, calculate the loss function value: calculate the loss function value between the true value and the predicted value. In linear regression, the commonly used loss function is the mean square error (MSE), and its calculation formula is:

[0125]

[0126] Where m is the number of samples in the training set, y i is the true value of the i-th sample, yhat i is the model's predicted value for the i-th sample.

[0127] S604, calculate gradient and update parameters: calculate the gradient of the loss function with respect to the current model parameters. The gradient indicates the direction and magnitude of the model parameters that should be adjusted in order to reduce the value of the loss function. Based on this gradient information, the gradient descent algorithm is used to update the value of the model parameters. Specifically, for each parameter β j (including the intercept term β0), the update formula is as follows:

[0128]

[0129] Among them, η is the learning rate, which controls the step size of parameter update; is the loss function for the parameter β j The partial derivative of , that is, the gradient.

[0130] S605, iterative optimization: repeat the above steps, and continuously iteratively update the model parameters until the loss function converges to a stable minimum value, or reaches a preset number of iterations. Through this process, the parameters of the linear regression model can be gradually optimized to improve the prediction accuracy of the model.

[0131] The linear regression algorithm has high computational efficiency, especially when dealing with large-scale data sets, and can quickly complete model training and prediction. This is especially important for focal length prediction tasks with high real-time requirements. The coefficients of the linear regression model can be directly interpreted as the degree of influence of the independent variable on the dependent variable. In the focal length prediction model, this means that the contribution of different image features to the prediction of the optimal focal length can be understood by analyzing the model coefficients, thereby optimizing the model performance.

[0132] Here is a Python code example for building and training a focal length prediction model:

[0133] import numpy as np

[0134] from sklearn.model_selection import train_test_split

[0135] from sklearn.linear_model import LinearRegression

[0136] from sklearn.metrics import mean_squared_error

[0137] from sklearn.preprocessing import StandardScaler

[0138] import cv2

[0139] #Assume that the function load_dataset() returns image features X and focal length label y

[0140] def load_dataset():

[0141] # Load data, for example, use random data

[0142] np.random.seed(0)

[0143] X = np.random.rand(1000,100) # Assume there are 1000 samples, each with 100 features

[0144] y = np.random.rand(1000) #corresponding 1000 focal length labels

[0145] return X,y

[0146] # Load the dataset

[0147] X,y=load_dataset()

[0148] # Divide into training set and test set

[0149] X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)

[0150] #Feature scaling

[0151] scaler = StandardScaler()

[0152] X_train_scaled=scaler.fit_transform(X_train)

[0153] X_test_scaled=scaler.transform(X_test)

[0154] #Create a linear regression model

[0155] model=LinearRegression()

[0156] #Train model

[0157] model.fit(X_train_scaled,y_train)

[0158] #Evaluate the model using the test set

[0159] y_pred=model.predict(X_test_scaled)

[0160] mse=mean_squared_error(y_test,y_pred)

[0161] print(f"Mean square error (MSE) of the test set: {mse}")

[0162] The following is a detailed description of the above code:

[0163] ①Import necessary libraries:

[0164] numpy: for manipulating numerical data.

[0165] train_test_split: Imported from sklearn.model_selection, used to split the dataset into training and test sets.

[0166] LinearRegression: Imported from sklearn.linear_model, used to create a linear regression model.

[0167] mean_squared_error: Imported from sklearn.metrics, used to calculate the mean squared error between the predicted value and the true value.

[0168] StandardScaler: Imported from sklearn.preprocessing, used to standardize features.

[0169] cv2: The OpenCV library, which, although not used directly in this code example, is commonly used for image processing tasks.

[0170] ② Loading the dataset: The load_dataset() function is defined, which should return the image features X and the corresponding focal length labels y. In this example, for demonstration purposes, we use randomly generated data.

[0171] ③ Divide the data set into training set and test set: Use the train_test_split function to divide the data set into training set and test set, where the test set accounts for 20% of the total data.

[0172] ④ Feature Scaling: Standardize the features of the training and test sets using StandardScaler. This step is important for many machine learning algorithms, especially when the scales of the features vary greatly.

[0173] ⑤Create and train a linear regression model: A linear regression model was created using LinearRegression and trained using the training set data.

[0174] ⑥Evaluate the model: The performance of the model was evaluated using the test set data, the mean square error (MSE) between the predicted value and the true value was calculated, and it was printed out.

[0175] In order to comprehensively evaluate the performance of the focal length prediction model, the present invention introduces two key indicators: precision and recall.

[0176] Precision refers to the proportion of samples whose actual focal length values ​​also fall within the predicted range among all samples predicted by the model as positive samples. In this context, positive samples specifically refer to samples whose predicted focal length values ​​fall within a specified range. In order to calculate precision, you first need to determine a prediction range for focal length values, such as an error range of ±5%. Then, the statistical model predicts the number of samples within this range, and checks the proportion of these samples whose actual focal length values ​​actually fall within this range.

[0177] Assume that the model predicts 100 samples, and the predicted focal length values ​​of 30 samples fall within the error range of ±5%. Further verification shows that the actual focal length values ​​of 25 of these 30 samples are also within this range. Therefore, the accuracy rate is 25 / 30=83.33%.

[0178] The recall rate refers to the proportion of samples whose actual focal length values ​​fall within a certain range that are correctly predicted by the model to be within that range. This indicator reflects the model's ability to capture actual positive samples. In order to calculate the recall rate, it is also necessary to determine the actual range of a focal length value and count the number of samples within the range and the number of samples correctly predicted by the model.

[0179] Continuing with the above example, suppose that out of 100 samples, the actual focal length values ​​of 40 samples fall within the ±5% error range. And the model successfully predicted 25 of them. Therefore, the recall rate is 25 / 40 = 62.50%.

[0180] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.

[0181] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A camera focus control method based on image processing, characterized in that: The method comprises: Capturing images of target scenes in real time through a camera; Decompose the captured image into image layers of different scales, each layer representing a different resolution and level of detail; Extract image features for each image layer, including edge gradient, texture information and high-frequency components of the image; The features extracted from image layers of different scales are fused to form a multi-scale feature vector; The fused multi-scale feature vector is input into a pre-trained focal length prediction model to predict the focal length required for the captured image to achieve optimal clarity; The focal length of the camera is adjusted according to the prediction result of the focal length prediction model; after the focal length is adjusted, the image of the target scene is recaptured.

2. The camera focus control method based on image processing according to claim 1, characterized in that: The Laplace pyramid analysis method is used to decompose the image into image layers of different scales. The specific steps include: Step 1: Perform Gaussian filtering on the captured image to smooth the image and remove high-frequency noise in preparation for building a Gaussian pyramid; Step 2: Downsample the filtered image by deleting all even rows and columns to obtain a low-resolution image with half the size as the first layer of the Gaussian pyramid; Step 3: Repeat steps 1 and 2, and perform Gaussian filtering and downsampling on the downsampled image again until the preset number of layers is reached or the image size is smaller than the preset value, and a complete Gaussian pyramid is constructed; Step 4: Starting from the top layer of the Gaussian pyramid, upsample each layer of the image by doubling the image size in each direction and filling the newly added rows and columns with zeros; Step 5: Perform Gaussian filtering on the upsampled image to estimate the approximate value of the newly added pixels to obtain the upsampled and filtered image; Step 6: Use the original image of the corresponding layer in the Gaussian pyramid to subtract the upsampled and filtered image obtained in step 5, calculate the difference, and obtain the image of the corresponding layer in the Laplacian pyramid; Step 7: Repeat steps 4 to 6 until all layers in the Gaussian pyramid are processed and a complete Laplacian pyramid is constructed; Step 8: Output each layer of the image in the Laplacian pyramid as an image layer of different scales, each layer representing a different resolution and level of detail.

3. The camera focus control method based on image processing according to claim 2, characterized in that: For each image layer after preprocessing, the Sobel edge gradient operator is used to calculate the edge gradient intensity and direction of each pixel in the image; According to the calculation result of the edge gradient operator, an edge gradient map of each image layer is generated; and non-maximum suppression processing is performed on the edge gradient map; The processed edge gradient map is used as the edge gradient feature representation of the image layer.

4. The camera focus control method based on image processing according to claim 3, characterized in that: Select the gray level co-occurrence matrix algorithm to extract texture features from each image layer, and calculate the texture features of each image layer according to the algorithm, including the roughness, contrast and directionality of the texture; The calculated texture features are sorted to form a texture feature vector for each image layer; The texture feature vector of each image layer is used as the texture feature representation of the image layer.

5. The camera focus control method based on image processing according to claim 4, characterized in that: Select the high-pass filtering-based high-frequency component extraction method, filter each image layer, and separate the high-frequency components in the image; the high-pass filter function is: Among them, H(u,v) represents the high-pass filter function, D(u,v) is the distance from the point (u,v) to the center of the frequency rectangle, and D0 is the cutoff frequency; The image layer is transformed from the spatial domain to the frequency domain using a two-dimensional discrete Fourier transform (DFT). The transformation formula is: F(u,v)=DFT{f(x,y)} Where DFT{} means performing a two-dimensional discrete Fourier transform on the image in the brackets. f(x,y) is the pixel value of the image in the spatial domain, and F(u,v) is the frequency domain representation after the transform; In the frequency domain, the high-pass filter function H(u,v) is multiplied by the frequency domain representation F(u,v) of the image layer to extract the high-frequency components: G(u,v)=H(u,v)·F(u,v) Among them, G(u,v) is the frequency domain representation after filtering; Use the two-dimensional inverse discrete Fourier transform IDFT to convert the filtered frequency domain representation G(u,v) back to the spatial domain to obtain the representation of the high-frequency component in the spatial domain; The extracted high-frequency components are normalized and encoded, and the encoded high-frequency feature representation is output as the high-frequency component feature of the image layer.

6. The camera focus control method based on image processing according to claim 5, characterized in that: The steps to obtain the focal length prediction model include: S1: Collect a training dataset containing images captured by the camera at different focal lengths and their corresponding optimal focal length labels; S2: Perform multi-scale decomposition on each image to obtain image layers with different resolutions and levels of detail; S3: extract image features for each image layer, including edge gradient, texture information and high-frequency components; S4: Fuse the features extracted from image layers at different scales to form a multi-scale feature vector; S5: Use a machine learning algorithm to build a focal length prediction model with multi-scale feature vectors as input parameters and the corresponding optimal focal length label as output; S6: Use the training data set to train the constructed focal length prediction model to obtain a trained focal length prediction model.

7. The camera focus control method based on image processing according to claim 6, characterized in that: The linear regression model is selected to build the focal length prediction model. The algorithm formula of the model is: y=β0+β1x1+β2x2+...+β n x n +∈ Among them, y is the target variable, representing the optimal focal length of the camera, x1, x2, ..., x n is the input variable, representing the multi-scale feature vector extracted from the image, β0 is the intercept term, β1, β2, ..., β n is the regression coefficient, ∈ is the error term; Initialize the model parameters for each feature x in the linear regression model i The corresponding parameter β i Assign an initial value, which is set to a random number close to 0, and also assign an initial value to the intercept term β0; Using the data in the training set, the parameters of the linear regression model are continuously updated iteratively through the gradient descent algorithm to minimize the loss function value between the true focal length value and the predicted focal length value; In each iteration, the values ​​of the model parameters are adjusted according to the gradient information of the loss function to the model parameters until the loss function converges or reaches the preset number of iterations.

8. The camera focus control method based on image processing according to claim 7, characterized in that: The performance of the focal length prediction model is evaluated using precision and recall. The precision indicates the proportion of samples whose actual focal length values ​​also fall within the range among all samples predicted by the model as positive samples. The positive samples are samples whose predicted focal length values ​​fall within the specified range. The recall indicates the proportion of samples whose actual focal length values ​​fall within a specific range that are correctly predicted by the model as falling within the range.

Citation Information

Cited By

  • Pet identity recognition method and device

    CN119559672A

  • Dynamic image acquisition method for time-space-frequency complementation of scene

    CN119919617A