Focusing method and apparatus, and electronic device and storage medium
By implementing focal length adjustment and image quality scoring analysis on the image acquisition device, the problem of increasing cost of distance sensors is solved, automatic focus is achieved and image quality is improved.
Patent Information
- Application Number
- PCT/CN2024/121138
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-09-25
- Filing Date
- 2024-09-25
- Publication Date
- 2025-04-03
AI Technical Summary
Existing image acquisition devices need to install distance sensors during autofocus, resulting in increased production costs.
Automatic focus is achieved by adjusting the focal length of the image acquisition device according to the preset step length starting from the initial focal length position until the optimal focal length position is determined, and the focus direction is adjusted according to the changing trend of the image quality score.
Without increasing the cost of image acquisition equipment, automatic focus is realized, which is suitable for photography and visual algorithm analysis scenes with real-time changes in long distances, large depth of field, and visual algorithms, and improve the focus effect of the image and the processing effect of the target object.
Smart Images

Figure CN2024121138_03042025_PF_FP_ABST
Abstract
Description
Focusing method, device, electronic device and storage medium
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on September 25, 2023, with application number 202311243823.2 and invention name “A focusing method, device, electronic device and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of image acquisition technology, and in particular to a focusing method, device, electronic device and storage medium. Background Art
[0003] When using an image acquisition device to identify target objects such as QR codes and barcodes, the image acquisition device first captures an image of the target object. However, the distance between the target object and the image acquisition device may change. In this case, an autofocus method can usually be used to enable the image acquisition device to quickly focus on the target object.
[0004] In the related art, a distance sensor installed on the image acquisition device is usually used to realize the automatic focus of the image acquisition device, that is, the distance between the target object and the image acquisition device is sensed with the help of the distance sensor, so that the image acquisition device can focus on the target object based on the sensed distance. However, installing a distance sensor on the image acquisition device also leads to an increase in the production cost of the image acquisition device.
[0005] Summary of the Invention
[0006] The purpose of the embodiments of the present application is to provide a focusing method, apparatus, electronic device, and storage medium to achieve automatic focusing of an image acquisition device without increasing the cost of the image acquisition device. The specific technical solution is as follows:
[0007] In a first aspect, an embodiment of the present application provides a focusing method, the method comprising:
[0008] Starting from an initial focal length position of the image acquisition device, adjusting the focal length of the image acquisition device according to a preset step length until an optimal focal length position is determined;
[0009] wherein, in response to adjusting the focal length position of the image acquisition device, determining a change trend of an image quality score of an image of a target object acquired by the image acquisition device before and after the adjustment; the image quality score is determined based on an image focus score and / or an algorithm processing score; the algorithm processing score is used to characterize a processing effect obtained by performing algorithmic processing on the image;
[0010] When the change trend is upward, the focusing direction is kept unchanged;
[0011] If the change trend is downward and the image quality score change is the first change, adjusting the focusing direction of the next focus adjustment;
[0012] When the change trend is downward and the change trend before and after the previous adjustment is upward, or when the change trend is downward and the image quality score change this time is not the first change, the focal length position before this adjustment is determined as the optimal focal length position.
[0013] Optionally, in a specific implementation, the focal length range of the image acquisition device is pre-divided into at least two intervals;
[0014] Starting from an initial focal length position of the image acquisition device, adjusting the focal length of the image acquisition device according to a preset step length until an optimal focal length position is determined, includes:
[0015] Selecting an initial focal length position for each of the intervals, and starting from the initial focal length position selected for each of the intervals, adjusting the focal length of the image acquisition device according to a preset step size within each of the intervals until a local optimal focal length position within each of the intervals is determined;
[0016] Among the at least two determined local optimal focal length positions, the local optimal focal length position corresponding to the highest image quality score of the acquired image is determined as the optimal focal length position.
[0017] Optionally, in a specific implementation, starting from an initial focal length position of the image acquisition device, adjusting the focal length of the image acquisition device according to a preset step length until an optimal focal length position is determined includes:
[0018] Starting from an initial focal length position of the image acquisition device, the focus of the image acquisition device is adjusted according to a preset step length within a specified interval within the focal length range of the image acquisition device until an optimal focal length position is determined.
[0019] Optionally, in a specific implementation, starting from an initial focal length position of the image acquisition device, adjusting the focal length of the image acquisition device according to a preset step length includes:
[0020] Obtaining an initial focal position of an image acquisition device and a focusing direction for a first focal adjustment;
[0021] Starting from the initial focal length position, the focus of the image acquisition device is adjusted according to the focusing direction and preset step length of the first focal length adjustment.
[0022] Optionally, in a specific implementation, obtaining the initial focal position of the image acquisition device and the focusing direction of the first focal adjustment includes:
[0023] Obtaining a preset initial focal length position of an image acquisition device and a preset focusing direction for a first focal length adjustment; or,
[0024] Obtain a historical optimal focal position of the image acquisition device as an initial focal position; compare the initial focal position with a middle position of a focal range of the image acquisition device; if the initial focal position is smaller than the middle position, increase the focusing direction of the adjusted focal position and determine it as the focusing direction for the first focal adjustment; if the initial focal position is larger than the middle position, decrease the focusing direction of the adjusted focal position and determine it as the focusing direction for the first focal adjustment.
[0025] Optionally, in a specific implementation, the method further includes:
[0026] When the focus position of the image acquisition device is the initial focus position and each time the focus adjustment is completed, respectively controlling the image acquisition device to acquire an image of the target object, and determining an image focus score and an algorithm processing score of the image;
[0027] A first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight are calculated, and a sum of the first product and the second product is calculated as the image quality score of the image.
[0028] Optionally, in a specific implementation, before calculating a first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight, the method further includes:
[0029] Selecting a target weight combination that matches the current application scenario of the image acquisition device from a plurality of preset mapping relationships between weight combinations and application scenarios; wherein each weight combination includes: an image focusing weight and an algorithm processing weight;
[0030] Calculating a first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight, includes:
[0031] A first product of the image focus score and the image focus weight included in the target weight combination and a second product of the algorithm processing score and the algorithm processing weight included in the target weight combination are calculated.
[0032] Optionally, in a specific implementation, the mapping relationship includes:
[0033] a mapping relationship between an application scenario for object processing for the target object and a first weight combination; wherein the image focusing weight included in the first weight combination is smaller than the algorithm processing weight; and
[0034] There is no mapping relationship between the image acquisition scene of the target object and the second weight combination; wherein the algorithm processing weight included in the second weight combination is 0.
[0035] Optionally, in a specific implementation, determining the image focus score and the algorithm processing score of the image includes:
[0036] A region of interest for algorithmic processing of the target object in the image is determined, and an image focus score and an algorithmic processing score of the region of interest are determined.
[0037] Optionally, in a specific implementation, determining a region of interest in the image for algorithmic processing of the target object includes:
[0038] Object recognition is performed on the image, and the image region where the recognized detection frame including the target object is located is determined as a region of interest for algorithm processing regarding the target object.
[0039] Optionally, in a specific implementation, in response to adjusting the focal length position of the image acquisition device, determining a change trend of image quality scores of images of the target object acquired by the image acquisition device before and after the adjustment includes:
[0040] In response to adjusting the focal length position of the image acquisition device, calculating a numerical relationship and a difference between image quality scores of images of the target object acquired by the image acquisition device before and after the adjustment;
[0041] If the difference is greater than a preset value and the numerical relationship indicates that the image quality score before the adjustment is less than the image quality score after the adjustment, it is determined that the change trend of the image quality score before and after the adjustment is an increase;
[0042] If the difference is greater than the preset value and the numerical relationship indicates that the image quality score before the current adjustment is greater than the image quality score after the current adjustment, it is determined that the change trend of the image quality score before and after the current adjustment is a decrease;
[0043] If the difference is not greater than the preset value, determining that the change trend of the image quality score before and after the adjustment is unchanged;
[0044] The method further includes: when the change trend is unchanged, keeping the focusing direction unchanged.
[0045] Optionally, in a specific implementation, the method further includes:
[0046] An adjustment ratio is determined based on the image acquisition device, and the preset value is calculated based on a preset reference value and the adjustment ratio.
[0047] Optionally, in a specific implementation, when the change trend is downward and the image quality score change is the first change, adjusting the focus direction of the next focal length adjustment includes:
[0048] If the change trend is downward or the change trends are both downward for a specified number of consecutive times, and there has not been a situation where the change trends are the same for the specified number of consecutive times before the current adjustment, adjusting the focusing direction for the next focal length adjustment;
[0049] In the case where the change trend is downward and the change trend before and after the previous adjustment is upward or downward, determining the focal length position before the current adjustment as the optimal focal length position includes:
[0050] When the change trend is downward and the number of consecutive times that the change trends are both downward reaches a specified number, and the change trends have been the same for a specified number of consecutive times before this adjustment, the focal length position before the first adjustment in the consecutive specified number of adjustments including this adjustment will be determined as the optimal focal length position.
[0051] Optionally, in a specific implementation, the method further includes:
[0052] Determining whether the optimal focal length position meets a preset focusing condition;
[0053] If the conditions are met, focusing the image acquisition device according to the optimal focus position;
[0054] Otherwise, traversing each focal length position in the focal length range of the image acquisition device, and determining an image quality score of the image acquired by the image acquisition device when traversing to each focal length position;
[0055] The optimal focal length position is updated to: the focal length position of the image acquisition device when an image with the highest image quality score is acquired.
[0056] Optionally, in a specific implementation, the target object is a graphic identification code, the algorithm processing score includes: code reading score, and the processing effect includes but is not limited to: at least one of recognition success rate, recognition accuracy and recognition speed.
[0057] In a second aspect, an embodiment of the present invention provides a focusing device, comprising:
[0058] A focusing module, configured to adjust the focus of the image acquisition device according to a preset step length starting from an initial focus position of the image acquisition device until an optimal focus position is determined;
[0059] Wherein, the focusing module includes:
[0060] a change trend determination submodule, configured to determine, in response to adjusting the focal length position of the image acquisition device, a change trend of an image quality score of an image of a target object acquired by the image acquisition device before and after the adjustment; the image quality score being determined based on an image focus score and / or an algorithm processing score; the algorithm processing score being used to characterize a processing effect obtained by performing algorithmic processing on the image;
[0061] A focusing direction maintaining submodule, configured to maintain the focusing direction unchanged when the changing trend is an upward trend;
[0062] A focus direction adjustment submodule, configured to adjust the focus direction of the next focus adjustment when the change trend is downward and the image quality score change is the first change;
[0063] The optimal focus position determination submodule is used to determine the focal length position before this adjustment as the optimal focus position when the change trend is downward and the change trend before and after the previous adjustment is upward, or when the change trend is downward and the image quality score change this time is not the first change.
[0064] Optionally, in a specific implementation, the focal length range of the image acquisition device is pre-divided into at least two intervals; and the focusing module is specifically configured to:
[0065] Selecting an initial focal length position for each of the intervals, and starting from the initial focal length position selected for each of the intervals, adjusting the focal length of the image acquisition device according to a preset step size within each of the intervals until a local optimal focal length position within each of the intervals is determined;
[0066] Among the at least two determined local optimal focal length positions, the local optimal focal length position corresponding to the highest image quality score of the acquired image is determined as the optimal focal length position.
[0067] Optionally, in a specific implementation, the focusing module is specifically configured to:
[0068] Starting from an initial focal length position of the image acquisition device, the focus of the image acquisition device is adjusted according to a preset step length within a specified interval within the focal length range of the image acquisition device until an optimal focal length position is determined.
[0069] Optionally, in a specific implementation, the focusing module further includes:
[0070] An information acquisition submodule, used to obtain the initial focal length position of the image acquisition device and the focusing direction of the first focal length adjustment;
[0071] The focusing module is specifically configured to start from the initial focal length position and adjust the focal length of the image acquisition device according to the focusing direction and preset step length of the first focal length adjustment.
[0072] Optionally, in a specific implementation, the information acquisition submodule is specifically configured to:
[0073] Obtaining a preset initial focal length position of an image acquisition device and a preset focusing direction for a first focal length adjustment; or,
[0074] Obtain a historical optimal focal position of the image acquisition device as an initial focal position; compare the initial focal position with a middle position of a focal range of the image acquisition device; if the initial focal position is smaller than the middle position, increase the focusing direction of the adjusted focal position and determine it as the focusing direction for the first focal adjustment; if the initial focal position is larger than the middle position, decrease the focusing direction of the adjusted focal position and determine it as the focusing direction for the first focal adjustment.
[0075] Optionally, in a specific implementation, the device further includes:
[0076] a score determination module, configured to control the image acquisition device to capture an image of the target object when the focus position of the image acquisition device is the initial focus position and each time the focus adjustment is completed, and to determine an image focus score and an algorithm processing score of the image;
[0077] A score calculation module is used to calculate a first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight, and calculate the sum of the first product and the second product as the image quality score of the image.
[0078] Optionally, in a specific implementation, the device further includes:
[0079] a weight selection module, configured to select, before calculating a first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight, a target weight combination that matches the current application scenario of the image acquisition device from a plurality of preset mapping relationships between weight combinations and application scenarios; wherein each weight combination includes: an image focus weight and an algorithm processing weight;
[0080] The score calculation module is specifically used to calculate a first product of the image focus score and the image focus weight included in the target weight combination, and a second product of the algorithm processing score and the algorithm processing weight included in the target weight combination.
[0081] Optionally, in a specific implementation, the mapping relationship includes:
[0082] a mapping relationship between an application scenario for object processing for the target object and a first weight combination; wherein the image focusing weight included in the first weight combination is smaller than the algorithm processing weight; and
[0083] There is no mapping relationship between the image acquisition scene of the target object and the second weight combination; wherein the algorithm processing weight included in the second weight combination is 0.
[0084] Optionally, in a specific implementation, the score determination module includes:
[0085] a region determination submodule, configured to determine a region of interest in the image for algorithmic processing of the target object;
[0086] The score determination submodule is used to determine the image focus score and algorithm processing score of the region of interest.
[0087] Optionally, in a specific implementation, the region determination submodule is specifically configured to:
[0088] Object recognition is performed on the image, and the image region where the recognized detection frame including the target object is located is determined as a region of interest for algorithm processing regarding the target object.
[0089] Optionally, in a specific implementation, the change trend determination submodule is specifically configured to:
[0090] In response to adjusting the focal length position of the image acquisition device, calculating a numerical relationship and a difference between image quality scores of images of the target object acquired by the image acquisition device before and after the adjustment;
[0091] If the difference is greater than a preset value and the numerical relationship indicates that the image quality score before the adjustment is less than the image quality score after the adjustment, it is determined that the change trend of the image quality score before and after the adjustment is an increase;
[0092] If the difference is greater than the preset value and the numerical relationship indicates that the image quality score before the current adjustment is greater than the image quality score after the current adjustment, it is determined that the change trend of the image quality score before and after the current adjustment is a decrease;
[0093] If the difference is not greater than the preset value, determining that the change trend of the image quality score before and after the adjustment is unchanged;
[0094] The focusing direction maintaining submodule is further configured to maintain the focusing direction unchanged when the changing trend remains unchanged.
[0095] Optionally, in a specific implementation, the device further includes:
[0096] The numerical value adjustment module is used to determine an adjustment ratio based on the image acquisition device, and calculate the preset numerical value based on a preset reference value and the adjustment ratio.
[0097] Optionally, in a specific implementation,
[0098] The focus direction adjustment submodule is specifically configured to adjust the focus direction for the next focal length adjustment when the change trend is downward or the change trends are both downward for a specified number of consecutive times, and the change trends have not been the same for the specified number of consecutive times before the current adjustment;
[0099] The optimal focus position determination submodule is specifically used to determine the focal length position before the first adjustment in the continuous specified number of adjustments including the current adjustment, when the change trend is downward and the continuous number of times the change trends are both downward reaches a specified number, and the change trends have been the same for a continuous specified number of times before the current adjustment.
[0100] Optionally, in a specific implementation, the device further includes:
[0101] A focus judgment module is used to judge whether the optimal focal length position meets the preset focus condition; if so, the device focus module is triggered; otherwise, the position traversal module is triggered;
[0102] The device focusing module is used to focus the image acquisition device according to the optimal focus position;
[0103] The position traversal module is used to traverse each focal length position in the focal length range of the image acquisition device, and determine the image quality score of the image captured by the image acquisition device when traversing to each focal length position;
[0104] A position updating module is configured to update the optimal focal length position to the focal length position of the image acquisition device when an image with the highest image quality score is acquired.
[0105] Optionally, in a specific implementation, the target object is a graphic identification code, the algorithm processing score includes: code reading score, and the processing effect includes but is not limited to: at least one of recognition success rate, recognition accuracy and recognition speed.
[0106] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0107] Memory for storing computer programs;
[0108] The processor is configured to implement any of the above-mentioned focusing methods when executing a program stored in the memory.
[0109] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements any of the above-mentioned focusing methods.
[0110] An embodiment of the present application further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-described focusing methods.
[0111] Beneficial effects of the embodiments of the present application:
[0112] As can be seen from the above, using the embodiments of the present application, when focusing an image acquisition device, the focus of the image acquisition device can be adjusted starting from an initial focal position according to a preset step size until an optimal focal position is determined. During this focus adjustment process, in response to adjusting the focal position of the image acquisition device, a changing trend in the image quality scores of images of the target object captured by the image acquisition device before and after the adjustment is determined, and the next focusing action is determined based on this changing trend.
[0113] Based on this, the focal position of the image acquisition device can be adjusted according to the changing trend of the image quality score of the image of the target object captured by the image acquisition device before and after the focal position adjustment, and the optimal focal position can be determined, thereby realizing automatic focus of the image acquisition device without using a distance sensor and without increasing the cost of the image acquisition device.
[0114] In other words, by applying the solution provided by the embodiments of the present application, it is possible to achieve automatic focus of an image acquisition device without utilizing a distance sensor. Therefore, it is unnecessary to install a distance sensor on the image acquisition device, thereby maintaining the cost of the image acquisition device and reducing the system complexity of the image acquisition device. Furthermore, because the image acquisition device can focus on a target object as the distance between the target object and the image acquisition device changes, the solution provided by the embodiments of the present application can be widely applied to scenarios such as long-distance photography, large depth of field, and real-time depth of field changes, as well as visual algorithm analysis.
[0115] In addition, since the image quality score is determined based on the image focus score and algorithm processing score of the image, the algorithm processing score is used to characterize the processing effect obtained by algorithmically processing the image. Therefore, applying the embodiment of the present application to focus the image acquisition device can also make the image captured by the focused image acquisition device have both a higher focusing effect and a better processing effect on the target object.
[0116] That is to say, by applying the solution provided in the embodiments of the present application, the image captured by the image acquisition device after focusing can have a high focusing effect, and the algorithmic processing of the target object in the above image can also achieve better processing effects. For example, while the above image has a high clarity, the difficulty of algorithmic processing of the above target object is reduced, and the accuracy of algorithmic recognition of the above target object is improved.
[0117] Of course, it is not necessary to achieve all the advantages described above at the same time when implementing any product or method of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0118] The drawings described herein are used to provide further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute improper limitations on the present application.
[0119] FIG1 is a flow chart of an implementation of a focal length adjustment process in a focusing method provided in an embodiment of the present application;
[0120] FIG2( a ) is a schematic diagram showing how image quality scores vary with focal length according to an embodiment of the present application;
[0121] FIG2( b ) is another schematic diagram showing how image quality scores vary with focal length provided in an embodiment of the present application;
[0122] FIG3 is a flow chart of another implementation of a focal length adjustment process in a focusing method provided in an embodiment of the present application;
[0123] FIG4 is a flow chart of a specific implementation of S101;
[0124] FIG5 is a schematic structural diagram of a focusing module in a focusing device provided in an embodiment of the present application;
[0125] FIG6 is a schematic structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0126] To make the objectives, technical solutions, and advantages of this application more clearly understood, the present application is further described below with reference to the accompanying drawings and examples. It is apparent that the described examples are only a portion of the embodiments of this application, and not all of them. All other embodiments derived by persons of ordinary skill in the art based on the examples in this application are intended to fall within the scope of protection of this application.
[0127] In related art, automatic focusing of image acquisition devices is typically achieved using a distance sensor installed on the device. Specifically, the distance sensor senses the distance between the target object and the device, allowing the device to focus on the target object based on the sensed distance. However, while using a distance sensor can achieve relatively fast and accurate focusing, installing a distance sensor on the device increases the production cost of the device.
[0128] In order to solve the above problems, an embodiment of the present application provides a focusing method.
[0129] The focusing method provided in the embodiments of the present application can be applied to various scenarios where the image acquisition device needs to be focused, for example, scenarios where the image acquisition device is used to read a QR code or a barcode, scenarios where the image acquisition device is used to identify a target, and so on. In this regard, the embodiments of the present application do not specifically limit it. Among them, the so-called focusing can refer to: the process of gradually making the image of the photographed object clearer by changing the distance and the position of the distance through the focusing mechanism of the image acquisition device, and can also be called light, focusing, focusing, etc. The process of focusing the image acquisition device is actually the process of adjusting the focal length of the image acquisition device.
[0130] In addition, the method can be applied to various electronic devices that can perform data processing. Among them, the electronic device can be various image acquisition devices with data processing functions, such as cameras and video recorders with data processing functions; it can also be various data processing devices with image acquisition functions, such as mobile phones with cameras installed, tablet computers with cameras installed, etc.; it can also be various other devices that are connected to the image acquisition device and have data processing functions, such as servers connected to the graphic recognition code scanning device, desktop computers connected to the camera, mobile phones connected to the graphic recognition code scanning device, etc. In addition, the electronic device can be an independent electronic device or a device cluster composed of multiple electronic devices. In the above, the above-mentioned electronic devices can include camera modules, cameras, industrial cameras, code reading devices, handheld code reading devices, PDAs (Personal Digital Assistants), bar guns, and electronic devices that integrate at least one small device. In this regard, the embodiments of the present application are not specifically limited, and are hereinafter referred to as electronic devices.
[0131] It is worth noting that in the technical solution of this application, the operations involved in obtaining, storing, using, processing, transmitting, providing and disclosing user personal information are all carried out with the user's authorization.
[0132] The focusing method provided in the embodiment of the present application may include the following steps:
[0133] Starting from an initial focal length position of the image acquisition device, adjusting the focal length of the image acquisition device according to a preset step length until an optimal focal length position is determined;
[0134] wherein, in response to adjusting the focal length position of the image acquisition device, determining a change trend of an image quality score of an image of a target object acquired by the image acquisition device before and after the adjustment; the image quality score is determined based on an image focus score and / or an algorithm processing score; the algorithm processing score is used to characterize a processing effect obtained by performing algorithmic processing on the image;
[0135] When the change trend is upward, the focusing direction is kept unchanged;
[0136] If the change trend is downward and the image quality score change is the first change, adjusting the focusing direction of the next focus adjustment;
[0137] When the change trend is downward and the change trend before and after the previous adjustment is upward, or when the change trend is downward and the image quality score change this time is not the first change, the focal length position before this adjustment is determined as the optimal focal length position.
[0138] As can be seen from the above, using the embodiments of the present application, when focusing an image acquisition device, the focus of the image acquisition device can be adjusted starting from an initial focal position according to a preset step size until an optimal focal position is determined. During this focus adjustment process, in response to adjusting the focal position of the image acquisition device, a changing trend in the image quality scores of images of the target object captured by the image acquisition device before and after the adjustment is determined, and the next focusing action is determined based on this changing trend.
[0139] Based on this, the focal position of the image acquisition device can be adjusted according to the changing trend of the image quality score of the image of the target object captured by the image acquisition device before and after the focal position adjustment, and the optimal focal position can be determined, thereby realizing automatic focus of the image acquisition device without using a distance sensor and without increasing the cost of the image acquisition device.
[0140] In other words, by applying the solution provided by the embodiments of the present application, it is possible to achieve automatic focus of an image acquisition device without utilizing a distance sensor. Therefore, it is unnecessary to install a distance sensor on the image acquisition device, thereby maintaining the cost of the image acquisition device and reducing the system complexity of the image acquisition device. Furthermore, because the image acquisition device can focus on a target object as the distance between the target object and the image acquisition device changes, the solution provided by the embodiments of the present application can be widely applied to scenarios such as long-distance photography, large depth of field, and real-time depth of field changes, as well as visual algorithm analysis.
[0141] In addition, since the image quality score is determined based on the image focus score and algorithm processing score of the image, the algorithm processing score is used to characterize the processing effect obtained by algorithmically processing the image. Therefore, applying the embodiment of the present application to focus the image acquisition device can also make the image captured by the focused image acquisition device have both a higher focusing effect and a better processing effect on the target object.
[0142] That is to say, by applying the solution provided in the embodiments of the present application, the image captured by the image acquisition device after focusing can have a high focusing effect, and the algorithmic processing of the target object in the above image can also achieve better processing effects. For example, while the above image has a high clarity, the difficulty of algorithmic processing of the above target object is reduced, and the accuracy of algorithmic recognition of the above target object is improved.
[0143] Below, in conjunction with the accompanying drawings, a focusing method provided in an embodiment of the present application is described in detail.
[0144] The embodiment of the present application provides a focusing method, comprising the following step 1:
[0145] Step 1: Starting from the initial focal length position of the image acquisition device, the focus of the image acquisition device is adjusted according to a preset step size until the optimal focal length position is determined.
[0146] In the embodiment of the present application, focusing the image acquisition device is essentially adjusting the focal length of the image acquisition device to ultimately determine the optimal focal length position of the image acquisition device.
[0147] Before adjusting the focus of the image acquisition device, the initial focus position of the image acquisition device is first determined. For example, the current focus position of the image acquisition device can be directly determined as the initial focus position, or the initial focus position can be pre-set randomly or based on the focus adjustment range of the image acquisition device, and the focus position of the image acquisition device is adjusted to the set initial focus position. In order to initiate the focus adjustment of the image acquisition device, the focus direction and preset step size of the initial focus adjustment need to be determined. For example, the focus direction of the first focus adjustment can be randomly determined, or the focus direction of the first focus adjustment can be determined based on the initial focus position. The preset step size can be limited according to the actual situation in the application scenario and is not specifically limited in the embodiments of the present application.
[0148] The essence of the aforementioned focus position is the focal length of the image acquisition device's lens. Based on the hardware characteristics of the image acquisition device and the precision requirements of the application scenario, the range of variation to which the focus position of the image acquisition device is set can be referred to as the focal length range of the image acquisition device. When the focal length of the image acquisition device's lens is a value within the aforementioned focal length range, the focus position of the image acquisition device can be represented as that value. Furthermore, the aforementioned focus direction can be understood as the direction in which the focal position (focal length) of the image acquisition device increases or decreases.
[0149] Thus, after the image capture device's focal position is at an initial focal position and the focusing direction and preset step size for the initial focal adjustment are determined, the image capture device's focal length is adjusted starting from the initial focal position according to the preset step size until an optimal focal position is determined. Furthermore, during this focal adjustment process, subsequent focal adjustments can be determined based on changes in image quality of images of the target object captured by the image capture device before and after the adjustment.
[0150] As shown in FIG1 , it is a flowchart of an implementation of the focus adjustment process in the above-mentioned focusing method. As shown in FIG1 , the above-mentioned focus adjustment process may include the following steps S101 - S104 .
[0151] S101: In response to adjusting a focal length position of an image acquisition device, determining a change trend of image quality scores of images of a target object acquired by the image acquisition device before and after the adjustment.
[0152] The image quality score is determined based on the image focus score and / or the algorithm processing score of the image; the algorithm processing score is used to characterize the processing effect obtained by performing algorithm processing on the image.
[0153] In an embodiment of the present application, the image acquisition device can capture images of the target object when the focus position is the initial focus position and when the focus adjustment is completed, and determine the image focus score and algorithm processing score of the image each time the above image is captured, and then determine the image quality score of the image based on the above image focus score and algorithm processing score.
[0154] The image focus score can be a clarity score, a contrast score, or a score output by an AI (Artificial Intelligence) model. The image focus score can reflect the image's focus effect; the better the image's focus effect, the higher the image focus score. For example, the clarity score can reflect the image's clarity, such as the clarity of detailed textures and their boundaries. Thus, the clearer the image, the higher the image clarity score.
[0155] The algorithmic processing score can be used to characterize the processing effect of algorithmic processing on an image. The processing effect can be one or more, and the better the processing effect, the higher the algorithmic processing score of the image. Optionally, the processing effect can include, but is not limited to, at least one of the following: recognition success rate, recognition accuracy, and recognition rate. For example, the algorithmic processing score of an image can be determined based on the recognition success rate and recognition rate of the target object in the image.
[0156] Among them, the determination method of the above algorithm processing score and the specific meaning represented can be set by those skilled in the art according to specific application situations, and the embodiments of this application do not specifically limit it.
[0157] Optionally, the target object may be a graphic identification code, and the algorithm processing score may include a code reading score. The code reading score evaluates the quality of the graphic identification code and the difficulty of algorithmic recognition, and can be used to indicate the difficulty of recognizing the graphic identification code in the current environment. Therefore, the code reading score can be used to indicate the recognition success rate of the graphic identification code in the image, and can also be used to indicate the recognition success rate and recognition rate of the graphic identification code in the image.
[0158] Optionally, the target object may be a specific object, and the algorithm processing score may include an object recognition score. Furthermore, the object recognition score may be used to represent the recognition accuracy of the object in the image.
[0159] In summary, the image quality score is a score that combines the above-mentioned image focus score and algorithm processing score to indicate the imaging quality of the image. The higher the image quality score, the higher the imaging quality of the image.
[0160] When capturing an image of a target object, within the focal length range of the image capture device, there is a focal length position where the image quality of the captured image is the best. This focal length position can be used as the optimal focal length position desired to be determined for this focusing. Generally, when the image capture device is at the optimal focal length position, the image quality score of the image of the target object captured by the image capture device is also the highest. For example, as shown in FIG2(a), generally, when the image capture device is at the optimal focal length position, the image quality score of the image of the target object captured by the image capture device is the highest. Moreover, for each focal length position within the upper focal length range, the closer the focal length position is to the optimal focal length position, the higher the image quality score of the image of the target object captured by the image capture device at the focal length position is.
[0161] Therefore, in response to adjusting the focal length position of the image acquisition device, a change trend of the image quality score of the image of the target object acquired by the image acquisition device before and after the adjustment is determined.
[0162] In which, in response to each adjustment of the focal position of the image acquisition device, the changing trend of the image quality score of the image of the target object captured by the image acquisition device before and after each adjustment can be determined, that is, the above-mentioned changing trend is determined once each time the focal position of the image acquisition device is adjusted.
[0163] In response to multiple adjustments to the focus position of an image capture device, a changing trend in the image quality scores of images of the target object captured by the image capture device before and after the multiple adjustments can be determined. Specifically, the changing trend is determined once for each successive adjustment of the focus position of the image capture device. For example, starting from the first adjustment, the changing trend is determined after two focus adjustments are completed. When determining the changing trend, the image quality score before adjustment is the image quality score of the image captured when the focus position of the image capture device is at the initial focus position, and the image quality score after adjustment is the image quality score of the image captured when the last two focus adjustments are completed.
[0164] The multiple adjustments can be a specified number of adjustments, so that the change trend can be determined each time the focal length of the image acquisition device is adjusted a specified number of times. When determining the change trend, the image quality scores of the images captured by the image acquisition device before and after the specified number of adjustments are compared. In this case, the specified number of adjustments can be set by those skilled in the art based on specific application scenarios.
[0165] S102: When the changing trend is upward, the focusing direction is kept unchanged.
[0166] If the trend is upward, it means that the most recent adjustment brought the image capture device's focus closer to the optimal focus position. Further, if the image capture device's focus is adjusted further in the direction of the most recent focus adjustment, the adjusted focus position may be closer to the optimal focus position. Therefore, the focus direction can be maintained unchanged. Therefore, when performing the next adjustment, the image capture device's focus position is adjusted further in the direction of the most recent adjustment, using a preset step size.
[0167] S103: When the change trend is downward and the image quality score change is the first change, adjust the focus direction of the next focus adjustment.
[0168] If the trend of change is downward, it indicates that the most recent adjustment caused the image capture device's focus position to move further away from the target focus position. Furthermore, if this change in image quality score is the first change in the image capture device's focus process, it indicates that, starting from the initial focus position, the image capture device's focus position was adjusted along the pre-set focus direction of the first focus adjustment, causing the image capture device's focus position to move away from the optimal focus position. Furthermore, if the image capture device's focus position is further adjusted along the focus direction of the first focus adjustment, the adjusted focus position will gradually move away from the optimal focus position. Thus, in order to gradually bring the adjusted focus position closer to the optimal focus position, the image capture device's focus position needs to be adjusted in the direction opposite to the focus direction of the first focus adjustment. Therefore, the focus direction of the next focus adjustment is adjusted to the direction opposite to the focus direction of the first focus adjustment. Thus, during the next adjustment, the focus position of the image capture device is adjusted in the direction opposite to the focus direction of the first focus adjustment, and according to a preset step size.
[0169] The above step S103 is described below by taking, as an example, determining the changing trend of the image quality score of the image of the target object captured by the image capture device before and after the adjustment in response to each adjustment of the focus position of the image capture device.
[0170] In Example 1, assuming that the image quality score shows a downward trend before and after the first adjustment, and that the change in image quality score caused by the first adjustment is the first change, the focus direction of the next focus adjustment is adjusted to the opposite direction of the first focus adjustment. Furthermore, the focus position of the image capture device is adjusted to the initial focus position through the second adjustment, and the third adjustment process is to adjust the focus position of the image capture device in the opposite direction of the first focus adjustment, using a preset step size.
[0171] Example 2: Assuming that the image quality score trend remains unchanged before and after the first adjustment, that is, the image quality score of the image captured by the image acquisition device does not change before and after the adjustment, then when performing the second adjustment, the focus position of the image acquisition device is adjusted according to the preset step size along the focusing direction of the first focal length adjustment. Assuming that the image quality score trend decreases before and after the second adjustment, the change in image quality score caused by the second adjustment is the first change. In this way, the focus direction of the next focal length adjustment is adjusted to the opposite direction of the focus direction of the first focal length adjustment, and the third adjustment process is to adjust the focus position of the image acquisition device along the opposite direction of the focus direction of the first focal length adjustment and according to the preset step size.
[0172] As previously mentioned, the first focus adjustment may or may not result in a change in the image quality score before and after the adjustment. Therefore, the first change in the image quality score may occur after the first focus adjustment, or at any focus adjustment after the first focus adjustment, such as the second or third focus adjustment. If the first change in the image quality score occurs at any focus adjustment after the first focus adjustment, then all focus adjustments prior to that focus adjustment did not result in a change in the image quality score before and after the adjustment.
[0173] S104: When the change trend is downward and the change trend before and after the previous adjustment is upward, or when the change trend is downward and this image quality score change is not the first change, the focal length position before this adjustment is determined as the optimal focal length position.
[0174] In the above step S104, there are the following two situations:
[0175] The first case: when the change trend is downward and the change trend before and after the previous adjustment is upward, the focal length position before this adjustment is determined as the optimal focal length position.
[0176] Among them, if the trend of change is downward, it means that the most recent adjustment has caused the focal position of the image acquisition device to move further away from the optimal focal position. Furthermore, if the trend of change before and after the previous adjustment is upward, it means that the previous adjustment has caused the focal position of the image acquisition device to move closer to the optimal focal position. For each focal position, the closer the focal position is to the optimal focal position, the higher the image quality score of the image captured by the image acquisition device at that focal position. Therefore, when the previous focal adjustment was completed, the focal position of the image acquisition device was closer to the optimal focus position than the focal position of the image acquisition device when the current focal adjustment was completed. Therefore, before this adjustment, the focal position of the image acquisition device was the focal position closest to the optimal focal position during the above-mentioned focal adjustment process, and thus, the focal position before this adjustment can be determined as the optimal focal position.
[0177] Optionally, in some cases, when the change trend before and after this adjustment is downward, the change trend before and after the previous adjustment may also be downward. Then, similar to the above step S104, when the change trend is downward and the change trend before and after the previous adjustment is upward, the focal length position before this adjustment is also determined as the optimal focal length position.
[0178] For example, if the image quality score shows a downward trend before and after the first adjustment, the focus direction of the second focus adjustment is adjusted. Furthermore, if the image quality score continues to show a downward trend before and after the second adjustment, the focus position at the completion of the first adjustment is determined as the optimal focus position.
[0179] Among them, in the case where the change trends of the image quality scores in the above two consecutive times are both downward, the previous focus adjustment makes the focal position of the image acquisition device further away from the optimal focus position, and this adjustment makes the focal position of the image acquisition device further away from the optimal focus position, which aggravates the deviation between the focal position of the image acquisition device and the optimal focus position. Therefore, the focal position before this adjustment can be determined as the optimal focus position.
[0180] In summary, in the above-mentioned focal length adjustment and focusing process, in response to adjusting the focal length position of the image acquisition device, when the changing trend of the image quality score before and after the adjustment is downward, and the changing trend before and after the previous adjustment is upward or downward, the focal length position before this adjustment is determined as the optimal focal length position.
[0181] The second scenario: when the change trend is downward and this image quality score change is not the first change, the focal length position before this adjustment is determined as the optimal focal length position.
[0182] If the trend is downward, it means that the most recent adjustment has caused the image acquisition device's focus position to move further away from the optimal focus position. Furthermore, if this image quality score change is not the first change, it means that the trend before and after the previous adjustment was upward or downward. Obviously, regardless of whether the trend before and after the previous adjustment was upward or downward, the focus position after the current adjustment is further away from the optimal focus position compared to the focus position after the previous adjustment.
[0183] That is, if the change trend is downward and this image quality score change is not the first change, the focal length position before the adjustment is closer to the optimal focal length position than the focal length position after the adjustment. Therefore, if the change trend is downward and this image quality score change is not the first change, the focal length position before the adjustment is determined to be the optimal focal length position.
[0184] In the embodiment of the present application, the purpose of focusing the image acquisition device is to enable the focused image acquisition device to capture an image of the target object that meets the image quality requirements. Therefore, after obtaining the above-mentioned optimal focal length position, the image acquisition device can be focused according to the above-mentioned optimal focal length position, and finally obtain the image of the target object captured by the image acquisition device when the focal length is at the above-mentioned optimal focal length position.
[0185] Optionally, the target object is a graphic recognition code, and the algorithm processing score includes: code reading score, and the processing effect includes but is not limited to: at least one of recognition success rate, recognition accuracy and recognition speed.
[0186] As can be seen from the above, using the embodiments of the present application, when focusing an image acquisition device, the focus of the image acquisition device can be adjusted starting from an initial focal position according to a preset step size until an optimal focal position is determined. During this focus adjustment process, in response to adjusting the focal position of the image acquisition device, a changing trend in the image quality scores of images of the target object captured by the image acquisition device before and after the adjustment is determined, and the next focusing action is determined based on this changing trend.
[0187] Based on this, the focal position of the image acquisition device can be adjusted according to the changing trend of the image quality score of the image of the target object captured by the image acquisition device before and after the focal position adjustment, and the optimal focal position can be determined, thereby realizing automatic focus of the image acquisition device without using a distance sensor and without increasing the cost of the image acquisition device.
[0188] In other words, by applying the solution provided by the embodiments of the present application, it is possible to achieve automatic focus of an image acquisition device without utilizing a distance sensor. Therefore, it is unnecessary to install a distance sensor on the image acquisition device, thereby maintaining the cost of the image acquisition device and reducing the system complexity of the image acquisition device. Furthermore, because the image acquisition device can focus on a target object as the distance between the target object and the image acquisition device changes, the solution provided by the embodiments of the present application can be widely applied to scenarios such as long-distance photography, large depth of field, and real-time depth of field changes, as well as visual algorithm analysis.
[0189] In addition, since the image quality score is determined based on the image focus score and algorithm processing score of the image, the algorithm processing score is used to characterize the processing effect obtained by algorithmically processing the image. Therefore, applying the embodiment of the present application to focus the image acquisition device can also make the image captured by the focused image acquisition device have both a higher focusing effect and a better processing effect on the target object.
[0190] That is to say, by applying the solution provided in the embodiments of the present application, the image captured by the image acquisition device after focusing can have a high focusing effect, and the algorithmic processing of the target object in the above image can also achieve better processing effects. For example, while the above image has a high clarity, the difficulty of algorithmic processing of the above target object is reduced, and the accuracy of algorithmic recognition of the above target object is improved.
[0191] According to steps S101-S104, it can be seen that the image quality score at the optimal focal length position is close to or is a peak in the curve of image quality score varying with focal length position. However, in real application scenarios, there may be multiple objects at different distances from the image acquisition device. For each of the multiple objects, the optimal focal length position determined may be different, that is, the multiple objects may meet the condition of the highest image quality score in different images captured when the image acquisition device is at different focal length positions. Therefore, as shown in FIG2(b), there may be multiple peaks in the curve of image quality score varying with focal length position, and the existence of multiple peaks may cause the optimal focus position determined above to be inaccurate, and thus lead to poor focusing effect.
[0192] Optionally, in a specific implementation, the above step 1: starting from the initial focal length position of the image acquisition device, adjusting the focal length of the image acquisition device according to a preset step length until the optimal focal length position is determined, may include the following step 11.
[0193] Step 11: Starting from the initial focal length position of the image acquisition device, the focus of the image acquisition device is adjusted according to a preset step size within a specified interval within the focal length range of the image acquisition device until the optimal focal length position is determined.
[0194] In this specific implementation, those skilled in the art can determine a designated interval within the focal length range of the image acquisition device based on the actual application scenario, such as shown in Figure 2(b). Furthermore, during the focus adjustment process, starting from the initial focal length position of the image acquisition device, the focus of the image acquisition device is adjusted within the designated interval according to a preset step size until the optimal focal length position is determined.
[0195] By adjusting the focal length of the image acquisition device, the distance between the focal plane of the image acquisition device and the image acquisition device can be changed. When the target object is exactly located on the focal plane, the image of the target object captured by the image acquisition device can be the clearest. In the same application scenario, when the image acquisition device captures images of various target objects, the distance between the image acquisition device and each target object can all fall within the same distance range. By adjusting the focal plane within this distance range to adjust the distance between the focal plane and the image acquisition device, the image acquisition device can focus on the target object.
[0196] For example, the target object can be a QR code on top of a shipment. The shipment can be located on a conveyor belt and move with the conveyor belt. The image capture device can be installed at a designated location 100 cm directly above the conveyor belt. The height of each shipment is no higher than 50 cm and no lower than 10 cm. Furthermore, when the image capture device captures the image of the QR code on each shipment, the distance between the image capture device and each QR code can fall within the distance interval of [50, 90] cm. For each QR code, the focal plane is adjusted within this distance interval to adjust the distance between the focal plane and the image capture device, thereby completing the focus of the image capture device on that QR code.
[0197] Therefore, optionally, those skilled in the art may determine a designated interval within the focal length range of the image acquisition device based on the above distance interval.
[0198] Since the designated interval is determined by technicians in this field within the focal length range of the image acquisition device based on the actual situation of the application scenario, in the curve of image quality score changing with focal length position, there can be fewer peaks in the designated interval compared to the focal length range, and the focal length position corresponding to the peak in the designated interval is more likely to be the optimal focus position. Therefore, focusing using this specific implementation method can have a better focusing effect.
[0199] Furthermore, because the designated interval is smaller than the focal length range, it contains fewer focal length positions than the focal length range. Determining the optimal focal length position in the designated interval can be faster than determining the optimal focal length position within the focal length range. This means that this specific implementation can also improve focusing speed.
[0200] However, in some cases, the specified interval may not be accurate enough, resulting in the absence of a peak within the specified interval. When the focal length position is adjusted to the boundary of the specified interval, if there is no downward trend and the trend before and after the previous adjustment is upward, it indicates that there is no peak within the specified interval, and the boundary position can be determined as the optimal focal length position of the image acquisition device.
[0201] Optionally, in one specific implementation, when an image capture device captures an image of a target object, it may output only the image region containing the target object. Furthermore, an image quality score for the target object region may be determined based on the image focus score and algorithm processing score for the target object region.
[0202] Based on this, the impact of objects other than the target object in the application scenario on the image quality score can be reduced, and the positive correlation between the image quality score, the imaging clarity of the target object, and the algorithm processing effect can be enhanced. Furthermore, in the case of multiple peaks in the curve of image quality score versus focal length position, as shown in Figure 2(b), applying this specific implementation method can reduce the number of peaks within the focal length range, thereby improving the accuracy of the determined optimal focal length position and enhancing the focusing effect of the image acquisition device.
[0203] Optionally, in a specific implementation, the focal length range of the image acquisition device may be divided into at least two intervals in advance.
[0204] Accordingly, in this specific implementation, the above step 1: starting from the initial focal length position of the image acquisition device, adjusting the focal length of the image acquisition device according to a preset step length until the optimal focal length position is determined, may include the following steps 12-13.
[0205] Step 12: Select an initial focal length position for each interval, and starting from the initial focal length position selected for each interval, adjust the focal length of the image acquisition device according to a preset step size in each interval until the local optimal focal length position in each interval is determined.
[0206] Step 13: Determine the local optimal focal length position with the highest image quality score of the captured image among the at least two determined local optimal focal length positions as the optimal focal length position.
[0207] In this specific implementation, the focal range of the image acquisition device is pre-divided into at least two intervals. For each interval, an initial focal position can be selected within the interval. Then, starting from the initial focal position selected within the interval, the focus of the image acquisition device is adjusted within the interval according to a preset step size until a local optimal focal position within the interval is reached. In this way, at least two local optimal focal positions can be obtained, as well as an image quality score of the image captured by the image acquisition device at each local optimal focal position. Thus, the local optimal focal position with the highest image quality score for the captured image of the at least two local optimal focal positions can be determined as the optimal focal position.
[0208] In this way, not only can the optimal focal length position of the image acquisition device be determined, but also the automatic focus of the image acquisition device can be realized without using a distance sensor and without increasing the cost of the image acquisition device. Moreover, in response to the subsequent need to determine the optimal focal length position within a certain focal length range, the local optimal focal length position whose interval belongs to the above-mentioned focal length range can be directly selected from the above-mentioned at least two local optimal focal length positions as the final optimal focal length position, thereby saving the subsequent focusing time of the image acquisition device and improving the focusing efficiency.
[0209] Optionally, in a specific implementation, as shown in FIG3 , the focal length adjustment process in the focusing method provided in the embodiment of the present application may further include the following steps S105 - S108 .
[0210] S105: Determine whether the optimal focal length position meets the preset focusing condition. If so, execute S106; if not, execute S107.
[0211] Because an image capture device can be used in a scenario where multiple objects exist, and these objects can be at varying distances from the device, the clarity of each object in the captured image can also vary when the device is at different focal lengths. Therefore, the image quality score may exhibit multiple peaks in the curve plotting the image quality score versus focal length. Consequently, the optimal focal length position determined above may only be close to or correspond to one of the multiple peaks, rather than being the focal length position that satisfies the preset focus conditions.
[0212] That is, the optimal focal length position determined in the above step S104 may not satisfy the preset focus condition. Therefore, after obtaining the optimal focal length position, it can be further determined whether the obtained optimal focal length position satisfies the preset focus condition.
[0213] Among them, the above-mentioned preset focus condition can be set by those skilled in the art according to the actual situation of the application scenario, and the embodiments of the present application are not specifically limited here. For example, the above-mentioned preset focus condition can be that the image quality score of the image captured by the image acquisition device at the optimal focus position is greater than the first score. For another example, the above-mentioned preset focus condition can also be that the image quality score of the image captured by the image acquisition device at the optimal focus position is greater than the first score, and the algorithm processing score is greater than the second score.
[0214] S106: Focusing the image acquisition device according to the optimal focal length position.
[0215] If the obtained optimal focal length position meets the preset focusing condition, the image acquisition device can be focused according to the optimal focal length position, so that the image acquisition device can capture the image of the target object at the optimal focal length position.
[0216] S107: traverse each focal length position in the focal length range of the image acquisition device, and when traversing to each focal length position, determine the image quality score of the image acquired by the image acquisition device.
[0217] If the obtained optimal focal length position does not meet the preset focusing condition, the various focal length positions in the focal length range of the image acquisition device can be traversed, and when each focal length position is traversed, the image quality score of the image of the target object captured by the image acquisition device is determined.
[0218] In some cases, considering the hardware characteristics of the image acquisition device, the focal length range of the image acquisition device can generally be a discrete interval, which can include multiple discrete values, each discrete value being a focal length position of the image acquisition device.
[0219] In other cases, the focal length range of the image capture device may also be a continuous interval, including a continuous range of values. Thus, multiple discrete values may be screened within the continuous range, and each screened discrete value may be used as a focal length position of the image capture device. For example, starting from the minimum value of the focal length range, a difference may be set at each interval to select a discrete value as the focal length position.
[0220] In this way, each focal length position in the focal length range determined above can be traversed in turn. When traversing to each focal length position, the focal length of the image acquisition device is adjusted to the focal length position, and when the image acquisition device is at the focal length position, the image acquisition device is controlled to capture an image of the target object, and then the image quality score of the captured image is determined.
[0221] Optionally, starting from the minimum position in the focal length range of the image acquisition device, a focal length position is determined at intervals of a specified step length along the direction of increasing focal length positions, and when each focus position is determined, an image quality score of the image of the target object captured by the image acquisition device at the focal length position is determined. Alternatively, starting from the maximum position in the focal length range of the image acquisition device, a focal length position is determined at intervals of a specified step length along the direction of decreasing focal length positions, and when each focus position is determined, an image quality score of the image of the target object captured by the image acquisition device at the focal length position is determined.
[0222] Optionally, to increase the speed of traversing focal positions and thereby improve focusing efficiency, when traversing the focal positions within the focal range of the image acquisition device, only the focal positions within a specified interval may be traversed. Since the specified interval is an interval determined within the focal range, the number of focal positions within the specified interval may be smaller than the number of focal positions within the focal range. Consequently, traversing the focal positions within the specified interval may take less time than traversing the focal positions within the entire focal range.
[0223] S108: Update the optimal focal length position to: the focal length position of the image acquisition device when an image with the highest image quality score is acquired.
[0224] After traversing each focal position within the focal length range of the image acquisition device, the image quality scores of the images of the target object captured by the image acquisition device at each focal length position can be obtained. Furthermore, the focal length position corresponding to the image with the highest image quality score, that is, the focal length position of the image acquisition device when the image with the highest image quality score was captured, can be used as the optimal focal length. In this way, the optimal focal length position determined in step S106 can be updated to the focal length position of the image acquisition device when the image with the highest image quality score was captured.
[0225] After the optimal focal length position is updated, the image acquisition device can be focused according to the updated optimal focal length position, so that the image acquisition device can capture an image of the target object at the updated optimal focal length position. Based on this, applying this specific implementation method can further improve the focus accuracy.
[0226] Optionally, in a specific implementation, a focusing method provided in an embodiment of the present application may further include the following steps 2-3.
[0227] Step 2: When the focus position of the image acquisition device is the initial focus position and each time the focus adjustment is completed, the image acquisition device is controlled to acquire an image of the target object, and an image focus score and an algorithm processing score of the image are determined.
[0228] In this specific implementation, the image acquisition device can be controlled to capture images of the target object when the focal position of the image acquisition device is at the initial focal position, and each time the focal adjustment is completed, and the image focusing score and algorithm processing score of the captured image can be determined.
[0229] In some application scenarios, when capturing images, the image acquisition device needs to ensure that the image area where the target object is located in the captured image is sufficiently clear, and the captured target object has good algorithm processing effects. For example, when using a QR code scanning device to scan a QR code, the image area where the QR code is located in the captured image needs to be sufficiently clear, and the captured QR code needs to be easily recognizable.
[0230] Based on this, optionally, in a specific implementation, in the above step 2, determining the image focus score and the algorithm processing score of the image may include the following step 21.
[0231] Step 21: Determine an algorithmically processed region of interest in the image regarding the target object, and determine an image focus score and an algorithm processing score for the region of interest.
[0232] In this specific implementation, generally, for an image of a target object captured by an image acquisition device, the higher the algorithmic processing score of the target object in the image, the better the effect of the algorithmic processing (e.g., recognition) of the target object in the image. Therefore, when determining the image focus score and the algorithmic processing score of an image, a region of interest for the algorithmic processing of the target object can be first determined in the image, and then the image focus score and the algorithmic processing score of the region of interest can be determined. Then, the image focus score of the determined region of interest can be used as the image focus score of the image, and the algorithmic processing score of the determined region of interest can be used as the algorithmic processing score of the image.
[0233] The region of interest in the image for the algorithm processing of the target object refers to the region in the image targeted by the algorithm when the algorithm processes the target object in the image. Typically, the region of interest is the region in the image where the target object is located.
[0234] Based on this, optionally, the above step 21 may include the following step 211.
[0235] Step 211: performing object recognition on the image, and determining the image region where the recognized detection frame including the target object is located as a region of interest for algorithm processing regarding the target object.
[0236] When an image of a target object is acquired by an image acquisition device, object recognition can be performed on the image to identify the target object in the image and obtain a detection frame that includes the target object. In this way, the image region containing the identified detection frame that includes the target object can be determined as a region of interest for algorithmic processing related to the target object.
[0237] Based on this, since the clarity score and the algorithm processing score are determined based on the area of interest of the algorithm processing regarding the target object in the image, and the image quality score is determined based on the clarity score and the algorithm processing score, therefore, the application of this specific implementation method can enhance the positive correlation between the determined image quality score of each image and the clarity of the area of interest in the image and the algorithm processing effect, and reduce the impact of the imaging effects of other objects other than the target object in the application scenario on the image quality score.
[0238] Furthermore, for the case where there are multiple peaks in the curve of image quality score changing with focus position as shown in Figure 2(b), the application of this specific implementation method can reduce the number of peaks in the focus position interval, thereby increasing the possibility that the determined target focus position is the optimal focus position, and improving the focusing effect of the image acquisition device.
[0239] Step 3: Calculate a first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight, and calculate the sum of the first product and the second product as the image quality score of the image.
[0240] In this specific implementation method, those skilled in the art can pre-set the image focus weight regarding the image focus score and the algorithm processing weight regarding the algorithm processing score according to the actual situation of the application scenario. Then, after determining the image focus score and the algorithm processing score of the image, the first product of the image focus score and the preset image focus weight, as well as the second product of the algorithm processing score and the preset algorithm processing weight can be calculated, and the sum of the first product and the second product can be calculated. Then, the calculated sum can be used as the image quality score of the image.
[0241] For example, when the actual situation of the application scenario focuses more on algorithmic processing of images captured by the image acquisition device, for example, recognizing QR codes in images captured by the image acquisition device, the algorithmic processing weight can be set to a larger value, so that the image captured by the image acquisition device at the target focus position can have a better algorithmic processing effect.
[0242] Optionally, in a specific implementation, before the above step 3, the focusing method provided in the embodiment of the present application may further include the following step 4.
[0243] Step 4: Select a target weight combination that matches the current application scenario of the image acquisition device from the preset mapping relationships between multiple weight combinations and application scenarios.
[0244] Each weight combination includes: an image focusing weight and an algorithm processing weight.
[0245] Accordingly, in this specific implementation, the above step 3 may include the following step 31.
[0246] Step 31: Calculate a first product of the image focus score and the image focus weight included in the target weight combination, and a second product of the algorithm processing score and the algorithm processing weight included in the target weight combination.
[0247] In this specific implementation method, the application scenarios for image acquisition by the image acquisition device can be determined in advance. Thus, based on the requirements and emphasis on the focusing effect of the image and the algorithmic processing of the target object in the image in the application scenario, the image focusing weight and algorithmic processing weight in each application scenario are determined as the weight combination corresponding to each application scenario. Thus, a mapping relationship between multiple pre-set weight combinations and application scenarios is obtained, and each weight combination includes: an image focusing weight and an algorithmic processing weight.
[0248] Optionally, the above mapping relationship may include:
[0249] a mapping relationship between an application scenario for object processing of a target object and a first weight combination; wherein the image focusing weight included in the first weight combination is smaller than the algorithm processing weight; and
[0250] There is no mapping relationship between the image acquisition scene of the target object and the second weight combination; wherein the algorithm processing weight included in the second weight combination is 0.
[0251] As mentioned above, in this specific implementation, when presetting the above-mentioned mapping relationship, when the application scenario focuses more on algorithmic processing of the target object in the image, then, it is necessary to set a larger algorithmic processing weight, so that the set image focusing weight is smaller than the algorithmic processing weight; and when the application scenario focuses more on the effect of image shooting, for example, focusing on shooting clearer images of the target object, or shooting images in the absence of a target object and focusing on shooting clearer environmental images, a smaller algorithmic processing weight can be set, and even the algorithmic processing weight can be 0.
[0252] In this way, when calculating the quality score of an image captured by an image acquisition device, a target weight combination that matches the current application scenario of the image acquisition device can be selected from the mapping relationship between multiple preset weight combinations and application scenarios. Furthermore, when calculating the image quality score of an image captured by the image acquisition device, a first product of the image focus score and the image focus weight included in the target weight combination, as well as a second product of the algorithm processing score and the algorithm processing weight included in the target weight combination can be calculated. Thereafter, the sum of the first and second products is calculated as the image quality score of the image captured by the image acquisition device.
[0253] Based on this, by applying this specific implementation method, the image focusing weight regarding the image focusing score and the algorithm processing weight regarding the algorithm processing score can be set according to the actual situation of the application scenario, so that the determined image quality score is more in line with the actual focusing requirements in the application scenario, thereby further improving the focusing effect of the image acquisition device.
[0254] Optionally, in a specific implementation, as shown in Figure 4, the above-mentioned step S101, in response to adjusting the focal position of the image acquisition device, determines the changing trend of the image quality score of the image of the target object captured by the image acquisition device before and after the adjustment, and may include the following steps S1011-S1014.
[0255] S1011: In response to adjusting the focal length position of the image acquisition device, calculating the numerical relationship and difference between image quality scores of images of the target object acquired by the image acquisition device before and after the adjustment.
[0256] In response to adjusting the focal position of the image acquisition device, the numerical relationship between the image quality scores of the images of the target object captured by the image acquisition device before and after the adjustment, as well as the difference in the image quality scores of the images of the target object captured by the image acquisition device before and after the adjustment can be calculated.
[0257] S1012: When the difference is greater than a preset value and the numerical relationship indicates that the image quality score before the current adjustment is less than the image quality score after the current adjustment, it is determined that the change trend of the image quality score before and after the current adjustment is an increase.
[0258] If the determined difference is greater than a preset value, and the determined numerical relationship indicates that the image quality score before the adjustment is less than the image quality score after the adjustment, it can be determined that the change trend of the image quality score before and after the adjustment is an upward trend.
[0259] S1013: When the difference is greater than a preset value and the numerical relationship indicates that the image quality score before the current adjustment is greater than the image quality score after the current adjustment, it is determined that the change trend of the image quality score before and after the current adjustment is a decrease.
[0260] If the determined difference is greater than a preset value, and the determined numerical relationship indicates that the image quality score before the adjustment is greater than the image quality score after the adjustment, it can be determined that the change trend of the image quality score before and after the adjustment is downward.
[0261] S1014: When the difference is not greater than the preset value, it is determined that the change trend of the image quality score before and after the adjustment is unchanged.
[0262] If the determined difference is no greater than a preset value, it indicates that the change in the image quality score before and after the current adjustment is small. Furthermore, since the change in the image quality score is small, it is likely due to interference with the image acquisition device during the focus adjustment process. Therefore, to reduce the impact of interference on the focus adjustment process, if the difference is no greater than a preset value, it can be determined that the trend of the image quality score before and after the current adjustment is unchanged.
[0263] Among them, the above-mentioned preset values can be set by those skilled in the art according to the actual situation of the application scenario, and are not specifically limited in the embodiments of this application.
[0264] Optionally, a focusing method provided in an embodiment of the present application may further include the following step 5.
[0265] Step 5: Based on the image acquisition device, determine the adjustment ratio, and calculate the preset value based on the preset reference value and the adjustment ratio.
[0266] Since different image acquisition devices may have different hardware characteristics, and different application scenarios may have different requirements for focus adjustment accuracy, and these hardware characteristics and accuracy requirements may affect the focusing process of the image acquisition device, when determining the preset value, the adjustment ratio may be determined based on the hardware characteristics of the image acquisition device itself, and then the preset value may be calculated based on the preset reference value and the adjustment ratio. The preset reference value may be a physical parameter set by the image acquisition device at the factory, or a parameter pre-set by a person skilled in the art based on the hardware characteristics of the image acquisition device, the application scenario, etc.
[0267] Accordingly, a focusing method provided in an embodiment of the present application may further include the following step 6.
[0268] Step 6: When the changing trend remains unchanged, keep the focusing direction unchanged.
[0269] If the trend of change is unchanged, it is impossible to determine whether the current adjustment has caused the focus position of the image acquisition device to be closer to the optimal focus position or further away from the optimal focus position. Therefore, the process returns to step S102 and continues to adjust the focus position in the specified focus direction and at the specified step size, thereby maintaining the focus direction unchanged. Therefore, when the next adjustment is performed, the focus position of the image acquisition device is adjusted in the focus direction of the most recent adjustment and at the preset step size.
[0270] Interference factors such as image acquisition device jitter can cause accidental changes in the image quality score's changing trend. The accuracy of the optimal focus position determined based on these accidental changes can be poor, leading to focus failure. Therefore, to reduce the impact of interference factors such as image acquisition device jitter on the focus results, the same changing trend that has been determined a specified number of times can be determined as a valid changing trend.
[0271] Based on this, optionally, in a specific implementation, the above step S103: when the change trend is downward and the current image quality score change is the first change, adjusting the focusing direction of the next focal length adjustment may include the following step 1031.
[0272] Step 1031: When the change trend is downward and the number of consecutive times of the change trends being downward reaches a specified number, and there has not been a situation where the change trends are the same for the specified number of consecutive times before this adjustment, adjust the focusing direction of the next focal length adjustment.
[0273] In response to adjusting the focal position of the image acquisition device, if the image quality score of the image of the target object captured by the image acquisition device before and after the adjustment shows a downward trend, and the downward trend has occurred for a specified number of consecutive times, then the image quality score change trend before and after the adjustment is a valid change trend. Furthermore, if the same change trend has not occurred for a specified number of consecutive times before the adjustment, then this image quality score change is the first valid image quality score change in the process of adjusting the focal length of the image acquisition device. Then, the focus direction of the next focus adjustment can be adjusted, that is, the focus direction of the next focus adjustment can be adjusted to the opposite direction of the focus direction of the first focus adjustment. In this way, when performing the next adjustment, the focus position of the image acquisition device is adjusted in the opposite direction of the focus direction of the first focus adjustment and according to a preset step size.
[0274] That is to say, in this specific implementation, the first change in the image quality score can be understood as: the first effective change in the image quality score. The first effective change in the image quality score is: during the focusing process, when the image quality score change trends caused by the first specified number of consecutive adjustments are the same, the image quality score change caused by the last adjustment in the above specified number of consecutive adjustments. Correspondingly, after the first specified number of consecutive adjustments, when the image quality score change trends caused by the first specified number of consecutive adjustments are the same, the image quality score change trends caused by the second specified number of consecutive adjustments are the same, the last image quality score change in the image quality score caused by the second specified number of consecutive adjustments can be regarded as a valid change in the image quality score, but it is not the first effective change in the image quality score.
[0275] For example, assuming that the specified number is 3, during the focusing process of the image acquisition device, after the first adjustment, the image quality score change trend is downward. At this time, the first adjustment cannot be regarded as the first effective change of the image quality score because it does not meet the requirement that the image quality score change trend caused by the continuous specified number of adjustments is the same, so the second adjustment is continued; after the second adjustment, the image quality score change trend is still downward. At this time, the second adjustment still does not meet the requirement that the image quality score change trend caused by the continuous specified number of adjustments is the same, so it still cannot be regarded as the first effective change of the image quality score, so the third adjustment is continued; after the third adjustment After the adjustment, the image quality score change trend is still downward. At this time, the change trends before and after the first adjustment, the second adjustment, and the third adjustment are all downward. Before the third adjustment, there is no situation where the change trends determined for three consecutive times are the same. Therefore, when the third adjustment is completed, the situation where the image quality score change trends caused by three consecutive adjustments are the same appears first. Therefore, the image quality score change caused by the third adjustment is the first effective change in the image quality score, and the change trends before and after the first adjustment, the second adjustment, and the third adjustment are all downward. Then, when the third adjustment is completed, the focusing direction of the next focal length adjustment can be adjusted.
[0276] Accordingly, the above step S104 : when the change trend is downward and the change trend before and after the previous adjustment is upward, determining the focal length position before the current adjustment as the optimal focal length position may include the following step 1041 .
[0277] Step 1041: When the number of consecutive times that the change trend is downward and the change trends are both downward reaches a specified number, and the same change trend has occurred for a specified number of consecutive times before this adjustment, the focal length position before the first adjustment in the specified number of consecutive adjustments including this adjustment will be determined as the optimal focal length position.
[0278] In response to adjusting the focal position of the image acquisition device, if the change trends determined are the same for a specified number of consecutive times before this adjustment, it means that the change in the image quality score this time is not the first change in the image quality score during the focal adjustment process. Furthermore, if the change trend is downward and the change trends are both downward for a specified number of consecutive times, and if the change trends are the same for a specified number of consecutive times before this adjustment, the focal position before the first adjustment in the consecutive specified number of adjustments including this adjustment can be determined as the optimal focal position.
[0279] For example, assuming the specified number is 3, and during the image acquisition device's focus adjustment process, the change trends caused by the first, second, and third adjustments are all upward, then the change in image quality score caused by the third adjustment is the first valid change in image quality score. If the change trends after the fourth, fifth, and sixth adjustments are all downward, then the change in image quality score caused by the sixth adjustment is the second valid change in image quality score. In this case, the focal length position of the image acquisition device before the fourth adjustment can be determined as the optimal focal length position.
[0280] Accordingly, in this specific implementation, as described above, during the focal length adjustment process, if the determined change trend is a downward trend, and the change trends determined for a specified number of consecutive times are not all downward trends, it means that when this adjustment is completed, although the image quality score has changed a specified number of times, since the change trends of the specified number of changes are not exactly the same, the image quality score change caused by this adjustment cannot be regarded as a valid change in the image quality score, then the focusing direction is kept unchanged and the focal length adjustment is continued.
[0281] Based on this, this specific implementation method only adjusts the focus direction for the next focus adjustment or determines the optimal focus position when the change trend is the same for a specified number of consecutive times. This reduces the impact of interference factors such as image acquisition device jitter on the changing trend of image quality scores, further improving focus accuracy.
[0282] Optionally, in a specific implementation, the above step 1, starting from the initial focal length position of the image acquisition device, adjusts the focal length of the image acquisition device according to a preset step length until the optimal focal length position is determined, may include the following steps 14-15.
[0283] Step 14: Obtain the initial focal position of the image acquisition device and the focusing direction of the first focal adjustment.
[0284] Before adjusting the focus of the image acquisition device, the initial focus position and the focusing direction of the first focus adjustment can be preset. In this way, when adjusting the focus of the image acquisition device, the focus position of the image acquisition device is first adjusted to the preset initial focus position.
[0285] Among them, those skilled in the art can set the focusing direction and initial focal length position of the above-mentioned first focal length adjustment according to the actual situation of the application scenario, and the embodiments of the present application do not specifically limit this.
[0286] Optionally, the above step 14 may include the following step 141.
[0287] Step 141: Acquire a preset initial focal length position of the image acquisition device and a preset focusing direction for the first focal length adjustment.
[0288] Those skilled in the art can randomly set the initial focal position of the image acquisition device and the focusing direction of the first focal adjustment, so that the electronic device can obtain the preset initial focal position of the image acquisition device and the preset focusing direction of the first focal adjustment.
[0289] For example, the initial focal length position may be the middle position of the focal length range of the image acquisition device. For example, the focal length range of the image acquisition device may be [0, P max ], and further, the above-mentioned starting focus position can be (P max / 2). Among them, P max The maximum focal length that can be set for the image acquisition device.
[0290] Optionally, the above step 14 may include the following steps 142-145.
[0291] Step 142: Obtain the best historical focal length position of the image acquisition device as the initial focal length position;
[0292] Step 143: Compare the initial focal length position with the middle position of the focal length range of the image acquisition device;
[0293] Step 144: When the initial focal length position is smaller than the intermediate position, the focus direction of the adjusted focal length position is increased and determined as the focus direction for the first focus adjustment;
[0294] Step 145: When the initial focal length position is greater than the middle position, the focusing direction of the adjusted focal length position is reduced and determined as the focusing direction of the first focal length adjustment.
[0295] Those skilled in the art can set the image capture device's historical optimal focal position as the device's initial focal position. Thus, the electronic device can use the device's historical optimal focal position as the initial focal position. For example, if the optimal focal position determined during the last focusing of the image capture device was P1, then the initial focal position for this focusing operation can be P1.
[0296] Since the optimal focal length position is usually close to the middle position of the above-mentioned focal length range, in order to reduce the number of focal length adjustments and improve the focusing speed, the focusing direction of the first focal length adjustment can be determined based on the size relationship between the above-mentioned initial focal length position and the middle position of the focal length range of the image acquisition device.
[0297] The initial focal length position is compared with the middle position of the focal length range of the image acquisition device to determine the size relationship between the initial focal length position and the middle position.
[0298] Among them, when the above-mentioned initial focal length position is smaller than the above-mentioned middle position, in order to make the adjusted focal length close to the above-mentioned middle position as soon as possible, the focusing direction of the adjusted focal length position will be increased and determined as the focusing direction of the first focal length adjustment; and when the above-mentioned initial focal length position is larger than the above-mentioned middle position, in order to make the adjusted focal length close to the above-mentioned middle position as soon as possible, the focusing direction of the adjusted focal length position will be lowered and determined as the focusing direction of the first focal length adjustment.
[0299] Step 15: Starting from the initial focal length position, adjust the focus of the image acquisition device according to the focusing direction and preset step length of the first focal length adjustment.
[0300] After obtaining the initial focal position of the image capture device and the focus direction of the first focus adjustment, the focus of the image capture device is adjusted starting from the initial focal position according to the focus direction of the first focus adjustment and a preset step size. When performing the first focus adjustment, the focus of the image capture device can be adjusted starting from the initial focal position along the focus direction of the first focus adjustment and according to the preset step size.
[0301] For example, if the focus adjustment direction of the first focus adjustment is the direction of reducing the focus position, the preset step size is ΔP, and the initial focus position is P mid , then, when the first focus adjustment is completed, the focus position of the image acquisition device is P mid Adjust to (P mid -ΔP). If the focusing direction remains unchanged, then when the second adjustment is completed, the focal position of the image acquisition device is adjusted again to (P mid -2ΔP).
[0302] For example, in order to better understand a focusing method provided in an embodiment of the present application, a focusing method provided in an embodiment of the present application may include the following steps 71-79.
[0303] In this example, the focal length range of the image acquisition device is [0, P max ], the initial focal length position is the middle value P of the focal length range mid ; The focusing direction that increases the focal length position is the positive direction, the focusing direction that decreases the focal length position is the negative direction, and the focusing direction of the first focal length adjustment is the positive direction, wherein the above-mentioned positive direction and negative direction are opposite directions to each other; the preset step size is ΔP; the threshold value for determining the effective trend change of the image quality score is Pt, that is, the preset value is Pt.
[0304] Step 71: Determine the positive direction as the focus direction for the first focus adjustment, and adjust the focus position of the image acquisition device to P mid , and control the image acquisition device to adjust the focal length to P mid An image 1 of the target object is collected.
[0305] Step 72: Determine the image quality score of the image 1 acquired in step 71.
[0306] Step 73: Adjust the focal length position of the image acquisition device in the positive direction by ΔP, and control the image acquisition device to acquire an image 2 of the target object when the adjustment is completed.
[0307] Step 74: With respect to the adjustment in step 73, the image quality score of image 1 of the target object captured by the image acquisition device at the focal position before this adjustment is recorded as S1, and the image quality score S2 of image 2 captured in step 73 is determined.
[0308] Step 75: Based on the numerical relationship and difference between S1 and S2, determine the changing trend of the image quality score before and after the adjustment:
[0309] (1) If S2 is greater than S1 and |S2-S1| is greater than Pt, it is determined that the image quality score before and after the current adjustment has an upward trend, and the focus direction remains unchanged in the positive direction, and then the process returns to step 73;
[0310] (2) If |S2-S1| is not greater than Pt, it is determined that the change trend of the image quality score before and after the current adjustment is unchanged, and the focus direction is kept in the positive direction, and then the process returns to step 73;
[0311] (3) If S1 is greater than S2 and |S2-S1| is greater than Pt, it is determined that the trend of the image quality score before and after this adjustment is a decrease;
[0312] If |S2-S1| is not greater than Pt for the first time during the focal length adjustment process, the focal length position of the image acquisition device before this adjustment is determined as the optimal focal length position;
[0313] If |S2-S1| is greater than Pt for the first time during the focus adjustment process, step 76 is executed.
[0314] Step 76: Adjust the focus direction of the next focus adjustment to the opposite direction (negative direction) of the positive direction.
[0315] Step 77: Adjust the focal length position of the image acquisition device in the negative direction by ΔP, and control the image acquisition device to acquire image 3 of the target object when the adjustment is completed.
[0316] Step 78: With respect to the adjustment in step 77, the image quality score of the image of the target object captured by the image acquisition device at the focus position before this adjustment is recorded as S1, and the image quality score S2 of the image 3 captured in step 77 is determined.
[0317] Step 79: Based on the numerical relationship and difference between S1 and S2, determine the changing trend of the image quality score before and after this adjustment:
[0318] (1) If S2 is greater than S1 and |S2-S1| is greater than Pt, it is determined that the change trend of the image quality score before and after the current adjustment is an upward trend, and the condition direction remains in the negative direction, and then returns to step 77;
[0319] (2) If |S2-S1| is not greater than Pt, it is determined that the change trend of the image quality score before and after the current adjustment is unchanged, and the condition direction remains unchanged in the negative direction, and then returns to step 77;
[0320] (3) If S1 is greater than S2 and |S2-S1| is greater than Pt, it is determined that the image quality score before and after this adjustment has a downward trend, and this change in image quality score is not the first change, then the focal length position of the image acquisition device before this adjustment is determined as the optimal focal length position.
[0321] Corresponding to the focusing method provided in the above-mentioned embodiment of the present application, the embodiment of the present application also provides a focusing device, which includes a focusing module, and the focusing module is used to adjust the focus of the image acquisition device according to a preset step size starting from the initial focal length position of the image acquisition device until the optimal focal length position is determined. Figure 5 is a schematic structural diagram of the above-mentioned focusing module. As shown in Figure 5, the focusing module may include the following submodules:
[0322] a change trend determination submodule 501 for determining, in response to adjusting the focus position of the image acquisition device, a change trend of an image quality score of an image of a target object acquired by the image acquisition device before and after the adjustment; the image quality score is determined based on the image focus score and / or the algorithm processing score; the algorithm processing score is used to represent a processing effect obtained by performing algorithmic processing on the image;
[0323] A focus direction maintaining submodule 502 is configured to maintain the focus direction unchanged when the change trend is an upward trend;
[0324] A focus direction adjustment submodule 503 is configured to adjust the focus direction of the next focus adjustment when the change trend is downward and the image quality score change is the first change;
[0325] The optimal focus position determination submodule 504 is used to determine the focal length position before this adjustment as the optimal focus position when the change trend is downward and the change trend before and after the previous adjustment is upward, or when the change trend is downward and the image quality score change this time is not the first change.
[0326] As can be seen from the above, using the embodiments of the present application, when focusing an image acquisition device, the focus of the image acquisition device can be adjusted starting from an initial focal position according to a preset step size until an optimal focal position is determined. During this focus adjustment process, in response to adjusting the focal position of the image acquisition device, a changing trend in the image quality scores of images of the target object captured by the image acquisition device before and after the adjustment is determined, and the next focusing action is determined based on this changing trend.
[0327] Based on this, the focal position of the image acquisition device can be adjusted according to the changing trend of the image quality score of the image of the target object captured by the image acquisition device before and after the focal position adjustment, and the optimal focal position can be determined, thereby realizing automatic focus of the image acquisition device without using a distance sensor and without increasing the cost of the image acquisition device.
[0328] In other words, by applying the solution provided by the embodiments of the present application, it is possible to achieve automatic focus of an image acquisition device without utilizing a distance sensor. Therefore, it is unnecessary to install a distance sensor on the image acquisition device, thereby maintaining the cost of the image acquisition device and reducing the system complexity of the image acquisition device. Furthermore, because the image acquisition device can focus on a target object as the distance between the target object and the image acquisition device changes, the solution provided by the embodiments of the present application can be widely applied to scenarios such as long-distance photography, large depth of field, and real-time depth of field changes, as well as visual algorithm analysis.
[0329] In addition, since the image quality score is determined based on the image focus score and algorithm processing score of the image, the algorithm processing score is used to characterize the processing effect obtained by algorithmically processing the image. Therefore, applying the embodiment of the present application to focus the image acquisition device can also make the image captured by the focused image acquisition device have both a higher focusing effect and a better processing effect on the target object.
[0330] That is to say, by applying the solution provided in the embodiments of the present application, the image captured by the image acquisition device after focusing can have a high focusing effect, and the algorithmic processing of the target object in the above image can also achieve better processing effects. For example, while the above image has a high clarity, the difficulty of algorithmic processing of the above target object is reduced, and the accuracy of algorithmic recognition of the above target object is improved.
[0331] Optionally, in a specific implementation, the focal length range of the image acquisition device is pre-divided into at least two intervals; and the focusing module is specifically configured to:
[0332] Selecting an initial focal length position for each of the intervals, and starting from the initial focal length position selected for each of the intervals, adjusting the focal length of the image acquisition device according to a preset step size within each of the intervals until a local optimal focal length position within each of the intervals is determined;
[0333] Among the at least two determined local optimal focal length positions, the local optimal focal length position corresponding to the highest image quality score of the acquired image is determined as the optimal focal length position.
[0334] Optionally, in a specific implementation, the focusing module is specifically configured to:
[0335] Starting from an initial focal length position of the image acquisition device, the focus of the image acquisition device is adjusted according to a preset step length within a specified interval within the focal length range of the image acquisition device until an optimal focal length position is determined.
[0336] Optionally, in a specific implementation, the focusing module further includes:
[0337] An information acquisition submodule, used to obtain the initial focal length position of the image acquisition device and the focusing direction of the first focal length adjustment;
[0338] The focusing module is specifically configured to start from the initial focal length position and adjust the focal length of the image acquisition device according to the focusing direction and preset step length of the first focal length adjustment.
[0339] Optionally, in a specific implementation, the information acquisition submodule is specifically configured to:
[0340] Obtaining a preset initial focal length position of an image acquisition device and a preset focusing direction for a first focal length adjustment; or,
[0341] Obtain a historical optimal focal position of the image acquisition device as an initial focal position; compare the initial focal position with a middle position of a focal range of the image acquisition device; if the initial focal position is smaller than the middle position, increase the focusing direction of the adjusted focal position and determine it as the focusing direction for the first focal adjustment; if the initial focal position is larger than the middle position, decrease the focusing direction of the adjusted focal position and determine it as the focusing direction for the first focal adjustment.
[0342] Optionally, in a specific implementation, the device further includes:
[0343] a score determination module, configured to control the image acquisition device to capture an image of the target object when the focus position of the image acquisition device is the initial focus position and each time the focus adjustment is completed, and to determine an image focus score and an algorithm processing score of the image;
[0344] A score calculation module is used to calculate a first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight, and calculate the sum of the first product and the second product as the image quality score of the image.
[0345] Optionally, in a specific implementation, the device further includes:
[0346] a weight selection module, configured to select, before calculating a first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight, a target weight combination that matches the current application scenario of the image acquisition device from a plurality of preset mapping relationships between weight combinations and application scenarios; wherein each weight combination includes: an image focus weight and an algorithm processing weight;
[0347] The score calculation module is specifically used to calculate a first product of the image focus score and the image focus weight included in the target weight combination, and a second product of the algorithm processing score and the algorithm processing weight included in the target weight combination.
[0348] Optionally, in a specific implementation, the mapping relationship includes:
[0349] a mapping relationship between an application scenario for object processing for the target object and a first weight combination; wherein the image focusing weight included in the first weight combination is smaller than the algorithm processing weight; and
[0350] There is no mapping relationship between the image acquisition scene of the target object and the second weight combination; wherein the algorithm processing weight included in the second weight combination is 0.
[0351] Optionally, in a specific implementation, the score determination module includes:
[0352] a region determination submodule, configured to determine a region of interest in the image for algorithmic processing of the target object;
[0353] The score determination submodule is used to determine the image focus score and algorithm processing score of the region of interest.
[0354] Optionally, in a specific implementation, the region determination submodule is specifically configured to:
[0355] Object recognition is performed on the image, and the image region where the recognized detection frame including the target object is located is determined as a region of interest for algorithm processing regarding the target object.
[0356] Optionally, in a specific implementation, the change trend determination submodule 501 is specifically configured to:
[0357] In response to adjusting the focal length position of the image acquisition device, calculating a numerical relationship and a difference between image quality scores of images of the target object acquired by the image acquisition device before and after the adjustment;
[0358] If the difference is greater than a preset value and the numerical relationship indicates that the image quality score before the adjustment is less than the image quality score after the adjustment, it is determined that the change trend of the image quality score before and after the adjustment is an increase;
[0359] If the difference is greater than the preset value, and the numerical relationship indicates that the image quality score before the current adjustment is greater than the image quality score after the current adjustment, it is determined that the change trend of the image quality score before and after the current adjustment is a decrease;
[0360] If the difference is not greater than the preset value, it is determined that the change trend of the image quality score before and after the adjustment is unchanged;
[0361] The focusing direction maintaining submodule is further configured to maintain the focusing direction unchanged when the changing trend remains unchanged.
[0362] Optionally, in a specific implementation, the device further includes:
[0363] The numerical value adjustment module is used to determine an adjustment ratio based on the image acquisition device, and calculate the preset numerical value based on a preset reference value and the adjustment ratio.
[0364] Optionally, in a specific implementation,
[0365] The focus direction adjustment submodule 502 is specifically configured to adjust the focus direction for the next focus adjustment if the number of consecutive times the change trend is downward or both the change trends are downward reaches a specified number, and if the change trends have not been the same for the specified number of consecutive times before the current adjustment;
[0366] The optimal focus position determination submodule 503 is specifically used to determine the focal length position before the first adjustment of the specified number of consecutive adjustments including the current adjustment, when the change trend is downward and the change trends are both downward for a specified number of consecutive times, and the change trends have been the same for a specified number of consecutive times before the current adjustment.
[0367] Optionally, in a specific implementation, the device further includes:
[0368] A focus judgment module is used to judge whether the optimal focal length position meets the preset focus condition; if so, the device focus module is triggered; otherwise, the position traversal module is triggered;
[0369] The device focusing module is used to focus the image acquisition device according to the optimal focus position;
[0370] The position traversal module is used to traverse each focal length position in the focal length range of the image acquisition device, and determine the image quality score of the image captured by the image acquisition device when traversing to each focal length position;
[0371] A position updating module is used to update the optimal focal length position to: the focal length position of the image acquisition device when an image with the highest image quality score is acquired.
[0372] Optionally, in a specific implementation, the target object is a graphic identification code, the algorithm processing score includes: code reading score, and the processing effect includes but is not limited to: at least one of recognition success rate, recognition accuracy and recognition speed.
[0373] The embodiment of the present application further provides an electronic device, as shown in FIG6 , including:
[0374] Memory 601, used for storing computer programs;
[0375] The processor 602 is configured to implement any focusing method provided in the embodiments of the present application when executing the program stored in the memory 601 .
[0376] Furthermore, the electronic device may further include a communication bus and / or a communication interface, and the processor 602, the communication interface, and the memory 601 communicate with each other via the communication bus.
[0377] The communication bus mentioned in the electronic device mentioned above may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not mean that there is only one bus or only one type of bus.
[0378] The communication interface is used for communication between the above electronic device and other devices.
[0379] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.
[0380] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.
[0381] The above-mentioned electronic devices can be lens components, camera components, focus components and other components, as well as cameras, mobile phones, personal terminals, handheld guns and other devices of the above components.
[0382] In another embodiment provided in the present application, a computer-readable storage medium is further provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the steps of any of the above-mentioned focusing methods are implemented.
[0383] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any one of the focusing methods in the above embodiments.
[0384] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a solid-state drive (SSD).
[0385] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.
[0386] Each embodiment in this specification is described in a related manner. Similar portions between the various embodiments can be referenced to each other. Each embodiment focuses on the differences between the other embodiments. In particular, since the apparatus embodiments, electronic device embodiments, computer-readable storage medium embodiments, and computer program product embodiments are generally similar to the method embodiments, their descriptions are relatively simple. For related portions, reference can be made to the descriptions of the method embodiments.
[0387] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A focusing method, characterized in that: The method comprises: Starting from an initial focal length position of the image acquisition device, adjusting the focal length of the image acquisition device according to a preset step length until an optimal focal length position is determined; Wherein, in response to adjusting the focal position of the image acquisition device, determining a change trend of an image quality score of an image of a target object acquired by the image acquisition device before and after the adjustment; the image quality score is determined based on an image focus score and / or an algorithm processing score; the algorithm processing score is used to characterize a processing effect obtained by performing algorithm processing on the image; When the change trend is an upward trend, the focusing direction is kept unchanged; When the change trend is downward and the image quality score change is the first change, adjusting the focusing direction of the next focal length adjustment; When the change trend is downward and the change trend before and after the previous adjustment is upward, or when the change trend is downward and the image quality score change this time is not the first change, the focal position before this adjustment is determined as the optimal focal position.
2. The focusing method according to claim 1, characterized in that: Dividing the focal length range of the image acquisition device into at least two intervals in advance; Starting from an initial focal length position of the image acquisition device, adjusting the focal length of the image acquisition device according to a preset step length until an optimal focal length position is determined, comprises: Selecting an initial focal length position for each of the intervals, and starting from the initial focal length position selected for each of the intervals, adjusting the focal length of the image acquisition device according to a preset step length in each of the intervals until a local optimal focal length position in each of the intervals is determined; Among the at least two determined local optimal focal length positions, the local optimal focal length position corresponding to the highest image quality score of the acquired image is determined as the optimal focal length position.
3. The method according to claim 1, characterized in that Starting from an initial focal length position of the image acquisition device, adjusting the focal length of the image acquisition device according to a preset step length until an optimal focal length position is determined, comprises: Starting from an initial focal position of the image acquisition device, the focus of the image acquisition device is adjusted according to a preset step length within a specified interval within the focal range of the image acquisition device until an optimal focal position is determined.
4. The method according to claim 1, characterized in that: The step of adjusting the focal length of the image acquisition device according to a preset step length starting from an initial focal length position of the image acquisition device comprises: Obtaining an initial focal position of an image acquisition device and a focusing direction of a first focal adjustment; Starting from the initial focal length position, the focal length of the image acquisition device is adjusted according to the focusing direction and the preset step length of the first focal length adjustment.
5. The method according to claim 4, characterized in that The obtaining of the initial focal position of the image acquisition device and the focusing direction of the first focal adjustment comprises: Acquire a preset initial focal position of an image acquisition device and a preset focusing direction of a first focal adjustment; or, Acquire the best historical focal position of the image acquisition device as the initial focal position; compare the initial focal position with the middle position of the focal range of the image acquisition device; when the initial focal position is smaller than the middle position, increase the focusing direction of the adjusted focal position and determine it as the focusing direction of the first focal adjustment; when the initial focal position is larger than the middle position, decrease the focusing direction of the adjusted focal position and determine it as the focusing direction of the first focal adjustment.
6. The method according to claim 1, characterized in that The method further comprises: When the focal position of the image acquisition device is the initial focus position and each time the focus adjustment is completed, respectively controlling the image acquisition device to acquire an image of the target object, and determining an image focus score and an algorithm processing score of the image; A first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight are calculated, and a sum of the first product and the second product is calculated as the image quality score of the image.
7. The method according to claim 6, characterized in that Before calculating a first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight, the method further includes: Selecting a target weight combination that matches the current application scenario of the image acquisition device from a mapping relationship between a plurality of preset weight combinations and application scenarios; wherein each weight combination includes: an image focusing weight and an algorithm processing weight; The calculating a first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight, comprises: A first product of the image focus score and the image focus weight included in the target weight combination and a second product of the algorithm processing score and the algorithm processing weight included in the target weight combination are calculated.
8. The method according to claim 7, characterized in that The mapping relationship includes: a mapping relationship between an application scenario for object processing for the target object and a first weight combination; wherein the image focusing weight included in the first weight combination is less than the algorithm processing weight; and There is no mapping relationship between the image acquisition scene of the target object and the second weight combination; wherein the algorithm processing weight included in the second weight combination is 0.
9. The method according to claim 6, characterized in that Determining the image focus score and the algorithm processing score of the image includes: An algorithmically processed region of interest in the image is determined with respect to the target object, and an image focus score and an algorithmic processing score of the region of interest are determined.
10. The method according to claim 9, characterized in that The determining of an area of interest in the image for algorithmic processing of the target object comprises: Object recognition is performed on the image, and the image region where the recognized detection frame including the target object is located is determined as a region of interest for algorithm processing regarding the target object.
11. The method according to claim 1, characterized in that: In response to adjusting the focal length position of the image acquisition device, determining a change trend of an image quality score of an image of the target object acquired by the image acquisition device before and after the adjustment includes: In response to adjusting the focal length position of the image acquisition device, calculating the numerical relationship and difference between image quality scores of images of the target object acquired by the image acquisition device before and after the adjustment; When the difference is greater than a preset value and the numerical relationship indicates that the image quality score before the current adjustment is less than the image quality score after the current adjustment, it is determined that the change trend of the image quality score before and after the current adjustment is an increase; In the case where the difference is greater than the preset value, and the numerical relationship indicates that the image quality score before the current adjustment is greater than the image quality score after the current adjustment, it is determined that the change trend of the image quality score before and after the current adjustment is a decrease; In a case where the difference is not greater than the preset value, determining that the change trend of the image quality score before and after the current adjustment is unchanged; The method further includes: when the change trend is unchanged, keeping the focusing direction unchanged.
12. The method according to claim 11, characterized in that The method further comprises: Based on the image acquisition device, an adjustment ratio is determined, and based on a preset reference value and the adjustment ratio, the preset value is calculated.
13. The method according to claim 1, characterized in that When the change trend is downward and the image quality score change is the first change, adjusting the focus direction of the next focus adjustment includes: When the change trend is downward and the change trends are both downward for a specified number of consecutive times, and there has not been a situation where the change trends are the same for a specified number of consecutive times before the current adjustment, adjusting the focusing direction of the next focal length adjustment; In the case where the change trend is downward and the change trend before and after the previous adjustment is upward, determining the focal length position before the current adjustment as the optimal focal length position includes: When the number of consecutive times that the change trend is downward or the change trends are both downward reaches a specified number, and the change trends have been the same for a specified number of consecutive times before this adjustment, the focal length position before the first adjustment in the specified number of consecutive adjustments including this adjustment will be determined as the optimal focal length position.
14. The method according to claim 1, characterized in that The method further comprises: Determining whether the optimal focal length position meets a preset focusing condition; If satisfied, focusing the image acquisition device according to the optimal focus position; Otherwise, traversing each focal length position in the focal length range of the image acquisition device, and determining the image quality score of the image acquired by the image acquisition device when traversing to each focal length position; The optimal focal position is updated to: the focal position of the image acquisition device when an image with the highest image quality score is acquired.
15. The method according to any one of claims 1 to 14, characterized in that: The target object is a graphic recognition code, the algorithm processing score includes: code reading score, and the processing effect includes but is not limited to: at least one of recognition success rate, recognition accuracy rate and recognition speed.
16. A focusing device, characterized in that: The device comprises: A focusing module, used to adjust the focus of the image acquisition device according to a preset step length starting from the initial focus position of the image acquisition device until the optimal focus position is determined; wherein the focusing module includes: a change trend determination submodule, configured to determine, in response to adjusting the focal position of the image acquisition device, a change trend of an image quality score of an image of a target object acquired by the image acquisition device before and after the adjustment; the image quality score is determined based on an image focus score and / or an algorithm processing score; the algorithm processing score is used to characterize a processing effect obtained by performing algorithm processing on the image; A focusing direction maintaining submodule, used for maintaining the focusing direction unchanged when the changing trend is an upward trend; A focus direction adjustment submodule, used for adjusting the focus direction of the next focus adjustment when the change trend is downward and the image quality score change this time is the first change; The optimal focus position determination submodule is used to determine the focal position before this adjustment as the optimal focal position when the change trend is downward and the change trend before and after the previous adjustment is upward, or when the change trend is downward and the image quality score change this time is not the first change.
17. The focusing device according to claim 16, characterized in that: The focal length range of the image acquisition device is pre-divided into at least two intervals; the focusing module is specifically used for: Selecting an initial focal length position for each of the intervals, and starting from the initial focal length position selected for each of the intervals, adjusting the focal length of the image acquisition device according to a preset step length in each of the intervals until a local optimal focal length position in each of the intervals is determined; Among the at least two determined local optimal focal length positions, the local optimal focal length position corresponding to the highest image quality score of the acquired image is determined as the optimal focal length position.
18. The device according to claim 16, characterized in that The focusing module is specifically used for: Starting from an initial focal position of the image acquisition device, the focus of the image acquisition device is adjusted according to a preset step length within a specified interval within the focal range of the image acquisition device until an optimal focal position is determined.
19. The device according to claim 16, characterized in that The focusing module also includes: An information acquisition submodule, used to acquire an initial focal position of an image acquisition device and a focusing direction of a first focal adjustment; The focusing module is specifically used to start from the initial focal length position and adjust the focal length of the image acquisition device according to the focusing direction and preset step length of the first focal length adjustment.
20. The device according to claim 19, characterized in that The information acquisition submodule is specifically used for: Obtaining a preset initial focal position of an image acquisition device and a preset focusing direction of a first focal adjustment; or, Acquire the best historical focal position of the image acquisition device as the initial focal position; compare the initial focal position with the middle position of the focal range of the image acquisition device; when the initial focal position is smaller than the middle position, increase the focusing direction of the adjusted focal position and determine it as the focusing direction of the first focal adjustment; when the initial focal position is larger than the middle position, decrease the focusing direction of the adjusted focal position and determine it as the focusing direction of the first focal adjustment.
21. The device according to claim 16, characterized in that The device also includes: A score determination module, used to control the image acquisition device to acquire an image of the target object when the focus position of the image acquisition device is the initial focus position and each time the focus adjustment is completed, and to determine the image focus score and the algorithm processing score of the image; A score calculation module is used to calculate a first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight, and calculate the sum of the first product and the second product as the image quality score of the image.
22. The device according to claim 15, characterized in that The device also includes: A weight selection module, used for selecting a target weight combination matching the current application scenario of the image acquisition device from a mapping relationship between a plurality of preset weight combinations and application scenarios before calculating a first product of the image focus score and a preset image focus weight, and a second product of the algorithm processing score and a preset algorithm processing weight; wherein each weight combination includes: an image focus weight and an algorithm processing weight; The score calculation module is specifically used to calculate a first product of the image focus score and the image focus weight included in the target weight combination, and a second product of the algorithm processing score and the algorithm processing weight included in the target weight combination.
23. The device according to claim 22, characterized in that The mapping relationship includes: a mapping relationship between an application scenario for object processing for the target object and a first weight combination; wherein the image focusing weight included in the first weight combination is less than the algorithm processing weight; and There is no mapping relationship between the image acquisition scene of the target object and the second weight combination; wherein the algorithm processing weight included in the second weight combination is 0.
24. The device according to claim 21, characterized in that The score determination module comprises: A region determination submodule, used to determine a region of interest in the image for algorithm processing with respect to the target object; The score determination submodule is used to determine the image focus score and algorithm processing score of the region of interest.
25. The device according to claim 24, characterized in that The region determination submodule is specifically used for: Object recognition is performed on the image, and the image region where the recognized detection frame including the target object is located is determined as a region of interest for algorithm processing regarding the target object.
26. The device according to claim 16, characterized in that The change trend determination submodule is specifically used for: In response to adjusting the focal length position of the image acquisition device, calculating the numerical relationship and difference between image quality scores of images of the target object acquired by the image acquisition device before and after the adjustment; When the difference is greater than a preset value and the numerical relationship indicates that the image quality score before the current adjustment is less than the image quality score after the current adjustment, it is determined that the change trend of the image quality score before and after the current adjustment is an increase; In the case where the difference is greater than the preset value, and the numerical relationship indicates that the image quality score before the current adjustment is greater than the image quality score after the current adjustment, it is determined that the change trend of the image quality score before and after the current adjustment is a decrease; If the difference is not greater than the preset value, it is determined that the change trend of the image quality score before and after the adjustment is unchanged; The focusing direction maintaining submodule is further used to maintain the focusing direction unchanged when the changing trend remains unchanged.
27. The device according to claim 26, characterized in that The device also includes: The numerical value adjustment module is used to determine the adjustment ratio based on the image acquisition device, and calculate the preset numerical value based on a preset reference value and the adjustment ratio.
28. The device according to claim 16, characterized in that The focus direction adjustment submodule is specifically used to adjust the focus direction of the next focal length adjustment when the change trend is downward and the change trends are both downward for a specified number of consecutive times, and the change trends have not been the same for a specified number of consecutive times before the current adjustment; The optimal focus position determination submodule is specifically used to determine the focal length position before the first adjustment of the consecutive specified number of adjustments including the current adjustment, when the consecutive number of times the change trend is downward and the change trends are both downward reaches a specified number, and the change trends have been the same for a consecutive specified number of times before the current adjustment.
29. The device according to claim 16, characterized in that The device also includes: A focus judgment module, used to judge whether the optimal focal length position meets the preset focus condition; if so, trigger the device focus module, otherwise, trigger the position traversal module; The device focusing module is used to focus the image acquisition device according to the optimal focusing position; The position traversal module is used to traverse each focal length position in the focal length range of the image acquisition device, and when traversing to each focal length position, determine the image quality score of the image acquired by the image acquisition device; The position updating module is used to update the optimal focal position to: the focal position of the image acquisition device when an image with the highest image quality score is acquired.
30. The device according to any one of claims 16 to 29, characterized in that The target object is a graphic recognition code, the algorithm processing score includes: code reading score, and the processing effect includes but is not limited to: at least one of recognition success rate, recognition accuracy rate and recognition speed.
31. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-15 when executing a program stored in a memory.
32. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 15 is implemented.
33. A computer program product comprising instructions, characterized in that When the computer program product is run on a computer, the computer is enabled to execute the method according to any one of claims 1 to 15.
Citation Information
Patent Citations
Focusing method and device, electronic equipment and storage medium
CN117319798A
Focusing method and device and storage medium
CN113364986A
Automatic focusing method and device, electronic equipment and storage medium
CN116723398A
Automatic focusing device
CN219678601U
Imaging apparatus and control method of the same
JP2019066542A
Cited By
Automatic focusing method and device
CN120751255A