Focusing method and device, electronic equipment, storage medium and computer program product
By generating and iteratively updating the position and size of the initial focus window, the problem of not considering the window position and size in the existing technology is solved, and high-accuracy focusing effects are achieved in different shooting scenarios, improving the user experience.
Patent Information
- Application Number
- CN202410361516.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-27
- Publication Date
- 2025-09-30
AI Technical Summary
Existing autofocus technology does not consider both the position and size of the window when searching for the optimal focus window, resulting in insufficient focus accuracy, an inability to achieve good imaging effects in different shooting scenarios, and a poor user experience.
By generating multiple initial focus windows, the position and size are adjusted based on the current window information and quality information during the iterative update process until the preset stop condition is met, and the target focus window is determined.
The accuracy of the target focus window in different shooting scenarios has been improved, which improves the focus effect of the finished film and the user experience.
Smart Images

Figure CN120730171A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing, and in particular to a focusing method, device, electronic device, storage medium, and computer program product. Background Art
[0002] In recent years, with the continuous development of image processing technology and the rapid iteration of camera equipment, the use of camera devices such as cameras and mobile phones has become increasingly widespread. Autofocus technology, as one of the key technologies for the operation of camera devices, enables cameras to automatically focus using different focusing methods to ensure the imaging quality of the camera device.
[0003] However, when using the focusing method of related technology for automatic focusing, the position and size of the window are not considered simultaneously during the process of searching for the best focus window, resulting in insufficient focusing accuracy, unable to meet the requirements of good focusing effects in different shooting scenes, and poor user experience. Summary of the Invention
[0004] To overcome the problems existing in the related art, the present disclosure provides a focusing method, device, electronic device, storage medium and computer program product.
[0005] According to a first aspect of an embodiment of the present disclosure, a focusing method is provided, the focusing method comprising:
[0006] Generate multiple initial focus windows for the image to be processed;
[0007] Taking each of the initial focus windows as the focus window to be updated, and iterating the window update process for each of the focus windows to be updated until a preset stop iteration condition is met;
[0008] Determining a target focus window according to an update result of the window update process when the preset stop iteration condition is met;
[0009] The window update process includes:
[0010] Based on the current window information and quality information of each of the focus windows to be updated, the position and size of each of the focus windows to be updated are updated to obtain the update result, wherein the update result includes the updated focus windows to be updated, and the current window information is used to characterize the current position and current size of the focus window to be updated.
[0011] In some embodiments of the present disclosure, before generating a plurality of initial focus windows for the image to be processed, the focusing method further includes:
[0012] Performing image preprocessing on the original image to obtain a preprocessed image;
[0013] Perform feature extraction processing on the pre-processed image to obtain a feature image, and use the feature image as the image to be processed.
[0014] In some embodiments of the present disclosure, before iterating the window update process for each of the focus windows to be updated, the focusing method further includes:
[0015] Determining a fitness function based on the feature extraction process, wherein the fitness function is used to determine a fitness value of each of the focus windows to be updated, and the fitness value is used to characterize a window quality of the focus window to be updated at the current position and the current size;
[0016] The fitness value of the focus window to be updated is used as the quality information of the focus window to be updated.
[0017] In some embodiments of the present disclosure, the feature extraction process includes image edge extraction processing or image salient object detection.
[0018] In some embodiments of the present disclosure, generating multiple initial focus windows for the image to be processed includes:
[0019] Dividing the image to be processed into regions to obtain multiple detection regions;
[0020] A plurality of initial focus windows are randomly generated in each of the detection areas.
[0021] In some embodiments of the present disclosure, the randomly generating a plurality of initial focus windows in each of the detection areas includes:
[0022] The following window generation process is performed for each of the detection areas:
[0023] Determining the size of each initial focus window within the detection area based on the size of the detection area;
[0024] Based on the size of the detection area and the size of each of the initial focus windows in the detection area, the position of each of the initial focus windows in the detection area is determined.
[0025] In some embodiments of the present disclosure, the quality information includes a fitness value, and the update result further includes a global optimal focus window;
[0026] Based on the current window information and quality information of each of the focus windows to be updated, updating the position and size of each of the focus windows to be updated includes:
[0027] updating the inertia weight and the learning factor of each of the focus windows to be updated based on the fitness value of each of the focus windows to be updated;
[0028] updating the position, size, and fitness value of each of the focus windows to be updated based on the current window information of each of the focus windows to be updated, the updated inertia weight and the learning factor of each of the focus windows to be updated, the current global optimal focus window, and the individual optimal focus window of each of the focus windows to be updated;
[0029] The global optimal focus window is updated based on the updated fitness values of the focus windows to be updated.
[0030] In some embodiments of the present disclosure, updating the global optimal focus window based on the updated fitness value of each of the focus windows to be updated includes:
[0031] The focus window to be updated with the largest updated fitness value is used as the global optimal focus window.
[0032] In some embodiments of the present disclosure, updating the inertia weight and learning factor of each of the focus windows to be updated includes:
[0033] updating the inertia weight of each of the focus windows to be updated in this window update process based on the fitness value of each of the focus windows to be updated;
[0034] Based on the number of iterations of the window update process, the learning factor of each focus window to be updated in the current window update process is updated.
[0035] In some embodiments of the present disclosure, updating the inertia weight of each focus window to be updated in the current window update process based on the fitness value of each focus window to be updated includes:
[0036] The following inertia weight update process is performed for each of the focus windows to be updated:
[0037] In response to the fitness value of the focus window to be updated being greater than or equal to the average of the fitness values of the focus windows to be updated, determining the updated inertia weight of the focus window to be updated based on the fitness value of the focus window to be updated, the average of the fitness values of the focus windows to be updated, the fitness value of the global optimal focus window, and the first preset inertia weight and the second preset inertia weight;
[0038] In response to the fitness value of the focus window to be updated being less than an average of the fitness values of the focus windows to be updated, the second preset inertia weight is determined as the updated inertia weight of the focus window to be updated.
[0039] In some embodiments of the present disclosure, updating the learning factor of each focus window to be updated in the current window update process based on the number of iterations of the window update process includes:
[0040] The following learning factor update process is performed for each of the focus windows to be updated:
[0041] In response to an increase in the number of iterations of the window update process, the first learning factor of the focus window to be updated is reduced and the second learning factor of the focus window to be updated is increased, wherein the first learning factor corresponds to the individual optimal focus window of the focus window to be updated, and the second learning factor corresponds to the current global optimal focus window.
[0042] In some embodiments of the present disclosure, updating the position, size, and fitness value of each focus window to be updated based on the current window information of each focus window to be updated, the updated inertia weight and the learning factor of each focus window to be updated, the current global optimal focus window, and the individual optimal focus window of each focus window to be updated includes:
[0043] Determining a position update speed of the focus window to be updated based on a current speed of the focus window to be updated, a current position of the focus window to be updated, the updated inertia weight and the learning factor, the position of the individual optimal focus window of the focus window to be updated, and the current position of the global optimal focus window;
[0044] Determining a target position of the focus window to be updated after the position is updated based on the position update speed and the current position of the focus window to be updated;
[0045] Determining a size update speed of the focus window to be updated based on a current speed of the focus window to be updated, a current size of the focus window to be updated, the updated inertia weight and the learning factor, the size of the individual optimal focus window of the focus window to be updated, and the current size of the global optimal focus window;
[0046] Determining a target size of the focus window to be updated after the size is updated based on the size update speed and the current size of the focus window to be updated;
[0047] The position and size of the focus window to be updated are updated to the target position and the target size, and based on the updated target position and the target size, a target fitness value is determined, the target fitness value is used as the updated fitness value, the target fitness value is compared with the historical target fitness value of the focus window to be updated, and the focus window to be updated with the maximum fitness value is updated as the individual optimal focus window of the focus window to be updated.
[0048] In some embodiments of the present disclosure, the updating of the position, size, and fitness value of each focus window to be updated based on the current window information of each focus window to be updated, the updated inertia weight and the learning factor of each focus window to be updated, the current global optimal focus window, and the individual optimal focus window of each focus window to be updated further includes:
[0049] In response to the current speed of any of the focus windows to be updated being less than a first preset speed, determining the first preset speed as the current speed of the focus window to be updated;
[0050] In response to the current speed of any focus window to be updated being greater than a second preset speed, the second preset speed is determined as the current speed of the focus window to be updated, and the second preset speed is greater than the first preset speed.
[0051] In some embodiments of the present disclosure, the preset stop iteration condition includes:
[0052] The number of iterations of the window update process reaches a preset number of iterations; and / or,
[0053] The global optimal focus window converges.
[0054] In some embodiments of the present disclosure, determining the target focus window according to the update result of the window update process when the preset stop iteration condition is met includes:
[0055] In response to satisfying the preset iteration stopping condition, the updated global optimal focus window is used as the target focus window.
[0056] According to a second aspect of an embodiment of the present disclosure, a focusing device is provided, comprising:
[0057] A generating module, the generating module being used to generate a plurality of initial focus windows for the image to be processed;
[0058] an iteration module, the iteration module being configured to use each of the initial focus windows as a focus window to be updated, and iterate the window update process for each of the focus windows to be updated until a preset stop iteration condition is met;
[0059] A determination module, configured to determine a target focus window according to an update result of the window update process when the preset stop iteration condition is met;
[0060] The window update process includes:
[0061] Based on the current window information and quality information of each of the focus windows to be updated, the position and size of each of the focus windows to be updated are updated to obtain the update result, wherein the update result includes the updated focus windows to be updated, and the current window information is used to characterize the current position and current size of the focus window to be updated.
[0062] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising:
[0063] processor;
[0064] a memory for storing processor-executable instructions;
[0065] Wherein, the processor is configured to:
[0066] Generate multiple initial focus windows for the image to be processed;
[0067] Taking each of the initial focus windows as the focus window to be updated, and iterating the window update process for each of the focus windows to be updated until a preset stop iteration condition is met;
[0068] Determining a target focus window according to an update result of the window update process when the preset stop iteration condition is met;
[0069] The window update process includes:
[0070] Based on the current window information and quality information of each of the focus windows to be updated, the position and size of each of the focus windows to be updated are updated to obtain the update result, wherein the update result includes the updated focus windows to be updated, and the current window information is used to characterize the current position and current size of the focus window to be updated.
[0071] According to a fourth aspect of an embodiment of the present disclosure, a non-transitory computer-readable storage medium is provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform a focusing method, the focusing method comprising:
[0072] Generate multiple initial focus windows for the image to be processed;
[0073] Taking each of the initial focus windows as the focus window to be updated, and iterating the window update process for each of the focus windows to be updated until a preset stop iteration condition is met;
[0074] Determining a target focus window according to an update result of the window update process when the preset stop iteration condition is met;
[0075] The window update process includes:
[0076] Based on the current window information and quality information of each of the focus windows to be updated, the position and size of each of the focus windows to be updated are updated to obtain the update result, wherein the update result includes the updated focus windows to be updated, and the current window information is used to characterize the current position and current size of the focus window to be updated.
[0077] According to a fifth aspect of the embodiments of the present disclosure, there is provided a computer program product, including a computer program, which, when executed by a processor, implements:
[0078] Generate multiple initial focus windows for the image to be processed;
[0079] Taking each of the initial focus windows as the focus window to be updated, and iterating the window update process for each of the focus windows to be updated until a preset stop iteration condition is met;
[0080] Determining a target focus window according to an update result of the window update process when the preset stop iteration condition is met;
[0081] The window update process includes:
[0082] Based on the current window information and quality information of each of the focus windows to be updated, the position and size of each of the focus windows to be updated are updated to obtain the update result, wherein the update result includes the updated focus windows to be updated, and the current window information is used to characterize the current position and current size of the focus window to be updated.
[0083] The technical solution provided by the embodiments of the present disclosure may include the following beneficial effects: the current window information used to characterize the current position and current size of the focus window to be updated is used as the basis for the iterative window update process, while taking into account the window position and window size factors, which can ensure the accuracy of the target focus window in different shooting scenes, so that the finished film has a good focus effect, and improves the user experience.
[0084] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0085] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0086] Figure 1 This is a schematic diagram of the ideal focus window in a macro camera scene.
[0087] Figure 2 This is a diagram of the ideal focus window when the subject is not in the center of the frame.
[0088] Figure 3 is a flowchart of a focusing method according to an exemplary embodiment.
[0089] Figure 4 is a flowchart of a focusing method according to another exemplary embodiment.
[0090] Figure 5 The flowchart of generating multiple initial focus windows for an image to be processed is shown according to an exemplary embodiment.
[0091] Figure 6 is a flowchart showing a window generation process performed for each detection area according to an exemplary embodiment.
[0092] Figure 7 The flowchart of updating the position and size of each focus window to be updated based on the current window information and quality information of each focus window to be updated according to an exemplary embodiment is shown.
[0093] Figure 8 The flowchart of updating the inertia weight and learning factor of each focus window to be updated is shown according to an exemplary embodiment.
[0094] Figure 9 is a flowchart showing an inertia weight updating process performed on each focus window to be updated according to an exemplary embodiment.
[0095] Figure 10 This is a flowchart for updating the position, size, and fitness value of each focus window to be updated based on the current window information of each focus window to be updated, the updated inertia weight and learning factor of each focus window to be updated, the current global optimal focus window, and the individual optimal focus window of each focus window to be updated, according to an exemplary embodiment.
[0096] Figure 11 This is a flowchart for updating the position, size, and fitness value of each focus window to be updated based on the current window information of each focus window to be updated, the updated inertia weight and learning factor of each focus window to be updated, the current global optimal focus window, and the individual optimal focus window of each focus window to be updated, according to another exemplary embodiment.
[0097] Figure 12 is a flowchart of a focusing method according to another exemplary embodiment.
[0098] Figure 13 is a block diagram of a focusing device according to an exemplary embodiment.
[0099] Figure 14is a block diagram of an electronic device according to an exemplary embodiment.
[0100] In the picture:
[0101] 10 - generation module; 20 - iteration module; 30 - determination module; 101 - processing component; 102 - memory; 103 - power component; 104 - multimedia component; 105 - audio component; 106 - input / output interface; 107 - sensor component; 108 - communication component; 109 - processor. DETAILED DESCRIPTION
[0102] Exemplary embodiments will be described in detail herein, examples of which are illustrated in the accompanying drawings. In the following description, when referring to the drawings, like numbers in different figures represent like or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all possible embodiments consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present invention, as detailed in the appended claims.
[0103] In recent years, with the continuous development of image processing technology and the rapid iteration of camera devices, cameras, mobile phones, and other camera devices have become widely used in people's daily lives and work. Autofocus technology is one of the key technologies for the operation of camera devices. Camera devices can automatically focus through focusing methods such as Phase Detection Auto Focus (PDAF), Contrast Detection Auto Focus (CDAF), and Time of Flight (TOF) to ensure the imaging effect of the camera device.
[0104] However, when focusing using PDAF, CDAF and other related technologies, the focus window is usually a central window with a fixed size and position. Figure 1 In the macro photography scene shown, it is impossible to make the focus window as Figure 1 Keep on small objects to capture more details. Figure 2 When the subject is not in the center of the picture, the focus window cannot be adjusted. Figure 2 As shown in the figure, the camera remains on the focus subject, resulting in insufficient focus accuracy, inability to guarantee the focus effect of the film, difficulty in meeting the shooting needs in different shooting scenes, and poor user experience.
[0105] Based on this, the exemplary embodiments of the present disclosure provide a focusing method that generates multiple initial focus windows as focus windows to be updated, and updates the position and size of each focus window to be updated based on the current window information and quality information of each focus window to be updated to perform a window update process. The method can determine the target focus window based on the update results of the window update process, thereby achieving automatic focusing. By using the current window information used to characterize the current position and current size of the focus window to be updated as the basis for the iterative window update process, while also taking into account the window position and window size factors, the accuracy of the target focus window can be guaranteed in different shooting scenarios, resulting in a good focus effect in the final film and an improved user experience.
[0106] In an exemplary embodiment, a focusing method is provided. The focusing method can be applied to a photographing device such as a mobile phone, a camera, or other electronic devices connected to the photographing device. Figure 3 As shown, the focusing methods include:
[0107] S100: Generate multiple initial focus windows for the image to be processed.
[0108] In step S100, the image to be processed may be, for example, an original image captured by a camera, subjected to image preprocessing and feature extraction, so that the image to be processed possesses certain characteristics that facilitate subsequent acquisition of quality information for the focus window to be updated. Multiple initial focus windows are generated for the image to be processed, each of which may have a different position and size and may, for example, be evenly distributed throughout the image to be processed.
[0109] S200 , taking each initial focus window as a focus window to be updated, and iterating the window update process for each focus window to be updated until a preset stop iteration condition is met.
[0110] In step S200, the generated multiple initial focus windows are used as multiple focus windows to be updated, and the window update process is iterated for each focus window to be updated. After each iteration of the window update process, the position and size of each focus window to be updated may change. When a preset stop iteration condition is met, the window update process is stopped.
[0111] For example, the window update process can be iterated through the particle swarm optimization algorithm (PSO), and each focus window to be updated is used as a particle in the particle swarm optimization algorithm. The sharing of information by individuals is used to make the movement of the entire group evolve from disorder to order in the problem-solving space, thereby finding the optimal solution to the problem, which has the characteristics of fast convergence speed and simplicity and ease of implementation.
[0112] S300: Determine a target focus window according to an update result of the window update process when a preset stop iteration condition is met.
[0113] In step S300, a target focus window is determined based on the update results of the window update process when a preset stop condition is met, i.e., the window update process stops iterating. This target focus window can be used as the focus window in the photo preview screen to assist the camera in determining the focus area of the current captured scene corresponding to the image to be processed, selecting the optimal focus point, and achieving clear imaging of the scene.
[0114] The window update process includes: based on the current window information and quality information of each focus window to be updated, updating the position and size of each focus window to be updated, and obtaining an update result. The update result includes the updated focus windows to be updated, and the current window information is used to represent the current position and current size of the focus window to be updated.
[0115] The window update process of each iteration is to update the position and size of each focus window to be updated according to the current window information and quality information of each focus window to be updated, and obtain the update results of each focus window to be updated after the update. The current window information is used to characterize the current position and current size of the focus window to be updated, that is, the position and size of the focus window to be updated after completing the previous window update process. Exemplarily, the current position can be represented by the position coordinates (x, y) of any corner point of the focus window to be updated, and the current size can be represented by the current width w and current height h of the focus window to be updated, so the current window information can be represented by four-dimensional data (x, y, w, h). The quality information can be, for example, a fitness value, and the window quality of the focus window to be updated at the current position and current size can be represented by the fitness value.
[0116] In this embodiment, a window update process is performed by generating multiple initial focus windows as focus windows to be updated, and updating the position and size of each focus window to be updated based on its current window information and quality information. The target focus window can be determined based on the update results of the window update process, thus achieving autofocus. By using the current window information representing the current position and size of the focus window to be updated as the basis for the iterative window update process, while also taking into account the window position and size factors, the accuracy of the target focus window can be guaranteed in different shooting scenarios, resulting in a well-focused final image and an improved user experience.
[0117] In some embodiments, reference Figure 4 As shown, before generating multiple initial focus windows for the image to be processed, the focusing method further includes:
[0118] S400: Perform image preprocessing on the original image to obtain a preprocessed image.
[0119] In step S400, the original image is an image obtained by the photographing device through the camera module, and the original image is preprocessed. The image preprocessing may include, for example, image denoising and image downsampling, so that the original image with a higher resolution is processed to obtain a preprocessed image with a lower resolution and noise removed, which can speed up the subsequent image calculation process.
[0120] S500 , performing feature extraction processing on the pre-processed image to obtain a feature image, and using the feature image as the image to be processed.
[0121] In step S500, feature extraction processing is performed on the pre-processed image. Exemplarily, the feature extraction processing can be, for example, image edge extraction processing or image salient target detection, which can correspond to obtaining a feature image with obvious visual features, and use the feature image as the image to be processed for subsequent generation of the initial focus window.
[0122] In this embodiment, the original image is preprocessed to obtain a preprocessed image, and feature extraction is performed on the preprocessed image to obtain a feature image. This feature image can be used as the preprocessed image to provide a basis for generating the initial focus window. The image preprocessing process can result in a lower resolution and noise-removed preprocessed image, which can accelerate subsequent image calculations. Furthermore, feature extraction can impart distinct visual features to the processed image, facilitating the subsequent determination of updated focus window quality information.
[0123] In some embodiments, before iterating the window update process for each focus window to be updated, the focusing method also includes: determining a fitness function based on feature extraction processing, the fitness function is used to determine the fitness value of each focus window to be updated, the fitness value is used to characterize the window quality of the focus window to be updated at the current position and current size, and the fitness value of the focus window to be updated is used as the quality information of the focus window to be updated.
[0124] Depending on the feature extraction processing method, a corresponding fitness function can be determined. This fitness function can be used to determine the fitness value of each focus window to be updated. The fitness value determined based on the fitness function can represent the window quality of the focus window to be updated at its current position and size. The higher the window quality of the focus window to be updated, the more it can meet the shooting requirements of the current shooting scene, and can achieve better focusing effects.
[0125] Since the fitness value of the focus window to be updated can represent the window quality of the focus window to be updated at the current position and current size, the fitness value of the focus window to be updated can be used as the quality information of the focus window to be updated, and as a basis for the iterative window update process. It should be noted that before each iterative window update process, the fitness value of the focus window to be updated needs to be updated according to the fitness function to ensure that the window information of the focus window to be updated can adapt to the current window information of the focus window to be updated during the iterative window update process.
[0126] In this embodiment, by determining the fitness function according to the feature extraction processing method, the fitness value of each focus window to be updated can be determined through the fitness function, and the fitness value can be used as the quality information of the focus window to be updated, thereby realizing the determination of the quality information of each focus window to be updated, providing a basis for the iterative window update process, ensuring that the final target focus window has good window quality, and improving the user experience.
[0127] In some embodiments, the feature extraction process includes image edge extraction or image salient object detection.
[0128] The feature extraction process may be image edge extraction process or image salient target detection. The image edge extraction process can extract the edge information of the object from the preprocessed image, and the image salient target detection can identify and locate the most salient area in the preprocessed image.
[0129] For example, when the feature extraction process is image edge extraction, the resulting feature image is an edge gradient map. The corresponding fitness function can be a square gradient algorithm for evaluating image clarity. The result of the square gradient algorithm is the fitness value determined by the fitness function, and the fitness value is used as quality information during the iterative window update process. When the feature extraction process is image salient object detection, the resulting feature image is a saliency map. The average saliency value within each focus window to be updated can be calculated as the fitness value determined by the fitness function, and the fitness value is used as quality information during the iterative window update process.
[0130] In this embodiment, by performing feature extraction processing using image edge extraction or image salient object detection, different types of feature images can be obtained, enabling acquisition of the image to be processed. Furthermore, fitness values can be determined based on the fitness functions corresponding to different feature extraction processing methods, enabling the determination of quality information. Image edge extraction takes edge information into account, while salient object detection takes saliency information into account. This allows the subsequent determination of the target focus window based on image features of different dimensions, improving the applicability of the focusing method and the user experience.
[0131] In some embodiments, reference Figure 5 As shown, multiple initial focus windows are generated for the image to be processed, including:
[0132] S110 , dividing the image to be processed into regions to obtain multiple detection regions.
[0133] In step S110, the image to be processed is divided into regions to obtain multiple detection regions. For example, the image to be processed can be evenly divided into 3*3 detection regions according to the number of pixel rows and pixel columns of the image to be processed, and the size of each detection region is the same as the number of pixels in the detection region.
[0134] S120 , randomly generating a plurality of initial focus windows in each detection area.
[0135] In step S120, multiple initial focus windows are randomly generated in each detection area obtained through the division. The number of randomly generated initial focus windows in each detection area can be, for example, the same, and the positions and sizes of the initial focus windows in each detection area are random. For example, the image to be processed can be divided into M detection areas, where M is a positive integer greater than 2, and N initial focus windows are randomly generated in each detection area, where N is a positive integer greater than 2. Thus, M*N initial focus windows are generated, thereby achieving the generation of multiple initial focus windows.
[0136] In this embodiment, multiple detection areas are obtained by dividing the image to be processed, and multiple initial focus windows are randomly generated in each detection area. Multiple initial focus windows can be generated relatively evenly in the entire image to be processed, so that the distribution of the initial focus windows is not completely random, which can ensure the iterative ability of the window update process, improve the global search ability of the particle swarm optimization algorithm, reduce the convergence time of the target focus window, and enhance the user experience.
[0137] In some embodiments, a plurality of initial focus windows are randomly generated in each detection area, including: performing the following steps on each detection area: Figure 6 The following window is shown:
[0138] S121 . Determine the size of each initial focus window in the detection area based on the size of the detection area.
[0139] In step S121, the size of each initial focus window in the detection area can be determined according to the size of the detection area. For example, the width of the detection area is W and the height is H. The width w and height h of each initial focus window can be determined by the following formula:
[0140] w=r1*W (1)
[0141] h=r2*H (2)
[0142] Among them, w and h are the width and height of the initial focus window, r1 and r2 are random numbers greater than 0 and less than 1. When the random numbers change randomly, the width w and height h of the initial focus window change accordingly. The size of each initial focus window in the detection area can be determined by the change of the random numbers.
[0143] S122: Determine the position of each initial focus window in the detection area based on the size of the detection area and the size of each initial focus window in the detection area.
[0144] In step S122, the position of each initial focus window in the detection area can be determined according to the size of the detection area and the size of each initial focus window in the detection area. For example, the position coordinates (x, y) of any corner point of each initial focus window can be determined by the following formula:
[0145] x=r3*(Ww) (3)
[0146] y=r4*(Hh) (4)
[0147] Among them, the sum is a random number greater than 0 and less than 1. When the random number changes randomly, the position coordinates of any foot pad of the initial focus window change accordingly. The position of each initial focus window in the detection area can be determined by the change of the random number.
[0148] In this embodiment, the size of each initial focus window within the detection area is determined based on the size of the detection area, and the position of each initial focus window within the detection area is determined based on the size of the detection area and the size of each initial focus window within the detection area, thereby achieving the determination of the size and position of the initial focus window. Multiple initial focus windows are randomly generated in each detection area, ensuring the randomness of each initial focus window within each detection area. This can provide multiple random initial particles for the subsequent execution of the particle swarm algorithm. By considering the position and size of the windows, the accuracy of the target focus window can be guaranteed in different shooting scenarios, resulting in a good focus effect in the final film and an improved user experience.
[0149] In some embodiments, the quality information includes a fitness value, and the update result also includes a global optimal focus window. The global optimal focus window is the focus window to be updated that has the largest fitness value among all the focus windows to be updated, that is, the window with the highest quality. Figure 7 As shown, based on the current window information and quality information of each focus window to be updated, the position and size of each focus window to be updated are updated, including:
[0150] S210 : Based on the fitness value of each focus window to be updated, update the inertia weight and learning factor of each focus window to be updated.
[0151] In step S210, the inertia weight and learning factor of each focus window to be updated are updated according to the fitness value of each focus window to be updated at the current size and current position. The inertia weight and learning factor are parameters in the particle swarm optimization algorithm. Both the inertia weight and the learning factor are used to determine the update speed of the focus window to be updated during this window update process. The inertia weight corresponds to the update speed of the previous window update process, and the learning factor corresponds to the current window information of the focus window to be updated, which can serve as the basis for the iterative window update process.
[0152] S220: Based on the current window information of each focus window to be updated, the updated inertia weight and learning factor of each focus window to be updated, the current global optimal focus window and the individual optimal focus window of each focus window to be updated, the position, size and fitness value of each focus window to be updated are updated.
[0153] In step S220, the individual optimal focus window for each focus window to be updated is the focus window to be updated that has the maximum fitness value during the multiple iterative window updates to date. Based on the particle swarm optimization algorithm, the position and size of each focus window to be updated can be updated based on the current window information of each focus window to be updated, the corresponding updated inertia weight and learning factor, the corresponding individual optimal focus window, and the current global optimal focus window, to achieve an update of the position and size of each focus window to be updated. After the position and size of the focus window to be updated are updated, the fitness value of the focus window to be updated changes accordingly, and the fitness value of each focus window to be updated is simultaneously updated.
[0154] S230 : updating the global optimal focus window based on the updated fitness values of the focus windows to be updated.
[0155] In step S230, the global optimal focus window can be updated according to the fitness values of the updated focus windows to be updated, ensuring that the global optimal focus window is selected in the updated focus window to be updated, so as to serve as the basis for updating the position and size of each focus window to be updated when the next window update process is executed, thereby ensuring that the window update process has adaptive characteristics.
[0156] In this embodiment, the inertia weight and learning factor of each focus window to be updated are updated based on the fitness value of each focus window to be updated at its current size and position. Furthermore, the position, size, and fitness value of each focus window to be updated are updated based on the current window information of each focus window to be updated, the updated inertia weight and learning factor of each focus window to be updated, the current global optimal focus window, and the individual optimal focus window of each focus window to be updated. The global optimal focus window is then updated based on the updated fitness value of each focus window to be updated, thus implementing each window update process. This updating of the inertia weight and learning factor is different from the particle swarm optimization algorithm used in related technologies, accelerating convergence and enhancing global search capabilities, improving the robustness of the window update process, and being applicable to processed images of different resolutions and sizes.
[0157] In some embodiments, updating the global optimal focus window based on the updated fitness values of the focus windows to be updated includes: using the focus window to be updated with the largest updated fitness value as the global optimal focus window.
[0158] As mentioned above, the position and size of each focus window to be updated change, and the corresponding fitness value changes accordingly. After the fitness value of each focus window to be updated is updated, the focus window to be updated with the largest updated fitness value can be used as the updated global optimal focus window.
[0159] In this embodiment, by taking the focus window to be updated with the largest updated fitness value as the global optimal focus window, a basis is provided for implementing the particle swarm optimization algorithm, so that the global optimal focus window is selected at the current position and current size of the focus window to be updated, ensuring the accuracy and timeliness of the global optimal focus window as one of the bases when the window update process is executed next time.
[0160] In some embodiments, reference Figure 8 As shown, the inertia weight and learning factor of each focus window to be updated are updated, including:
[0161] S211 : Based on the fitness value of each focus window to be updated, update the inertia weight of each focus window to be updated in this window update process.
[0162] In step S211, the inertia weight of each focus window to be updated in this window update process can be updated according to the fitness value of each focus window to be updated at the current position and current size, so that each focus window to be updated can determine the distance between the focus window to be updated and the current global optimal focus window through the size of the fitness value, and adaptively adjust the inertia weight of the particle swarm optimization algorithm according to the distance as the basis of the window update process, so as to improve the global search capability and convergence speed of the particle swarm optimization algorithm.
[0163] S212: Based on the number of iterations of the window update process, update the learning factor of each focus window to be updated in this window update process.
[0164] In step S212, the learning factor of each focus window to be updated in this window update process can be updated according to the number of iterations of the window update process, so that each focus window to be updated can adaptively adjust the learning factor of the particle swarm optimization algorithm as the basis of the window update process to improve the global search ability and convergence speed of the particle swarm optimization algorithm.
[0165] In this embodiment, the inertia weight of each focus window to be updated in this window update process is updated according to the fitness value of each focus window to be updated at the current position and current size, and the learning factor of each focus window to be updated in this window update process is updated according to the number of iterations of the window update process. This can adaptively adjust the parameters of the particle swarm optimization algorithm, provide a basis for updating the position and size of the focus window to be updated, and improve the global search capability and convergence speed of the particle swarm optimization algorithm.
[0166] In some embodiments, based on the fitness value of each focus window to be updated, the inertia weight of each focus window to be updated in this window update process is updated, including: performing the following steps on each focus window to be updated: Figure 9 The following inertia weight update process is shown:
[0167] S211-1. In response to the fitness value of the focus window to be updated being greater than or equal to the average of the fitness values of each focus window to be updated, determine the updated inertia weight of the focus window to be updated based on the fitness value of the focus window to be updated, the average of the fitness values of each focus window to be updated, the fitness value of the global optimal focus window, and the first preset inertia weight and the second preset inertia weight.
[0168] In step S211-1, the fitness value of the focus window to be updated is compared with the average fitness value of each focus window to be updated. If the fitness value of the focus window to be updated is greater than or equal to the average fitness value of each focus window to be updated, the inertia weight of the focus window to be updated after update can be determined based on the fitness value of the focus window to be updated, the average fitness value of each focus window to be updated, the fitness value of the global optimal focus window, and the first preset inertia weight and the second preset inertia weight.
[0169] For example, if the fitness value f of the focus window to be updated is greater than or equal to the average fitness value f of each focus window to be updated avg , that is, f≥f avg When , the updated inertia weight w of the focus window to be updated can be determined by the following formula:
[0170]
[0171] Among them, f max is the fitness value of the global optimal focus window, w min is the first preset inertia weight, w max is the second preset inertia weight, the first preset weight w min For example, it can be 0.4, and the second preset weight w max For example, it may be 0.9.
[0172] S211 - 2 : In response to the fitness value of the focus window to be updated being less than the average fitness value of each focus window to be updated, determine a second preset inertia weight as the updated inertia weight of the focus window to be updated.
[0173] In step S211-2, the fitness value of the focus window to be updated is compared with the average fitness value of each focus window to be updated. If the fitness value of the focus window to be updated is less than the average fitness value of each focus window to be updated, the second preset inertia weight can be used as the inertia weight of the focus window to be updated after update.
[0174] For example, if the fitness value f of the focus window to be updated is less than the average fitness value f of each focus window to be updated avg , that is, f <f avg When , the updated inertia weight w of the focus window to be updated can be determined by the following formula:
[0175] w=w max (6)
[0176] It should be noted that a larger inertia weight is beneficial for global search, while a smaller inertia weight is beneficial for local search. The smaller the fitness value corresponding to the focus window to be updated, the farther the focus window to be updated is from the current global optimal focus window. In this case, according to the above steps, a larger inertia weight can be selected for global search. The larger the fitness value corresponding to the focus window to be updated, the closer the focus window to be updated is to the current global optimal focus window. In this case, according to the above steps, a smaller inertia weight can be selected for local search.
[0177] In this embodiment, by comparing the fitness value of the focus window to be updated with the average fitness value of each focus window to be updated, different calculation methods can be selected according to different comparison results to determine the inertia weight of the focus window to be updated after the update, so that fitness values of different sizes can be selected in different situations as the basis for updating the position and size of the focus window to be updated, thereby improving the global search capability and convergence speed of the particle swarm optimization algorithm.
[0178] In some embodiments, based on the number of iterations of the window update process, updating the learning factor of each focus window to be updated in this window update process includes: performing the following learning factor update process for each focus window to be updated:
[0179] In response to an increase in the number of iterations of the window update process, the first learning factor of the focus window to be updated is reduced and the second learning factor of the focus window to be updated is increased, the first learning factor corresponds to the individual optimal focus window of the focus window to be updated, and the second learning factor corresponds to the current global optimal focus window.
[0180] The learning factor of the focus window to be updated includes a first learning factor corresponding to the individual optimal focus window of the focus window to be updated and a second learning factor corresponding to the current global optimal focus window, which can respectively represent the acceleration of the learning of the updated focus window towards the individual optimal focus window and the global optimal focus window. As the number of window iterations gradually increases, the first learning factor of the focus window to be updated can be reduced and the second learning factor of the focus window to be updated can be increased, so that the focus window can gradually transition from global search to a more precise local search, thereby improving the global search capability and convergence speed of the particle swarm optimization algorithm.
[0181] In this embodiment, when the number of iterations of the window update process increases, by reducing the first learning factor of the focus window to be updated and increasing the second learning factor of the focus window to be updated, the learning factor of the particle swarm optimization algorithm can be adaptively adjusted, providing a basis for updating the position and size of the focus window to be updated, and enabling the focus window to gradually transition from global search to more precise local search, thereby improving the global search capability and convergence speed of the particle swarm optimization algorithm.
[0182] In some embodiments, reference Figure 10 As shown, based on the current window information of each focus window to be updated, the updated inertia weight and learning factor of each focus window to be updated, the current global optimal focus window and the individual optimal focus window of each focus window to be updated, the position, size and fitness value of each focus window to be updated are updated, including:
[0183] S221. Determine a position update speed of the focus window to be updated based on the current speed of the focus window to be updated, the current position of the focus window to be updated, the updated inertia weight and learning factor, the position of the individual optimal focus window of the focus window to be updated, and the current position of the global optimal focus window.
[0184] In step S221, the position update speed of the focus window to be updated can be determined based on the current speed of the focus window to be updated, the current position of the focus window to be updated, the updated inertia weight and learning factor, the position of the individual optimal focus window of the focus window to be updated, and the position of the current global optimal focus window.
[0185] For example, the current speed of the focus window to be updated is v ij (t), the current position of the focus window to be updated is the position x determined by the position coordinates (x, y) of any corner point of the focus window to be updated ij (t), the updated inertia weight is w, the updated first learning factor and the second learning factor are c1 and c2, and the position of the individual optimal focus window of the focus window to be updated is p ij (t), the current position of the global optimal focus window is p gj (t), the position update speed v of the focus window to be updated can be determined according to the following formula: ij (t+1):
[0186] v ij (t+1)=wv ij (t)+c1r5[p ij (t)-x ij (t)]+c2r6[p gj (t)-x ij(t)](7)
[0187] S222: Determine a target position of the focus window to be updated after the position is updated based on the position update speed and the current position of the focus window to be updated.
[0188] In step S222, the target position of the focus window to be updated after the position update can be determined according to the position update speed and the current position of the focus window to be updated. For example, the target position x of the focus window to be updated after the position update can be determined according to the following formula: ij (t+1):
[0189] x ij (t+1)=x ij (t)+v ij (t+1)(8)
[0190] S223. Determine a size update speed of the focus window to be updated based on the current speed of the focus window to be updated, the current size of the focus window to be updated, the updated inertia weight and learning factor, the size of the individual optimal focus window of the focus window to be updated, and the size of the current global optimal focus window.
[0191] In step S223, the size update speed of the focus window to be updated can be determined based on the current speed of the focus window to be updated, the current size of the focus window to be updated, the updated inertia weight and learning factor, the size of the individual optimal focus window of the focus window to be updated, and the size of the current global optimal focus window.
[0192] It can be understood that the calculation method of the size update speed is similar to the calculation method of the position update speed in formula (7). It is necessary to replace the current position of the focus window to be updated in formula (7) with the current size of the focus window to be updated, and replace the position of the individual optimal focus window of the focus window to be updated and the position of the current global optimal focus window in formula (7) with the size of the individual optimal focus window of the focus window to be updated and the size of the current global optimal focus window, so as to obtain the size update speed of the focus window to be updated. The size of each window can be determined and characterized according to the width w and height h of each window.
[0193] S224: Determine a target size of the focus window to be updated after the size is updated based on the size update speed and the current size of the focus window to be updated.
[0194] In step S224, the target size of the focus window to be updated after the size update can be determined based on the size update speed and the current size of the focus window to be updated. It is understood that the calculation method of the target size of the focus window to be updated after the size update is similar to the calculation method of the target position in formula (8). It is necessary to replace the current position of the focus window to be updated in formula (8) with the current size of the focus window to be updated, and replace the position update speed in formula (8) with the size update speed to obtain the target size of the focus window to be updated.
[0195] S225. Update the position and size of the focus window to be updated to the target position and target size, and determine the target fitness value based on the updated target position and target size. The target fitness value is used as the updated fitness value. The target fitness value is compared with the historical target fitness value of the focus window to be updated, and the focus window to be updated with the largest fitness value is updated as the individual optimal focus window of the focus window to be updated.
[0196] In step S225, the position and size of the focus window to be updated are updated to the target position and target size, and the target fitness value is determined based on the fitness function and the updated target position and target size, so that the target fitness value is used as the updated fitness value, thereby realizing the update of the position, size and fitness value of the focus window to be updated.
[0197] The target fitness value is then compared with the historical target fitness value of the focus window to be updated, and the focus window to be updated with the maximum fitness value is updated to the individual optimal focus window of the focus window to be updated, so as to ensure that the individual optimal focus window of the focus window to be updated has the maximum fitness value in the historical update process of the focus window, that is, the highest window quality, and realizes the real-time update of the individual optimal focus window, which provides a basis for determining the target position and target size of the next window update process.
[0198] It can be understood that the determination of the target position and the target size of the focus window to be updated can be performed independently or simultaneously. The current position and current size of the focus window to be updated can be simultaneously characterized by the four-dimensional data (x, y, w, h) as described above, and the two-dimensional matrix in the above calculation method can be converted into a four-dimensional matrix to directly and simultaneously determine the target position and target size of the focus window to be updated.
[0199] In this embodiment, the target position of the focus window to be updated after the position update and the target size after the size update are determined based on multiple parameters during the current window update process. The position and size of the focus window to be updated can be updated to the target position and target size, and a target fitness value can be determined based on the updated target position and target size. This achieves the update of the position, size, and fitness value of the focus window to be updated, providing a basis for determining the target focus window. By updating the focus window to be updated with the maximum fitness value to the individual optimal focus window of the focus window to be updated, real-time updating of the individual optimal focus window is achieved, providing a basis for determining the target position and target size of the next window update process.
[0200] In some embodiments, reference Figure 11 Based on the current window information of each focus window to be updated, the updated inertia weight and learning factor of each focus window to be updated, the current global optimal focus window and the individual optimal focus window of each focus window to be updated, the position, size and fitness value of each focus window to be updated are updated, and the following is also included:
[0201] S240: In response to a current speed of any focus window to be updated being less than a first preset speed, determine the first preset speed as the current speed of the focus window to be updated.
[0202] In step S240, the first preset speed may be, for example, -v max , if the current speed v of any focus window to be updated ij (t) is less than the first preset speed -v max , which means that the absolute value of the current speed of the focus window to be updated is too large, and the search speed of the focus window to be updated needs to be limited. Therefore, the first preset speed - v max Determine the current speed v of the focus window to be updated ij (t).
[0203] S250: In response to a current speed of any focus window to be updated being greater than a second preset speed, determine the second preset speed as the current speed of the focus window to be updated, where the second preset speed is greater than the first preset speed.
[0204] In step S250, the second preset speed may be, for example, v max , if the current speed v of any focus window to be updated ij (t) is greater than the second preset speed v max , which means that the absolute value of the current speed of the focus window to be updated is too large, and the search speed of the focus window to be updated needs to be limited. Therefore, the second preset speed v max Determine the current speed v of the focus window to be updated ij(t).
[0205] In this embodiment, when the current speed of any focus window to be updated is less than the first preset speed, the first preset speed is determined as the current speed of the focus window to be updated, and when the current speed of any focus window to be updated is greater than the second preset speed, the second preset speed is determined as the current speed of the focus window to be updated. This allows the current speed of each focus window to be updated to always be limited to the range from the first preset speed to the second preset speed, thereby avoiding the current speed of the focus window to be updated being too large, causing the update of its position and size to miss the optimal value, and improving the window quality of the focus window to be updated at the target position and target size.
[0206] In some embodiments, the preset stop iteration condition includes: the number of iterations of the window update process reaches a preset number of iterations, or the global optimal focus window converges. It can also be that the number of iterations of the window update process reaches a preset number of iterations and the global optimal focus window converges.
[0207] As previously mentioned, the window update process is stopped when a preset stop iteration condition is met, and the target focus window is determined based on the update result of the window update process at that time. Therefore, it is necessary to ensure that the window position and window size of each focus window to be updated meet the focus requirements of the current scene when the preset stop iteration condition is met. The preset stop condition can be that the number of iterations of the window update process reaches a preset number of iterations or that the global optimal focus window converges to a fixed value after a sufficient number of window update processes are executed, so that the position and size of the global optimal focus window gradually approach fixed values, so that the target focus window finally determined has the required window quality.
[0208] In this embodiment, the number of iterations of the window update process reaching a preset number of iterations or the convergence of the global optimal focus window is used as a preset stop condition, which can ensure that the window update process is executed a sufficient number of times or the position and size of the global optimal focus window gradually approach fixed values, so that the final target focus window has a window quality that meets the requirements, thereby ensuring the accuracy of the target focus window in different shooting scenarios, so that the finished film has a good focus effect, and improving the user experience.
[0209] In some embodiments, determining the target focus window according to the update result of the window update process when a preset stop iteration condition is met includes: in response to meeting the preset stop iteration condition, using the updated global optimal focus window as the target focus window.
[0210] In this embodiment, when the preset iteration stop condition is met, the target focus window is determined by taking the updated global optimal focus window as the target focus window, so that the target focus window is the focus window to be updated with the maximum fitness value, that is, the highest window quality, when the iterative window update process is stopped. This ensures that the target focus window can be applied to the current shooting scene, so that the finished film has a good focus effect, and improves the user experience.
[0211] In an exemplary embodiment, a focusing method is provided, referring to Figure 12 As shown, the focusing methods include:
[0212] S1, performing image preprocessing on the original image to obtain a preprocessed image;
[0213] S2. Performing image edge extraction or image salient object detection on the preprocessed image to obtain a feature image, and using the feature image as the image to be processed;
[0214] S3. Determine a fitness function based on image edge extraction or image salient object detection, where the fitness function is used to determine a fitness value of each focus window to be updated, and the fitness value is used to characterize the window quality of the focus window to be updated at the current position and current size;
[0215] S4, dividing the image to be processed into regions to obtain multiple detection regions;
[0216] S5. randomly generating a plurality of initial focus windows in each detection area;
[0217] S6. Using each initial focus window as a focus window to be updated, iterating the following window update process for each focus window to be updated until a preset stop iteration condition is met;
[0218] S7. Based on the fitness value of each focus window to be updated, updating the inertia weight and learning factor of each focus window to be updated;
[0219] S8. Based on the current window information of each focus window to be updated, the updated inertia weight and learning factor of each focus window to be updated, the current global optimal focus window, and the individual optimal focus window of each focus window to be updated, the position, size, and fitness value of each focus window to be updated are updated;
[0220] S9, taking the focus window to be updated with the largest updated fitness value as the global optimal focus window;
[0221] S10: Using the updated global optimal focus window as the target focus window.
[0222] In this embodiment, a window update process is performed by generating multiple initial focus windows as focus windows to be updated, and updating the position and size of each focus window to be updated based on its current window information and quality information. The target focus window can be determined based on the update results of the window update process, thus achieving autofocus. By using the current window information representing the current position and size of the focus window to be updated as the basis for the iterative window update process, while also taking into account the window position and size factors, the accuracy of the target focus window can be guaranteed in different shooting scenarios, resulting in a well-focused final image and an improved user experience.
[0223] In an exemplary embodiment, a focusing device is provided, referring to Figure 13 As shown, the focusing device includes a generation module 10, an iteration module 20 and a determination module 30. The generation module 10 is used to generate multiple initial focus windows for the image to be processed. The iteration module 20 is used to use each initial focus window as a focus window to be updated, and iterate the window update process for each focus window to be updated until a preset stop iteration condition is met. The determination module 30 is used to determine the target focus window based on the update result of the window update process when the preset stop iteration condition is met.
[0224] The window update process includes: based on the current window information and quality information of each focus window to be updated, updating the position and size of each focus window to be updated, and obtaining an update result. The update result includes the updated focus windows to be updated, and the current window information is used to represent the current position and current size of the focus window to be updated.
[0225] In this embodiment, a generation module 10 generates multiple initial focus windows as focus windows to be updated. An iteration module 20 updates the position and size of each focus window to be updated based on its current window information and quality information to execute a window update process. A determination module 30 determines the target focus window based on the update results of the window update process, thereby achieving autofocus. Using the current window information representing the current position and size of the focus window to be updated as the basis for the iterative window update process, while also taking into account the window position and size factors, the accuracy of the target focus window can be guaranteed in different shooting scenarios, resulting in a well-focused final image and an improved user experience.
[0226] In one embodiment, the focusing device further includes a preprocessing module and a feature extraction processing module. The preprocessing module is used to perform image preprocessing on the original image to obtain a preprocessed image. The feature extraction module is used to perform feature extraction processing on the preprocessed image to obtain a feature image, and use the feature image as the image to be processed.
[0227] In one embodiment, the focusing apparatus further includes a fitness module configured to determine a fitness function based on feature extraction processing. The fitness function is configured to determine a fitness value for each focus window to be updated. The fitness value is configured to represent the quality of the focus window to be updated at its current position and size. The fitness value of the focus window to be updated serves as quality information for the focus window to be updated.
[0228] In one embodiment, the feature extraction process includes image edge extraction or image salient object detection.
[0229] In one embodiment, the generating module 10 is further configured to: divide the image to be processed into regions to obtain a plurality of detection regions; and randomly generate a plurality of initial focus windows in each detection region.
[0230] In one embodiment, the generation module 10 is further used to: perform the following window generation process for each detection area: determine the size of each initial focus window in the detection area based on the size of the detection area; determine the position of each initial focus window in the detection area based on the size of the detection area and the size of each initial focus window in the detection area.
[0231] In one embodiment, the iteration module 20 is further used to: update the inertia weight and learning factor of each focus window to be updated based on the fitness value of each focus window to be updated; update the position, size and fitness value of each focus window to be updated based on the current window information of each focus window to be updated, the updated inertia weight and learning factor of each focus window to be updated, the current global optimal focus window and the individual optimal focus window of each focus window to be updated; and update the global optimal focus window based on the updated fitness value of each focus window to be updated.
[0232] In one embodiment, the iteration module 20 is further configured to: use the focus window to be updated with the largest updated fitness value as the global optimal focus window.
[0233] In one embodiment, the iteration module 20 is further configured to: update the inertia weight of each focus window to be updated in this window update process based on the fitness value of each focus window to be updated; and update the learning factor of each focus window to be updated in this window update process based on the number of iterations of the window update process.
[0234] In one embodiment, the iteration module 20 is further used to: perform the following inertia weight update process for each focus window to be updated: in response to the fitness value of the focus window to be updated being greater than or equal to the average fitness value of each focus window to be updated, based on the fitness value of the focus window to be updated, the average fitness value of each focus window to be updated, the fitness value of the global optimal focus window, and the first preset inertia weight and the second preset inertia weight, determine the updated inertia weight of the focus window to be updated; in response to the fitness value of the focus window to be updated being less than the average fitness value of each focus window to be updated, determine the second preset inertia weight as the updated inertia weight of the focus window to be updated.
[0235] In one embodiment, the iteration module 20 is further used to: perform the following learning factor update process for each focus window to be updated: in response to an increase in the number of iterations of the window update process, reduce the first learning factor of the focus window to be updated and increase the second learning factor of the focus window to be updated, the first learning factor corresponds to the individual optimal focus window of the focus window to be updated, and the second learning factor corresponds to the current global optimal focus window.
[0236] In one embodiment, the iteration module 20 is further configured to: determine a position update speed of the focus window to be updated based on the current speed of the focus window to be updated, the current position of the focus window to be updated, the updated inertia weight and learning factor, the position of the individual optimal focus window of the focus window to be updated, and the position of the current global optimal focus window. Determine a target position of the focus window to be updated after the position update based on the position update speed and the current position of the focus window to be updated. Determine a size update speed of the focus window to be updated based on the current speed of the focus window to be updated, the current size of the focus window to be updated, the updated inertia weight and learning factor, the size of the individual optimal focus window of the focus window to be updated, and the size of the current global optimal focus window. Determine a target size of the focus window to be updated after the size update based on the size update speed and the current size of the focus window to be updated. The position and size of the focus window to be updated are updated to the target position and target size, and based on the updated target position and target size, the target fitness value is determined, the target fitness value is used as the updated fitness value, the target fitness value is compared with the historical target fitness value of the focus window to be updated, and the focus window to be updated with the maximum fitness value is updated as the individual optimal focus window of the focus window to be updated.
[0237] In one embodiment, the iteration module 20 is further used to: in response to the current speed of any focus window to be updated being less than a first preset speed, determine the first preset speed as the current speed of the focus window to be updated; in response to the current speed of any focus window to be updated being greater than a second preset speed, determine the second preset speed as the current speed of the focus window to be updated, and the second preset speed is greater than the first preset speed.
[0238] In one embodiment, the preset conditions for stopping iteration include: the number of iterations of the window update process reaches a preset number of iterations; and / or the global optimal focus window converges.
[0239] In one embodiment, the determining module 30 is further configured to: in response to a preset iteration stopping condition being met, use the updated global optimal focus window as the target focus window.
[0240] In an exemplary embodiment, an electronic device is provided. The electronic device may be, for example, a mobile phone, a camera or other photographing device, or other electronic device communicatively connected to the photographing device.
[0241] refer to Figure 14 As shown, the electronic device may include one or more of the following components: a processing component 101 , a memory 102 , a power component 103 , a multimedia component 104 , an audio component 105 , an input / output (I / O) interface 106 , a sensor component 107 , and a communication component 108 .
[0242] The processing component 101 generally controls the overall operation of the electronic device, such as operations associated with display, phone calls, data communications, camera operation, and recording operations. The processing component 101 may include one or more processors 109 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 101 may include one or more modules to facilitate interaction between the processing component 101 and other components. For example, the processing component 101 may include a multimedia module to facilitate interaction between the multimedia component 104 and the processing component 101.
[0243] The memory 102 is configured to store various types of data to support operations on the electronic device. Examples of such data include instructions for any application or method operating on the electronic device, contact data, phone book data, messages, pictures, videos, etc. The memory 102 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk, or optical disk.
[0244] The power component 103 provides power to various components of the electronic device. The power component 103 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device.
[0245] The multimedia component 104 includes a screen that provides an output interface between the electronic device and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, slides, and gestures on the touch panel. The touch sensor can not only sense the boundaries of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 104 includes a front camera and / or a rear camera. When the electronic device is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each front camera and rear camera can be a fixed optical lens system or have a focal length and optical zoom capability.
[0246] The audio component 105 is configured to output and / or input audio signals. For example, the audio component 105 includes a microphone (MIC), which is configured to receive external audio signals when the electronic device is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal can be further stored in the memory 102 or transmitted via the communication component 108. In some embodiments, the audio component 105 also includes a speaker for outputting audio signals.
[0247] I / O interface 106 provides an interface between processing component 101 and peripheral interface modules, such as a keyboard, click wheel, buttons, etc. These buttons may include but are not limited to: a home button, volume buttons, a start button, and a lock button.
[0248] The sensor assembly 107 includes one or more sensors for providing various aspects of status assessment for the electronic device. For example, the sensor assembly 107 can detect the open / closed state of the electronic device, the relative positioning of components, such as the display and keypad of the electronic device. The sensor assembly 107 can also detect changes in the position of the electronic device or a component of the electronic device, the presence or absence of user contact with the electronic device, the orientation or acceleration / deceleration of the electronic device, and the temperature change of the electronic device. The sensor assembly 107 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 107 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 107 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0249] The communication component 108 is configured to facilitate wired or wireless communication between the electronic device and other devices. The device can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 108 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 108 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0250] In an exemplary embodiment, the electronic device may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to execute the above-mentioned focusing method applied to the electronic device.
[0251] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 102 including instructions. The instructions can be executed by the processor 109 of the electronic device to perform the above-mentioned focusing method applied to the electronic device. For example, the non-transitory computer-readable storage medium can be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device. When the instructions in the storage medium are executed by the processor 109 of the electronic device, the electronic device is enabled to perform the focusing method shown in the above-mentioned embodiment.
[0252] In an exemplary embodiment, a computer program product is further provided, including a computer program, which implements the above-mentioned focusing method when executed by the processor 109 .
[0253] Other embodiments of the present invention will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, with the true scope and spirit of the invention being indicated by the following claims.
[0254] It should be understood that the present invention is not limited to the exact construction described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A focusing method, characterized in that: The focusing method comprises: Generate multiple initial focus windows for the image to be processed; Taking each of the initial focus windows as the focus window to be updated, and iterating the window update process for each of the focus windows to be updated until a preset stop iteration condition is met; Determining a target focus window according to an update result of the window update process when the preset stop iteration condition is met; The window update process includes: Based on the current window information and quality information of each of the focus windows to be updated, the position and size of each of the focus windows to be updated are updated to obtain the update result, wherein the update result includes the updated focus windows to be updated, and the current window information is used to characterize the current position and current size of the focus window to be updated.
2. The focusing method according to claim 1, wherein: Before generating a plurality of initial focus windows for the image to be processed, the focusing method further includes: Performing image preprocessing on the original image to obtain a preprocessed image; Perform feature extraction processing on the pre-processed image to obtain a feature image, and use the feature image as the image to be processed.
3. The focusing method according to claim 2, wherein: Before iterating the window update process for each of the focus windows to be updated, the focusing method further includes: Determining a fitness function based on the feature extraction process, wherein the fitness function is used to determine a fitness value of each of the focus windows to be updated, and the fitness value is used to characterize a window quality of the focus window to be updated at the current position and the current size; The fitness value of the focus window to be updated is used as the quality information of the focus window to be updated.
4. The focusing method according to claim 2, wherein: The feature extraction process includes image edge extraction process or image salient object detection.
5. The focusing method according to any one of claims 1 to 4, characterized in that: Generating a plurality of initial focus windows for the image to be processed includes: Dividing the image to be processed into regions to obtain multiple detection regions; A plurality of initial focus windows are randomly generated in each of the detection areas.
6. The focusing method according to claim 5, wherein: The randomly generating a plurality of initial focus windows in each of the detection areas includes: The following window generation process is performed for each of the detection areas: Determining the size of each initial focus window within the detection area based on the size of the detection area; Based on the size of the detection area and the size of each of the initial focus windows in the detection area, the position of each of the initial focus windows in the detection area is determined.
7. The focusing method according to claim 1, wherein: The quality information includes a fitness value, and the update result also includes a global optimal focus window; Based on the current window information and quality information of each of the focus windows to be updated, updating the position and size of each of the focus windows to be updated includes: updating the inertia weight and the learning factor of each of the focus windows to be updated based on the fitness value of each of the focus windows to be updated; updating the position, size, and fitness value of each of the focus windows to be updated based on the current window information of each of the focus windows to be updated, the updated inertia weight and the learning factor of each of the focus windows to be updated, the current global optimal focus window, and the individual optimal focus window of each of the focus windows to be updated; The global optimal focus window is updated based on the updated fitness values of the focus windows to be updated.
8. The focusing method according to claim 7, wherein: The updating of the global optimal focus window based on the updated fitness value of each focus window to be updated includes: The focus window to be updated with the largest updated fitness value is used as the global optimal focus window.
9. The focusing method according to claim 7, wherein: The updating of the inertia weight and the learning factor of each of the focus windows to be updated includes: updating the inertia weight of each of the focus windows to be updated in this window update process based on the fitness value of each of the focus windows to be updated; Based on the number of iterations of the window update process, the learning factor of each focus window to be updated in the current window update process is updated.
10. The focusing method according to claim 9, wherein: The updating of the inertia weight of each of the focus windows to be updated in the current window update process based on the fitness value of each of the focus windows to be updated includes: The following inertia weight update process is performed for each of the focus windows to be updated: In response to the fitness value of the focus window to be updated being greater than or equal to the average of the fitness values of the focus windows to be updated, determining the updated inertia weight of the focus window to be updated based on the fitness value of the focus window to be updated, the average of the fitness values of the focus windows to be updated, the fitness value of the global optimal focus window, and the first preset inertia weight and the second preset inertia weight; In response to the fitness value of the focus window to be updated being less than an average of the fitness values of the focus windows to be updated, the second preset inertia weight is determined as the updated inertia weight of the focus window to be updated.
11. The focusing method according to claim 9, wherein: The updating of the learning factor of each focus window to be updated in the current window updating process based on the number of iterations of the window updating process includes: The following learning factor update process is performed for each of the focus windows to be updated: In response to an increase in the number of iterations of the window update process, the first learning factor of the focus window to be updated is reduced and the second learning factor of the focus window to be updated is increased, wherein the first learning factor corresponds to the individual optimal focus window of the focus window to be updated, and the second learning factor corresponds to the current global optimal focus window.
12. The focusing method according to claim 7, wherein: The updating of the position, size, and fitness value of each focus window to be updated based on the current window information of each focus window to be updated, the updated inertia weight and the learning factor of each focus window to be updated, the current global optimal focus window, and the individual optimal focus window of each focus window to be updated, including: Determining a position update speed of the focus window to be updated based on a current speed of the focus window to be updated, a current position of the focus window to be updated, the updated inertia weight and the learning factor, the position of the individual optimal focus window of the focus window to be updated, and the current position of the global optimal focus window; Determining a target position of the focus window to be updated after the position is updated based on the position update speed and the current position of the focus window to be updated; Determining a size update speed of the focus window to be updated based on a current speed of the focus window to be updated, a current size of the focus window to be updated, the updated inertia weight and the learning factor, the size of the individual optimal focus window of the focus window to be updated, and the current size of the global optimal focus window; Determining a target size of the focus window to be updated after the size is updated based on the size update speed and the current size of the focus window to be updated; The position and size of the focus window to be updated are updated to the target position and the target size, and based on the updated target position and the target size, a target fitness value is determined, the target fitness value is used as the updated fitness value, the target fitness value is compared with the historical target fitness value of the focus window to be updated, and the focus window to be updated with the maximum fitness value is updated as the individual optimal focus window of the focus window to be updated.
13. The focusing method according to claim 12, wherein: The updating of the position, size, and fitness value of each focus window to be updated based on the current window information of each focus window to be updated, the updated inertia weight and the learning factor of each focus window to be updated, the current global optimal focus window, and the individual optimal focus window of each focus window to be updated further includes: In response to the current speed of any of the focus windows to be updated being less than a first preset speed, determining the first preset speed as the current speed of the focus window to be updated; In response to the current speed of any focus window to be updated being greater than a second preset speed, the second preset speed is determined as the current speed of the focus window to be updated, and the second preset speed is greater than the first preset speed.
14. The focusing method according to any one of claims 7 to 13, characterized in that: The preset stop iteration condition includes: The number of iterations of the window update process reaches a preset number of iterations; and / or, The global optimal focus window converges.
15. The focusing method according to claim 14, wherein: The determining the target focus window according to the update result of the window update process when the preset stop iteration condition is met includes: In response to satisfying the preset iteration stopping condition, the updated global optimal focus window is used as the target focus window.
16. A focusing device, characterized in that: The focusing device comprises: A generating module, the generating module being used to generate a plurality of initial focus windows for the image to be processed; an iteration module, the iteration module being configured to use each of the initial focus windows as a focus window to be updated, and iterate the window update process for each of the focus windows to be updated until a preset stop iteration condition is met; A determination module, configured to determine a target focus window according to an update result of the window update process when the preset stop iteration condition is met; The window update process includes: Based on the current window information and quality information of each of the focus windows to be updated, the position and size of each of the focus windows to be updated are updated to obtain the update result, wherein the update result includes the updated focus windows to be updated, and the current window information is used to characterize the current position and current size of the focus window to be updated.
17. An electronic device, characterized in that: The electronic device comprises: processor; a memory for storing processor-executable instructions; Wherein, the processor is configured to: Generate multiple initial focus windows for the image to be processed; Taking each of the initial focus windows as the focus window to be updated, and iterating the window update process for each of the focus windows to be updated until a preset stop iteration condition is met; Determining a target focus window according to an update result of the window update process when the preset stop iteration condition is met; The window update process includes: Based on the current window information and quality information of each of the focus windows to be updated, the position and size of each of the focus windows to be updated are updated to obtain the update result, wherein the update result includes the updated focus windows to be updated, and the current window information is used to characterize the current position and current size of the focus window to be updated.
18. A non-transitory computer-readable storage medium, characterized in that When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform a focusing method, the focusing method comprising: Generate multiple initial focus windows for the image to be processed; Taking each of the initial focus windows as the focus window to be updated, and iterating the window update process for each of the focus windows to be updated until a preset stop iteration condition is met; Determining a target focus window according to an update result of the window update process when the preset stop iteration condition is met; The window update process includes: Based on the current window information and quality information of each of the focus windows to be updated, the position and size of each of the focus windows to be updated are updated to obtain the update result, wherein the update result includes the updated focus windows to be updated, and the current window information is used to characterize the current position and current size of the focus window to be updated.
19. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, it realizes: Generate multiple initial focus windows for the image to be processed; Taking each of the initial focus windows as the focus window to be updated, and iterating the window update process for each of the focus windows to be updated until a preset stop iteration condition is met; Determining a target focus window according to an update result of the window update process when the preset stop iteration condition is met; The window update process includes: Based on the current window information and quality information of each of the focus windows to be updated, the position and size of each of the focus windows to be updated are updated to obtain the update result, wherein the update result includes the updated focus windows to be updated, and the current window information is used to characterize the current position and current size of the focus window to be updated.