PTZ camera automatic zoom method, device, equipment, storage medium and computer program products
By constructing a set of focal length and image size ratios for PTZ cameras and combining it with the size ratio of the current frame image, the target focal length is found, thus solving the adaptiveness and speed issues of zoom control for PTZ cameras and achieving more efficient and precise zoom adjustment.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 武汉船舶职业技术学院
- Filing Date
- 2025-06-12
- Publication Date
- 2026-07-17
AI Technical Summary
Existing PTZ camera zoom control cannot adapt to changes in the distance of the target, resulting in decreased image clarity or the target falling out of the frame. Furthermore, the zoom convergence speed is slow, and the zoom performance is poor.
Based on the current focal length, query the preset focal length and image size ratio set to obtain multiple image size ratios; determine the current image size ratio based on the current frame image size and the target size; construct a size focal length ratio set, and find the target focal length within this set by using the preset target size focal length ratio to ensure the stability and accuracy of zoom calculation.
The zoom performance of the PTZ camera has been improved, enabling a rapid response to changes in target size and image size, ensuring that the target remains stable in the zoomed image, and improving zoom accuracy and consistency.
Smart Images

Figure CN120640133B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of camera focusing technology, and in particular to a method, apparatus, device, storage medium, and computer program product for automatic zooming of a PTZ camera. Background Technology
[0002] PTZ (Pan-Tilt-Zoom) cameras are widely used in intelligent video surveillance, intelligent transportation, drone aerial photography, industrial inspection, and other fields. To ensure the camera can capture clear target images in real time, the focal length typically needs to be adjusted according to changes in the target's size within the frame to maintain appropriate proportions and resolution. However, existing PTZ camera zoom control is either only suitable for static monitoring scenarios, unable to adapt to changes in target distance, resulting in decreased image clarity or the target falling out of the frame; or it involves continuously adjusting the focal length and comparing the target size with a preset proportion after each adjustment until the target size range is reached, which is computationally complex and results in slow zoom convergence, leading to poor zoom performance. Therefore, improving the automatic zoom performance of PTZ cameras has become a pressing technical problem. Summary of the Invention
[0003] The main objective of this application is to provide a method, apparatus, device, storage medium, and computer program product for automatic zooming of a PTZ camera, aiming to solve the technical problem of how to improve the automatic zooming performance of a PTZ camera.
[0004] To achieve the above objectives, this application provides an automatic zoom method for a PTZ camera, the method comprising the following steps:
[0005] Based on the current focal length, query the preset focal length and image size ratio set to obtain multiple image size ratios;
[0006] Determine the aspect ratio of the current image based on the size of the current frame image and the size of the target in the current frame image;
[0007] Based on the multiple image size ratios and the current image size ratio, a size-focal-length ratio set is obtained, wherein the size-focal-length ratio set includes the ratios of the image size of the shooting target at different focal lengths;
[0008] Based on the preset target size focal length ratio, a search is performed within the set of size focal length ratios;
[0009] Based on the search results, determine the target focal length.
[0010] In one embodiment, before the step of querying a preset focal length and image size ratio set based on the current focal length to obtain multiple image size ratios, the method further includes:
[0011] Obtain the width and height of images captured by the preset calibration board at different focal lengths;
[0012] The width and height are normalized, and the preset calibration plate is used as a reference to obtain the preset focal length and image size ratio set.
[0013] In one embodiment, before the step of determining the current image size ratio based on the size of the current frame image and the size of the target in the current frame image, the method further includes:
[0014] Acquire the current frame image captured by the PTZ camera and identify the size of the current frame image;
[0015] Based on a preset target detection algorithm, the captured target in the current frame image is identified;
[0016] The size of the target in the current frame image is determined based on the size of the current frame image.
[0017] In one embodiment, the step of searching within the set of focal length ratios based on a preset target size focal length ratio includes:
[0018] Calculate the difference between the preset target size focal length ratio and each ratio in the set of size focal length ratios;
[0019] The matching degree is determined based on the difference, wherein the larger the difference, the smaller the matching degree;
[0020] The ratio corresponding to the maximum matching degree of the size focal length ratio is used as the search result.
[0021] In one embodiment, after the step of determining the target focal length based on the search result, the method further includes:
[0022] The target focal length is verified, and the verified target focal length is transmitted to the PTZ camera.
[0023] In one embodiment, before the step of obtaining the size focal length ratio set based on the plurality of image size ratios and the current image size ratio, the method further includes:
[0024] A Kalman filter is used to smooth the size of the current frame image and the size of the target in the current frame image.
[0025] Furthermore, to achieve the above objectives, this application also proposes an automatic zoom device for a PTZ camera, the automatic zoom device for a PTZ camera comprising:
[0026] The query module is used to query a set of preset focal length and image size ratios based on the current focal length, and obtain multiple image size ratios;
[0027] The current aspect ratio module is used to determine the current image size ratio based on the size of the current frame image and the size of the target in the current frame image;
[0028] The size focal length ratio module is used to obtain a size focal length ratio set based on the multiple image size ratios and the current image size ratio. The size focal length ratio set includes the ratios of the image size of the shooting target at different focal lengths.
[0029] The matching module is used to search within the set of preset target size focal length ratios.
[0030] The target module is used to determine the target focal length based on the search results.
[0031] In addition, to achieve the above objectives, this application also proposes a PTZ camera auto-zoom device, the device comprising: a memory, a processor, and a PTZ camera auto-zoom program stored in the memory and executable on the processor, the PTZ camera auto-zoom program being configured to implement the steps of the PTZ camera auto-zoom method as described above.
[0032] In addition, to achieve the above objectives, this application also proposes a storage medium storing a PTZ camera auto-zoom program, which, when executed by a processor, implements the steps of the PTZ camera auto-zoom method described above.
[0033] In addition, to achieve the above objectives, this application also proposes a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the PTZ camera auto-zoom method described above.
[0034] This application, based on the current focal length, queries a preset focal length and image size ratio set to obtain multiple image size ratios; determines the current image size ratio based on the size of the current frame image and the size of the target in the current frame image; obtains a size-focal length ratio set based on the multiple image size ratios and the current image size ratio, the size-focal length ratio set including the image size ratios of multiple targets at different focal lengths; searches within the size-focal length ratio set based on a preset target size-focal length ratio; and determines the target focal length based on the search results. This application queries a preset set of focal lengths and image size ratios to obtain multiple image size ratios corresponding to different focal lengths based on the current focal length, providing reference data for subsequent zoom calculations and ensuring the stability of the zoom calculation. By calculating the current frame image size ratio, the proportion of the target in the current frame image is obtained in real time, enabling the zoom calculation to adapt to different target sizes and image size changes. Furthermore, by combining multiple image size ratios with the current image size ratio, a size-focal length ratio set is constructed. This ratio set contains the size change pattern of the target at different focal lengths, improving the accuracy of focal length calculation and zoom matching. Subsequently, based on the preset target size-focal length ratio, a search is performed in the size-focal length ratio set to directly match the closest ratio item, avoiding the inefficient calculation method of traditional step-by-step focal length adjustment, and improving the speed and response of zoom. Finally, the target focal length is determined based on the search results to ensure that the target size remains stable in the zoomed image, improving zoom accuracy and consistency, and thus enhancing the overall zoom performance of the PTZ camera. Attached Figure Description
[0035] Figure 1 This is a flowchart illustrating the first embodiment of the PTZ camera automatic zoom method of this application;
[0036] Figure 2 This is a schematic diagram of a sub-process in the second embodiment of the PTZ camera automatic zoom method of this application;
[0037] Figure 3 This is a schematic diagram of a sub-process in the third embodiment of the PTZ camera automatic zoom method of this application;
[0038] Figure 4 This is a schematic diagram of the module structure of the PTZ camera automatic zoom device according to an embodiment of this application;
[0039] Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the PTZ camera automatic zoom method in the embodiments of this application.
[0040] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0041] It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of this application.
[0042] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0043] It's important to note that PTZ (Pan-Tilt-Zoom) cameras are widely used in intelligent video surveillance, intelligent transportation, drone aerial photography, and industrial inspection. To ensure the camera can capture clear target images in real time, the focal length typically needs to be adjusted based on changes in the target's size within the frame to maintain appropriate proportions and resolution. However, existing PTZ camera zoom control either only works for static monitoring scenarios, failing to adapt to changes in target distance, resulting in decreased image clarity or the target falling out of the frame; or it involves continuously adjusting the focal length and comparing the target size with a preset proportion after each adjustment until the target size range is reached, leading to complex calculations, slow zoom convergence, and poor zoom performance. Therefore, improving the automatic zoom performance of PTZ cameras has become a pressing technical problem.
[0044] The main solution of this application is as follows: Based on the current focal length, query a preset focal length and image size ratio set to obtain multiple image size ratios; determine the current image size ratio based on the size of the current frame image and the size of the target in the current frame image; obtain a size-focal length ratio set based on the multiple image size ratios and the current image size ratio, the size-focal length ratio set including the ratios of the image sizes of multiple targets at different focal lengths; search within the size-focal length ratio set based on the preset target size-focal length ratio; and determine the target focal length based on the search results.
[0045] This application queries a preset set of focal lengths and image size ratios to obtain multiple image size ratios corresponding to different focal lengths based on the current focal length, providing reference data for subsequent zoom calculations and ensuring the stability of the zoom calculation. By calculating the current frame image size ratio, the proportion of the target in the current frame image is obtained in real time, enabling the zoom calculation to adapt to different target sizes and image size changes. Furthermore, by combining multiple image size ratios with the current image size ratio, a size-focal length ratio set is constructed. This ratio set contains the size change pattern of the target at different focal lengths, improving the accuracy of focal length calculation and zoom matching. Subsequently, based on the preset target size-focal length ratio, a search is performed in the size-focal length ratio set to directly match the closest ratio item, avoiding the inefficient calculation method of traditional step-by-step focal length adjustment, and improving the speed and response of zoom. Finally, the target focal length is determined based on the search results to ensure that the target size remains stable in the zoomed image, improving zoom accuracy and consistency, and thus enhancing the overall zoom performance of the PTZ camera.
[0046] It should be noted that the execution subject of the method in this embodiment can be a computing service device with data processing, network communication, and program execution functions, or it can be the aforementioned PTZ camera auto-zoom device with the same or similar functions. This embodiment and the following embodiments will be described using a PTZ camera auto-zoom device as an example.
[0047] Based on this, a first embodiment of the PTZ camera automatic zoom method of this application is proposed. Please refer to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the PTZ camera automatic zoom method of this application.
[0048] In this embodiment, the PTZ camera automatic zoom method includes the following steps:
[0049] S1: Based on the current focal length, query the preset focal length and image size ratio set to obtain multiple image size ratios;
[0050] It should be noted that the current focal length refers to the optical focal length value used by the PTZ camera at the current moment, which determines the camera's magnification and shooting angle. The preset focal length to image size ratio set refers to the image size ratio data at different focal lengths pre-stored during the camera calibration phase, describing the size variation of the target captured by the camera at different focal lengths. The image size ratio refers to the ratio of the target size to the overall image size at a specific focal length, typically including the ratio of the target width to the image width and the ratio of the target height to the image height.
[0051] Specifically, before a PTZ camera performs automatic zoom, it first needs to obtain the current focal length value. The current focal length parameter of the camera is read, and this focal length value is used to query a preset set of focal length and image size ratios to find the image size ratio data corresponding to the current focal length. Furthermore, to obtain more comprehensive ratio information, the ratio data corresponding to multiple focal length values adjacent to the current focal length is also queried to ensure more accurate interpolation matching in subsequent calculations.
[0052] Furthermore, after the query is completed, it returns the image size ratios at multiple different focal lengths. These ratios reflect the size variation trend of the target at different focal lengths, providing a reference for subsequent zoom calculations. Since the preset ratio set is measured and stored during the calibration phase, its data is stable and has small errors, providing reliable basic data for zoom calculations. By obtaining the ratio data for multiple focal lengths, interpolation calculations can be performed between different focal lengths, ensuring more accurate and smooth zoom adjustments.
[0053] By querying a preset set of focal length and image size ratios based on the current focal length, the system obtains image size ratios at multiple different focal lengths, ensuring the stability, accuracy, and adaptability of zoom calculations. Compared to traditional methods that directly measure the current target size and calculate the focal length, this step utilizes preset ratio data, reducing calculation errors and improving the stability of zoom calculations. Furthermore, querying image size ratios at multiple focal lengths allows the system to more accurately predict changes in target size at different focal lengths, thereby improving the accuracy of zoom calculations, ensuring a more stable target size in the image, and providing accurate input data for subsequent automatic zoom calculations, making zoom adjustments more precise, efficient, and smooth.
[0054] S2: Determine the aspect ratio of the current image based on the size of the current frame image and the size of the target in the current frame image;
[0055] It's important to note that the current frame image size refers to the overall width and height of the single frame image captured by the camera, typically measured in pixels. This size is used to calculate the proportion of the target within the image. The captured target size refers to the width and height of the target detected by the camera within the current frame image, usually identified using object detection algorithms (such as YOLO or Faster R-CNN). The current image size ratio refers to the proportional relationship between the size of the captured target and the overall size of the current frame image, typically including the ratio of target width to image width and the ratio of target height to image height, used to describe the target's proportion within the frame.
[0056] Specifically, after the camera captures the current frame image, it first obtains the overall size information of the frame image, namely the width and height of the image. This data is usually provided by the camera's imaging module and serves as a reference for calculating the target's proportions. Subsequently, an object detection algorithm is used to analyze the current frame image, identify the location of the captured target, and obtain the target's width and height. The object detection algorithm can be based on deep learning (such as YOLO, Faster R-CNN) or on traditional image processing (such as edge detection, color segmentation, etc.), and the specific method is selected according to the application requirements.
[0057] Furthermore, after obtaining the overall size and target size of the current frame image, the proportion of the target size in the image is calculated, i.e., the current image size ratio. This ratio can be normalized to convert the target size into a relative proportion, so that the calculation result is not affected by the image resolution. The calculation result of the current image size ratio will be used for subsequent zoom calculations, matched with preset ratio data at different focal lengths to determine the optimal focal length.
[0058] By calculating the ratio between the current frame image size and the target size, the proportion of the target in the current image is provided, offering crucial input data for automatic zoom calculation. Compared to traditional methods that directly calculate focal length based on the absolute target size, this step ensures greater adaptability and consistency in zoom calculation by calculating the target's proportion within the entire frame. This method can adapt to variations in resolution, target size, and camera angle, making zoom calculation more accurate. Furthermore, by matching with a preset set of focal length to image size ratios, this ratio can be further used for focal length calculation, making zoom adjustments more stable and improving the zoom accuracy and image consistency of the PTZ camera.
[0059] S3: Based on the multiple image size ratios and the current image size ratio, a size-focal-length ratio set is obtained, wherein the size-focal-length ratio set includes the ratios of the image size of the multiple shooting targets at different focal lengths;
[0060] It should be noted that the multiple image size ratios refer to the image size ratios corresponding to different focal lengths obtained from a set of preset focal lengths and image size ratios, reflecting the size changes of the target at different focal lengths. The current image size ratio refers to the target size proportion calculated based on the size of the current frame image and the size of the captured target, representing the relative size of the target in the current frame image. The size-focal-length ratio set refers to a set of correspondences between target size and different focal lengths generated by combining multiple image size ratios and the current image size ratio, used for subsequent zoom calculations. This ratio set can reflect the size change trend of the target at different focal lengths, providing reference data for accurately matching the optimal focal length.
[0061] Specifically, by combining the image size ratios at multiple focal lengths with the current image size ratio, a size-focal-length ratio set is generated. This ratio set records the trend of target size variation at different focal lengths and can be used to calculate the optimal focal length.
[0062] Optionally, missing focal length-size ratio terms in the ratio set can be filled in using data interpolation methods (such as linear interpolation or polynomial fitting) to make the data more continuous and improve the accuracy of matching calculations. If the current image size ratio does not directly match a certain term in the ratio set, a closer ratio can be obtained through interpolation to optimize focal length calculations.
[0063] By integrating image size ratios at multiple focal lengths with the current image size ratio, a complete set of size-focal length correspondences is established, providing high-precision reference data for subsequent zoom calculations. Compared to traditional methods that calculate focal length based solely on the current target size, this step incorporates the target size variation trend across multiple focal lengths, ensuring more accurate and stable focal length calculations. Furthermore, data interpolation optimizes matching accuracy; even if the target size ratio does not directly match, the optimal focal length can be inferred through calculation, avoiding zoom errors caused by missing data. Ultimately, this step ensures the efficiency, accuracy, and stability of zoom calculations, improving the automatic zoom performance of the PTZ camera and enabling it to maintain a stable target size under varying scene conditions and target size changes, thus optimizing image quality.
[0064] S4: Based on the preset target size focal length ratio, search within the set of size focal length ratios;
[0065] S5: Determine the target focal length based on the search results.
[0066] It's important to note that the preset target size focal length ratio refers to the ideal size ratio of the target within the image, i.e., the desired size standard for the target in the image. This ratio is used to find a matching focal length. The search result refers to the closest match found in the set of size focal length ratios to the preset target size focal length ratio; the focal length value corresponding to this match is the basis for zoom adjustment. The target focal length refers to the final calculated optimal focal length, ensuring that the target's size in the image conforms to the set expected ratio, achieving precise zoom.
[0067] Specifically, a target size ratio is preset, representing the ideal size of the target in the final image. For example, in an intelligent monitoring system, the target (such as pedestrians or vehicles) should occupy a certain proportion of the image to ensure clarity and recognizability. The system searches the set of size-to-focal-length ratios for the closest match to the preset target size ratio. If a perfectly matching ratio exists, the corresponding focal length is directly selected. If no perfectly matching ratio exists, the ratio with the smallest error to the preset target size ratio is used as the initial match. If the target ratio falls between two ratios, an interpolation algorithm is used to calculate the optimal matching ratio, and the focal length is calculated accordingly to improve calculation accuracy.
[0068] Furthermore, by searching for a matching ratio, the corresponding focal length value is obtained. This focal length value is the optimal zoom parameter calculated by the system, used to adjust the camera's focal length so that the target size meets the expectation. The calculated target focal length is transmitted to the zoom control module of the PTZ camera, and the camera adjusts to this focal length value so that the target size is consistent with the preset standard. This process can be automated without manual intervention, ensuring that the camera can adapt to changes in target size in real time and maintain stable monitoring or shooting quality.
[0069] This step finds the element whose focal length ratio best matches the preset target size ratio and calculates the target focal length, ensuring the PTZ camera can automatically adjust its focus to ensure the target's size in the frame conforms to the set standard. Compared to traditional manual adjustments or gradual trial-and-error methods, this step quickly determines the optimal focal length through data matching and interpolation, reducing the number of zoom calculation iterations and improving zoom efficiency. Furthermore, combining this with the preset target size ratio makes zoom adjustment more intelligent and standardized, avoiding fluctuations in target size due to changes in target distance. Ultimately, this step improves zoom accuracy, computational efficiency, and image stability, enabling the PTZ camera to accurately maintain target size and improve video shooting quality in applications such as intelligent surveillance, drone tracking, and traffic monitoring.
[0070] This embodiment, based on the current focal length, queries a preset focal length and image size ratio set to obtain multiple image size ratios; determines the current image size ratio based on the size of the current frame image and the size of the target in the current frame image; obtains a size-focal length ratio set based on the multiple image size ratios and the current image size ratio, the size-focal length ratio set including the image size ratios of multiple targets at different focal lengths; searches are performed in the size-focal length ratio set based on the preset target size-focal length ratio; and the target focal length is determined based on the search results. This embodiment queries a preset set of focal lengths and image size ratios to obtain multiple image size ratios corresponding to different focal lengths based on the current focal length, providing reference data for subsequent zoom calculations and ensuring the stability of the zoom calculation. By calculating the current frame image size ratio, the proportion of the target in the current frame image is obtained in real time, enabling the zoom calculation to adapt to different target sizes and image size changes. Furthermore, by combining multiple image size ratios with the current image size ratio, a size-focal length ratio set is constructed. This ratio set contains the size change pattern of the target at different focal lengths, improving the accuracy of focal length calculation and zoom matching. Subsequently, based on the preset target size-focal length ratio, a search is performed in the size-focal length ratio set to directly match the closest ratio item, avoiding the inefficient calculation method of traditional step-by-step focal length adjustment, and improving the speed and response of zoom. Finally, the target focal length is determined according to the search results to ensure that the target size remains stable in the zoomed image, improving zoom accuracy and consistency, and thus enhancing the overall zoom performance of the PTZ camera.
[0071] Based on the first embodiment described above, a second embodiment of the PTZ camera auto-zoom method of this application is proposed. Please refer to... Figure 2 , Figure 2 This is a schematic diagram of a sub-process in the second embodiment of the PTZ camera automatic zoom method of this application.
[0072] like Figure 2 As shown, in this embodiment, before step S1, the following steps are also included:
[0073] S1a: Obtain the width and height of images captured by the preset calibration board at different focal lengths;
[0074] S1b: Normalize the width and height, and use the preset calibration plate as a reference to obtain the preset focal length and image size ratio set.
[0075] It should be noted that the preset calibration plate is a standard reference used in the camera focal length calibration process. It is usually a rectangular plate of known size, used to measure the changes in image size at different focal lengths. Normalization refers to converting the measured image size into a relative scale so that it is independent of the camera's resolution and shooting conditions. This usually involves scaling the width and height of the calibration plate to a standardized value (such as 1) as a proportional reference.
[0076] Specifically, during camera installation or calibration, a fixed-size calibration board (e.g., a 60cm x 60cm square plate) is needed as a reference. The calibration board is photographed at different focal lengths to obtain its width and height in the image. The process is as follows: First, fix the camera position and shooting angle: ensure the camera's optical axis is perpendicular to the calibration board to avoid perspective distortion; use fixed lighting conditions to prevent brightness variations from affecting measurement accuracy. Then, adjust the focal length sequentially and photograph the calibration board: starting from the minimum focal length, take one image of the calibration board after each focal length adjustment. For example, if the camera has 30x optical zoom, 30 images at different focal lengths are needed. In each image, measure the width and height of the calibration board in the frame and record the data. It should be noted that the calibration board is placed 120 meters away from the camera for photographing.
[0077] Furthermore, after obtaining the width and height of the calibration board at different focal lengths, they are normalized to establish a universal focal length-image size ratio. The specific steps are as follows: First, normalize the calibration board size: set a standard value (e.g., normalize the width and height of the calibration board to 1), and then calculate the aspect ratio of the calibration board in the image at each focal length. This way, regardless of changes in camera resolution, the same ratio data can be used for zoom calculations. Next, establish a preset focal length-image size ratio set: organize the normalized width and height at different focal lengths into a table, forming a preset focal length-image size ratio set. This dataset serves as the matching basis for subsequent automatic zoom, used to calculate the correspondence between target size and focal length, thereby accurately determining the appropriate focal length.
[0078] This step establishes a standardized set of focal length-to-image size ratios by acquiring and normalizing the image dimensions of the calibration board at different focal lengths, providing accurate reference data for subsequent zoom calculations. Compared to traditional methods that rely on iterative calculations through successive focal length adjustments, this application uses offline calibration to pre-build a focal length-to-image size ratio data table, making zoom calculations more efficient and accurate. Furthermore, this method eliminates the influence of environmental factors such as camera resolution and lighting conditions on zoom calculations, improving the stability and consistency of the calculations and ensuring that PTZ cameras can achieve accurate automatic zoom in various application scenarios.
[0079] Based on the first embodiment described above, in this embodiment, before step S2, the following is further included:
[0080] S2a: Acquire the current frame image captured by the PTZ camera and identify the size of the current frame image;
[0081] S2b: Identify the target being captured in the current frame image based on a preset target detection algorithm;
[0082] S2c: Determine the size of the target in the current frame image based on the size of the current frame image.
[0083] It should be noted that the preset object detection algorithm is either YOLO (You Only Look Once) or Faster R-CNN algorithm based on deep learning.
[0084] Specifically, the PTZ camera operates continuously, capturing a video stream at a set frame rate. At a given moment, it acquires a current frame image. This image contains the entire monitored scene or shooting area, including the background and multiple potential targets. The resolution information of the current frame image, i.e., the image width (W_image) and height (H_image), is read through the camera system interface or image processing software for subsequent target size calculations. A preset target detection algorithm is used to analyze the current frame image to identify potential targets. The choice of target detection algorithm depends on the application requirements. For example, deep learning-based target detection (such as YOLO and Faster R-CNN) is suitable for complex environments and multi-target detection; traditional target detection based on color, edge, or shape is suitable for regular targets, such as industrial parts inspection. The target detection algorithm outputs a bounding box, marking the target's location in the image.
[0085] Furthermore, the target size is determined by the target's bounding box, which represents the target's actual pixel size in the current frame image and is a core parameter for subsequent zoom calculations. After the target size is calculated, it is combined with the overall size of the current frame image to calculate the target's proportion in the image, serving as a key basis for zoom adjustments.
[0086] This step acquires the current frame image, applies a target detection algorithm to identify the target, and calculates the target's size in the image, providing crucial input data for automatic zoom. Compared to traditional methods that rely on manually setting the target size, this approach can automatically detect targets in dynamic environments and calculate their size in real time, improving intelligence and adaptability. Furthermore, through pre-set target detection algorithms, it can adapt to different scenarios, such as intelligent surveillance, drone target tracking, and intelligent transportation, ensuring accurate target identification even when the target size changes. This provides stable and accurate input data for subsequent zoom calculations, thereby improving the automatic zoom accuracy and response speed of the PTZ camera.
[0087] This embodiment, based on the current focal length, queries a preset focal length and image size ratio set to obtain multiple image size ratios; determines the current image size ratio based on the size of the current frame image and the size of the target in the current frame image; obtains a size-focal length ratio set based on the multiple image size ratios and the current image size ratio, the size-focal length ratio set including the image size ratios of multiple targets at different focal lengths; searches are performed in the size-focal length ratio set based on the preset target size-focal length ratio; and the target focal length is determined based on the search results. This embodiment queries a preset set of focal lengths and image size ratios to obtain multiple image size ratios corresponding to different focal lengths based on the current focal length, providing reference data for subsequent zoom calculations and ensuring the stability of the zoom calculation. By calculating the current frame image size ratio, the proportion of the target in the current frame image is obtained in real time, enabling the zoom calculation to adapt to different target sizes and image size changes. Furthermore, by combining multiple image size ratios with the current image size ratio, a size-focal length ratio set is constructed. This ratio set contains the size change pattern of the target at different focal lengths, improving the accuracy of focal length calculation and zoom matching. Subsequently, based on the preset target size-focal length ratio, a search is performed in the size-focal length ratio set to directly match the closest ratio item, avoiding the inefficient calculation method of traditional step-by-step focal length adjustment, and improving the speed and response of zoom. Finally, the target focal length is determined according to the search results to ensure that the target size remains stable in the zoomed image, improving zoom accuracy and consistency, and thus enhancing the overall zoom performance of the PTZ camera.
[0088] Based on the second embodiment described above, a third embodiment of the PTZ camera automatic zoom method of this application is proposed. Please refer to... Figure 3 , Figure 3This is a schematic diagram of a sub-process in the third embodiment of the PTZ camera automatic zoom method of this application.
[0089] In this embodiment, step S4 includes:
[0090] S41: Calculate the difference between the preset target size focal length ratio and each ratio in the set of size focal length ratios;
[0091] S42: Determine the matching degree based on the difference, wherein the larger the difference, the smaller the matching degree;
[0092] S43: Use the ratio corresponding to the maximum matching degree of the size focal length ratio as the search result.
[0093] It should be noted that the difference refers to the numerical deviation between the preset target size focal length ratio and each ratio item in the set of size focal length ratios. It is used to measure the degree of matching; the smaller the difference, the higher the degree of matching. The degree of matching indicates the similarity between the preset target size focal length ratio and each ratio in the set of size focal length ratios. The higher the degree of matching, the closer the ratio item is to the target size ratio. The search result refers to the ratio item with the highest degree of matching in the set of size focal length ratios; the focal length corresponding to this ratio item is the final calculated target focal length.
[0094] Specifically, the preset target size focal length ratio is read. This ratio is a user-defined target size standard, representing the optimal size the target should maintain in the image. Each ratio item in the size focal length ratio set is read sequentially, and the difference between it and the preset target size focal length ratio is calculated. The difference can be calculated using absolute difference to ensure it is not affected by positive or negative values.
[0095] Furthermore, the matching degree is inversely proportional to the difference; that is, the smaller the difference, the higher the matching degree; the larger the difference, the lower the matching degree. By calculating the matching degree, it is possible to determine which ratio items are closest to the target size ratio. Among all the calculated matching degrees, the ratio item with the highest matching degree is selected, that is, the ratio item that is closest to the preset target size ratio. The focal length corresponding to this matching item will be used for subsequent zoom calculations. The focal length value corresponding to this search result will be used as the final target focal length and transmitted to the PTZ camera for automatic zoom adjustment.
[0096] This step calculates the difference between the preset target size focal length ratio and each ratio in the set of target size focal length ratios. Based on the difference, it calculates the matching degree and selects the ratio with the highest matching degree as the search result, ensuring the accuracy and stability of the focal length calculation. Compared to traditional methods that gradually adjust the focal length and compare it with the target size, this step quickly determines the optimal focal length through numerical matching, reducing the number of iterations in zoom calculation and improving the efficiency of zoom calculation. In addition, through matching degree calculation and minimum difference matching, it ensures the optimal match between the target size ratio and the ideal size ratio, avoiding the problem of the target appearing to be larger or smaller in the image. Ultimately, this improves zoom accuracy, response speed, and image stability, enabling PTZ cameras to accurately maintain the target size in scenarios such as intelligent monitoring, automatic tracking, and drone aerial photography, thereby improving video shooting quality.
[0097] Based on the second embodiment described above, in this embodiment, after step S5, the method further includes:
[0098] S5a: Verify the target focal length and transmit the verified target focal length to the PTZ camera.
[0099] It should be noted that verification refers to checking the reasonableness of the target focal length to ensure that the calculation results meet the physical limitations of the camera and the actual application requirements, and to avoid zoom instability caused by calculation errors.
[0100] Specifically, the optical focal length range of the PTZ camera (e.g., 10mm-300mm) is read to ensure the target focal length value falls within this range. If the calculated target focal length exceeds the camera's physical focal length limit, corrections are made (e.g., setting it to the maximum or minimum supported focal length). Based on the target focal length, the size of the target in the image after focal length adjustment is predicted to ensure the target does not exceed the frame or become too small due to excessive zoom. If the target size does not conform to the set expected range, the focal length value is adjusted to maintain the target's appropriate size in the image.
[0101] Furthermore, the verified target focal length is sent to the PTZ camera's zoom control module via the camera control interface (such as serial port commands, network API, or camera SDK). After receiving the focal length value, the camera adjusts the lens focal length to ensure the target size meets the set requirements. After adjusting the focal length, the target size can be reacquired to check if it meets the set expected proportions. If there is still a deviation after adjustment, a compensation mechanism can be triggered to recalculate the focal length and perform fine-tuning to ensure a stable and consistent target size.
[0102] This step verifies the reasonableness of the target focal length and transmits the verified target focal length to the PTZ camera, ensuring that the zoom calculation results are accurate, stable, and conform to physical limitations. Compared to traditional methods that directly apply the calculated focal length, this step first performs a reasonableness check to prevent the focal length from exceeding the camera's range or causing abnormal target size, thus improving the reliability of the zoom calculation.
[0103] Based on the second embodiment described above, in this embodiment, before step S3, the following is further included:
[0104] S3a: Use a Kalman filter to smooth the size of the current frame image and the size of the target in the current frame image.
[0105] It should be noted that the Kalman filter is a recursive algorithm for state estimation. It provides the optimal estimate of the true value even when measurement data is subject to noise interference, and is widely used in target tracking, signal processing, and vision systems. Smoothing refers to making size estimation more stable and accurate by removing measurement errors and noise, avoiding zoom calculation errors caused by measurement fluctuations. Smoothing specifically refers to making target size estimation more stable by eliminating noise in the measurement data, reducing short-term size fluctuations, and thus improving the accuracy and stability of zoom calculations.
[0106] Specifically, state variables are defined, including: target size state (width, height): representing the estimated size of the target in the current frame image; and a state transition matrix: assuming the target size changes smoothly between adjacent frames, allowing the state variables to be updated over time. The current frame image size and target size provided by the target detection algorithm are used as measurement inputs to the filter. Since target detection may be subject to noise (e.g., partial occlusion of the target, detection errors due to lighting variations), the Kalman filter provides a more reliable size estimate by fusing multiple measurements. An initial state estimate is set, i.e., the target size detected in the first frame image. The process noise covariance matrix and measurement noise covariance matrix are defined to control the stability and response speed of the filter.
[0107] Furthermore, based on the target size of the previous frame, the target size of the current frame is predicted, and the prediction error covariance is calculated. Since the target size typically does not change drastically in a short period, the filter can reasonably predict the target size of the next frame, reducing the impact of instantaneous errors on zoom calculations. The target size detected in the current frame is compared with the predicted value, the Kalman gain is calculated, and the predicted value is adjusted to be closer to the true target size. The Kalman gain is dynamically adjusted according to the magnitude of measurement noise; when the measurement data is stable, the gain is smaller, resulting in a smoother filtering result; when the measurement data fluctuates significantly, the gain is larger, allowing the filter to respond quickly to changes. After filtering, the final smoothed target size is obtained, which is more stable, has a smaller error, and can be used for subsequent automatic zoom calculations.
[0108] This step smooths the size of the current frame image and the target size using a Kalman filter, effectively reducing size fluctuations caused by target detection errors, lighting changes, occlusion, and other factors, thus improving the stability and accuracy of size estimation. Compared to directly using unfiltered detection data for zoom calculation, this step makes target size estimation smoother, avoiding zoom focus jitter caused by measurement noise, thereby improving the automatic zoom accuracy of the PTZ camera and the stability of the video image. Furthermore, this step is adaptable to dynamic environments; even if the target size changes within a short period, the filter can still provide a stable and reliable size estimate, making zoom calculation more accurate and improving the effectiveness of applications such as intelligent surveillance, drone tracking, and automatic target recognition.
[0109] This embodiment, based on the current focal length, queries a preset focal length and image size ratio set to obtain multiple image size ratios; determines the current image size ratio based on the size of the current frame image and the size of the target in the current frame image; obtains a size-focal length ratio set based on the multiple image size ratios and the current image size ratio, the size-focal length ratio set including the image size ratios of multiple targets at different focal lengths; searches are performed in the size-focal length ratio set based on the preset target size-focal length ratio; and the target focal length is determined based on the search results. This embodiment queries a preset set of focal lengths and image size ratios to obtain multiple image size ratios corresponding to different focal lengths based on the current focal length, providing reference data for subsequent zoom calculations and ensuring the stability of the zoom calculation. By calculating the current frame image size ratio, the proportion of the target in the current frame image is obtained in real time, enabling the zoom calculation to adapt to different target sizes and image size changes. Furthermore, by combining multiple image size ratios with the current image size ratio, a size-focal length ratio set is constructed. This ratio set contains the size change pattern of the target at different focal lengths, improving the accuracy of focal length calculation and zoom matching. Subsequently, based on the preset target size-focal length ratio, a search is performed in the size-focal length ratio set to directly match the closest ratio item, avoiding the inefficient calculation method of traditional step-by-step focal length adjustment, and improving the speed and response of zoom. Finally, the target focal length is determined according to the search results to ensure that the target size remains stable in the zoomed image, improving zoom accuracy and consistency, and thus enhancing the overall zoom performance of the PTZ camera.
[0110] This application also provides an automatic zoom device for a PTZ camera. Please refer to... Figure 4 , Figure 4 This is a schematic diagram of the module structure of the PTZ camera automatic zoom device according to an embodiment of this application. The PTZ camera automatic zoom device includes:
[0111] The query module 401 is used to query a set of preset focal length and image size ratios based on the current focal length, and obtain multiple image size ratios;
[0112] The current ratio module 402 is used to determine the current image size ratio based on the size of the current frame image and the size of the target in the current frame image;
[0113] The size focal length ratio module 403 is used to obtain a size focal length ratio set based on the plurality of image size ratios and the current image size ratio, wherein the size focal length ratio set includes the ratio of the image size of the shooting target at different focal lengths;
[0114] Matching module 404 is used to search within the set of size focal length ratios based on a preset target size focal length ratio;
[0115] The target module 405 is used to determine the target focal length based on the search results.
[0116] The PTZ camera auto-zoom device provided in this application, employing the PTZ camera auto-zoom method described in the above embodiments, can solve the technical problem of how to improve the auto-zoom performance of PTZ cameras. Compared with the prior art, the beneficial effects of the PTZ camera auto-zoom device provided in this application are the same as those of the PTZ camera auto-zoom method described in the above embodiments, and other technical features in the PTZ camera auto-zoom device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0117] This application provides a PTZ camera auto-zoom device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the PTZ camera auto-zoom method in the above embodiments.
[0118] The following is for reference. Figure 5 , Figure 5 This is a schematic diagram of the hardware operating environment involved in the PTZ camera automatic zoom method in the embodiments of this application, showing a schematic diagram of the structure of the PTZ camera automatic zoom device suitable for implementing the embodiments of this application. Figure 5 The PTZ camera auto-zoom device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0119] like Figure 5As shown, the PTZ camera auto-zoom device may include a processing unit 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1002 or a program loaded from storage device 1003 into random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the PTZ camera auto-zoom device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the PTZ camera autofocus device to communicate wirelessly or wiredly with other devices to exchange data. Although PTZ camera autofocus devices with various systems are shown in the figures, it should be understood that it is not required to implement or possess all the systems shown. More or fewer systems can be implemented alternatively.
[0120] In particular, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. When the computer program is executed by the processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0121] The PTZ camera auto-zoom device provided in this application, employing the PTZ camera auto-zoom method in the above embodiments, can solve the technical problem of how to improve the auto-zoom performance of PTZ cameras. Compared with the prior art, the beneficial effects of the PTZ camera auto-zoom device provided in this application are the same as those of the PTZ camera auto-zoom method provided in the above embodiments, and other technical features in this PTZ camera auto-zoom device are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0122] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0123] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0124] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the PTZ camera auto-zoom method in the above embodiments.
[0125] The aforementioned computer-readable storage medium carries one or more programs that, when executed by the PTZ camera auto-zoom device, cause the PTZ camera auto-zoom device to: query a preset focal length and image size ratio set based on the current focal length to obtain multiple image size ratios; determine the current image size ratio based on the size of the current frame image and the size of the target in the current frame image; obtain a size-focal length ratio set based on the multiple image size ratios and the current image size ratio, the size-focal length ratio set including the ratios of the image sizes of multiple targets at different focal lengths; search within the size-focal length ratio set based on a preset target size-focal length ratio; and determine the target focal length based on the search result. Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0126] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0127] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0128] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described PTZ camera auto-zoom method, thereby solving the technical problem of how to improve the auto-zoom performance of PTZ cameras. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the PTZ camera auto-zoom method provided in the above embodiments, and will not be repeated here.
[0129] This application provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the PTZ camera auto-zoom method described above.
[0130] The computer program product provided in this application can solve the technical problem of how to improve the automatic zoom performance of PTZ cameras. Compared with the prior art, the beneficial effects of the computer program product provided in the embodiments of this application are the same as the beneficial effects of the PTZ camera automatic zoom method provided in the above embodiments, and will not be repeated here.
[0131] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent scope of this application.
Claims
1. A method for automatic zooming of a PTZ camera, characterized in that, The method includes: Obtain the width and height of images captured by the preset calibration board at different focal lengths; The width and height are normalized, and the preset calibration plate is used as a reference to obtain a preset focal length and image size ratio set; Based on the current focal length, query the preset focal length and image size ratio set to obtain multiple image size ratios; Acquire the current frame image captured by the PTZ camera and identify the size of the current frame image; Based on a preset target detection algorithm, the target in the current frame image is identified; The size of the target in the current frame image is determined based on the size of the current frame image; The current image size ratio is determined based on the size of the current frame image and the size of the target in the current frame image; Based on the multiple image size ratios and the current image size ratio, a size-focal-length ratio set is obtained, which includes the ratios of multiple shooting targets and image sizes at different focal lengths; Calculate the difference between the preset target size focal length ratio and each ratio in the set of size focal length ratios; The matching degree is determined based on the difference, wherein the larger the difference, the smaller the matching degree; The ratio corresponding to the maximum matching degree of the size focal length ratio is used as the search result; Based on the search results, determine the target focal length; The target focal length is verified, and the verified target focal length is transmitted to the PTZ camera. If the target focal length exceeds the physical focal length limit of the PTZ camera, the maximum supported focal length or the minimum supported focal length is taken as the target focal length. After the PTZ camera adjusts its focus, it determines whether the compensation mechanism is triggered by checking the target size against the expected ratio.
2. The method as described in claim 1, characterized in that, Before the step of obtaining the size focal length ratio set based on the plurality of image size ratios and the current image size ratio, the method further includes: A Kalman filter is used to smooth the size of the current frame image and the size of the target in the current frame image.
3. An automatic zoom device for a PTZ camera, characterized in that, The device includes: The query module is used to obtain the width and height of images captured by a preset calibration board at different focal lengths; normalize the width and height, and use the preset calibration board as a reference to obtain a set of preset focal length to image size ratios; based on the current focal length, query the set of preset focal length to image size ratios to obtain multiple image size ratios; The current aspect ratio module is used to acquire the current frame image captured by the PTZ camera and identify the size of the current frame image; identify the shooting target in the current frame image based on a preset target detection algorithm; determine the size of the shooting target in the current frame image according to the size of the current frame image; and determine the current image size ratio according to the size of the current frame image and the size of the shooting target in the current frame image. The size focal length ratio module is used to obtain a size focal length ratio set based on the multiple image size ratios and the current image size ratio. The size focal length ratio set includes the ratios of multiple shooting targets and image sizes at different focal lengths. The matching module is used to calculate the difference between the preset target size focal length ratio and each ratio in the set of size focal length ratios; determine the matching degree based on the difference, wherein the larger the difference, the smaller the matching degree; and take the ratio corresponding to the maximum matching degree in the set of size focal length ratios as the search result. The target module is used to determine the target focal length based on the search results; verify the target focal length, and transmit the verified target focal length to the PTZ camera. If the target focal length exceeds the physical focal length limit of the PTZ camera, the maximum supported focal length or the minimum supported focal length is used as the target focal length. After the PTZ camera adjusts its focus, it determines whether the compensation mechanism is triggered by checking the target size against the expected ratio.
4. A computer device, characterized in that, The device includes: a memory, a processor, and a PTZ camera auto-zoom program stored in the memory and executable on the processor, the PTZ camera auto-zoom program being configured to implement the steps of the PTZ camera auto-zoom method as described in any one of claims 1 to 2.
5. A storage medium, characterized in that, The storage medium stores a PTZ camera auto-zoom program, which, when executed by a processor, implements the steps of the PTZ camera auto-zoom method as described in any one of claims 1 to 2.
6. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the steps of the PTZ camera auto-zoom method as described in any one of claims 1 to 2.