def test_sigle_file(file): Algorithm.file = file Algorithm.reset() input_video = VideoReader(file) result = [] while 1: frame = Frame(input_video) if not input_video.is_good(): break frame = Algorithm.resize(frame) frame, mask, records = Algorithm.perform(frame, db, img_saver, True) if records is not None and len(records) > 0: for rec in records: result.append((round(rec['width'], 2), round(rec["speed"], 2))) return result
def algorithm(self): if self.__exit_flag: return False if self.__play_file_flag: if self.__input_video is None: path = self.__get_file_path(self.__played_file) Algorithm.set_file(path) self.__input_video = VideoReader(path) self.__current_frame_index = 1 frame = Frame(self.__input_video) self.window.files_treeview.set_cursor(self.__played_file) if not self.__input_video.is_good(): # Zresetuj dane przechowywane przez algorytm przed otwarciem nowego pliku Algorithm.reset() if (self.__played_file + 1) < self.__files_list_length(): # Pobierz następny plik do przetwarzania self.__current_frame_index = 1 self.__played_file += 1 path = self.__get_file_path(self.__played_file) self.window.files_treeview.set_cursor(self.__played_file) self.__input_video = VideoReader(path) Algorithm.set_file(path) else: # Zakończ odtwarzanie jeśli nie ma żadnych plików self.__play_file_flag = False self.__played_file = 0 self.__open_files_button_enable(True) self.__play_button_enable(True) self.__pause_button_enable(False) self.__stop_button_enable(False) self.__replay_button_enable(False) self.__input_video = None self.__enable_main_menu(True) self.__write_msg("Koniec") else: # Konwersja rozmiaru frame = Algorithm.resize(frame) # Krok algorytmu frame, mask, records = Algorithm.perform( frame, self.database, self.img_saver, self.__run_alg_flag) # Nagrywanie wyniku if self.__record_video_flag: # Stwórz wynikowy plik wideo if self.__output_video is None: self.__output_video = VideoWriter() # Zapisz klatkę obrazu self.__output_video.write(frame.img) # Dodanie wyniku do listview self.__add_result_to_list( records, self.__get_file_path(self.__played_file)) # Zapisz klatkę obrazu do tymczasowego pliku if not self.__display_mask_flag: self.__save_image(frame.img) self.__current_image = frame.img else: self.__save_image(mask) self.__current_image = mask # Zamień plik na pixbuf pixbuf = self.__conver_image_to_pixbuf() self.window.main_image.set_from_pixbuf(pixbuf) self.__write_current_number() self.__current_frame_index += 1 return True
def algorithm(self): if self.__exit_flag: return False if self.__play_file_flag: if self.__input_video is None: path = self.__get_file_path(self.__played_file) Algorithm.set_file(path) self.__input_video = VideoReader(path) self.__current_frame_index = 1 frame = Frame(self.__input_video) self.window.files_treeview.set_cursor(self.__played_file) if not self.__input_video.is_good(): # Zresetuj dane przechowywane przez algorytm przed otwarciem nowego pliku Algorithm.reset() if (self.__played_file + 1) < self.__files_list_length(): # Pobierz następny plik do przetwarzania self.__current_frame_index = 1 self.__played_file += 1 path = self.__get_file_path(self.__played_file) self.window.files_treeview.set_cursor(self.__played_file) self.__input_video = VideoReader(path) Algorithm.set_file(path) else: # Zakończ odtwarzanie jeśli nie ma żadnych plików self.__play_file_flag = False self.__played_file = 0 self.__open_files_button_enable(True) self.__play_button_enable(True) self.__pause_button_enable(False) self.__stop_button_enable(False) self.__replay_button_enable(False) self.__input_video = None self.__enable_main_menu(True) self.__write_msg("Koniec") else: # Konwersja rozmiaru frame = Algorithm.resize(frame) # Krok algorytmu frame, mask, records = Algorithm.perform(frame, self.database, self.img_saver, self.__run_alg_flag) # Nagrywanie wyniku if self.__record_video_flag: # Stwórz wynikowy plik wideo if self.__output_video is None: self.__output_video = VideoWriter() # Zapisz klatkę obrazu self.__output_video.write(frame.img) # Dodanie wyniku do listview self.__add_result_to_list(records, self.__get_file_path(self.__played_file)) # Zapisz klatkę obrazu do tymczasowego pliku if not self.__display_mask_flag: self.__save_image(frame.img) self.__current_image = frame.img else: self.__save_image(mask) self.__current_image = mask # Zamień plik na pixbuf pixbuf = self.__conver_image_to_pixbuf() self.window.main_image.set_from_pixbuf(pixbuf) self.__write_current_number() self.__current_frame_index += 1 return True