@@ -143,6 +143,39 @@ def drawFPS(self, img: np.ndarray) -> np.ndarray:
143143 return annotated_img
144144
145145
146+ def drawTime (self , img : np .ndarray , frame_num : int ) -> np .ndarray :
147+ """ Draw Time on the image/frame
148+
149+ Args:
150+ img (np.ndarray): opencv image
151+ img (int): current absolute frame number
152+
153+ Returns:
154+ np.ndarray: opencv image with Time Text
155+ """
156+ annotated_img = img .copy ()
157+ current_timestamp = FFmpegStream .millisec_to_timestamp (
158+ self .frame_to_millisec (frame_num , self .video_info .fps )
159+ )
160+ current_timestamp = '' .join (current_timestamp [:- 4 ])
161+
162+ if self .params .end_frame < 1 :
163+ end_timestamp = FFmpegStream .millisec_to_timestamp (
164+ self .frame_to_millisec (self .video_info .length , self .video_info .fps )
165+ )
166+ end_timestamp = '' .join (end_timestamp [:- 4 ])
167+ else :
168+ end_timestamp = FFmpegStream .millisec_to_timestamp (
169+ self .frame_to_millisec (self .params .end_frame , self .video_info .fps )
170+ )
171+ end_timestamp = '' .join (end_timestamp [:- 4 ])
172+
173+ txt = current_timestamp + ' / ' + end_timestamp
174+ cv2 .putText (annotated_img , txt , (max (( 0 , img .shape [1 ] - self .x_text_start - round (len (txt )* 17 * self .font_size ) )), 50 ),
175+ cv2 .FONT_HERSHEY_SIMPLEX , self .font_size , (0 ,0 ,255 ), 2 )
176+ return annotated_img
177+
178+
146179 def drawText (self , img : np .ndarray , txt : str , y :int = 50 , color :tuple = (0 ,0 ,255 )) -> np .ndarray :
147180 """ Draw text to an image/frame
148181
@@ -619,6 +652,7 @@ def tracking(self) -> str:
619652 last_frame = self .drawFPS (last_frame )
620653 cv2 .putText (last_frame , "Press 'q' if the tracking point shifts or a video cut occured" ,
621654 (self .x_text_start , 75 ), cv2 .FONT_HERSHEY_SIMPLEX , self .font_size , (255 ,0 ,0 ), 2 )
655+ last_frame = self .drawTime (last_frame , frame_num + self .params .start_frame )
622656 cv2 .imshow (self .window_name , self .preview_scaling (last_frame ))
623657
624658 if self .was_key_pressed ('q' ) or cv2 .waitKey (1 ) == ord ('q' ):
0 commit comments