1515from pathlib import Path
1616from typing import List , Optional , Tuple , Union
1717
18+ import cv2
1819import numpy as np
1920
2021from ..utils .log import logger
@@ -38,17 +39,32 @@ def vis(self, save_path: Optional[Union[str, Path]] = None) -> Optional[np.ndarr
3839 logger .warning ("No image or txts to visualize." )
3940 return None
4041
42+ vis = VisRes ()
43+
4144 txts = [f"{ txt } { score :.2f} " for txt , score in self .cls_res ]
42- scores = [ score for _ , score in self .cls_res ]
45+ img_degrees , scores = list ( zip ( * self .cls_res ))
4346
44- vis = VisRes ( )
45- vis_img = vis .draw_rec_res (self . img_list , txts , scores )
47+ raw_img_list = self . restore_image_orientation ( self . img_list , img_degrees )
48+ vis_img = vis .draw_rec_res (raw_img_list , txts , list ( scores ) )
4649
4750 if save_path is not None :
4851 save_img (save_path , vis_img )
4952 logger .info ("Visualization saved as %s" , save_path )
5053 return vis_img
5154
55+ def restore_image_orientation (
56+ self , img_list : List [np .ndarray ], img_degrees : Tuple [str ]
57+ ) -> List [np .ndarray ]:
58+ results = []
59+ for img , rotate_degree in zip (img_list , img_degrees ):
60+ if rotate_degree != "180" :
61+ results .append (img )
62+ continue
63+
64+ rotate_img = cv2 .rotate (img , cv2 .ROTATE_180 )
65+ results .append (rotate_img )
66+ return results
67+
5268
5369class ClsPostProcess :
5470 def __init__ (self , label_list : List [str ]):
0 commit comments