Determine the camera's focus position

By calculating the distance and mapping relationship in the PTZ camera using the target plane equation to calculate the distance and mapping relationship, the problem of time-consuming and target blur in the prior art is solved, and a fast and accurate focusing effect is achieved.

CN116193256BActive Publication Date: 2025-08-22HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310184881.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-17
Publication Date
2025-08-22
Estimated Expiration
2043-02-17

AI Technical Summary

Technical Problem

The prior art takes a long time to determine the focus position of the camera, making it difficult to accurately focus the moving target, especially when the target is relatively small in the image and is prone to focus on the background, resulting in blurring of the target.

Method used

By obtaining the horizontal rotation and vertical rotation angles of the PTZ camera, the target distance is determined using the target plane equation, and the focus position is calculated based on the mapping relationship to achieve fast and accurate focus.

Benefits of technology

The ability to quickly and accurately focus on moving targets in the image ensures clear targets, reduces focus time, avoids focusing on the background, and improves image clarity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116193256B_ABST
    Figure CN116193256B_ABST
Patent Text Reader

Abstract

In one embodiment, the present application provides a method, apparatus, and device for determining a focus position, the method comprising: obtaining a target deflection angle for horizontal rotation and a target pitch angle for vertical rotation of a PTZ camera; determining a target distance between a target to be detected and the PTZ camera based on the coordinates of the intersection between the direction vectors pointed to by the target deflection angle and the target pitch angle and the target plane equation; querying a configured mapping relationship based on the target distance to obtain a target focus position corresponding to the target distance; wherein the mapping relationship represents the relationship between distance and focus position; focusing the PTZ camera based on the target focus position, and after the PTZ camera is focused, capturing a target image of the target to be detected by the PTZ camera. Through the technical solution of the present application, the target to be detected can be accurately focused, the time spent searching for the target focus position is relatively short, and a clear focus position can be found, so that the target to be detected is clear.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing, and in particular to a method, apparatus, and device for determining a focus position of a camera. Background Art

[0002] A camera usually has a zoom (also called a magnification) function and a focus function. For example, a camera includes a zoom motor, a focus motor, a zoom lens and a focus lens. The zoom function is achieved by driving the zoom lens to move through the zoom motor, and the focus function is achieved by driving the focus lens to move through the focus motor.

[0003] When implementing the focusing function, the focus position must first be determined. Based on this focus position, the focus lens is driven to move to achieve the focusing function. To ensure image clarity, the AFD (autofocus image clarity evaluation parameter) statistical value is also required when determining the focus position. Based on the AFD statistical value, the focus lens is driven to oscillate near the clear focus position, gradually approaching the focus position with the maximum AFD statistical value. This focus position is also the focus position with the highest clarity. When the focus lens is driven to move to achieve the focusing function based on this focus position, a very clear image can be captured, thus ensuring image clarity.

[0004] However, in the above method, it takes a long time to search for the focus position, and the clearest focus position cannot be found for a moving target to be detected. In addition, the proportion of the target to be detected in the image is usually very small. When searching for the clearest focus position, the focus is usually on the background, and the target to be detected is relatively blurred. Summary of the Invention

[0005] The present application provides a method for determining a focus position, which is applied to a PTZ camera and includes:

[0006] Obtaining a target deflection angle for horizontal rotation and a target pitch angle for vertical rotation of the PTZ camera;

[0007] Determining a target distance between the target to be detected and the PTZ camera based on the coordinates of an intersection between a direction vector pointed by the target deflection angle and the target pitch angle and a target plane equation;

[0008] Querying a configured mapping relationship based on the target distance to obtain a target focus position corresponding to the target distance; wherein the mapping relationship represents a relationship between the distance and the focus position;

[0009] The PTZ camera is focused based on the target focus position. After the PTZ camera is focused, a target image of the target to be detected is collected by the PTZ camera.

[0010] It can be seen from the above technical solutions that in the embodiments of the present application, the target distance between the target to be detected and the PTZ camera can be determined based on the target plane equation, the target focus position can be determined based on the target distance between the target to be detected and the PTZ camera, and the PTZ camera can be focused based on the target focus position, so that the target to be detected can be accurately focused. The time consumption for searching the target focus position is relatively short, and a clear focus position can be found for a moving target to be detected. Even if the proportion of the target to be detected in the image is very small, when searching for a clear target focus position, it can be focused on the target to be detected and will not be focused on the background, that is, the target to be detected is clear, and the focus position can be accurately made to fall on the target to be detected, ensuring that the target to be detected is always in a clear state. The focus position of each point in the physical space can be accurately calculated. When the target to be detected appears in the picture, the clear focus position of the target to be detected can be calculated in real time, so that it can be focused quickly. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments of the present application or the description of the prior art. Obviously, the drawings described below are only some embodiments recorded in this application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings of the embodiments of the present application.

[0012] Figure 1 is a flow chart of a method for determining a focus position in one embodiment of the present application;

[0013] Figure 2 This is a schematic diagram of the process of constructing a plane equation in one embodiment of the present application;

[0014] Figure 3A This is a schematic diagram of image acquisition in one embodiment of the present application;

[0015] Figure 3B is a schematic diagram of an embodiment of the present application with ZOY as the cross section;

[0016] Figure 4 is a schematic diagram of a curve showing the relationship between focus position and distance in one embodiment of the present application;

[0017] Figure 5 is a schematic diagram of a sharpness score and a focus position in one embodiment of the present application;

[0018] Figure 6 This is a schematic diagram of a process for determining a focus position based on a plane equation in one embodiment of the present application. DETAILED DESCRIPTION

[0019] The terms used in the embodiments of this application are only for the purpose of describing specific embodiments and are not intended to limit this application. The singular forms "a," "the," and "the" used in this application and claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to any or all possible combinations of one or more associated listed items.

[0020] It should be understood that although the terms first, second, third, etc. may be used to describe various information in the embodiments of the present application, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" used may also be interpreted as "at the time of" or "when" or "in response to determining".

[0021] In the embodiment of the present application, a method for determining a focus position is proposed, which can be applied to a PTZ (Pan Tilt Zoom) camera (also known as a PTZ camera) or other types of cameras. Figure 1 FIG. 5 is a flow chart of the method, which may include:

[0022] Step 101: Obtain a target yaw angle for horizontal rotation of a PTZ camera (ie, an angle for horizontal rotation of the PTZ camera) and a target pitch angle for vertical rotation of the PTZ camera (ie, an angle for vertical rotation of the PTZ camera).

[0023] Step 102 : Determine the target distance between the target to be detected and the PTZ camera based on the coordinates of the intersection between the direction vectors pointed by the target deflection angle and the target pitch angle and the target plane equation.

[0024] Step 103 : querying a configured mapping relationship based on the target distance to obtain a target focus position corresponding to the target distance; wherein the mapping relationship represents a relationship between the distance and the focus position.

[0025] Step 104 : focusing the PTZ camera based on the target focus position. After the PTZ camera has focused, capturing a target image of the target to be detected by the PTZ camera.

[0026] In one possible embodiment, a target plane equation may also be obtained. The process of obtaining the target plane equation may include, but is not limited to: obtaining multiple sample space coordinates; wherein each sample space coordinate is obtained by: determining a first sample focus position based on a first sample distance between the sample target and the PTZ camera; searching for focus positions surrounding the first sample focus position to obtain a second sample focus position; determining a second sample distance based on the second sample focus position, and obtaining the sample space coordinates based on the second sample distance. After obtaining the multiple sample space coordinates, plane equation parameters may be determined based on the multiple sample space coordinates, and an initial plane equation may be determined based on the plane equation parameters. After obtaining the initial plane equation, the initial plane equation may be determined as the target plane equation; alternatively, the plane equation parameters of the initial plane equation may be corrected, and the corrected plane equation may be determined as the target plane equation.

[0027] Exemplarily, the pitch angle range of the PTZ camera may include multiple pitch angle intervals. For each pitch angle interval, the sample space coordinates corresponding to the pitch angle interval are selected from all sample space coordinates, and the target plane equation corresponding to the pitch angle interval is determined based on the sample space coordinates corresponding to the pitch angle interval.

[0028] Determining the target distance between the target to be detected and the PTZ camera based on the coordinates of the intersection between the direction vectors pointed by the target deflection angle and the target pitch angle and the target plane equation may include but is not limited to: determining the target pitch angle interval in which the target pitch angle is located from multiple pitch angle intervals; determining the target distance between the target to be detected and the PTZ camera based on the coordinates of the intersection between the direction vectors pointed by the target deflection angle and the target pitch angle and the target plane equation corresponding to the target pitch angle interval.

[0029] Exemplarily, determining the first sample focus position based on the first sample distance between the sample target and the PTZ camera may include, but is not limited to: determining the first sample distance based on the longitudinal field of view angle of the PTZ camera, the sample pitch angle of the vertical rotation of the PTZ camera, the hanging height of the PTZ camera, the height of the sample target, the longitudinal pixel coordinates corresponding to the sample target in the picture, and the total number of longitudinal pixels in the picture, and querying the mapping relationship based on the first sample distance to obtain the first sample focus position.

[0030] Exemplarily, searching for focal positions surrounding a first sample focal position to obtain a second sample focal position may include, but is not limited to, obtaining multiple scanning steps corresponding to multiple object distance segments; wherein, for each object distance segment, obtaining the focal position corresponding to the first object distance by querying a mapping relationship corresponding to the first object distance of the segment, and obtaining the focal position corresponding to the second object distance by querying a mapping relationship corresponding to the second object distance of the segment; and determining the scanning step corresponding to the object distance segment based on the first object distance, the second object distance, the focal position corresponding to the first object distance, and the focal position corresponding to the second object distance. Then, for each scanning step, searching for focal positions surrounding the first sample focal position based on the scanning step, focusing the PTZ camera based on the searched focal positions, capturing sample images of the sample target, and determining a sharpness score based on the sample images. Then, based on the sharpness scores corresponding to each searched focal position, the focal position corresponding to the maximum sharpness score may be determined as the second sample focal position.

[0031] Exemplarily, determining the second sample distance based on the second sample focus position and obtaining the sample space coordinates based on the second sample distance may include but is not limited to: querying the mapping relationship through the second sample focus position to obtain the second sample distance corresponding to the second sample focus; determining the spherical coordinates of the sample target in the polar coordinate system based on the second sample distance, the sample deflection angle of the horizontal rotation of the PTZ camera, and the sample pitch angle of the vertical rotation; and converting the spherical coordinates of the sample target in the polar coordinate system into the sample space coordinates of the sample target in the three-dimensional coordinate system based on the conversion relationship between the polar coordinate system and the three-dimensional coordinate system.

[0032] Exemplarily, correcting the plane equation parameters of the initial plane equation and determining the corrected plane equation as the target plane equation may include, but is not limited to: obtaining parameter correction data corresponding to a correction target, which may be a target preceding the target to be detected. The parameter correction data may include the target distance between the correction target and the PTZ camera, the target deflection angle and target pitch angle of the PTZ camera, and the target focus position corresponding to the target distance. Searching for focal positions surrounding the target focus position, selecting a clear focus position from the searched focus positions, and determining the correction distance between the correction target and the PTZ camera based on the clear focus position. Determining the first spatial coordinates of the correction target in a three-dimensional coordinate system based on the target distance, the target deflection angle, and the target pitch angle; and determining the second spatial coordinates of the correction target in the three-dimensional coordinate system based on the correction distance, the target deflection angle, and the target pitch angle. Determining a deviation vector based on the first and second spatial coordinates, and correcting the plane equation parameters based on the deviation vector and a configured correction coefficient to obtain the target plane equation.

[0033] It can be seen from the above technical solutions that in the embodiments of the present application, the target distance between the target to be detected and the PTZ camera can be determined based on the target plane equation, the target focus position can be determined based on the target distance between the target to be detected and the PTZ camera, and the PTZ camera can be focused based on the target focus position, so that the target to be detected can be accurately focused. The time consumption for searching the target focus position is relatively short, and a clear focus position can be found for a moving target to be detected. Even if the proportion of the target to be detected in the image is very small, when searching for a clear target focus position, it can be focused on the target to be detected and will not be focused on the background, that is, the target to be detected is clear, and the focus position can be accurately made to fall on the target to be detected, ensuring that the target to be detected is always in a clear state. The focus position of each point in the physical space can be accurately calculated. When the target to be detected appears in the picture, the clear focus position of the target to be detected can be calculated in real time, so that it can be focused quickly.

[0034] The above technical solutions of the embodiments of the present application are described below in conjunction with specific application scenarios.

[0035] During the camera's focusing process, to improve image clarity, it is necessary to refer to the AFD statistical value. Based on the AFD statistical value, the focus lens is driven to oscillate near the clear focus position, gradually approaching the focus position where the maximum AFD statistical value is located. This focus position is also the clearest focus position. When the focus lens is driven based on this focus position, a very high-definition image can be captured, thereby ensuring image clarity.

[0036] However, in the above method, it takes a long time to search for the focus position, and the clearest focus position cannot be found for a moving target to be detected. In addition, the proportion of the target to be detected in the image is usually very small. When searching for the clearest focus position, the focus is usually on the background, and the target to be detected is relatively blurred.

[0037] In response to the above findings, an adaptive focusing method based on image clarity is proposed in an embodiment of the present application, which can determine the clear focus position of the target to be detected, accurately focus on the target to be detected, and the focusing process takes a relatively short time, and can accurately make the focus position fall on the target to be detected.

[0038] The adaptive focusing method of the embodiment of the present application can be applied to PTZ cameras or other types of cameras without limitation. The PTZ camera is used as an example for illustration. The PTZ camera can also be called a spherical camera. The PTZ camera can rotate in the horizontal direction. The horizontal rotation angle of the PTZ camera is called the deflection angle. The PTZ camera can rotate in the vertical direction. The vertical rotation angle of the PTZ camera is called the pitch angle.

[0039] The adaptive focusing method of the present embodiment is used to adaptively focus on a target. Specifically, the method rotates the PTZ camera so that the target is within the camera's field of view, and then focuses the PTZ camera so that the focus falls on the target, ensuring that the target remains in focus. The "target" in this embodiment can be a part of the human body, a certain area of ​​a vehicle (such as a license plate), etc., without limitation.

[0040] The adaptive focusing method of the embodiments of the present application may involve a plane equation construction process (also referred to as a model construction process) and a focus position determination process based on the plane equation (also referred to as a model utilization process). During the plane equation construction process, an initial plane equation may be constructed, and during the focus position determination process based on the plane equation, the focus position may be determined based on the initial plane equation.

[0041] For the construction process of the plane equation, see Figure 2 As shown, the process may include:

[0042] Step 201: Determine a first sample distance between a sample target and the PTZ camera based on the longitudinal field of view of the PTZ camera, a sample pitch angle of the vertical rotation of the PTZ camera, the hanging height of the PTZ camera, the height of the sample target, the longitudinal pixel coordinates corresponding to the sample target in the picture, and the total number of longitudinal pixels in the picture.

[0043] For example, during the plane equation construction process, the target can be moved into the field of view of a PTZ camera, and the PTZ camera collects data related to the target, and the plane equation is constructed based on this data. For convenience, the "target" in the plane equation construction process can be referred to as a sample target.

[0044] For example, a polar coordinate system (also called a spherical coordinate system) is established with the PTZ camera as the center of the sphere O'. The position P in space (i.e. the intersection of the optical axes) is expressed in spherical coordinates in the polar coordinate system. represents, θ represents the sample pitch angle of the vertical rotation of the PTZ camera, represents the sample deflection angle of the horizontal rotation of the PTZ camera, and r represents the distance between position P and the PTZ camera (i.e., the distance between position P and the center O' of the PTZ camera). θ can be obtained from the coordinates of the motor that drives the PTZ camera to rotate vertically, and can be a known value. It can be obtained from the coordinates of the motor that drives the PTZ camera to rotate horizontally, and can be a known value.

[0045] A three-dimensional coordinate system XYZ (also called a three-dimensional plane coordinate system) is established with the projection point of the PTZ camera on the ground as the origin O. When the sample target moves in the plane of the three-dimensional coordinate system XYZ, the PTZ camera can rotate in multiple directions around the center O' to capture images of different scenes. Figure 3A As shown, it shows images of two scenes (scene A and scene B) captured when the PTZ camera rotates around the sphere center O'.

[0046] When the distance between the sample target and the PTZ camera is relatively close, the PTZ camera can "lower its head" to collect the image of the sample target. When the distance between the sample target and the PTZ camera is relatively far, the PTZ camera can "raise its head" to collect the image of the sample target. The hanging height of the PTZ camera can be between 2-8 meters (of course, it can also be other heights, there is no restriction on this), and the hanging height of the PTZ camera can be greater than the height of the sample target. For the sake of convenience, let the projection point O of the PTZ camera's sphere center O' on the ground be 0 degrees, then the range of the sample pitch angle θ is 0 degrees < θ < 90 degrees, and the sample deflection angle The range is 0 degrees to 360 degrees, so Degrees, then, taking ZOY as the cross-section diagram, you can refer to Figure 3B shown.

[0047] See also Figure 3B As shown in the figure, position Q is the location of the sample target, α is the longitudinal field of view angle of the PTZ camera, which is a known parameter after the lens optical design is completed, and β is the lateral field of view angle of the PTZ camera (in Figure 3B (not shown in the figure), the lateral field of view angle β is a known parameter after the lens optical design is completed.

[0048] See also Figure 3B As shown in Figure 1, θ is the sample pitch angle of the PTZ camera's vertical rotation, i.e., the angle between O'O and the longitudinal field of view centerline, or the angle between O'S and O'O. Line segment MN is the line segment perpendicular to the longitudinal field of view centerline O'S. ε is the angle at which the sample target deviates from the longitudinal field of view centerline. H represents the suspension height of the PTZ camera, which can be a constant. h is the height of the sample target, which can also be a constant.

[0049] Assuming that the vertical pixel coordinate corresponding to position Q in the picture is vp, half of the total number of vertical pixels in the picture is Vp, the horizontal pixel coordinate corresponding to position Q in the picture is hp, half of the total number of horizontal pixels in the picture is Hp, and the ratio of the number of QS pixels to the number of SN pixels in the imaging picture is γ, then the relationship of formula (1) can be obtained, and after converting formula (1), the relationship of formula (2) can be obtained.

[0050] tan(ε) / tan(α / 2)=SQ / SN=(Vp-vp) / Vp=γ Formula (1)

[0051] ε=arctan(γtan(α / 2))=arctan((Vp-vp) / Vp*tan(α / 2)) Formula (2)

[0052] from Figure 3B It can be seen that the distance L between the sample target and the PTZ camera (ie, the distance between positions Q and O') can be shown in formula (3). After converting formula (3), formula (4) can be obtained.

[0053] L = (Hh) / cos(θ-ε) Formula (3)

[0054] L = (Hh) / cos(θ-arctan((Vp-vp) / Vp*tan(α / 2))) Formula (4)

[0055] As can be seen from formula (4), the first sample distance L between the sample target and the PTZ camera can be determined based on the longitudinal field of view angle α of the PTZ camera, the sample pitch angle θ of the vertical rotation of the PTZ camera, the hanging height H of the PTZ camera, the height h of the sample target, the longitudinal pixel coordinate vp corresponding to the sample target in the picture, and the total number of longitudinal pixels in the picture (such as half of the total number of longitudinal pixels, i.e., Vp).

[0056] Step 202: Query the mapping relationship based on the first sample distance to obtain the first sample focus position. For example, the configured mapping relationship may represent the relationship between distance and focus position. Based on this, the mapping relationship may be queried based on the first sample distance to obtain the first sample focus position corresponding to the first sample distance.

[0057] For example, the key factor for a PTZ camera to have clear focus is to determine the focus position F, and the focus position F is related to the distance L (i.e., the distance between the target and the PTZ camera), see Figure 4 As shown, it is a relationship curve between the focus position F and the distance L, which shows the relationship between the focus position F and the distance L. The horizontal axis represents the distance L between the target and the PTZ camera, which can also be called the object distance, and the vertical axis represents the focus position F.

[0058] For example, it can be represented by the function f Figure 4 As shown in the relationship curve, the relationship between the focus position F and the distance L can also be expressed by the following formula: F=f(L).

[0059] For example, the mapping relationship can be Figure 4 The relationship curve shown is queried by the first sample distance (ie, the first sample distance is taken as L) Figure 4The relationship curve shown can be used to obtain the first sample focus position corresponding to the first sample distance (the first sample focus position is referred to as F). Alternatively, the mapping relationship can be a formula F=f(L). Substituting the first sample distance (i.e., the first sample distance is referred to as L) into this formula, the first sample focus position corresponding to the first sample distance (the first sample focus position is referred to as F) can be obtained.

[0060] For example, by combining the formula F=f(L) and the formula (4), the following formula (5) can be obtained. The first sample focus position corresponding to the first sample distance can be determined by the formula (5).

[0061] F=f(L)=f((Hh) / cos(θ-ε))=f((Hh) / cos(θ-arctan((Vp-vp) / Vp*tan(α / 2)))) Formula (5)

[0062] Step 203: Search for focal positions surrounding the first sample focal position to obtain a second sample focal position.

[0063] For example, after obtaining the first sample focus position, since the first sample focus position may not be a clear focus position, the first sample focus position can also be used as the initial focus position. Based on the first sample focus position, a clear focus position is searched for from the peripheral focus positions of the first sample focus position, and this clear focus position is used as the second sample focus position.

[0064] In a possible implementation, the second sample focus position may be obtained by using the following steps:

[0065] Step 2031: Acquire multiple scanning step lengths corresponding to multiple object distance segments.

[0066] For example, the entire object distance range can be divided into m object distance segments, where m can be a positive integer greater than 1, and the i-th object distance segment is recorded as (L1 i , L2 i ), L1 i Indicates the starting object distance of the i-th object distance segment, L2 i The focus position range corresponding to the i-th object distance segment is recorded as (F1 i , F2 i ), F1 i Indicates the starting focus position of the i-th object distance segment, F2 i Indicates the end focus position of the i-th object distance segment. i Query Figure 4 The relationship curve shown or the formula F=f(L) can be used to obtain F1 i , through L2i Query Figure 4 The relationship curve shown or the formula F=f(L) can be used to obtain F2 i .

[0067] From the above, it can be seen that for each object distance segment (such as the i-th object distance segment), the first object distance corresponding to the object distance segment (such as the starting object distance L1 i Or at the starting object distance L1 i and end object distance L2 i ) query the mapping relationship to obtain the focus position corresponding to the first object distance, such as the starting focus position F1 i , the second object distance corresponding to the object distance segment (such as the end object distance L2 i Or at the starting object distance L1 i and end object distance L2 i The mapping relationship is queried to obtain the focus position corresponding to the second object distance, such as the end focus position F2 i .

[0068] For each object distance segment, the scanning step length corresponding to the object distance segment can be determined based on the first object distance, the second object distance, the focus position corresponding to the first object distance, and the focus position corresponding to the second object distance. For example, if the first object distance is the starting object distance, the second object distance is the ending object distance, the focus position corresponding to the first object distance is the starting focus position, and the focus position corresponding to the second object distance is the ending focus position, then the scanning step length STEP corresponding to the i-th object distance segment is i It can be expressed by the following formula: K*(F1 i -F2 i ) / (L1 i -L2 i Obviously, for each object distance segment, the scanning step length corresponding to the object distance segment can be obtained by the above formula, thereby obtaining multiple scanning step lengths corresponding to multiple object distance segments, such as m scanning step lengths corresponding to m object distance segments.

[0069] In the above formula, K is the focusing operation coefficient, which can be configured according to experience, (F1 i -F2 i ) / (L1 i -L2 i ) is the sensitivity of the lens focus to the object distance G, G = (focus1-focus2) / (L1-L2).

[0070] For example, multiple scanning step sizes corresponding to multiple object distance segments can be recorded in a configuration table. That is, the configuration table can include multiple scanning step sizes corresponding to multiple object distance segments. For example, if the frame rate of the PTZ camera is 25 fps, the configuration table can include p scanning step sizes, where p can be less than 25 without limitation.

[0071] Step 2032: For each scanning step, search for a peripheral focus position of the first sample focus position based on the scanning step, focus the PTZ camera based on the searched focus position, acquire a sample image of the sample target, and determine a clarity score based on the sample image.

[0072] For example, for each scanning step, a focus position is searched by subtracting the scanning step from the first sample focus position, and another focus position is searched by adding the scanning step to the first sample focus position. Obviously, based on multiple scanning steps corresponding to multiple object distance segments, multiple focus positions can be searched.

[0073] For each focus position found, the PTZ camera can be focused based on that focus position, with no restrictions placed on the focusing process. During the PTZ camera's focusing process, a sample image of the sample target is captured, thereby obtaining a sample image corresponding to that focus position. Obviously, when multiple focus positions are found, a sample image corresponding to each focus position can be obtained.

[0074] After obtaining the sample image corresponding to the focus position, the clarity score corresponding to the focus position can be determined based on the sample image, thereby obtaining the clarity score corresponding to the focus position. Obviously, when multiple focus positions are searched, the clarity score corresponding to each focus position can be obtained.

[0075] In a possible implementation, after obtaining a sample image corresponding to a focus position, the following formula (6) may be used to determine the clarity score corresponding to the focus position:

[0076] Score=r*Score1+(1-r)*Score2 Formula (6)

[0077] In formula (6), Score represents the clarity score corresponding to the focus position. Score1 represents the first clarity score corresponding to the focus position. For example, the area where the sample target is located is determined from the sample image, the area where the sample target is located is cut out from the sample image, and the first clarity score Score1 of the area where the sample target is located is calculated by a filtering algorithm. There is no restriction on this calculation method. Score2 represents the second clarity score corresponding to the focus position. For example, a recognition algorithm is used to directly determine the second clarity score Score2 of the area where the sample target is located based on the sample image (that is, there is no need to cut out the area where the sample target is located from the sample image). There is no restriction on this determination method. r represents the weight coefficient of Score1, and 1-r represents the weight coefficient of Score2. r can be greater than or equal to 0 and less than or equal to 1.

[0078] Step 2033: Based on the clarity scores corresponding to each searched focus position, the focus position corresponding to the maximum clarity score may be determined as the second sample focus position.

[0079] For example, see Figure 5 As shown, after obtaining the clarity score corresponding to each focus position, the focus position corresponding to the highest clarity score can be used as the second sample focus position.

[0080] For example, assuming the clarity score ranges from 0 to 100, a clarity score less than 20 is considered unclear, while a clarity score greater than 80 is considered clear. The higher the clarity score, the higher the clarity. Each object has a unique ID, and the ID does not change when the object moves within the frame. The clarity of multiple objects can be calculated simultaneously within a single frame.

[0081] For example, assuming that the image acquisition process of the PTZ camera lasts k seconds, in order to search for the peripheral focus positions of the first sample focus position and obtain the second sample focus position, the PTZ camera can complete the focusing process in accordance with steps 2032-2033 in the first 1 second of the k seconds or even less to obtain the second sample focus position. The above process is an active focusing action, which will affect the image preview display, but this action only lasts for a maximum of 1 second, and at the end of the action, a clear point will be output to make the image clear, that is, the remaining time of the k seconds can ensure that the image is clear, thereby meeting the image acquisition requirements.

[0082] At this point, step 203 is completed, and a second sample focus position can be found from the peripheral focus positions of the first sample focus position, and the second sample focus position is a clear focus position.

[0083] Step 204: Determine the second sample distance based on the second sample focus position. For example, query the mapping relationship through the second sample focus position to obtain the second sample distance corresponding to the second sample focus.

[0084] For example, the mapping relationship can be Figure 4 The relationship curve shown is queried by the second sample focus position F Figure 4 Alternatively, the mapping relationship may be a formula F=f(L), and the second sample focus position F may be substituted into the formula to obtain the second sample distance.

[0085] Step 205 : Determine the spherical coordinates of the sample target in the polar coordinate system based on the second sample distance, the sample yaw angle of the horizontal rotation, and the sample pitch angle of the vertical rotation of the PTZ camera.

[0086] For example, the spherical coordinates of the sample target in the polar coordinate system can be marked as (L, ω, ρ), where L represents the distance between the sample target and the PTZ camera, i.e., the second sample distance mentioned above, ω represents the longitudinal rotation angle of the sample target relative to the PTZ camera, and ρ represents the lateral rotation angle of the sample target relative to the PTZ camera. The longitudinal rotation angle ω of the sample target relative to the PTZ camera can be determined based on the sample pitch angle θ of the vertical rotation of the PTZ camera, and the sample yaw angle θ of the horizontal rotation of the PTZ camera can be determined based on the sample yaw angle θ of the horizontal rotation of the PTZ camera. Determine the lateral rotation angle ρ of the sample target relative to the PTZ camera.

[0087] For example, based on the sample pitch angle θ, the longitudinal rotation angle ω can be determined using formula (7):

[0088] ω=θ-ε=θ-arctan((Vp-vp) / Vp*tan(α / 2)) Formula (7)

[0089] In formula (7), ε is the angle at which the sample target deviates from the centerline of the longitudinal field of view, Vp is half the total number of longitudinal pixels in the image, vp is the longitudinal pixel coordinate corresponding to the sample target in the image, and α is the longitudinal field of view angle of the PTZ camera. In summary, the longitudinal rotation angle ω can be determined based on the sample pitch angle θ, the total number of longitudinal pixels, the longitudinal pixel coordinate vp of the sample target, and the longitudinal field of view angle α of the PTZ camera.

[0090] For example, based on the sample deflection angle The lateral rotation angle ρ can be determined using formula (8):

[0091]

[0092] In formula (8), λ is the angle at which the sample target deviates from the center line of the horizontal field of view, Hp is half of the total number of horizontal pixels in the picture, hp is the horizontal pixel coordinate corresponding to the sample target in the picture, and β is the horizontal field of view angle of the PTZ camera. In summary, based on the sample deflection angle The lateral rotation angle ρ is determined by the total number of lateral pixels, the lateral pixel coordinates hp of the sample target, and the lateral field of view β of the PTZ camera.

[0093] In formula (7) and formula (8), the sample pitch angle θ is obtained from the motor coordinates that drive the PTZ camera to rotate vertically and is a known value. The sample deflection angle The coordinates of the motor that drives the PTZ camera's horizontal rotation are known values. The vertical field of view angle α is a known parameter after the lens optical design is completed, and the horizontal field of view angle β is also a known parameter after the lens optical design is completed. The total number of vertical and horizontal pixels is related to the image resolution: the total number of vertical pixels represents the vertical resolution, and the total number of horizontal pixels represents the horizontal resolution. Therefore, Vp and Hp are known values. The vertical pixel coordinate vp and the horizontal pixel coordinate hp are related to the position of the sample target in the image and can be obtained by the recognition algorithm without any restrictions.

[0094] From the above, we can see that based on the parameters Determine the spherical coordinates of the sample target in the polar coordinate system. For example, the sample pitch angle θ and the longitudinal pixel coordinate vp are used to determine the longitudinal rotation angle ω and the sample deflection angle The horizontal pixel coordinate hp is used to determine the horizontal rotation angle ρ, and the focus position F is used to determine the distance L between the sample target and the PTZ camera, that is, the second sample distance mentioned above.

[0095] In one possible implementation, referring to step 201, the distance between the sample target and the PTZ camera can be obtained, that is, based on the longitudinal field of view angle α, the sample pitch angle θ, the hanging height H of the PTZ camera, the height h of the sample target, the longitudinal pixel coordinate vp corresponding to the sample target in the picture, and half of the total number of longitudinal pixels in the picture Vp, the first sample distance between the sample target and the PTZ camera is determined, and then the focus position F is accurately calculated based on the distance. However, due to the complex and changeable installation conditions of the PTZ camera, especially the tilt condition of the PTZ camera, the flatness of the ground, etc., it is difficult to ensure a clear image with the final calculated focus position F. In order to solve this problem and improve the stability and adaptability of the prediction model, in this embodiment, the lateral parameters hp, Hp, β and Finally, the prediction model can be compared with the parameters For details, set the parameter Convert to spherical coordinates (L, ω, ρ).

[0096] Step 206 : Based on the conversion relationship between the polar coordinate system and the three-dimensional coordinate system, convert the spherical coordinates of the sample target in the polar coordinate system into the sample space coordinates of the sample target in the three-dimensional coordinate system.

[0097] For example, the polar coordinates of any position in the physical space and the three-dimensional coordinates (x, y, z) of the position can be converted to each other, for example, based on the conversion relationship between the polar coordinate system and the three-dimensional coordinate system, and the conversion relationship between the polar coordinate system and the three-dimensional coordinate system can be shown in formula (9).

[0098]

[0099] In Formula 9, L represents the distance between the sample target and the PTZ camera, i.e., the second sample distance described above. ω represents the longitudinal rotation angle of the sample target relative to the PTZ camera. ρ represents the lateral rotation angle of the sample target relative to the PTZ camera. Obviously, given the known spherical coordinates (L, ω, ρ) of the sample target in the polar coordinate system, the spherical coordinates (L, ω, ρ) can be converted to the three-dimensional coordinates (x, y, z) of the sample target in the three-dimensional coordinate system based on the conversion relationship shown in Formula (9). The three-dimensional coordinates (x, y, z) of the sample target in the three-dimensional coordinate system can be called the sample space coordinates.

[0100] Step 207 : Determine the plane equation parameters based on the multiple sample space coordinates, and determine the initial plane equation based on the plane equation parameters. At this point, the plane equation construction process is completed, and the initial plane equation is obtained.

[0101] For example, during the plane equation construction process, multiple sample objects can be moved into the field of view of a PTZ camera, and the PTZ camera can collect data related to the sample objects. When each sample object moves into the field of view of the PTZ camera, the sample space coordinates corresponding to the sample object can be obtained based on steps 201-206, thereby obtaining multiple sample space coordinates. After obtaining the multiple sample space coordinates, plane equation parameters are determined based on the multiple sample space coordinates, and the initial plane equation is determined based on the plane equation parameters.

[0102] In a possible implementation, an example of a plane equation can be shown in formula (10):

[0103] z=a*x+b*y+c Formula (10)

[0104] In formula (10), a, b, and c are plane equation parameters. In order to solve the plane equation parameters, plane fitting can be performed on multiple sample space coordinates (x, y, z), and the plane equation parameters can be solved using the least squares method. See formula (11), which is an example of solving the plane equation parameters.

[0105]

[0106] In formula (11), n ​​represents the total number of sample space coordinates, and n can be a positive integer greater than or equal to 3. j ,y j , z j ) represents the jth sample space coordinate. Obviously, after substituting the n sample space coordinates (x, y, z) into formula (11), the plane equation parameters a, b, and c can be obtained. After obtaining the plane equation parameters a, b, and c, the initial plane equation shown in formula (10) can be obtained.

[0107] In one possible implementation, in order to ensure the stability and adaptability of the initial plane equation, the pitch angle range of the PTZ camera can also be divided into multiple pitch angle intervals. Assuming that the range of the pitch angle θ is 0 degrees <θ < 90 degrees, the pitch angle range can be divided into pitch angle interval 1, pitch angle interval 2 and pitch angle interval 3. Pitch angle interval 1 is (0, 30], pitch angle interval 2 is (30, 60], and pitch angle interval 3 is (60, 30). Of course, the above is only an example of dividing the pitch angle intervals and is not limited to this.

[0108] For each pitch angle interval, in step 207, the sample space coordinates corresponding to the pitch angle interval can be selected from all sample space coordinates. For example, if the sample pitch angle of the vertical rotation of the PTZ camera is in pitch angle interval 1, the sample space coordinates corresponding to the sample target belong to coordinate set 1 corresponding to pitch angle interval 1; if the sample pitch angle of the vertical rotation of the PTZ camera is in pitch angle interval 2, the sample space coordinates corresponding to the sample target belong to coordinate set 2 corresponding to pitch angle interval 2; if the sample pitch angle of the vertical rotation of the PTZ camera is in pitch angle interval 3, the sample space coordinates corresponding to the sample target belong to coordinate set 3 corresponding to pitch angle interval 3. In summary, coordinate set 1 corresponding to pitch angle interval 1, coordinate set 2 corresponding to pitch angle interval 2, and coordinate set 3 corresponding to pitch angle interval 3 can be obtained.

[0109] For each pitch angle interval, in step 207, plane equation parameters corresponding to the pitch angle interval may be determined based on the multiple sample space coordinates corresponding to the pitch angle interval, and an initial plane equation corresponding to the pitch angle interval may be determined based on the plane equation parameters. For example, plane equation parameters corresponding to pitch angle interval 1 may be determined based on the multiple sample space coordinates in coordinate set 1 corresponding to pitch angle interval 1, and the initial plane equation corresponding to pitch angle interval 1 may be determined based on the plane equation parameters, and so on.

[0110] For example, an example of the plane equation for the i-th pitch angle interval can be seen in formula (12):

[0111] z=a i *x+b i *y+c i Formula (12)

[0112] In formula (12), a i 、b i 、c iare the plane equation parameters of the i-th pitch angle interval. In order to solve the plane equation parameters, a plane fitting can be performed on multiple sample space coordinates (x, y, z) of the i-th pitch angle interval, and the plane equation parameters can be solved using the least squares method, as shown in formula (13).

[0113]

[0114] In formula (13), n represents the total number of sample space coordinates corresponding to the i-th pitch angle interval, and n can be a positive integer greater than or equal to 3. j ,y j , z j ) represents the j-th sample space coordinate corresponding to the i-th pitch angle interval. Based on formula (13), the initial plane equation of the i-th pitch angle interval is finally obtained.

[0115] At this point, the plane equation construction process is completed and the initial plane equation can be obtained. After obtaining the initial plane equation, the focus position can be determined based on the plane equation. For the focus position determination process based on the plane equation, see Figure 6 As shown, the process may include the following steps:

[0116] Step 601: When the target to be detected moves into the field of view of the PTZ camera, obtain a target deflection angle of the PTZ camera for horizontal rotation and a target pitch angle of the PTZ camera for vertical rotation.

[0117] Step 602: Obtain a target plane equation for determining the distance between the target to be detected and the PTZ camera.

[0118] In one possible implementation, the initial plane equation can be determined as the target plane equation. In another possible implementation, if the pitch angle range of the PTZ camera is divided into multiple pitch angle intervals, and the initial plane equation corresponding to each pitch angle interval has been obtained, then a target pitch angle interval in which the target pitch angle is located can be determined from the multiple pitch angle intervals (i.e., the target pitch angle is within the target pitch angle interval), and the initial plane equation corresponding to the target pitch angle interval can be determined as the target plane equation.

[0119] Step 603: Determine the target distance between the target to be detected and the PTZ camera based on the coordinates of the intersection between the direction vectors pointed by the target deflection angle and the target pitch angle and the target plane equation.

[0120] For example, based on the target yaw angle and target pitch angle, a direction vector can be determined, i.e., the direction vector pointed by the target yaw angle and target pitch angle. Since the target plane equation represents a plane, and there is an intersection between the direction vector and the plane, the coordinates of the intersection between the direction vector and the target plane equation can be determined. This intersection coordinate represents the three-dimensional coordinates (x, y, z) of the target to be detected in a three-dimensional coordinate system. The target distance between the target to be detected and the PTZ camera can then be determined based on this intersection coordinate.

[0121] Step 604: query a configured mapping relationship based on the target distance to obtain a target focus position corresponding to the target distance; wherein the mapping relationship represents a relationship between the distance and the focus position.

[0122] For example, the mapping relationship can be Figure 4 The relationship curve shown is queried by the target distance L Figure 4 The target focus position F corresponding to the target distance can be obtained by using the relationship curve shown. Alternatively, the mapping relationship can be a formula F=f(L). Substituting the target distance L into the formula, the target focus position F can be obtained.

[0123] Step 605: Focus the PTZ camera based on the target focus position. After the PTZ camera has focused, capture a target image of the target to be detected through the PTZ camera.

[0124] In one possible implementation, based on the parameters When determining the spherical coordinates of the sample target in the polar coordinate system, because clarity is a relative quantity and contains random noise, and the scanning step size of the focusing process cannot be very small, it leads to a certain error in the focus position F, which in turn leads to a certain error in the spherical coordinates and a certain error in the initial plane equation. Based on this, during the process of determining the focus position based on the plane equation, the plane equation can also be continuously corrected. The correction method is to use the normal vector superposition offset method. When continuously iteratively correcting the plane equation, it can be determined whether the deviation vector is approaching invariance. If not, the correction process continues; if it is, the correction process is stopped.

[0125] For example, to iteratively correct the plane equation, the following steps may be used:

[0126] Step S11, obtaining parameter correction data corresponding to a correction target, where the correction target may be a target before the target to be detected. The parameter correction data may include a target distance between the correction target and the PTZ camera, a target deflection angle and a target pitch angle of the PTZ camera, and a target focus position corresponding to the target distance.

[0127] For example, assuming the current target to be detected is target A, and the target to be detected before target A is target B, target B can be referred to as the calibration target. When determining the target focus position corresponding to the calibration target using steps 601-605, parameter calibration data corresponding to the calibration target can be collected. Referring to steps 601-605, parameter calibration data such as the target distance between the calibration target and the PTZ camera, the target deflection angle and target pitch angle of the PTZ camera, and the target focus position corresponding to the target distance can be obtained.

[0128] Step S12: searching for peripheral focus positions of the target focus position, selecting a clear focus position from the searched focus positions, and determining a calibration distance between the calibration target and the PTZ camera based on the clear focus position.

[0129] For example, to obtain a sharp focus position, multiple scanning steps corresponding to multiple object distance segments are obtained. For each scanning step, a focus position surrounding the target focus position is searched based on the scan step. The PTZ camera is focused based on the searched focus position. After focusing is completed, an image of the calibration target is captured, and a sharpness score is determined based on the image. Based on the sharpness scores corresponding to each searched focus position, the focus position corresponding to the maximum sharpness score can be determined as the sharp focus position. The implementation process for obtaining the sharp focus position can be described in step 203 and will not be repeated here.

[0130] After obtaining the clear focus position, the mapping relationship can be queried through the clear focus position to obtain the distance corresponding to the clear focus position. This distance is the calibration distance between the calibration target and the PTZ camera.

[0131] For example, assuming that the image acquisition process of the PTZ camera lasts k seconds, in order to search for the peripheral focus positions of the target focus position and obtain a clear focus position, the focusing process can be completed in the first 1 second of the k seconds or even shorter to obtain a clear focus position. The above process is an active focusing action, which will affect the image preview display, but this action lasts for a maximum of 1 second, and at the end of the action, a clear point will be output to make the image clear, that is, the remaining time of the k seconds ensures that the image is clear, meeting the image acquisition requirements.

[0132] Step S13: Determine the first spatial coordinates of the calibration target in the three-dimensional coordinate system based on the target distance, the target deflection angle, and the target pitch angle; and determine the second spatial coordinates of the calibration target in the three-dimensional coordinate system based on the calibration distance, the target deflection angle, and the target pitch angle.

[0133] For example, since the parameter calibration data includes the target distance between the calibration target and the PTZ camera, the target deflection angle and the target pitch angle of the PTZ camera, the first spatial coordinates of the calibration target in the three-dimensional coordinate system can be determined based on the target distance, the target deflection angle and the target pitch angle. The determination method can be referred to in steps 205 and 206, which will not be repeated here. Among them, this first spatial coordinate can be understood as the predicted spatial coordinate, that is, after obtaining the predicted focus parameter Afterwards, the focus parameters are predicted Convert to the first space coordinate (x P ,y P , z P ).

[0134] For example, since the parameter calibration data includes the target focus position, and the clear focus position is searched based on the target focus position, and the calibration distance between the calibration target and the PTZ camera is determined based on the clear focus position, the second spatial coordinates of the calibration target in the three-dimensional coordinate system can be determined based on the calibration distance, the target deflection angle, and the target pitch angle. The determination method can be referred to in steps 205 and 206, which will not be repeated here. Among them, this second spatial coordinate can be understood as the real space coordinate, that is, based on the real focus parameter After that, the real focus parameter Transformed into the second space coordinate (x R ,y R , z R ). In real focus parameters In, F R Indicates the clear focus position, which is based on the target focus position F P Found by search.

[0135] Step S14: Determine a deviation vector based on the first space coordinate and the second space coordinate.

[0136] For example, for the deviation vector The determination method can be shown in formula (14):

[0137]

[0138] (x R ,y R , z R ) is the second space coordinate, (x P ,y P , z P ) is the first space coordinate.

[0139] Step S15: Correct the plane equation parameters based on the deviation vector and the configured correction coefficient to obtain a corrected plane equation, and determine the corrected plane equation as the target plane equation.

[0140] For example, the plane equation parameters can be corrected as shown in formula (15):

[0141]

[0142] In formula (15), represents the modified plane equation parameters, Indicates the plane equation parameters before correction and the plane equation parameters after correction and the plane equation parameters before correction can be the plane normal vector of the plane equation. For example, assuming the plane equation before correction is: z = a0 i *x+b0 i *y+c0 i , then the plane equation parameters before correction are It can be: In addition, k can represent a configured correction coefficient, which can be a value greater than 0 and less than 1. can represent the bias vector.

[0143] In one possible implementation, assuming that the current target to be detected is target A, and the target to be detected before target A is target B, then after the processing process of target B is completed, the plane equation can be corrected based on the parameter correction data of target B to obtain a corrected plane equation. When processing target A, this corrected plane equation is used as the target plane equation of target A.

[0144] In a possible implementation, after obtaining the deviation vector, it is also possible to determine whether the plane equation tends to be stable based on the deviation vector. For example, if the deviation vector is less than a preset threshold value, it is determined that the plane equation tends to be stable. Otherwise, it is determined that the plane equation does not tend to be stable. If the plane equation tends to be stable, the plane equation correction process is terminated (i.e., the plane equation correction process is exited), and the plane equation is no longer corrected in the subsequent process. If the plane equation does not tend to be stable, the plane equation correction process can be continued. For example, after the processing process of target A is completed, the plane equation is corrected based on the parameter correction data of target A to obtain a corrected plane equation. When processing the next target to be detected after target A, this corrected plane equation is used as the target plane equation of the target to be detected, and so on.

[0145] As the image acquisition process continues, the plane equation (also called the focus prediction model) will be continuously corrected, and eventually the focus prediction model for multiple pitch angle intervals will be output. In this way, the model of the entire area is completed, and finally a fast and accurate target acquisition and focusing process is achieved.

[0146] In a possible implementation, when correcting the plane equation based on parameter correction data, the pitch angle interval in which the target pitch angle in the parameter correction data is located can be determined first, and then the plane equation corresponding to the pitch angle interval can be corrected based on the parameter correction data.

[0147] It can be seen from the above technical solutions that in the embodiments of the present application, the target distance between the target to be detected and the PTZ camera can be determined based on the target plane equation, the target focus position can be determined based on the target distance between the target to be detected and the PTZ camera, and the PTZ camera can be focused based on the target focus position, so that the target to be detected can be accurately focused. The time consumption for searching the target focus position is relatively short, and a clear focus position can be found for a moving target to be detected. Even if the proportion of the target to be detected in the image is very small, when searching for a clear target focus position, it can be focused on the target to be detected and will not be focused on the background, that is, the target to be detected is clear, and the focus position can be accurately made to fall on the target to be detected, ensuring that the target to be detected is always in a clear state. The focus position of each point in the physical space can be accurately calculated. When the target to be detected appears in the picture, the clear focus position of the target to be detected can be calculated in real time, so that it can be focused quickly.

[0148] It can accurately focus on the target object distance. For example, traditional focusing is easily affected by the external environment and is likely to focus on the background, while the area of ​​interest is blurred. In this embodiment, the target clarity is used as the premise for model parameter adaptation, avoiding external environmental interference factors, and can accurately focus on the target, keeping the area of ​​interest in the picture always in a clear state. It can focus quickly. After the model is established, the focus position of each position in the space can be accurately calculated. When the target appears in the picture, the required focus position F can be calculated and predicted in real time, and the focus motor can be directly driven to the predicted position to make the target clear. Especially for fast-moving targets, fast image acquisition can be achieved, and the target can be kept in a clear state during the entire image acquisition process. It reduces maintenance costs. The model calibration and establishment process does not require human intervention and is not restricted by installation conditions. After the installation position changes, the model can be adaptively corrected and improved again.

[0149] Based on the same application concept as the above method, an embodiment of the present application proposes a focus position determination device applied to a PTZ camera, the device comprising:

[0150] An acquisition module 71 is configured to acquire a target deflection angle of the horizontal rotation of the PTZ camera and a target pitch angle of the vertical rotation of the PTZ camera;

[0151] a determination module 72 for determining a target distance between the target to be detected and the PTZ camera based on the coordinates of an intersection point between the direction vectors pointed by the target deflection angle and the target pitch angle and the target plane equation;

[0152] A query module 73 is configured to query a configured mapping relationship based on the target distance to obtain a target focus position corresponding to the target distance; the mapping relationship represents a relationship between the distance and the focus position;

[0153] The processing module 74 is configured to focus the PTZ camera based on the target focus position, and after the PTZ camera has focused, collect a target image of the target to be detected through the PTZ camera.

[0154] Exemplarily, the acquisition module 71 is also used to obtain the target plane equation; when the acquisition module 71 obtains the target plane equation, it is specifically used to: obtain multiple sample space coordinates, and the acquisition method of each sample space coordinate includes: determining a first sample focus position based on a first sample distance between the sample target and the PTZ camera; searching for peripheral focus positions of the first sample focus position to obtain a second sample focus position; determining a second sample distance based on the second sample focus position, and obtaining sample space coordinates based on the second sample distance; determining plane equation parameters based on the multiple sample space coordinates; determining an initial plane equation based on the plane equation parameters; determining the initial plane equation as the target plane equation, or, correcting the plane equation parameters of the initial plane equation, and determining the corrected plane equation as the target plane equation.

[0155] Exemplarily, the pitch angle range of the PTZ camera includes multiple pitch angle intervals. For each pitch angle interval, the sample space coordinates corresponding to the pitch angle interval are selected from all sample space coordinates, and the target plane equation corresponding to the pitch angle interval is determined based on the sample space coordinates corresponding to the pitch angle interval; the determination module 72 determines the target distance between the target to be detected and the PTZ camera based on the intersection coordinates between the target deflection angle and the direction vector pointed to by the target pitch angle and the target plane equation, and is specifically used to: determine the target pitch angle interval in which the target pitch angle is located from the multiple pitch angle intervals; determine the target distance between the target to be detected and the PTZ camera based on the intersection coordinates between the direction vector and the target plane equation corresponding to the target pitch angle interval.

[0156] Exemplarily, when determining the first sample focus position based on the first sample distance between the sample target and the PTZ camera, the acquisition module 71 is specifically used to: determine the first sample distance based on the longitudinal field angle of the PTZ camera, the sample pitch angle of the vertical rotation of the PTZ camera, the hanging height of the PTZ camera, the height of the sample target, the longitudinal pixel coordinates corresponding to the sample target in the picture, and the total number of longitudinal pixels of the picture; and query the mapping relationship based on the first sample distance to obtain the first sample focus position.

[0157] Exemplarily, the acquisition module 71 searches for peripheral focus positions of the first sample focus position, and when obtaining the second sample focus position, is specifically used to: obtain multiple scanning steps corresponding to multiple object distance segments; wherein, for each object distance segment, the mapping relationship is queried through the first object distance corresponding to the object distance segment to obtain the focus position corresponding to the first object distance, and the mapping relationship is queried through the second object distance corresponding to the object distance segment to obtain the focus position corresponding to the second object distance; based on the first object distance, the second object distance, the focus position corresponding to the first object distance and the focus position corresponding to the second object distance, the scanning step corresponding to the object distance segment is determined; for each scanning step, the peripheral focus position of the first sample focus position is searched based on the scanning step, the PTZ camera is focused based on the searched focus position, a sample image of the sample target is collected, and a clarity score is determined based on the sample image; and the focus position corresponding to the maximum clarity score is determined as the second sample focus position.

[0158] Exemplarily, the acquisition module 71 determines the second sample distance based on the second sample focus position, and when acquiring the sample space coordinates based on the second sample distance, is specifically used to: obtain the second sample distance by querying the mapping relationship through the second sample focus position; determine the spherical coordinates of the sample target in the polar coordinate system based on the second sample distance, the sample deflection angle of the horizontal rotation of the PTZ camera, and the sample pitch angle of the vertical rotation; and convert the spherical coordinates of the sample target in the polar coordinate system into the sample space coordinates of the sample target in the three-dimensional coordinate system based on the conversion relationship between the polar coordinate system and the three-dimensional coordinate system.

[0159] Exemplarily, the acquisition module 71 corrects the plane equation parameters of the initial plane equation, and when determining the corrected plane equation as the target plane equation, is specifically used to: obtain parameter correction data corresponding to the correction target, where the correction target is the target before the target to be detected, and the parameter correction data includes the target distance between the correction target and the PTZ camera, the target deflection angle and target pitch angle of the PTZ camera, and the target focus position corresponding to the target distance; search for peripheral focus positions of the target focus position, select a clear focus position from the searched focus positions, and determine the correction distance between the correction target and the PTZ camera based on the clear focus position; determine the first spatial coordinate of the correction target in the three-dimensional coordinate system based on the target distance, the target deflection angle and the target pitch angle; determine the second spatial coordinate of the correction target in the three-dimensional coordinate system based on the correction distance, the target deflection angle and the target pitch angle; determine the deviation vector based on the first spatial coordinate and the second spatial coordinate, and correct the plane equation parameters based on the deviation vector and the configured correction coefficient to obtain the target plane equation.

[0160] Based on the same application concept as the above method, an electronic device is proposed in an embodiment of the present application, which includes a processor 81 and a machine-readable storage medium 82, and the machine-readable storage medium 82 stores machine-executable instructions that can be executed by the processor 81; the processor 81 is used to execute the machine-executable instructions to implement the focus position determination method disclosed in the above example of this application.

[0161] The systems, devices, modules, or units described in the above embodiments may be implemented by a computer entity or by a product having certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email transceiver, game console, tablet computer, wearable device, or any combination of these devices.

[0162] For the convenience of description, the above devices are described as being divided into various units according to their functions. Of course, when implementing this application, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0163] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the embodiments of the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0164] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0165] Furthermore, these computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0166] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0167] The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.

Claims

1. A method for determining a focus position, characterized in that: Applicable to PTZ cameras, including: Obtaining a target deflection angle for horizontal rotation and a target pitch angle for vertical rotation of the PTZ camera; Determining a target distance between the target to be detected and the PTZ camera based on the coordinates of an intersection between a direction vector pointed by the target deflection angle and the target pitch angle and a target plane equation; Querying a configured mapping relationship based on the target distance to obtain a target focus position corresponding to the target distance; wherein the mapping relationship represents a relationship between the distance and the focus position; focusing the PTZ camera based on the target focus position, and after the PTZ camera is focused, collecting a target image of the target to be detected by the PTZ camera; The method further includes: obtaining the target plane equation, and the process of obtaining the target plane equation includes: Acquire a plurality of sample space coordinates; wherein each sample space coordinate is acquired in a manner comprising: determining a first sample focus position based on a first sample distance between a sample target and the PTZ camera; searching for focus positions surrounding the first sample focus position to obtain a second sample focus position; determining a second sample distance based on the second sample focus position, and acquiring the sample space coordinate based on the second sample distance; determining plane equation parameters based on the plurality of sample space coordinates; determining an initial plane equation based on the plane equation parameters; The initial plane equation is determined as the target plane equation; or, the plane equation parameters of the initial plane equation are corrected, and the corrected plane equation is determined as the target plane equation.

2. The method according to claim 1, characterized in that The pitch angle range of the PTZ camera includes a plurality of pitch angle intervals. For each pitch angle interval, a sample space coordinate corresponding to the pitch angle interval is selected from all sample space coordinates, and a target plane equation corresponding to the pitch angle interval is determined based on the sample space coordinates corresponding to the pitch angle interval. The determining of the target distance between the target to be detected and the PTZ camera based on the coordinates of the intersection between the direction vectors pointed to by the target deflection angle and the target pitch angle and the target plane equation includes: Determining a target pitch angle interval in which the target pitch angle is located from the multiple pitch angle intervals; A target distance between the target to be detected and the PTZ camera is determined based on the coordinates of an intersection point between the direction vector and a target plane equation corresponding to the target pitch angle interval.

3. The method according to claim 1, characterized in that The determining a first sample focus position based on a first sample distance between a sample target and the PTZ camera comprises: Determining the first sample distance based on the longitudinal field of view of the PTZ camera, the sample pitch angle of the vertical rotation of the PTZ camera, the hanging height of the PTZ camera, the height of the sample target, the longitudinal pixel coordinates corresponding to the sample target in the picture, and the total number of longitudinal pixels in the picture; The mapping relationship is queried based on the first sample distance to obtain the first sample focus position.

4. The method according to claim 1, wherein The step of searching for a peripheral focal position of the first sample focal position to obtain a second sample focal position includes: Acquire multiple scanning step sizes corresponding to multiple object distance segments; wherein, for each object distance segment, query the mapping relationship using a first object distance corresponding to the object distance segment to obtain a focus position corresponding to the first object distance, and query the mapping relationship using a second object distance corresponding to the object distance segment to obtain a focus position corresponding to the second object distance; and determine the scanning step size corresponding to the object distance segment based on the first object distance, the second object distance, the focus position corresponding to the first object distance, and the focus position corresponding to the second object distance; For each scanning step, searching for a peripheral focus position of the first sample focus position based on the scanning step, focusing the PTZ camera based on the searched focus position, acquiring a sample image of the sample target, and determining a clarity score based on the sample image; The focus position corresponding to the maximum clarity score is determined as the second sample focus position.

5. The method according to claim 1, wherein The determining a second sample distance based on the second sample focus position, and acquiring sample space coordinates based on the second sample distance, comprises: querying the mapping relationship through the second sample focus position to obtain the second sample distance; determining the spherical coordinates of the sample target in a polar coordinate system based on the second sample distance, a sample yaw angle of horizontal rotation, and a sample pitch angle of vertical rotation of the PTZ camera; Based on the conversion relationship between the polar coordinate system and the three-dimensional coordinate system, the spherical coordinates of the sample target in the polar coordinate system are converted into the sample space coordinates of the sample target in the three-dimensional coordinate system.

6. The method according to claim 1, characterized in that The step of correcting the plane equation parameters of the initial plane equation and determining the corrected plane equation as the target plane equation includes: Acquire parameter correction data corresponding to a calibration target, where the calibration target is a target in front of the target to be detected, the parameter correction data including a target distance between the calibration target and the PTZ camera, a target deflection angle and a target pitch angle of the PTZ camera, and a target focus position corresponding to the target distance; Searching for peripheral focus positions of the target focus position, selecting a clear focus position from the searched focus positions, and determining a calibration distance between the calibration target and the PTZ camera based on the clear focus position; Determining a first spatial coordinate of the calibration target in a three-dimensional coordinate system based on the target distance, the target deflection angle, and the target pitch angle; determining a second spatial coordinate of the calibration target in a three-dimensional coordinate system based on the calibration distance, the target deflection angle, and the target pitch angle; A deviation vector is determined based on the first spatial coordinate and the second spatial coordinate, and plane equation parameters are corrected based on the deviation vector and a configured correction coefficient to obtain a target plane equation.

7. A focus position determination device, characterized in that: Applicable to PTZ cameras, including: an acquisition module, configured to acquire a target deflection angle of the horizontal rotation of the PTZ camera and a target pitch angle of the vertical rotation of the PTZ camera; a determination module, configured to determine a target distance between a target to be detected and a PTZ camera based on the coordinates of an intersection point between a direction vector pointed to by the target deflection angle and the target pitch angle and a target plane equation; A query module, configured to query a configured mapping relationship based on the target distance to obtain a target focus position corresponding to the target distance; the mapping relationship represents a relationship between the distance and the focus position; a processing module, configured to focus the PTZ camera based on the target focus position, and after the PTZ camera has focused, acquire a target image of the target to be detected by the PTZ camera; Wherein, the acquisition module is also used to obtain the target plane equation; when the acquisition module obtains the target plane equation, it is specifically used to: obtain multiple sample space coordinates, and the acquisition method of each sample space coordinate includes: determining a first sample focus position based on a first sample distance between the sample target and the PTZ camera; searching for peripheral focus positions of the first sample focus position to obtain a second sample focus position; determining a second sample distance based on the second sample focus position, and obtaining sample space coordinates based on the second sample distance; determining plane equation parameters based on the multiple sample space coordinates; determining an initial plane equation based on the plane equation parameters; determining the initial plane equation as the target plane equation, or, correcting the plane equation parameters of the initial plane equation, and determining the corrected plane equation as the target plane equation.

8. The device according to claim 7, It is characterized by: in, The pitch angle range of the PTZ camera includes a plurality of pitch angle intervals. For each pitch angle interval, a sample space coordinate corresponding to the pitch angle interval is selected from all sample space coordinates, and a target plane equation corresponding to the pitch angle interval is determined based on the sample space coordinates corresponding to the pitch angle interval. The determination module determines the target distance between the target to be detected and the PTZ camera based on the target deflection angle and the intersection coordinates of the direction vector pointed to by the target pitch angle and the target plane equation, and is specifically used to: determine the target pitch angle interval in which the target pitch angle is located from the plurality of pitch angle intervals; and determine the target distance between the target to be detected and the PTZ camera based on the intersection coordinates of the direction vector and the target plane equation corresponding to the target pitch angle interval. The acquisition module is specifically configured to determine the first sample focus position based on the first sample distance between the sample target and the PTZ camera: determine the first sample distance based on the longitudinal field of view of the PTZ camera, the sample pitch angle of the vertical rotation of the PTZ camera, the hanging height of the PTZ camera, the height of the sample target, the longitudinal pixel coordinates corresponding to the sample target in the picture, and the total number of longitudinal pixels in the picture; and query the mapping relationship based on the first sample distance to obtain the first sample focus position; The acquisition module searches for peripheral focus positions of the first sample focus position to obtain the second sample focus position, and is specifically used to: obtain multiple scanning steps corresponding to multiple object distance segments; wherein, for each object distance segment, query the mapping relationship through the first object distance corresponding to the object distance segment to obtain the focus position corresponding to the first object distance, and query the mapping relationship through the second object distance corresponding to the object distance segment to obtain the focus position corresponding to the second object distance; determine the scanning step corresponding to the object distance segment based on the first object distance, the second object distance, the focus position corresponding to the first object distance, and the focus position corresponding to the second object distance; for each scanning step, search for peripheral focus positions of the first sample focus position based on the scanning step, focus the PTZ camera based on the searched focus position, collect sample images of the sample target, and determine the clarity score based on the sample image; determine the focus position corresponding to the maximum clarity score as the second sample focus position; The acquisition module determines a second sample distance based on the second sample focus position, and acquires the sample space coordinates based on the second sample distance by querying the mapping relationship through the second sample focus position to obtain the second sample distance; determines the spherical coordinates of the sample target in the polar coordinate system based on the second sample distance, a sample deflection angle of horizontal rotation, and a sample pitch angle of vertical rotation of the PTZ camera; and converts the spherical coordinates of the sample target in the polar coordinate system into the sample space coordinates of the sample target in the three-dimensional coordinate system based on a conversion relationship between the polar coordinate system and the three-dimensional coordinate system; Among them, the acquisition module corrects the plane equation parameters of the initial plane equation, and when determining the corrected plane equation as the target plane equation, is specifically used to: obtain parameter correction data corresponding to the correction target, where the correction target is the target before the target to be detected, and the parameter correction data includes the target distance between the correction target and the PTZ camera, the target deflection angle and target pitch angle of the PTZ camera, and the target focus position corresponding to the target distance; search for peripheral focus positions of the target focus position, select a clear focus position from the searched focus positions, and determine the correction distance between the correction target and the PTZ camera based on the clear focus position; determine the first spatial coordinate of the correction target in the three-dimensional coordinate system based on the target distance, the target deflection angle, and the target pitch angle; determine the second spatial coordinate of the correction target in the three-dimensional coordinate system based on the correction distance, the target deflection angle, and the target pitch angle; determine a deviation vector based on the first spatial coordinate and the second spatial coordinate, and correct the plane equation parameters based on the deviation vector and the configured correction coefficient to obtain the target plane equation.

9. An electronic device, characterized in that: include: a processor and a machine-readable storage medium storing machine-executable instructions capable of being executed by the processor; The processor is configured to execute machine-executable instructions to implement the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Automatic focusing method and PTZ (Pan / Tilt / Zoom) camera

    CN108076281A