A focusing method, device, electronic device and storage medium

By detecting whether the focus position is an interfering object and updating the weight value, the problem of poor anti-interference ability of preset point focus in the prior art is solved, and a more accurate focus effect is achieved.

CN118695094BActive Publication Date: 2024-11-19ZHEJIANG DAHUA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411157861.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-21
Publication Date
2024-11-19
Estimated Expiration
2044-08-21

AI Technical Summary

Technical Problem

In the prior art, the anti-interference ability of preset point focus is poor, and it is easy to cause inaccurate focus due to the interference, focusing on the interference rather than the target object.

Method used

By acquiring the image of the focus motor at each position, determining the definition evaluation value based on the preset weight value, detecting whether the focus position is an interfering object, and if so, reducing the weight of the interfering object area, performing secondary focus to determine the focus position of the target object .

Benefits of technology

Improves the accuracy of focus and ensures that the target object can be clearly focused in the presence of interference.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118695094B_ABST
    Figure CN118695094B_ABST
Patent Text Reader

Abstract

The present application discloses a focusing method, device, electronic device and storage medium. First, the first focusing is performed according to a pre-set first weight value, that is, after acquiring the images collected by the Focus motor at each focus position, the first clarity evaluation value of each image is determined according to the first weight value, and then the first focus position of the Focus motor corresponding to the peak value in each first clarity evaluation value is determined. The second focus position of the Focus motor corresponding to the target object is pre-calibrated, and according to the first focus position difference between the second focus position and the first focus position, the first focus position is detected as the focus position corresponding to the interference object, the weight of the area where the interference object is located is reduced, and the second weight value is obtained, and then the second focus is performed according to the second weight value to determine the target focus position of the target object. The present application updates the weight and performs secondary focusing in the presence of interference objects to improve the accuracy of focusing on the target object.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of camera focusing technology, and in particular to a focusing method, device, electronic device and storage medium. Background Art

[0002] The focusing strategy commonly used in engineering applications is: after the position of the Zoom motor is fixed, the lens is driven to traverse all possible focusing positions by driving the Focus motor, analyzing the collected image information at each focusing position, and finally returning to the optimal focusing position.

[0003] Preset point focusing is a very important mode in the field of focusing, and is widely used in solutions such as power inspection, intelligent tracking, and traffic management. In preset point focusing, the position of the target object is fixed, and the camera's pan / tilt angle and other information are pre-configured to focus on the target object. The problem with the prior art is that the preset point focusing has poor anti-interference ability. Once there is an interference object between the camera and the target object, the interference object partially blocks the target object. At this time, it is very likely to focus on the interference object, so that after focusing is completed, the interference object is clear but the target object is not clear, that is, the prior art has the problem of inaccurate focusing. Summary of the invention

[0004] The present application provides a focusing method, device, electronic device and storage medium to solve the problem of inaccurate focusing in the prior art.

[0005] In a first aspect, the present application provides a focusing method, the method comprising:

[0006] Acquire images containing the target object captured by the focus motor at each focus position, and determine a first clarity evaluation value of each image according to a preset first weight value; determine a first focus position of the focus motor corresponding to a peak value in each first clarity evaluation value;

[0007] Determine whether the first focus position is the focus position corresponding to the interference object according to the difference between the second focus position of the focus motor corresponding to the target object and the first focus position; if yes, reduce the weight of the area where the interference object is located to obtain a second weight value;

[0008] According to the second weight value, the second clarity evaluation value of each of the images is determined, and the target focus position for focusing on the target object is determined according to the focus position of the focus motor corresponding to the peak value in each of the second clarity evaluation values.

[0009] In a second aspect, the present application provides a focusing device, the device comprising:

[0010] A first determination module is used to obtain images containing the target object captured by the focus motor at each focus position, and determine the first clarity evaluation value of each image according to a preset first weight value; and determine the first focus position of the focus motor corresponding to the peak value in each first clarity evaluation value;

[0011] A second determination module is used to determine whether the first focus position is the focus position corresponding to the interference object according to the difference between the second focus position of the focus motor corresponding to the target object and the first focus position of the first focus position that is pre-calibrated; if yes, reduce the weight of the area where the interference object is located to obtain a second weight value;

[0012] The third determination module is used to determine the second clarity evaluation value of each of the images according to the second weight value, and determine the target focus position for focusing on the target object according to the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value.

[0013] In a third aspect, the present application provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;

[0014] Memory, used to store computer programs;

[0015] The processor is used to implement the method steps when executing the program stored in the memory.

[0016] In a fourth aspect, 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, the method steps described are implemented.

[0017] The present application provides a focusing method, device, electronic device and storage medium, the method comprising: acquiring images containing a target object captured by a focusing motor at various focusing positions, and determining a first clarity evaluation value of each image according to a preset first weight value; determining a first focusing position of the focusing motor corresponding to a peak value in each first clarity evaluation value; determining whether the first focusing position is a focusing position corresponding to an interference object according to a pre-calibrated second focusing position of the focusing motor corresponding to the target object and a first focusing position difference between the first focusing position and a second focusing position; if so, reducing the weight of the area where the interference object is located to obtain a second weight value; determining a second clarity evaluation value of each image according to the second weight value, and determining a target focusing position for focusing on the target object according to the focusing position of the focusing motor corresponding to the peak value in each second clarity evaluation value.

[0018] The above technical solution has the following advantages or beneficial effects:

[0019] In the present application, the first focusing is first performed according to a pre-set first weight value, that is, after acquiring the images collected by the Focus motor at each focus position, the first clarity evaluation value of each image is determined according to the first weight value, and then the first focus position of the Focus motor corresponding to the peak value in each first clarity evaluation value is determined. The second focus position of the Focus motor corresponding to the target object is pre-calibrated, and according to the first focus position difference between the second focus position and the first focus position, it is detected whether the first focus position is the focus position corresponding to the interference object. If so, the weight of the area where the interference object is located is reduced to obtain the second weight value, and then the second focus is performed according to the second weight value to determine the target focus position of the target object. In the solution provided in the present application, whether there is an interference object is detected according to the focus position of the Focus motor, and the weight is updated and the second focus is performed in the presence of an interference object to improve the accuracy of focusing on the target object. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0021] Figure 1 A schematic diagram of the focusing process provided for this application;

[0022] Figure 2 A schematic diagram of an object distance curve provided for this application;

[0023] Figure 3 A schematic diagram of a target object being blocked by an interfering object provided in this application;

[0024] Figure 4 A schematic diagram showing the effect of different fill light type information provided in this application on the object distance curve;

[0025] Figure 5 The influence of different shooting temperature information provided by this application on the object distance curve;

[0026] Figure 6 A schematic diagram of a focus curve provided by the present application when there are no interferences;

[0027] Figure 7 A schematic diagram of a focus curve when interference is present provided by the present application;

[0028] Figure 8 Focus flow chart provided for this application;

[0029] Fig. 9 A schematic diagram of the focusing device structure provided in this application;

[0030] Fig.10 This is a schematic diagram of the electronic device structure provided in this application. DETAILED DESCRIPTION

[0031] In order to make the purpose and implementation method of the present application clearer, the exemplary implementation method of the present application will be clearly and completely described below in conjunction with the drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only part of the embodiments of the present application, rather than all the embodiments.

[0032] It should be noted that the brief description of terms in this application is only for the convenience of understanding the embodiments described below, and is not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their common and usual meanings.

[0033] The terms "first", "second", "third", etc. in the specification and claims of this application and the above drawings are used to distinguish similar or similar objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise noted. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances.

[0034] The terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device comprising a list of components is not necessarily limited to all the components expressly listed but may include other components not expressly listed or inherent to such product or device.

[0035] The term "module" refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic or combination of hardware and / or software code that is capable of performing the functions associated with that element.

[0036] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

[0037] For the convenience of explanation, the above description has been made in conjunction with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or limit the embodiments to the specific forms disclosed above. Based on the above teachings, various modifications and variations can be obtained. The selection and description of the above embodiments are to better explain the principles and practical applications, so that those skilled in the art can better use the embodiments and various different variations of the embodiments suitable for specific use considerations.

[0038] Figure 1 A schematic diagram of the focusing process provided for this application, the process includes the following steps:

[0039] S101: Acquire images containing the target object captured by the focus motor at various focus positions, determine a first clarity evaluation value of each image according to a preset first weight value; and determine a first focus position of the focus motor corresponding to a peak value in each first clarity evaluation value.

[0040] S102: Determine whether the first focus position is the focus position corresponding to the interference object based on the difference between the second focus position of the focus motor corresponding to the target object and the first focus position; if so, reduce the weight of the area where the interference object is located to obtain a second weight value.

[0041] S103: Determine the second clarity evaluation value of each of the images according to the second weight value, and determine the target focus position for focusing on the target object according to the focus position of the focus motor corresponding to the peak value in each of the second clarity evaluation values.

[0042] The focusing method provided in the present application is applied to an electronic device, which may be a PC, a tablet computer, or a focusing device itself. The focusing device is, for example, an image acquisition device such as a camera for focusing, including but not limited to a tilt-shift camera, an infrared camera, a face monitoring camera, a pan-tilt zoom camera, etc.

[0043] The focusing method provided in the present application includes a preset point focusing method. Preset point focusing means that the position of the target object to be focused is fixed, and the pan / tilt parameters of the focusing device and the position of the zoom motor are pre-calibrated when the focusing device is clearly focused on the target object. During calibration, the focus position of the focus motor when the focusing device is clearly focused on the target object is also calibrated. However, due to interference such as environmental factors or aging of the focusing device, the focus position of the calibrated focus motor may not be the clearest focus position of the target object, so a focusing process is required.

[0044] During the focusing process of the focusing device, the pan / tilt parameters and the position of the zoom motor are adjusted according to the calibrated pan / tilt parameters of the focusing device, the position of the zoom motor, etc., and then the image containing the target object captured by the focus motor of the focusing device at each focus position is obtained. The purpose of focusing is to maximize the clarity of the target object in the image. Optionally, the focusing device can traverse each focus position from any focus position of the focus motor, and capture an image containing the target object at each focus position.

[0045] For each image, a first clarity evaluation value of the image is determined according to a preset first weight value. It should be noted that when determining the first clarity evaluation value of the image, the image is first divided into sub-images according to a preset division rule, and then the clarity evaluation values ​​of each sub-image are determined, and then the first clarity evaluation value of the image is determined according to the clarity evaluation values ​​of each sub-image and the preset first weight value. Among them, the preset first weight value is the weight value corresponding to each sub-image, and the first clarity evaluation value of the image can be determined by weighted summation according to the clarity evaluation values ​​of each sub-image and the preset first weight value. Optionally, the preset weight values ​​corresponding to each sub-image can be the same or different. When determining the clarity evaluation value of each sub-image, the clarity evaluation value of each sub-image can be determined according to a preset clarity evaluation function. The clarity evaluation function can be, for example, any one of a grayscale change function, a gradient function, and an image grayscale entropy function. Each pixel in the sub-image is processed by the clarity evaluation function, so that the clarity evaluation value of the sub-image can be obtained.

[0046] After determining the first clarity evaluation value of each image, determine the first focus position of the focus motor corresponding to the peak value in each first clarity evaluation value. In addition, obtain the second focus position of the focus motor when the pre-calibrated focus device is clearly focused on the target object. Determine the first focus position difference between the first focus position and the second focus position. Determine whether the first focus position is the focus position corresponding to the interference object based on the first focus position difference. Optionally, a focus position difference threshold a can be set in advance. If the first focus position difference is greater than the focus position difference threshold a, it can be considered that the first focus position is not the focus position corresponding to the clearest target object. At this time, it is determined that there is an interference object, that is, the first focus position is the focus position corresponding to the interference object. If the first focus position difference is not greater than the focus position difference threshold a, it can be considered that the first focus position is inconsistent with the second focus position due to interference such as environmental factors or aging of the focus device, rather than focusing on the interference object due to the presence of the interference object. At this time, it is determined that there is no interference object.

[0047] If it is determined that there is no interference, the focus motor of the focusing device focuses to the first focus position, and the focusing process ends. If it is determined that there is an interference, the weight of the area where the interference is located is reduced to obtain a second weight value. Optionally, the process of reducing the weight of the area where the interference is located to obtain the second weight value may be, for each sub-area, determining the third focus position corresponding to the peak value of the clarity evaluation value of the sub-image corresponding to the sub-area; if the difference between the third focus position and the second focus position of the second focus position is greater than a preset first threshold, the sub-area is determined to be the area where the interference is located, and the weight value corresponding to the sub-area is reduced; and the second weight value corresponding to each of the sub-areas is obtained. The preset first threshold may be a value set based on experience.

[0048] For example, the second focus position is 100, and the preset first threshold is 8. For each sub-region, the third focus position corresponding to the peak value of the clarity evaluation value of the sub-image corresponding to the sub-region is determined to be 110, 110-100=10>8, so the sub-region is determined to be the area where the interference is located, and the weight value corresponding to the sub-region is reduced. For another example, the third focus position corresponding to the peak value of the clarity evaluation value of the sub-image corresponding to the sub-region is determined to be 102, 102-100=2<8, so the sub-region is determined not to be the area where the interference is located, and the weight value corresponding to the sub-region is not reduced. Optionally, when reducing the weight value, it can be directly reduced to 0, that is, the second weight value obtained after the weight value corresponding to the sub-region is reduced is 0.

[0049] After determining the second weight value, the second clarity evaluation value of each image is determined according to the second weight value, and the target focus position of the focus target object is determined according to the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value. The process of determining the second clarity evaluation value of each image according to the second weight value is similar to the process of determining the first clarity evaluation value of each image according to the first weight value, and will not be repeated here.

[0050] In the present application, the first focusing is first performed according to the pre-set first weight value, that is, after acquiring the images collected by the Focus motor at each focus position, the first clarity evaluation value of each image is determined according to the first weight value, and then the first focus position of the Focus motor corresponding to the peak value in each first clarity evaluation value is determined. The second focus position of the Focus motor corresponding to the target object is pre-calibrated, and according to the first focus position difference between the second focus position and the first focus position, it is detected whether the first focus position is the focus position corresponding to the interference object. If so, the weight of the area where the interference object is located is reduced to obtain the second weight value, and then the second focus is performed according to the second weight value to determine the target focus position of the target object. In the solution provided in the present application, whether there is an interference object is detected according to the focus position of the Focus motor, and the weight is updated and the second focus is performed in the presence of interference objects to improve the accuracy of focusing on the target object.

[0051] In the present application, determining the first clarity evaluation value of each image according to the preset first weight value includes:

[0052] Divide the monitoring area into a plurality of sub-areas according to a preset rule, and pre-set a first weight value corresponding to each sub-area;

[0053] For each of the images, the sub-images corresponding to the sub-regions in the image are determined; and the first clarity evaluation value of the image is determined according to the clarity evaluation values ​​of the sub-images corresponding to the sub-regions and the first weight values ​​corresponding to the sub-regions.

[0054] The focusing device is set according to the calibrated pan / tilt parameters and the position of the Zoom motor, and the monitoring area is divided into multiple sub-areas according to the preset rules. The monitoring area refers to the display screen area where the monitoring scene is imaged in the focusing device. The preset rule is, for example, to evenly divide the monitoring area into a certain number of sub-areas, such as 3×3=9 sub-areas, or 5×5=25 sub-areas, etc.

[0055] The monitoring area is divided into multiple sub-areas according to preset rules, and the images contained in the sub-areas are called sub-images. The first weight values ​​corresponding to each sub-area are preset, wherein the first weight values ​​corresponding to each sub-area can be the same weight value or different weight values. For each image, the sub-image corresponding to each sub-area in the image is determined; the clarity evaluation value of each sub-image is determined, and the first clarity evaluation value of the image is calculated through weighted fusion according to the respective clarity evaluation values ​​and the respective corresponding first weight values.

[0056] In the present application, determining whether the first focus position is the focus position corresponding to the interference object according to the difference between the second focus position of the focus motor corresponding to the target object and the first focus position in advance; if yes, reducing the weight of the area where the interference object is located to obtain the second weight value includes:

[0057] Acquire the current first shooting state information and the second shooting state information when the second focus position of the focus motor corresponding to the target object is pre-calibrated; wherein the shooting state information includes shooting temperature information, fill light type information and filter state information;

[0058] If the first shooting state information and the second shooting state information are the same, if the first focus position difference between the second focus position and the first focus position is greater than a preset second threshold, and the object distance corresponding to the first focus position is a close object distance compared to the object distance corresponding to the second focus position, determine that the first focus position is the focus position corresponding to the interference object; reduce the weight of the area where the interference object is located to obtain a second weight value;

[0059] If the first focus position difference between the second focus position and the first focus position is not greater than a preset second threshold, or the object distance corresponding to the first focus position is far from the object distance corresponding to the second focus position, it is determined that the interference is invalid or there is no interference.

[0060] When the focusing device is currently focusing, the current first shooting status information is obtained, and the first shooting status information includes the current first shooting temperature information, the first fill light type information, and the first filter status information. In addition, the second shooting status information is obtained when the second focus position of the focusing motor corresponding to the pre-calibrated target object is obtained, and the second shooting status information includes the current second shooting temperature information, the second fill light type information, and the second filter status information. The above-mentioned shooting temperature information includes the device temperature information of the focusing device, the fill light type information includes infrared fill light or visible fill light, and the filter status information includes day film status or night film status.

[0061] If the first shooting state information and the second shooting state information are the same, that is, the first shooting temperature information, the first fill light type information, the first filter state information, and the second shooting temperature information, the second fill light type information, and the second filter state information are all the same, it is determined that the current situation is that the direction of the clear point cannot be determined. At this time, the following two conditions are used to determine whether there is an interference object. Condition 1: The difference between the first focus position of the second focus position and the first focus position is greater than the preset second threshold. The preset second threshold can be a value set based on experience, and the preset second threshold and the preset first threshold can be the same or different. Condition 2: The object distance corresponding to the first focus position is a close object distance compared to the object distance corresponding to the second focus position. There is a corresponding relationship between the focus position and the object distance. For example, a small focus position corresponds to a large object distance. Therefore, it can be determined whether the current focus position is a close object distance or a long object distance based on the size of the focus position. When the above two conditions are met at the same time, the first focus position is determined to be the focus position corresponding to the interference object. Then the weight of the area where the interference object is located is reduced to obtain a second weight value. According to the second weight value, the second clarity evaluation value of each image is determined, and the target focus position of the focus target object is determined according to the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value.

[0062] In the present application, determining whether the first focus position is the focus position corresponding to the interference object according to the difference between the second focus position of the focus motor corresponding to the target object and the first focus position in advance; if yes, reducing the weight of the area where the interference object is located to obtain the second weight value includes:

[0063] Acquire current first shooting state information and second shooting state information when a second focus position of the focus motor corresponding to the target object is pre-calibrated;

[0064] If the first shooting state information and the second shooting state information are different, and the focusing direction is determined to be a far object distance direction compared to the second focusing position according to the first shooting state information and the second shooting state information;

[0065] If a first focus position difference between the second focus position and the first focus position is greater than a preset third threshold, and the object distance corresponding to the first focus position is a close object distance compared to the object distance corresponding to the second focus position, determine that the first focus position is a focus position corresponding to the interference object; reduce the weight of the area where the interference object is located to obtain a second weight value;

[0066] If the first focus position difference between the second focus position and the first focus position is not greater than a preset third threshold, or the object distance corresponding to the first focus position is far from the object distance corresponding to the second focus position, it is determined that the interference is invalid or there is no interference.

[0067] There is a corresponding relationship between the influence of different ambient temperatures on the focus position deviation, the influence of different fill light type information on the focus position deviation, and the influence of different filter status information on the focus position deviation. The above corresponding relationship is generally related to the model of the focusing device, and the above corresponding relationship can be determined according to the model of the focusing device.

[0068] If the first shooting state information and the second shooting state information are different, the position deviation value and the focusing direction affected by the change of the shooting state information can be determined according to the above corresponding relationships. The focusing direction includes the far object distance direction and the near object distance direction.

[0069] If the first shooting state information and the second shooting state information are different, and the focus direction is determined to be a far object distance direction compared to the second focus position according to the first shooting state information and the second shooting state information. It is determined that the current situation is that the clear point direction can be determined, and the clear point direction is a far object distance direction. At this time, it is determined whether there is an interference object by the following two conditions. Condition 1: The first focus position difference between the second focus position and the first focus position is greater than the preset third threshold. The preset third threshold is, for example, data set based on experience, and the preset third threshold and the preset first threshold can be the same or different. Condition 2: The object distance corresponding to the first focus position is a close object distance compared to the object distance corresponding to the second focus position. For example, the first focus position is 120 and the second focus position is 100. At this time, the object distance corresponding to the first focus position is a close object distance compared to the object distance corresponding to the second focus position. When the above two conditions are met at the same time, the first focus position is determined to be the focus position corresponding to the interference object. Then the weight of the area where the interference object is located is reduced to obtain a second weight value. According to the second weight value, the second clarity evaluation value of each image is determined, and the target focus position of the focus target object is determined according to the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value.

[0070] In this application, the method further includes:

[0071] Acquire current first shooting state information and second shooting state information when a second focus position of the focus motor corresponding to the target object is pre-calibrated;

[0072] If the first shooting state information and the second shooting state information are different, and the focusing direction is determined to be a close object distance direction compared to the second focusing position according to the first shooting state information and the second shooting state information;

[0073] If there are two focusing extreme value points in the focusing process, and among the two focusing extreme value points, the extreme value point corresponding to the first focusing position is a near object distance extreme value point, and the first focusing position difference between the second focusing position and the first focusing position is greater than a preset fourth threshold, the first focusing position is determined to be the focusing position corresponding to the interference object; and the focusing position corresponding to the far object distance extreme value point among the two focusing extreme value points is used as the target focusing position for focusing on the target object;

[0074] If the extreme point corresponding to the first focus position is the extreme point of the far object distance, or the first focus position difference between the second focus position and the first focus position is not greater than a preset fourth threshold, it is determined that the interference is invalid or there is no interference.

[0075] If the first shooting state information and the second shooting state information are different, and the focusing direction is determined to be the near object distance direction compared to the second focusing position according to the first shooting state information and the second shooting state information. It is determined that the current situation is that the clear point direction can be determined, and the clear point direction is the near object distance direction. At this time, it is determined whether there is an interference object by the following two conditions. Condition 1: There are two focus extreme points in the focusing process, and among the two focus extreme points, the extreme point corresponding to the first focus position is the near object distance extreme point. It should be noted that the extreme point refers to the extreme point of the clarity evaluation value. Condition 2: The first focus position difference between the second focus position and the first focus position is greater than the preset fourth threshold. The preset fourth threshold is, for example, a value set according to experience, and the preset fourth threshold and the preset first threshold can be the same or different. When the above two conditions are met at the same time, the first focus position is determined to be the focus position corresponding to the interference object. At this time, there is no need to update the weight, and the focus position corresponding to the far object distance extreme point in the two focus extreme points is directly used as the target focus position for focusing the target object.

[0076] For example, the focusing direction is determined to be the near object distance direction compared to the second focusing position according to the first shooting state information and the second shooting state information. The first focusing position is 28, the second focusing position is 10, and the preset fourth threshold is 5. That is, there are two extreme focus points in the focusing process, and the extreme point corresponding to the first focusing position is the near object distance extreme point; and the first focusing position difference between the second focusing position and the first focusing position is greater than the preset fourth threshold, at this time, the first focusing position is determined to be the focusing position corresponding to the interference object. Then the second focusing position is used as the target focusing position for focusing the target object.

[0077] In the present application, determining the target focus position for focusing on the target object according to the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value includes:

[0078] Determine a third focus position difference between the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value and the second focus position, and if the third focus position difference is less than a preset fifth threshold, determine the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value as the target focus position for focusing on the target object; wherein the fifth threshold is determined according to the current first shooting state information and the second shooting state information when the second focus position of the focus motor corresponding to the target object is pre-calibrated;

[0079] The method further comprises:

[0080] If the third focus position difference is not less than the fifth threshold, the second focus position is determined as a target focus position for focusing on the target object.

[0081] After determining the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value, determine the third focus position difference between the focus position and the second focus position, and then compare the third focus position difference with the preset fifth threshold value, and determine whether the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value is an accurate focus position according to the comparison result. If the third focus position difference is less than the preset fifth threshold value, it is determined that the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value is an accurate focus position. At this time, the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value is determined as the target focus position for focusing on the target object.

[0082] If the third focus position difference is not less than the preset fifth threshold, it is determined that the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value is not an accurate focus position. At this time, the second focus position is determined as the target focus position for focusing on the target object.

[0083] Wherein, the preset fifth threshold is determined according to the current first shooting state information and the second shooting state information when the second focus position of the focus motor corresponding to the target object is pre-calibrated. Optionally, according to the corresponding relationship between the first shooting temperature information, the second shooting temperature information and the influence of different ambient temperatures on the focus position deviation, the first position deviation value is determined; according to the corresponding relationship between the first fill light type information, the second fill light type information and the influence of different fill light type information on the focus position deviation, the second position deviation value is determined; according to the corresponding relationship between the first filter state information, the second filter state information and the influence of different filter state information on the focus position deviation, the third position deviation value is determined. Assign corresponding weight values ​​to the first position deviation value, the second position deviation value and the third position deviation value respectively. For example, the first position deviation value is △ 1 , the second position deviation value is △ 2 , the third position deviation value is △ 3 The weight value corresponding to the first position deviation value is α, the weight value corresponding to the second position deviation value is β, and the weight value corresponding to the third position deviation value is γ, then the preset fifth threshold thrd=α△ 1 +β△ 2 +γ△ 3 .

[0084] In the present application, when acquiring images containing the target object captured by the focus motor at various focus positions, it is possible to obtain the current first shooting status information and the second shooting status information when the second focus position of the focus motor corresponding to the target object is pre-calibrated, and determine the focusing direction according to the first shooting status information and the second shooting status information; adjust the focus motor to the second focus position, focus according to the focusing direction, and acquire images containing the target object at various focus positions.

[0085] In the present application, the current first shooting state information and the second shooting state information when the second focus position of the focus motor corresponding to the target object is pre-calibrated are obtained. The focus position deviation value is determined according to the first shooting state information and the second shooting state information. Among them, the focus position deviation value includes a specific value and a deviation direction, and the deviation direction includes a near object distance direction or a far object distance direction. There is a corresponding relationship between the focus position of the focus motor and the object distance. The focus direction can be determined according to the deviation direction.

[0086] The focusing solution provided in this application is described in detail below with reference to the accompanying drawings.

[0087] The focusing strategy commonly used in engineering applications is to analyze the collected image information, obtain the current focusing state of the focusing device, drive the Focus motor to drive the lens through all possible focusing positions, and finally return to the best focusing position. This focusing algorithm mainly relies on the object distance curve provided by the lens manufacturer when it leaves the factory. Figure 2 The object distance curve diagram provided for this application is as follows: Figure 2 As shown, the horizontal axis represents the Zoom motor position, and the vertical axis represents the Focus motor position. Figure 2 Different curves in the figure correspond to different object distance information. The bottom curve is the infinity (inf) curve, and the top curve corresponds to an object distance of 10 cm. The autofocus algorithm is that when the Zoom motor is determined, the focus algorithm actually keeps cutting the object distance, searching for the correct object distance of the target object, thereby determining the position of the Focus motor.

[0088] Preset point focusing is a very important mode in the field of focusing, which is widely used in power inspection, intelligent tracking, traffic management and other solutions. However, the anti-interference performance of preset point focusing has always been a problem. The main reason is that the current general focusing solution has a fixed weight, which cannot be updated to the interference of the actual monitoring environment changes. Finally, in these applications, the problem of focusing on the interference object occurs. Figure 3 The target object provided in this application is blocked by an interference object, such as Figure 3 As shown, the target object is partially blocked, and when the preset point is focused, the focus may be focused on the obstruction due to the appearance of multiple extreme values ​​in the focus curve. The present application proposes a method of identifying the focus object distance of the target weight area, combining the filter status information and the configuration information of the preset point itself, effectively identifying the interference area, and performing secondary fast focusing after updating the weight according to the interference area, so as to effectively improve the robustness of the preset point focusing.

[0089] Preset point: The pan / tilt and focus configuration point with target configured in advance by the user according to his / her own needs.

[0090] Object distance curve: also known as zoom following curve, usually a curve with a certain curvature. Usually lens manufacturers will provide this curve at different object distances when they leave the factory. Its physical meaning can be understood as that the Zoom motor and Focus motor are clear along this curve at a specified object distance, such as Figure 2 As shown in the figure, when the zoom is fixed, the closer the object distance is, the larger the focus position is. Generally, the lens imaging system will be affected by the filter status information (ICR switching), fill light type information and shooting temperature information, causing the focal plane to shift. Usually, this shift is certain and measurable. Figure 4 A schematic diagram showing the effect of different fill light type information provided in this application on the object distance curve, such as Figure 4As shown, the ICR switches to night film and has the infinity (inf) curve data size of the lens under infrared fill light and visible light. The infrared fill light causes the inf curve to shift toward the near end. Figure 5 The influence of different shooting temperature information provided by this application on the object distance curve, such as Figure 5 As shown, when the temperature is 70 degrees, the inf curve is shifted toward the proximal end compared to when the temperature is -40 degrees.

[0091] Focus curve: Auto focus is to continuously optimize the target image and drive the focus motor to adjust the focus to the best position. By calculating the clarity evaluation value at each focus motor position, a relationship curve between the focus motor position (focus motor position) and the clarity evaluation value (fv value) is formed, which is called the focus curve. The clearer the image, the larger the fv value. The peak value of the focus curve, maxfv, corresponds to the focus point, indicating that the focus motor is at the optimal imaging position. Figure 6 This is a schematic diagram of a focus curve when there is no interference provided in this application. When there is no interference, the only focus position can be found by searching for the maximum fv value. Figure 7 The present application provides a schematic diagram of a focus curve when an interference object is present. When an interference object appears, the focus curve has two extreme values, which may cause the automatic focusing algorithm to search for the wrong fv extreme value during the search process, so that the focus is not focused on the target object.

[0092] Figure 8 The focus flow chart provided for this application includes the following steps:

[0093] S201: Acquire current shooting temperature information, filter status information, fill light type information, and similar information when the preset point is generated. If there is a filter switch or a drastic temperature change, determine the clear focus direction of the correct target object through the filter status information, fill light type information, and shooting temperature information, and enter S202; otherwise, enter S204;

[0094] S202: If the focusing direction is determined to be the far object distance direction, if the motor that stopped last corresponds to the far object distance, it is determined that the interference is invalid or there is no interference. If the motor is interfered by the interference object and stays at the near object distance, the area whose extreme value characteristics meet the near object distance is removed, and the weight is re-assigned for secondary fast focusing;

[0095] S203: If the focus direction is determined to be the direction of the near object distance, then the actual clear point must be passed, and it is only necessary to compare the last stopped object distance with the two extreme object distances in the process. If they are consistent, it is determined that the interference is invalid or there is no interference. If they are inconsistent, the farther extreme point is used for direct correction;

[0096] S204: For the same filter, after focusing, the extreme point features are counted, including the extreme point focus position and weight information. According to the extreme point focus position, if the clear point where the focus stops this time is at a closer object distance, the weight of the area corresponding to the extreme point is reset to zero, and the original weights of other areas are retained, and the new weight information is used for secondary focusing;

[0097] S205: Perform a global judgment, add exception processing, and perform threshold thrd control. If the object distance of the focus stop deviates from the object distance when the preset point is configured by a large amount and exceeds thrd, it is considered abnormal and directly returns to the original configured object distance. The thrd is set based on the step difference between the visible light and infrared light curves of the focusing device under the corresponding zoom and the temperature offset data table of the focusing device corresponding to the current temperature deviation feature. The more stringent data is superimposed.

[0098] Optional, thrd = α△ 1 +β△ 2 +γ△ 3 ; The first position deviation value affected by temperature is △ 1 , the second position deviation value affected by the fill light type is △ 2 , the third position deviation value affected by the filter state is △ 3 The weight value corresponding to the first position deviation value is α, the weight value corresponding to the second position deviation value is β, and the weight value corresponding to the third position deviation value is γ.

[0099] The focusing method provided in the present application combines the judgment of preset point generation data and current data when performing preset point focusing, and performs focusing logic of classification processing, which scientifically and effectively improves the robustness and solves the current preset point focusing pain points. By judging the relevant data at the time of current and preset point generation, the classification processing of the preset point focusing scheme is realized, making this scheme more scientific and accurate. By judging the extreme points of the current focusing process, the identification of abnormal areas is realized, and secondary focusing is performed using the re-assignment of weights, which solves the current market pain points of preset point focusing. By reasonably classifying and superimposing the absolute abnormal threshold offset value generated, it is ensured that the preset point focusing will not directly affect the basic functions of the user, such as intelligence and other related performance.

[0100] Fig. 9 The schematic diagram of the focusing device structure provided for this application includes:

[0101] A first determination module 91 is used to obtain images containing the target object captured by the focus motor at each focus position, determine the first clarity evaluation value of each image according to a preset first weight value; and determine the first focus position of the focus motor corresponding to the peak value in each first clarity evaluation value;

[0102] A second determination module 92 is used to determine whether the first focus position is the focus position corresponding to the interference object according to the difference between the second focus position of the focus motor corresponding to the target object and the first focus position of the first focus position that is pre-calibrated; if yes, reduce the weight of the area where the interference object is located to obtain a second weight value;

[0103] The third determination module 93 is used to determine the second clarity evaluation value of each of the images according to the second weight value, and determine the target focus position for focusing on the target object according to the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value.

[0104] The first determination module 91 is used to divide the monitoring area into multiple sub-areas according to a preset rule, and pre-set the first weight value corresponding to each sub-area; for each image, determine the sub-image corresponding to each sub-area in the image; and determine the first clarity evaluation value of the image according to the clarity evaluation value of the sub-image corresponding to each sub-area and the first weight value corresponding to each sub-area.

[0105] The second determination module 92 is used to determine, for each of the sub-regions, a third focus position corresponding to a peak value of a clarity evaluation value of a sub-image corresponding to the sub-region; if a second focus position difference between the third focus position and the second focus position is greater than a preset first threshold, determine that the sub-region is an area where an interference object is located, and reduce a weight value corresponding to the sub-region; and obtain a second weight value corresponding to each of the sub-regions.

[0106] The second determination module 92 is used to obtain the current first shooting state information and the second shooting state information when the second focus position of the focus motor corresponding to the target object is pre-calibrated; wherein the shooting state information includes shooting temperature information, fill light type information and filter state information; if the first shooting state information is the same as the second shooting state information, if the first focus position difference between the second focus position and the first focus position is greater than a preset second threshold, and the object distance corresponding to the first focus position is a close object distance compared to the object distance corresponding to the second focus position, determine that the first focus position is the focus position corresponding to the interference object; reduce the weight of the area where the interference object is located to obtain a second weight value; wherein, if the first focus position difference between the second focus position and the first focus position is not greater than a preset second threshold, or the object distance corresponding to the first focus position is a long object distance compared to the object distance corresponding to the second focus position, determine that the interference is invalid or there is no interference.

[0107] The second determination module 92 is used to obtain the current first shooting state information and the second shooting state information when the second focus position of the focus motor corresponding to the target object is pre-calibrated; if the first shooting state information is different from the second shooting state information, and the focusing direction is determined to be a far object distance direction compared to the second focus position according to the first shooting state information and the second shooting state information; if the first focus position difference between the second focus position and the first focus position is greater than a preset third threshold, and the object distance corresponding to the first focus position is a close object distance compared to the object distance corresponding to the second focus position, the first focus position is determined to be the focus position corresponding to the interference object; the weight of the area where the interference object is located is reduced to obtain a second weight value; wherein, if the first focus position difference between the second focus position and the first focus position is not greater than the preset third threshold, or the object distance corresponding to the first focus position is a far object distance compared to the object distance corresponding to the second focus position, it is determined that the interference is invalid or there is no interference.

[0108] The second determination module 92 is further used to obtain the current first shooting state information and the second shooting state information when the second focus position of the focus motor corresponding to the target object is pre-calibrated; if the first shooting state information and the second shooting state information are different, and the focusing direction is determined to be the near object distance direction compared to the second focus position according to the first shooting state information and the second shooting state information; if there are two focus extreme points in the focusing process, and among the two focus extreme points, the extreme point corresponding to the first focus position is the near object distance extreme point, and the first focus position difference between the second focus position and the first focus position is greater than a preset fourth threshold, the first focus position is determined to be the focus position corresponding to the interference object; and the focus position corresponding to the far object distance extreme point among the two focus extreme points is used as the target focus position for focusing the target object; if the extreme point corresponding to the first focus position is the far object distance extreme point, or the first focus position difference between the second focus position and the first focus position is not greater than the preset fourth threshold, it is determined that the interference is invalid or there is no interference.

[0109] The third determination module 93 is used to determine the third focus position difference between the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value and the second focus position; if the third focus position difference is less than a preset fifth threshold, the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value is determined as the target focus position for focusing on the target object; wherein the fifth threshold is determined based on the current first shooting state information and the second shooting state information when the second focus position of the focus motor corresponding to the target object is pre-calibrated; if the third focus position difference is not less than the fifth threshold, the second focus position is determined as the target focus position for focusing on the target object.

[0110] The present application also provides an electronic device, such as Fig.10 As shown, it includes: a processor 301, a communication interface 302, a memory 303 and a communication bus 304, wherein the processor 301, the communication interface 302, and the memory 303 communicate with each other through the communication bus 304;

[0111] The memory 303 stores a computer program, and when the program is executed by the processor 301, the processor 301 executes any one of the above method steps.

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

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

[0114] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0115] The above-mentioned processor can be a general-purpose processor, including a central processing unit, a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.

[0116] The present application also provides a computer storage readable storage medium, wherein the computer readable storage medium stores a computer program executable by an electronic device, and when the program runs on the electronic device, the electronic device implements any of the above method steps when executing.

[0117] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.

[0118] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A focusing method, characterized in that: The method comprises: Acquire images containing the target object captured by the focus motor at each focus position, and determine a first clarity evaluation value of each image according to a preset first weight value; determine a first focus position of the focus motor corresponding to a peak value in each first clarity evaluation value; Determine whether the first focus position is the focus position corresponding to the interference object according to the difference between the second focus position of the focus motor corresponding to the target object and the first focus position; if yes, reduce the weight of the area where the interference object is located to obtain a second weight value; According to the second weight value, the second clarity evaluation value of each of the images is determined, and the target focus position for focusing on the target object is determined according to the focus position of the focus motor corresponding to the peak value in each of the second clarity evaluation values.

2. The method according to claim 1, characterized in that Determining the first clarity evaluation value of each image according to the preset first weight value includes: Divide the monitoring area into a plurality of sub-areas according to a preset rule, and pre-set a first weight value corresponding to each sub-area; For each of the images, the sub-images corresponding to the sub-regions in the image are determined; and the first clarity evaluation value of the image is determined according to the clarity evaluation values ​​of the sub-images corresponding to the sub-regions and the first weight values ​​corresponding to the sub-regions.

3. The method according to claim 2, characterized in that Reducing the weight of the area where the interferer is located to obtain a second weight value includes: For each of the sub-regions, determine a third focus position corresponding to a peak value of a clarity evaluation value of a sub-image corresponding to the sub-region; if a second focus position difference between the third focus position and the second focus position is greater than a preset first threshold, determine that the sub-region is an area where an interference object is located, and reduce a weight value corresponding to the sub-region; and obtain a second weight value corresponding to each of the sub-regions.

4. The method according to claim 1, characterized in that determining whether the first focus position is the focus position corresponding to the interference object according to the difference between the second focus position of the focus motor corresponding to the target object and the first focus position which is pre-calibrated; If yes, reducing the weight of the area where the interferer is located to obtain a second weight value includes: Acquire the current first shooting state information and the second shooting state information when the second focus position of the focus motor corresponding to the target object is pre-calibrated; wherein the shooting state information includes shooting temperature information, fill light type information and filter state information; If the first shooting state information and the second shooting state information are the same, if the first focus position difference between the second focus position and the first focus position is greater than a preset second threshold, and the object distance corresponding to the first focus position is a close object distance compared to the object distance corresponding to the second focus position, determine that the first focus position is the focus position corresponding to the interference object; reduce the weight of the area where the interference object is located to obtain a second weight value; If the first focus position difference between the second focus position and the first focus position is not greater than a preset second threshold, or the object distance corresponding to the first focus position is far from the object distance corresponding to the second focus position, it is determined that the interference is invalid or there is no interference.

5. The method according to claim 1, characterized in that determining whether the first focus position is the focus position corresponding to the interference object according to the difference between the second focus position of the focus motor corresponding to the target object and the first focus position which is pre-calibrated; If yes, reducing the weight of the area where the interferer is located to obtain a second weight value includes: Acquire current first shooting state information and second shooting state information when a second focus position of the focus motor corresponding to the target object is pre-calibrated; If the first shooting state information and the second shooting state information are different, and the focusing direction is determined to be a far object distance direction compared to the second focusing position according to the first shooting state information and the second shooting state information; If a first focus position difference between the second focus position and the first focus position is greater than a preset third threshold, and the object distance corresponding to the first focus position is a close object distance compared to the object distance corresponding to the second focus position, determine that the first focus position is a focus position corresponding to the interference object; reduce the weight of the area where the interference object is located to obtain a second weight value; If the first focus position difference between the second focus position and the first focus position is not greater than a preset third threshold, or the object distance corresponding to the first focus position is far from the object distance corresponding to the second focus position, it is determined that the interference is invalid or there is no interference.

6. The method according to claim 1, characterized in that The method further comprises: Acquire current first shooting state information and second shooting state information when a second focus position of the focus motor corresponding to the target object is pre-calibrated; If the first shooting state information and the second shooting state information are different, and the focusing direction is determined to be a close object distance direction compared to the second focusing position according to the first shooting state information and the second shooting state information; If there are two focusing extreme value points in the focusing process, and among the two focusing extreme value points, the extreme value point corresponding to the first focusing position is a near object distance extreme value point, and the first focusing position difference between the second focusing position and the first focusing position is greater than a preset fourth threshold, the first focusing position is determined to be the focusing position corresponding to the interference object; and the focusing position corresponding to the far object distance extreme value point among the two focusing extreme value points is used as the target focusing position for focusing on the target object; If the extreme point corresponding to the first focus position is the extreme point of the far object distance, or the first focus position difference between the second focus position and the first focus position is not greater than a preset fourth threshold, it is determined that the interference is invalid or there is no interference.

7. The method according to claim 1, characterized in that Determining the target focus position for focusing on the target object according to the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value includes: Determine a third focus position difference between the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value and the second focus position, and if the third focus position difference is less than a preset fifth threshold, determine the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value as the target focus position for focusing on the target object; wherein the fifth threshold is determined according to the current first shooting state information and the second shooting state information when the second focus position of the focus motor corresponding to the target object is pre-calibrated; The method further comprises: If the third focus position difference is not less than the fifth threshold, the second focus position is determined as a target focus position for focusing on the target object.

8. A focusing device, characterized in that: The device comprises: A first determination module is used to obtain images containing the target object captured by the focus motor at each focus position, and determine the first clarity evaluation value of each image according to a preset first weight value; and determine the first focus position of the focus motor corresponding to the peak value in each first clarity evaluation value; A second determination module is used to determine whether the first focus position is the focus position corresponding to the interference object according to the difference between the second focus position of the focus motor corresponding to the target object and the first focus position of the first focus position that is pre-calibrated; if yes, reduce the weight of the area where the interference object is located to obtain a second weight value; The third determination module is used to determine the second clarity evaluation value of each of the images according to the second weight value, and determine the target focus position for focusing on the target object according to the focus position of the focus motor corresponding to the peak value in each second clarity evaluation value.

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

10. 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 7 is implemented.