def main():
    input_file_name, model_name, show_video = check_args()

    print(f"Input Video: {input_file_name}")
    print(f"Model Name: {model_name}")

    detector = Detector()
    detector.initialize(model_name, input_file_name)

    can_read_frames = True
    current_frame = 0

    start_time = time.time()
    while can_read_frames:
        current_frame += 1
        can_read_frames, frame = detector.analyze_frame(current_frame)

        print(f"\rAnalyzing Frame {current_frame}", end='')
        if current_frame % 3 == 0:
            print(" \\", end='')
        elif current_frame % 3 == 1:
            print(" |", end='')
        elif current_frame % 3 == 2:
            print(" /", end='')
        if show_video and frame is not None:
            cv2.imshow("Frame", frame)
            cv2.waitKey(1)

    analyze_time = int(time.time() - start_time)

    print()
    print(f"Total Frames: {current_frame}")
    print(f"Analyze Time: {analyze_time}s")
    print(f"Average Frames Per Second: {current_frame // analyze_time}")
class DetectorThread(QThread):
    update_image_signal = pyqtSignal(np.ndarray)
    video_finished_signal = pyqtSignal()

    def __init__(self):
        super().__init__()
        self.Detector = Detector()
        self.current_frame_count = 0
        self.is_running = False
        self.is_paused = False
        self.is_video_finished = True
        self.video_path = ""
        self.model_name = ""

    def set_video_path(self, video_path):
        self.reset()
        self.video_path = video_path

    def set_model_name(self, model_name):
        self.reset()
        self.model_name = model_name

    def initialize_detector(self):
        if self.is_video_finished:
            self.Detector.initialize(self.model_name, self.video_path)

    def run(self):
        self.is_running = True
        while self.is_running:
            while not self.is_paused:
                can_analyze, analyzed_frame = self.Detector.analyze_frame(
                    self.current_frame_count)
                self.current_frame_count += 1
                if can_analyze:
                    self.is_video_finished = False
                    if analyzed_frame is not None:
                        self.update_image_signal.emit(analyzed_frame)
                else:
                    self.video_finished_signal.emit()
                    self.is_paused = True

    def reset(self):
        self.is_video_finished = True
        self.current_frame_count = 0

    def pause(self):
        self.is_paused = True