55# actual behavior of the functions in the context of this program (and to
66# correct problems in the 'opencv-python' type hints).
77
8+ import os
89from pathlib import Path
910from typing import Sequence
1011from json import JSONDecodeError
@@ -165,7 +166,7 @@ def text_pos(
165166 return round (x + ox ), round (y + oy )
166167
167168
168- def run_annotate (
169+ def run_processing (
169170 meta : PanoramaMetadata ,
170171 output : Path ,
171172 images : dict [str , Path ],
@@ -193,7 +194,6 @@ def run_annotate(
193194 label_justify : str = "tl" ,
194195) -> None :
195196 corners : list [Sequence [int ]] = []
196- centers : list [tuple [int , int , Angle , Angle ]] = []
197197 images_warped : list [npt .NDArray [np .uint8 ]] = []
198198 masks_warped : list [npt .NDArray [np .uint8 ]] = []
199199
@@ -300,15 +300,6 @@ def run_annotate(
300300 cv .INTER_NEAREST ,
301301 cv .BORDER_CONSTANT
302302 )
303- cx , cy = warper .warpPoint (
304- (width / 2 , height / 2 ), instrinsics , rot )
305-
306- centers .append (
307- (
308- int (cx ), int (cy ),
309- hz , v
310- )
311- )
312303 corners .append (corner )
313304 images_warped .append (image_warped )
314305 masks_warped .append (mask_warped )
@@ -392,17 +383,15 @@ def run_annotate(
392383 )
393384
394385 if len (points ) > 0 :
395- # Top left image center point for reference
386+ # Top left image top left point for reference
396387 origin_x , origin_y , _ , _ = cv .detail .resultRoi (
397388 corners ,
398389 [(i .shape [1 ], i .shape [0 ]) for i in images_warped ]
399390 )
400- tl_x , tl_y , tl_hz , tl_v = centers [0 ]
401- tl_x -= origin_x
402- tl_y -= origin_y
403-
404391 full_360 = round (scale * np .pi * 2 )
405392
393+ hz_0 = Angle (0 )
394+
406395 for pt , coord , label in progress .track (
407396 points ,
408397 description = "Annotating points"
@@ -412,20 +401,26 @@ def run_annotate(
412401 # is rotated with the preliminary angles.
413402 prelim_hz , prelim_v , _ = (coord - center ).to_polar ()
414403 offset_rot = (
415- rot_z (float ((prelim_hz - shift ).normalized ()) - camera_yaw )
404+ rot_z (
405+ float (prelim_hz )
406+ - np .asin (
407+ camera_yaw / np .sin (
408+ float (prelim_v )
409+ - camera_pitch
410+ )
411+ )
412+ )
416413 @ rot_x (np .pi / 2 - float (prelim_v ) - camera_pitch )
417414 )
418415 pt_hz , pt_v , _ = (
419416 coord
420- - (center + apply_rotation (camera_offset , offset_rot ))
417+ - (center + apply_rotation (camera_offset * 2 , offset_rot ))
421418 ).to_polar ()
422-
423419 pt_hz = (pt_hz - shift ).normalized ()
424420
425- pt_hz_f = float (pt_hz - tl_hz )
426- pt_v_f = float (pt_v - tl_v )
427- pt_x = round (tl_x + pt_hz_f * scale ) % full_360
428- pt_y = round (tl_y + pt_v_f * scale ) % full_360
421+ pt_hz_rel = pt_hz .relative_to (hz_0 )
422+ pt_x = round (float (pt_hz_rel ) * scale - origin_x ) % full_360
423+ pt_y = round (float (pt_v ) * scale - origin_y ) % full_360
429424
430425 cv .drawMarker (
431426 result ,
@@ -613,8 +608,13 @@ def main(
613608 if label_offset is None :
614609 label_offset = (label_fontsize // 2 , label_fontsize // 2 )
615610
611+ # Suppress OpenCV native warning logs if the user did not set a specific
612+ # logging level. Warnings break the rich console feedback.
613+ if "OPENCV_LOG_LEVEL" not in os .environ :
614+ os .environ ["OPENCV_LOG_LEVEL" ] = "OFF"
615+
616616 try :
617- run_annotate (
617+ run_processing (
618618 meta ,
619619 output ,
620620 image_map ,
0 commit comments