Explorar el Código

fix 增加zoom计算

wzh hace 1 semana
padre
commit
2157aa3bac
Se han modificado 2 ficheros con 23 adiciones y 6 borrados
  1. 12 3
      pixel_to_lonlat.py
  2. 11 3
      video_location.py

+ 12 - 3
pixel_to_lonlat.py

@@ -10,7 +10,7 @@ from scipy.spatial.transform import Rotation as R
 
 # --- 核心函数 ---
 
-def compute_hfov_by_zoom(hfov_max, zoom, camera_type="dahua"):
+def compute_hfov_by_zoom(hfov_max, zoom, camera_type="dahua", hfov_min=None):
     """
     将缩放等级(zoom)映射为水平视场角(hfov)。
     规则:
@@ -30,7 +30,14 @@ def compute_hfov_by_zoom(hfov_max, zoom, camera_type="dahua"):
         z = min_zoom
     elif z > max_zoom:
         z = max_zoom
-
+    if hfov_min is None:
+        hfov_min = 1.5
+    if hfov_min is not None:
+        span = max_zoom - min_zoom
+        if span <= 1e-9:
+            return float(hfov_min)
+        t = (z - min_zoom) / span
+        return float(hfov_max) + (float(hfov_min) - float(hfov_max)) * t
     return hfov_max * (min_zoom / z)
 
 def pixel_to_lonlat(u, v, camera_params, ptz_params):
@@ -57,7 +64,8 @@ def pixel_to_lonlat(u, v, camera_params, ptz_params):
     hfov = compute_hfov_by_zoom(
         hfov_max=hfov_max,
         zoom=zoom_value,
-        camera_type=camera_params.get('camera_type', 'dahua')
+        camera_type=camera_params.get('camera_type', 'dahua'),
+        hfov_min=camera_params.get('hfov_min')
     )
     north_p = float(camera_params['north_p_value'])
     p, t = float(ptz_params['pan']), float(ptz_params['tilt'])
@@ -116,6 +124,7 @@ if __name__ == '__main__':
     CAMERA_PARAMS = {
         "height": 28.0000,
         "hfov": 61.0000,
+        "hfov_min": 1.15,
         "resolution_w": 1280,
         "resolution_h": 720,
         "cam_lon": 112.893799,

+ 11 - 3
video_location.py

@@ -23,7 +23,7 @@ def lonlat_to_enu(lon, lat, center_lon, center_lat):
     y = EARTH_RADIUS * delta_lat
     return np.array([x, y, 0])
 
-def compute_hfov_by_zoom(hfov_max, zoom, camera_type="dahua"):
+def compute_hfov_by_zoom(hfov_max, zoom, camera_type="dahua", hfov_min=None):
     """
     将缩放等级(zoom)映射为水平视场角(hfov)。
     规则:
@@ -44,8 +44,15 @@ def compute_hfov_by_zoom(hfov_max, zoom, camera_type="dahua"):
         z = min_zoom
     elif z > max_zoom:
         z = max_zoom
-
+    if hfov_min is None:
+        hfov_min = 1.5
     # assume hfov scales inversely with zoom
+    if hfov_min is not None:
+        span = max_zoom - min_zoom
+        if span <= 1e-9:
+            return float(hfov_min)
+        t = (z - min_zoom) / span
+        return float(hfov_max) + (float(hfov_min) - float(hfov_max)) * t
     return hfov_max * (min_zoom / z)
 
 def project_lonlat_to_pixel(target_lon, target_lat, resolution_w, resolution_h,
@@ -170,7 +177,8 @@ def process_geojson_for_frontend(geojson_data, camera_params, calibrated_params)
     hfov = compute_hfov_by_zoom(
         hfov_max=hfov_max,
         zoom=zoom_value,
-        camera_type=camera_params.get('camera_type', 'dahua')
+        camera_type=camera_params.get('camera_type', 'dahua'),
+        hfov_min=camera_params.get('hfov_min')
     )
     # 1. Batch convert all geographic points to pixel points
     for lon, lat in geo_coords: