PTZ camera automatic zooming method, device and equipment, storage medium and computer program product

By building a size and focal length ratio set for PTZ cameras, adapting to changes in target size, and quickly determining the target focal length, the problem of insufficient zoom performance of PTZ cameras is solved, achieving more efficient and accurate zoom control.

CN120640133AActive Publication Date: 2025-09-12武汉船舶职业技术学院
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202510783943.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-12
Publication Date
2025-09-12
Estimated Expiration
2045-06-12

AI Technical Summary

Technical Problem

The existing PTZ camera zoom control cannot adapt to changes in the distance of the target, resulting in a decrease in image clarity or the target leaving the picture, and the zoom convergence speed is slow and the zoom performance is poor.

Method used

By querying the preset focal length and image size ratio set based on the current focal length, multiple image size ratios are obtained. Combined with the current frame image size ratio, a size-focal length ratio set is constructed, and the closest ratio item is found in the set to determine the target focal length, avoiding the traditional inefficient calculation method of gradually adjusting the focal length.

Benefits of technology

Improves the zoom performance of PTZ cameras, ensuring that the target remains stable in the zoomed image, improves zoom accuracy and consistency, and enhances the stability and speed of zoom calculation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120640133A_ABST
    Figure CN120640133A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of camera focusing, in particular to an automatic zooming method, device and equipment for a PTZ camera, a storage medium and a computer program product. The method comprises the steps of querying a preset focal length and image size proportion set based on a current focal length to obtain a plurality of image size proportions; determining the size proportion of the current image according to the size of the current frame image and the size of the shooting target in the current frame image; according to the plurality of image size proportions and the current image size proportion, a size focal length proportion set is obtained, and the size focal length proportion set comprises the proportions of the image sizes of the plurality of shooting targets under different focal lengths; searching in the size focal length proportion set based on a preset target size focal length proportion; and according to the search result, the target focal length is determined, and the automatic zooming performance of the PTZ camera is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of camera focusing technology, and in particular to a PTZ camera automatic focusing method, apparatus, device, storage medium and computer program product. Background Art

[0002] PTZ (Pan-Tilt-Zoom) cameras are widely used in intelligent video surveillance, intelligent transportation, drone aerial photography, industrial inspection and other fields. In order to ensure that the camera can capture clear target images in real time, it is usually necessary to adjust the focal length according to the size changes of the target in the picture to ensure that the target always maintains the appropriate proportion and resolution. However, the zoom control of existing PTZ cameras is either only applicable to static monitoring scenes and cannot adapt to changes in the distance of the target, resulting in reduced image clarity or the target being out of the picture; or it continuously adjusts the focal length and compares the target size with the preset ratio after each adjustment until the target size range is reached. The calculation is complex and the zoom convergence speed is slow, resulting in poor zoom performance. Therefore, how to improve the automatic zoom performance of PTZ cameras has become a technical problem that needs to be solved urgently. Summary of the Invention

[0003] The main purpose of this application is to provide a PTZ camera automatic zoom method, device, equipment, storage medium and computer program product, aiming to solve the technical problem of how to improve the automatic zoom performance of PTZ cameras.

[0004] To achieve the above object, the present application provides a PTZ camera automatic zoom method, the method comprising the following steps:

[0005] Based on the current focal length, query a preset focal length and image size ratio set to obtain multiple image size ratios;

[0006] Determine the current image size ratio according to the size of the current frame image and the size of the photographed object in the current frame image;

[0007] Obtaining a size-focal-length ratio set according to the multiple image size ratios and the current image size ratio, wherein the size-focal-length ratio set includes ratios of image sizes of multiple objects at different focal lengths;

[0008] Based on a preset target size focal length ratio, searching is performed in the size focal length ratio set;

[0009] Determine the target focal length based on the search results.

[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 a plurality of image size ratios, the method further includes:

[0011] Get the width and height of the preset calibration plate in images taken 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 photographed object 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, identifying the shooting target in the current frame image;

[0016] The size of the shooting target in the current frame image is determined according to the size of the current frame image.

[0017] In one embodiment, the step of searching in the set of size-to-focus ratios based on a preset target size-to-focus ratio includes:

[0018] Calculating the difference between the preset target size focal length ratio and each ratio in the size focal length ratio set respectively;

[0019] Determining a matching degree according to the difference, wherein the greater the difference, the smaller the matching degree;

[0020] The ratio corresponding to the maximum matching degree of the size-focal-length ratio is taken as the search result.

[0021] In one embodiment, after the step of determining the target focal length according to 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 a size-focal-length ratio set according to the multiple image size ratios and the current image size ratio, the step further includes:

[0024] A Kalman filter is used to smooth the size of the current frame image and the size of the photographed object in the current frame image.

[0025] In addition, to achieve the above-mentioned purpose, the present application also proposes an automatic zoom device for a PTZ camera, the automatic zoom device for a PTZ camera comprising:

[0026] A query module, configured to query a preset focal length and image size ratio set based on the current focal length to obtain multiple image size ratios;

[0027] A current ratio module is used to determine the current image size ratio according to the size of the current frame image and the size of the photographed object in the current frame image;

[0028] a size-focal-length ratio module, configured to obtain a size-focal-length ratio set according to the multiple image size ratios and the current image size ratio, wherein the size-focal-length ratio set includes ratios of the image sizes of the multiple photographed objects at different focal lengths;

[0029] A matching module, configured to search the set of size-focus ratios based on a preset target size-focus ratio;

[0030] The target module is used to determine the target focal length based on the search results.

[0031] In addition, to achieve the above-mentioned purpose, the present application also proposes a PTZ camera automatic zoom device, which includes: a memory, a processor, and a PTZ camera automatic zoom program stored in the memory and runnable on the processor, and the PTZ camera automatic zoom program is configured to implement the steps of the PTZ camera automatic zoom method described above.

[0032] In addition, to achieve the above objectives, the present application also proposes a storage medium, on which a PTZ camera automatic zoom program is stored. When the PTZ camera automatic zoom program is executed by a processor, the steps of the PTZ camera automatic zoom method described above are implemented.

[0033] In addition, to achieve the above-mentioned purpose, the present application also proposes a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of the PTZ camera automatic zoom method as described above are implemented.

[0034] This application queries a preset focal length and image size ratio set based on the current focal length 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 shooting 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, and the size focal length ratio set includes the image size ratios of multiple shooting targets at different focal lengths; searches in the size focal length ratio set based on the preset target size focal length ratio; and determines the target focal length based on the search results. This application queries a preset focal length and image size ratio set, obtains image size ratios corresponding to multiple different focal lengths based on the current focal length, provides reference data for subsequent zoom calculations, and ensures the stability of zoom calculations; by calculating the current frame image size ratio, the target's proportion in the current frame image is obtained in real time, so that the zoom calculation can adapt to different target sizes and image size changes; further combining multiple image size ratios with the current image size ratio, constructs a size focal length ratio set, which contains the size change rules of the target at different focal lengths, thereby improving the accuracy of focal length calculation and zoom matching; then, based on the preset target size focal length ratio, searches in the size focal length ratio set and directly matches the closest ratio item, avoiding the traditional inefficient calculation method of gradually adjusting the focal length, and improving the rapidity and response speed of zoom; finally, determines the target focal length based on the search results, ensures that the target size remains stable in the zoomed picture, improves zoom accuracy and consistency, and thereby improves the overall zoom performance of the PTZ camera. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 This is a flow chart of the first embodiment of the automatic zoom method for a PTZ camera of the present application;

[0036] Figure 2 This is a schematic diagram of a sub-flow in the second embodiment of the PTZ camera automatic zoom method of the present application;

[0037] Figure 3 This is a schematic diagram of a sub-flow in the third embodiment of the automatic zoom method for a PTZ camera of the present application;

[0038] Figure 4 This is a schematic diagram of the module structure of the automatic zoom device for a PTZ camera according to an embodiment of the present 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 embodiment of the present application.

[0040] The realization of the objectives, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0041] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0042] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0043] It should be noted that PTZ (Pan-Tilt-Zoom) cameras are widely used in intelligent video surveillance, intelligent transportation, drone aerial photography, industrial inspection and other fields. In order to ensure that the camera can capture clear target images in real time, it is usually necessary to adjust the focal length according to the size change of the target in the picture to ensure that the target always maintains the appropriate proportion and resolution. However, the zoom control of existing PTZ cameras is either only applicable to static monitoring scenes and cannot adapt to changes in the distance of the target, resulting in reduced image clarity or the target being out of the picture; or it continuously adjusts the focal length and compares the target size with the preset ratio after each adjustment until the target size range is reached. The calculation is complex and the zoom convergence speed is slow, resulting in poor zoom performance. Therefore, how to improve the automatic zoom performance of PTZ cameras has become a technical problem that needs to be solved urgently.

[0044] The main solution of this application is: 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 according to the size of the current frame image and the size of the shooting 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, and the size focal length ratio set includes the image size ratios of multiple shooting targets at different focal lengths; based on the preset target size focal length ratio, search in the size focal length ratio set; determine the target focal length according to the search results.

[0045] This application queries a preset focal length and image size ratio set, obtains image size ratios corresponding to multiple different focal lengths based on the current focal length, provides reference data for subsequent zoom calculations, and ensures the stability of zoom calculations; by calculating the current frame image size ratio, the target's proportion in the current frame image is obtained in real time, so that the zoom calculation can adapt to different target sizes and image size changes; further combining multiple image size ratios with the current image size ratio, constructs a size focal length ratio set, which contains the size change rules of the target at different focal lengths, thereby improving the accuracy of focal length calculation and zoom matching; then, based on the preset target size focal length ratio, searches in the size focal length ratio set and directly matches the closest ratio item, avoiding the traditional inefficient calculation method of gradually adjusting the focal length, and improving the rapidity and response speed of zoom; finally, determines the target focal length based on the search results, ensures that the target size remains stable in the zoomed picture, improves zoom accuracy and consistency, and thereby improves the overall zoom performance of the PTZ camera.

[0046] It should be noted that the execution entity of the method of this embodiment can be a computing service device with data processing, network communication, and program execution functions, or it can be the above-mentioned PTZ camera automatic zoom device with the same or similar functions. This embodiment and the following embodiments will be described using the PTZ camera automatic zoom device as an example.

[0047] Based on this, the first embodiment of the PTZ camera automatic zoom method of this application is proposed, please refer to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the automatic zoom method for a PTZ camera of the present application.

[0048] In this embodiment, the PTZ camera automatic zoom method includes the following steps:

[0049] S1: Based on the current focal length, query a 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 used by the PTZ camera at the current moment, which determines the camera's magnification and viewing angle. The preset focal length and image size ratio set refers to the image size ratio data for different focal lengths stored during the camera calibration phase. This data describes the size variation of objects captured by the camera at different focal lengths. The image size ratio refers to the ratio of the object's size to the total image size at a specific focal length, typically including the ratio of the object's width to the image width and the ratio of the object's height to the image height.

[0051] Specifically, before a PTZ camera performs auto-zooming, it first needs to obtain the current focal length value. The camera's focal length parameter is read and used to query a set of preset 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 are also queried, ensuring more accurate interpolation matching during subsequent calculations.

[0052] Furthermore, after the query is completed, the image size ratios at multiple different focal lengths are returned. These ratios reflect the size trend of the target at different focal lengths, providing a reference for subsequent zoom calculations. Because the preset ratio set is measured and stored during the calibration phase, its data is stable and has low errors, providing a reliable foundation for zoom calculations. By obtaining 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 image size ratios at multiple different focal lengths are obtained, ensuring the stability, accuracy, and adaptability of the zoom calculation. Compared to the traditional method of directly measuring the current target size and calculating the focal length, this step utilizes preset ratio data, reducing calculation errors and improving the stability of the zoom calculation. In addition, querying the image size ratios at multiple focal lengths enables the system to more accurately predict changes in target size at different focal lengths, thereby improving the accuracy of the zoom calculation, 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 current image size ratio according to the size of the current frame image and the size of the photographed object in the current frame image;

[0055] It should be noted that the current frame image size refers to the overall width and height of the single frame image currently captured by the camera, usually in pixels. This size is used to calculate the proportion of the target in the image. The captured target size refers to the width and height of the target detected by the camera in the current frame image, usually identified by target detection algorithms (such as YOLO and 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, usually including the ratio of the target width to the image width and the ratio of the target height to the image height, which is used to describe the proportion of the target in the picture.

[0056] Specifically, after the camera captures the current frame, it first obtains the overall size information of the frame, namely the width and height of the image. This data is typically provided by the camera's imaging module and serves as a reference for calculating the target scale. Subsequently, an object detection algorithm is used to analyze the current frame, 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 and Faster R-CNN) or traditional image processing (such as edge detection and color segmentation). The specific method is selected based on the application requirements.

[0057] Furthermore, after obtaining the overall size of the current frame image and the target size, the target size's proportion within the image is calculated, known as the current image size ratio. This ratio can be normalized to convert the target size into a relative ratio, making the calculation unaffected by image resolution. The calculated current image size ratio is then used in subsequent zoom calculations and matched against preset ratio data for different focal lengths to determine the optimal focal length.

[0058] By calculating the proportional relationship between the current frame image size and the target size, information about the target's proportion in the current image is provided, providing key input data for automatic zoom calculations. Compared to traditional methods that directly calculate focal length based on the absolute size of the target, this step ensures that the zoom calculation is more adaptable and consistent by calculating the proportion of the target size in the entire picture. This method can adapt to changes in different resolutions, different target sizes, and camera viewing angles, making zoom calculations more accurate. In addition, by matching with a preset focal length and image size ratio set, this ratio can be further used in focal length calculations, making zoom adjustments more stable and improving the zoom accuracy and image consistency of PTZ cameras.

[0059] S3: obtaining a size-focal-length ratio set according to the multiple image size ratios and the current image size ratio, wherein the size-focal-length ratio set includes ratios of the image sizes of the multiple shooting targets at different focal lengths;

[0060] It should be noted that 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 change of the target at different focal lengths. The current image size ratio refers to the target size ratio calculated based on the size of the current frame image and the size of the captured target, indicating 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 with the current image size ratio, and is used for subsequent zoom calculations. This ratio set can reflect the size change trend of the target at different focal lengths and provide reference data for accurately matching the optimal focal length.

[0061] Specifically, the image size ratios at multiple focal lengths are combined with the current image size ratio to generate a size-to-focus ratio set. This ratio set records the changing trend of the target size at different focal lengths and can be used to calculate the optimal focal length.

[0062] Optionally, data interpolation methods (such as linear interpolation or polynomial fitting) can be used to fill in missing focal length-size ratio terms in the ratio set, making the data more continuous and improving the accuracy of the matching calculation. If the current image size ratio does not directly match an item in the ratio set, interpolation can be used to obtain a closer ratio to optimize the focal length calculation.

[0063] By integrating the 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 the traditional method of calculating the focal length based only on the current target size, this step combines the target size change trend at multiple focal lengths to ensure that the focal length calculation is more accurate and stable. In addition, the matching accuracy can be optimized through data interpolation. Even if the target size ratio cannot be directly matched, the optimal focal length can be inferred through calculation to avoid zoom errors caused by missing data. Ultimately, this step ensures the efficiency, accuracy and stability of the zoom calculation, improves the automatic zoom performance of the PTZ camera, and enables it to always keep the target size stable in different scenes and when the target size changes, thereby optimizing the shooting quality.

[0064] S4: searching in the size-focal-length ratio set based on a preset target size-focal-length ratio;

[0065] S5: Determine the target focal length based on the search result.

[0066] It should be noted that the preset target size-to-focal-length ratio refers to the ideal size ratio of the target in the image, that is, the desired size standard for the target in the image. This ratio is used to search for a matching focal length. The search result is the closest match found in the size-to-focal-length ratio set to the preset target size-to-focal-length ratio. The focal length corresponding to this match serves as the basis for zoom adjustment. The target focal length is the final calculated optimal focal length, ensuring that the target size in the image meets the desired ratio, achieving precise zoom.

[0067] Specifically, the target size ratio is pre-set to indicate the ideal size of the target in the final image. For example, in an intelligent monitoring system, the target (such as pedestrians and vehicles) should occupy a certain proportion of the image to ensure clarity and recognizability. The closest matching item to the preset target size ratio is found in the size focal length ratio set. If there is an item in the ratio set that is exactly the same as the preset ratio, the corresponding focal length is directly selected. If there is no completely matching item, the item with the smallest error from the preset target size ratio is found as the preliminary matching result. If the target ratio falls between two ratio items, the interpolation algorithm is used to calculate the optimal matching ratio, and the focal length is inferred based on this to improve the calculation accuracy.

[0068] Furthermore, by searching for matching scale items, the corresponding focal length value is obtained. This focal length value, the system's calculated optimal zoom parameter, is used to adjust the camera's focal length to ensure the target size meets the desired target. The calculated target focal length is transmitted to the PTZ camera's zoom control module, which adjusts the camera to this focal length value to ensure the target size matches the preset standard. This process can be automated, eliminating the need for human intervention, ensuring that the camera can adapt to changes in target size in real time, maintaining stable monitoring or filming quality.

[0069] This step ensures that the PTZ camera can automatically adjust the focal length by finding the item in the size-focal-length ratio set that best matches the preset target size ratio and calculating the target focal length, so that the size of the target in the picture meets the set standard. Compared with the traditional method of manual adjustment or gradual trial of focal length, this step quickly determines the optimal focal length through data matching and interpolation calculation, reduces the number of iterations of zoom calculation, and improves zoom efficiency. In addition, combined with the preset target size ratio, the zoom adjustment is more intelligent and standardized, avoiding the problem of target size fluctuating due to changes in target distance. Ultimately, this step improves zoom accuracy, calculation efficiency, and image stability, enabling PTZ cameras to accurately maintain target size and improve video shooting quality in application scenarios such as intelligent monitoring, drone tracking, and traffic monitoring.

[0070] This embodiment queries a preset focal length and image size ratio set based on the current focal length 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 photographed 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, where the size focal length ratio set includes ratios of the image sizes of multiple photographed targets at different focal lengths; searches in the size focal length ratio set based on the preset target size focal length ratio; and determines the target focal length based on the search results. This embodiment queries a preset focal length and image size ratio set, obtains image size ratios corresponding to multiple different focal lengths based on the current focal length, provides reference data for subsequent zoom calculations, and ensures the stability of the zoom calculation; by calculating the current frame image size ratio, the target's proportion in the current frame image is obtained in real time, so that the zoom calculation can adapt to different target sizes and image size changes; further combining multiple image size ratios with the current image size ratio, constructs a size focal length ratio set, which contains the size change rules of the target at different focal lengths, thereby improving the accuracy of focal length calculation and zoom matching; then, based on the preset target size focal length ratio, searches in the size focal length ratio set and directly matches the closest ratio item, avoiding the traditional inefficient calculation method of gradually adjusting the focal length, and improving the rapidity and response speed of zoom; finally, determines the target focal length based on the search result, ensures that the target size remains stable in the zoomed image, improves zoom accuracy and consistency, and thereby improves the overall zoom performance of the PTZ camera.

[0071] Based on the above first embodiment, a second embodiment of the PTZ camera automatic zoom method of the present application is proposed. Figure 2 , Figure 2 This is a schematic diagram of a sub-flow in the second embodiment of the automatic zoom method for a PTZ camera of the present application.

[0072] like Figure 2 As shown, in this embodiment, before step S1, the following steps are further included:

[0073] S1a: Obtain the width and height of the preset calibration plate in the image taken at different focal lengths;

[0074] S1b: normalizing the width and height, and using the preset calibration plate as a reference to obtain the preset focal length and image size ratio set.

[0075] It's important to note that a preset calibration plate is a standard reference object used during camera focal length calibration. Typically, it's a rectangular plate of known dimensions, used to measure image size changes at different focal lengths. Normalization converts the measured image dimensions into relative proportions, independent of camera resolution and shooting conditions. Typically, the width and height of the calibration plate are scaled to standardized values ​​(e.g., 1) to serve as a scale reference.

[0076] Specifically, when installing or calibrating a camera, a preset calibration plate of fixed size (e.g., a 60cm×60cm square plate) is used as a reference. The calibration plate is photographed at different focal lengths to obtain the width and height of the calibration plate in the image. The specific process is as follows: First, fix the camera position and shooting angle: ensure that the camera's optical axis is vertically aligned with the calibration plate to avoid perspective distortion; use fixed lighting conditions to prevent brightness changes from affecting measurement accuracy. Then adjust the focal length and capture the calibration plate image in sequence: starting from the minimum focal length, capture an image of the calibration plate after each focus adjustment. For example, if the camera has a 30x optical zoom, capture 30 images at different focal lengths; in each image, measure the width and height of the calibration plate in the picture and record the data. It should be noted that the calibration plate is placed 120 meters away from the camera for shooting.

[0077] Furthermore, after obtaining the width and height of the calibration plate at different focal lengths, they are normalized to establish a universal focal length and image size ratio relationship. The specific steps are as follows: first normalize the calibration plate size: set a standard value (for example, normalize the width and height of the calibration plate to 1), and then calculate the width and height ratio of the calibration plate in the image at each focal length. In this way, no matter how the camera resolution changes, the same ratio data can be used for zoom calculation; then establish a preset focal length and image size ratio set: organize the normalized width and height at different focal lengths into a table to form a preset focal length and image size ratio set. This data set is used as the matching basis for subsequent automatic zooming, and is used to calculate the correspondence between the target size and the focal length, so as to accurately determine the appropriate focal length.

[0078] This step establishes a standardized relationship set between focal length and image size ratio by obtaining the image size of the calibration plate at different focal lengths and performing normalization processing, providing accurate reference data for subsequent zoom calculations. Compared with the traditional method that relies on trial calculations by adjusting the focal length one by one, this application pre-builds a data table of focal length and image size ratios through offline calibration, making zoom calculations more efficient and accurate. In addition, this method eliminates the influence of environmental factors such as camera resolution and lighting conditions on zoom calculations, improves the stability and consistency of the calculations, and ensures that PTZ cameras can achieve accurate automatic zoom in various application scenarios.

[0079] Based on the first embodiment above, in this embodiment, before step S2, the following steps are 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: Identifying the shooting target in the current frame image based on a preset target detection algorithm;

[0082] S2c: Determine the size of the shooting target in the current frame image according to the size of the current frame image.

[0083] It should be noted that the preset target detection algorithm is a pre-set YOLO (You Only Look Once) or Faster R-CNN algorithm based on deep learning.

[0084] Specifically, the PTZ camera runs continuously, capturing video streams at a set frame rate, and at a certain moment, obtains a current frame image. This image contains the entire monitoring scene or shooting area, including the background, multiple possible targets, etc. The resolution information of the current frame image, that is, the width (W_image) and height (H_image) of the image, is read through the camera system interface or image processing software for subsequent target size calculation. The current frame image is analyzed using a preset target detection algorithm to identify possible targets. The choice of target detection algorithm depends on application requirements. For example: target detection based on deep learning (such as YOLO, FasterR-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 detection. The target detection algorithm outputs a bounding box (Bounding Box) to mark the position of the target in the image.

[0085] Furthermore, the target size is determined by its bounding box. This size represents the actual pixel size of the target within the current frame and is a key parameter for subsequent zoom calculations. Once the target size is calculated, it is combined with the overall size of the current frame to calculate the target's proportion within the frame, which serves as the key basis for zoom adjustments.

[0086] This step provides key input data for automatic zoom by acquiring the current frame image, applying a target detection algorithm to identify the target, and calculating the target's size in the image. Compared to traditional methods that rely on manually setting the target size, this method can automatically detect targets in dynamic environments and calculate their size in real time, improving its intelligence and adaptability. In addition, through the preset target detection algorithm, it can adapt to different scenarios such as intelligent monitoring, drone target tracking, and intelligent transportation, ensuring that even if the target size changes, it can still be accurately identified and providing 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 queries a preset focal length and image size ratio set based on the current focal length 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 photographed 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, where the size focal length ratio set includes ratios of the image sizes of multiple photographed targets at different focal lengths; searches in the size focal length ratio set based on the preset target size focal length ratio; and determines the target focal length based on the search results. This embodiment queries a preset focal length and image size ratio set, obtains image size ratios corresponding to multiple different focal lengths based on the current focal length, provides reference data for subsequent zoom calculations, and ensures the stability of the zoom calculation; by calculating the current frame image size ratio, the target's proportion in the current frame image is obtained in real time, so that the zoom calculation can adapt to different target sizes and image size changes; further combining multiple image size ratios with the current image size ratio, constructs a size focal length ratio set, which contains the size change rules of the target at different focal lengths, thereby improving the accuracy of focal length calculation and zoom matching; then, based on the preset target size focal length ratio, searches in the size focal length ratio set and directly matches the closest ratio item, avoiding the traditional inefficient calculation method of gradually adjusting the focal length, and improving the rapidity and response speed of zoom; finally, determines the target focal length based on the search result, ensures that the target size remains stable in the zoomed image, improves zoom accuracy and consistency, and thereby improves the overall zoom performance of the PTZ camera.

[0088] Based on the above second embodiment, a third embodiment of the PTZ camera automatic zoom method of the present application is proposed. Figure 3 , Figure 3This is a schematic diagram of a sub-flow in the third embodiment of the automatic zoom method for a PTZ camera of the present application.

[0089] In this embodiment, step S4 includes:

[0090] S41: Calculating the difference between the preset target size-focal-length ratio and each ratio in the size-focal-length ratio set respectively;

[0091] S42: Determine a matching degree according to the difference, wherein the larger the difference, the smaller the matching degree;

[0092] S43: taking 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 in the size focal length ratio set. It is used to measure the degree of match. The smaller the difference, the higher the match. The degree of match indicates the degree of similarity between the preset target size focal length ratio and each ratio in the size focal length ratio set. The higher the degree of match, the closer the ratio is to the target size ratio. The search result refers to the ratio with the highest degree of match in the size focal length ratio set. The focal length corresponding to this ratio is the final calculated target focal length.

[0094] Specifically, the preset target size-to-focus ratio is read. This ratio is a user-defined target size standard that represents the optimal size the target should maintain in the image. Each ratio item in the size-to-focus ratio set is read in sequence, and the difference between it and the preset target size-to-focus ratio is calculated. The difference can be calculated as an absolute difference to ensure that it is not affected by positive or negative values.

[0095] Furthermore, the degree of match is inversely proportional to the difference: smaller the difference, the higher the degree of match; larger the difference, the lower the degree of match. By calculating the degree of match, we can determine which proportions are closest to the target size ratio. Among all calculated proportions, the proportion with the highest degree of match is selected—that is, the proportion closest to the preset target size ratio. The focal length corresponding to this matching proportion is used in subsequent zoom calculations. The focal length corresponding to this search result is 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 item in the size focal length ratio set, calculates the matching degree based on the difference, and selects the ratio item with the highest matching degree as the search result, thereby ensuring the accuracy and stability of the focal length calculation. Compared with the traditional method of gradually adjusting the focal length and comparing the target size, this step quickly determines the optimal focal length through numerical matching, reduces the number of iterations of the zoom calculation, and improves the efficiency of the zoom calculation. In addition, through matching degree calculation and minimum difference matching, the optimal match between the target size ratio and the ideal size ratio is ensured, avoiding the problem of the target appearing large or small in the picture. Ultimately, the zoom accuracy, response speed and image stability are improved, enabling the PTZ camera to accurately maintain the target size and improve the video shooting quality in scenarios such as intelligent monitoring, automatic tracking, and drone aerial photography.

[0097] Based on the above second embodiment, in this embodiment, after step S5, the following steps are further included:

[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 a rationality check of the target focal length to ensure that the calculated results meet the physical limitations of the camera and actual application requirements, and to avoid zoom instability caused by calculation errors.

[0100] Specifically, the PTZ camera's optical focal length range (e.g., 10mm-300mm) is read to ensure the target focal length 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 target's size in the image after the focus adjustment is predicted to ensure the target does not extend beyond the frame or become too small due to excessive zooming. If the target size does not fall within the expected range, the focal length 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 a camera control interface (such as serial port commands, network APIs, or camera SDKs). Upon receiving this focal length value, the camera adjusts the lens focal length to ensure the target size meets the specified requirements. After adjusting the focal length, the camera re-acquires the target size to check whether it meets the expected ratio. If deviations remain after adjustment, a compensation mechanism is triggered to recalculate the focal length and perform fine-tuning to ensure a stable and consistent target size.

[0102] This step verifies the rationality of the target focal length and transmits the verified target focal length to the PTZ camera, ensuring that the zoom calculation result is accurate, stable, and complies with physical limitations. Compared to traditional methods that directly apply the calculated focal length, this step first performs a rationality check to prevent the focal length from exceeding the camera range or causing abnormal target size, thereby improving the reliability of the zoom calculation.

[0103] Based on the above second embodiment, in this embodiment, before step S3, the following steps are further included:

[0104] S3a: Using a Kalman filter to smooth the size of the current frame image and the size of the photographed object in the current frame image.

[0105] It should be noted that the Kalman filter is a recursive algorithm for state estimation. It can provide an optimal estimate of the true value when the measurement data is affected by noise. It is widely used in target tracking, signal processing, and vision systems. Smoothing refers to removing measurement errors and noise to make size estimation more stable and accurate, avoiding zoom calculation errors caused by measurement fluctuations. Smoothing refers to eliminating noise in the measurement data to make the target size estimation more stable, reduce size fluctuations in a short period of time, and thus improve the accuracy and stability of the zoom calculation.

[0106] Specifically, the state variables are set, including: target size state (width, height): indicating the estimated size of the target in the current frame in the image; state transition matrix: assuming that the target size changes smoothly between adjacent frames, so that the state variables can be updated over time. The size of the current frame image and the target size provided by the target detection algorithm are used as the measurement input of the filter. Since target detection may be noisy (for example, the target is partially obscured, and illumination changes lead to detection errors), the Kalman filter provides a more reliable size estimate by fusing multiple measurements. Set the initial state estimate, that is, the target size detected in the first frame image. Set the process noise covariance matrix and the measurement noise covariance matrix to control the stability and response speed of the filter.

[0107] Furthermore, the target size of the current frame is predicted based on the target size of the previous frame, and the prediction error covariance is calculated. Since the target size usually does not change drastically in a short period of time, the filter can reasonably predict the target size of the next frame, reducing the impact of instantaneous errors on the zoom calculation. 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 make it closer to the actual target size. The Kalman gain is dynamically adjusted according to the size of the measurement noise. When the measurement data is stable, the gain is small and the filtering result is smoother; when the measurement data fluctuates greatly, the gain is large, and the filter can respond quickly to changes. After filtering, the final smoothed target size is obtained. This size is more stable, has a smaller error, and can be used for subsequent automatic zoom calculations.

[0108] This step uses a Kalman filter to smooth the size of the current frame image and the target size, effectively reducing size fluctuations caused by factors such as target detection errors, lighting changes, and occlusions, thereby improving the stability and accuracy of size estimation. Compared to directly using unfiltered detection data for zoom calculations, this step makes target size estimation smoother, avoiding zoom focal length jitter caused by measurement noise, thereby improving the automatic zoom accuracy of PTZ cameras and the stability of video images. In addition, this step can adapt to dynamic environments. Even if the target size changes in a short period of time, the filter can still provide a smooth and reliable size estimate, making zoom calculations more accurate and improving the effectiveness of applications such as intelligent monitoring, drone tracking, and automatic target recognition.

[0109] This embodiment queries a preset focal length and image size ratio set based on the current focal length 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 photographed 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, where the size focal length ratio set includes ratios of the image sizes of multiple photographed targets at different focal lengths; searches in the size focal length ratio set based on the preset target size focal length ratio; and determines the target focal length based on the search results. This embodiment queries a preset focal length and image size ratio set, obtains image size ratios corresponding to multiple different focal lengths based on the current focal length, provides reference data for subsequent zoom calculations, and ensures the stability of the zoom calculation; by calculating the current frame image size ratio, the target's proportion in the current frame image is obtained in real time, so that the zoom calculation can adapt to different target sizes and image size changes; further combining multiple image size ratios with the current image size ratio, constructs a size focal length ratio set, which contains the size change rules of the target at different focal lengths, thereby improving the accuracy of focal length calculation and zoom matching; then, based on the preset target size focal length ratio, searches in the size focal length ratio set and directly matches the closest ratio item, avoiding the traditional inefficient calculation method of gradually adjusting the focal length, and improving the rapidity and response speed of zoom; finally, determines the target focal length based on the search result, ensures that the target size remains stable in the zoomed image, improves zoom accuracy and consistency, and thereby improves the overall zoom performance of the PTZ camera.

[0110] The present application also provides a PTZ camera automatic zoom device, 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 the present application, and the PTZ camera automatic zoom device includes:

[0111] A query module 401 is configured to query a preset focal length and image size ratio set based on the current focal length to obtain a plurality of image size ratios;

[0112] The current ratio module 402 is used to determine the current image size ratio according to the size of the current frame image and the size of the photographed object in the current frame image;

[0113] A size-focal-length ratio module 403 is configured to obtain a size-focal-length ratio set according to the multiple image size ratios and the current image size ratio, wherein the size-focal-length ratio set includes ratios of the image sizes of the multiple objects at different focal lengths.

[0114] A matching module 404 is configured to search the set of size-focus ratios based on a preset target size-focus ratio;

[0115] The target module 405 is used to determine the target focal length according to the search result.

[0116] The PTZ camera automatic zoom device provided in the embodiments of this application utilizes the PTZ camera automatic zoom method described in the above embodiments, thereby solving the technical problem of improving the automatic zoom performance of PTZ cameras. Compared to the prior art, the PTZ camera automatic zoom device provided in the embodiments of this application achieves the same beneficial effects as the PTZ camera automatic zoom method described in the above embodiments. Other technical features of the PTZ camera automatic zoom device are the same as those disclosed in the above embodiments and are not further described here.

[0117] The present application provides a PTZ camera automatic 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, and the instructions are executed by the at least one processor to enable the at least one processor to execute the PTZ camera automatic zoom method in the above-mentioned embodiment.

[0118] Reference below Figure 5 , 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 embodiment of the present application, which shows a schematic diagram of the structure of the PTZ camera automatic zoom device suitable for implementing the embodiment of the present application. Figure 5 The PTZ camera automatic zoom device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0119] like Figure 5As shown, the PTZ camera automatic zoom device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes based on programs stored in a read-only memory (ROM) 1002 or programs loaded from a storage device 1003 into a random access memory (RAM) 1004. RAM 1004 also stores various programs and data required for the operation of the PTZ camera automatic zoom device. Processing device 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 the I / O interface 1006: input devices 1007 including, for example, a touch screen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, hard disk, etc.; and communication devices 1009. The communication devices 1009 can allow the PTZ camera automatic zoom device to communicate with other devices wirelessly or by wire to exchange data. While the figure shows a PTZ camera automatic zoom device with various systems, it should be understood that implementation or presence of all the illustrated systems is not required. More or fewer systems may alternatively be implemented or present.

[0120] In particular, according to the embodiments disclosed herein, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed herein include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for executing the methods shown in the flowcharts. When the computer program is executed by the processing device 1001, the functions defined in the methods of the embodiments disclosed herein are performed.

[0121] The PTZ camera automatic zoom device provided in this application utilizes the PTZ camera automatic zoom method described in the aforementioned embodiment, solving the technical problem of improving the automatic zoom performance of PTZ cameras. Compared to the prior art, the PTZ camera automatic zoom device provided in this application achieves the same beneficial effects as the PTZ camera automatic zoom method described in the aforementioned embodiment. Other technical features of the PTZ camera automatic zoom device are the same as those disclosed in the aforementioned embodiment and are not further elaborated 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 one or more embodiments or examples in a suitable manner.

[0123] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.

[0124] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer program) stored thereon, wherein the computer-readable program instructions are used to execute the PTZ camera automatic zoom method in the above embodiment.

[0125] The computer-readable storage medium carries one or more programs. When executed by a PTZ camera automatic zoom device, the one or more programs cause the PTZ camera automatic 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 photographed 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 image size ratios of multiple photographed targets at different focal lengths; search 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 result. The computer program code for performing the operations of the present 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++, as well as conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer, or entirely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, through the Internet using an Internet service provider).

[0126] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.

[0127] The modules described in the embodiments of the present application may be implemented in software or hardware, wherein the name of a module does not necessarily limit the unit itself.

[0128] The computer-readable storage medium provided in this application stores computer-readable program instructions (i.e., a computer program) for executing the aforementioned automatic zoom method for PTZ cameras. This computer-readable storage medium addresses the technical problem of improving the automatic zoom performance of PTZ cameras. Compared to the prior art, the beneficial effects of the computer-readable storage medium provided in this application are similar to those of the automatic zoom method for PTZ cameras provided in the aforementioned embodiments and are not further elaborated here.

[0129] An embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the above-mentioned PTZ camera automatic zoom method.

[0130] The computer program product provided in this application can solve the technical problem of improving 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 those of the automatic zoom method for PTZ cameras provided in the above embodiments, and will not be elaborated here.

[0131] The above are only preferred embodiments of the present application and do not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent processing scope of the present application.

Claims

1. A PTZ camera automatic zoom method, characterized in that: The method comprises: 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 according to the size of the current frame image and the size of the photographed object in the current frame image; Obtaining a size-focal-length ratio set according to the multiple image size ratios and the current image size ratio, wherein the size-focal-length ratio set includes ratios of image sizes of multiple objects at different focal lengths; Based on a preset target size focal length ratio, searching is performed in the size focal length ratio set; Determine the target focal length based on the search results.

2. The method according to claim 1, wherein 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: Get the width and height of the preset calibration plate in images taken at different focal lengths; 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.

3. The method according to claim 1, wherein Before the step of determining the current image size ratio according to the size of the current frame image and the size of the photographed object in the current frame image, the method further includes: 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, identifying the shooting target in the current frame image; The size of the shooting target in the current frame image is determined according to the size of the current frame image.

4. The method according to claim 1, wherein The step of searching in the set of size-focus ratios based on the preset target size-focus ratio comprises: Calculating the difference between the preset target size focal length ratio and each ratio in the size focal length ratio set respectively; Determining a matching degree according to the difference, wherein the greater the difference, the smaller the matching degree; The ratio corresponding to the maximum matching degree of the size-focal-length ratio is taken as the search result.

5. The method according to claim 3, wherein After the step of determining the target focal length according to the search result, the method further includes: The target focal length is verified, and the verified target focal length is transmitted to the PTZ camera.

6. The method according to claim 3, wherein Before the step of obtaining a size-focal-length ratio set according to the multiple 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 photographed object in the current frame image.

7. A PTZ camera automatic zoom device, characterized in that: The device comprises: A query module, configured to query a preset focal length and image size ratio set based on the current focal length to obtain multiple image size ratios; A current ratio module is used to determine the current image size ratio according to the size of the current frame image and the size of the photographed object in the current frame image; a size-focal-length ratio module, configured to obtain a size-focal-length ratio set according to the multiple image size ratios and the current image size ratio, wherein the size-focal-length ratio set includes ratios of the image sizes of the multiple photographed objects at different focal lengths; A matching module, configured to search the set of size-focus ratios based on a preset target size-focus ratio; The target module is used to determine the target focal length based on the search results.

8. A computer device, characterized in that: The device includes: a memory, a processor, and a PTZ camera automatic zoom program stored in the memory and executable on the processor, wherein the PTZ camera automatic zoom program is configured to implement the steps of the PTZ camera automatic zoom method according to any one of claims 1 to 6.

9. A storage medium, characterized in that: The storage medium stores a PTZ camera automatic zoom program, and when the PTZ camera automatic zoom program is executed by the processor, the steps of the PTZ camera automatic zoom method according to any one of claims 1 to 6 are implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the PTZ camera automatic zoom method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

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

    CN108076281A

  • Automatic zooming method and device, storage medium and electronic device

    CN116347221A

  • Target detection-based automatic zooming method for PTZ (Pan / Tilt / Zoom) camera

    CN118118780A

  • Method and apparatus for controlling zoom-convergenceinterlock in parallel axis typed stereo camera system

    KR1020070096177A

  • Quick Automatic Focusing Method and Image Acquisition Apparatus

    US20150124155A1