def load_config(self): logger.debug("load_config()") tmp_config_file = filedialog.askopenfilename( initialdir=ConfigurationHandler.get_configuration_path()) tmp_options = ConfigurationHandler.read_config_file(tmp_config_file) # update file selection boxes and GUI self.set_input_video_folder(tmp_options['GUI']['video_path']) self.set_user_folder(tmp_options['GUI']['user_path']) self.status_label_text.set("Ready")
def __init__(self, arg_input_video_file_path: str, arg_start_time: datetime, arg_output_video_path: str, arg_init_bbox: list): logger.debug("Created full clip spec for " + arg_output_video_path + " from video file: " + arg_input_video_file_path) tmp_options = ConfigurationHandler.get_configuration() self.video_file_path = arg_input_video_file_path self.start_time = arg_start_time + datetime.timedelta(seconds=float(tmp_options['FULL_CLIP_SPECIFICATION']['start_time_offset'])) self.output_video_path = arg_output_video_path self.init_bbox = arg_init_bbox
def __init__(self, arg_user_folder): logger.info("Creating user: " + arg_user_folder.name) tmp_options = ConfigurationHandler.get_configuration() self.name = arg_user_folder.name self.user_folder = arg_user_folder.path self.user_GPS_input_files = os.path.join( self.user_folder, tmp_options['USER']['user_GPS_input_files_subpath']) self.location_data_folder = os.path.join( self.user_folder, tmp_options['USER']['location_data_subpath']) self.full_clip_output_video_folder = os.path.join( self.user_folder, tmp_options['USER']['full_clip_output_video_subpath']) self.tracker_clip_output_video_folder = os.path.join( self.user_folder, tmp_options['USER']['tracker_clip_output_video_subpath']) self.maximum_distance = float(tmp_options['USER']['maximum_distance']) self.minimum_velocity = float(tmp_options['USER']['minimum_velocity'] ) / 3.6 # convert from km/h to m/s self.time_search_range = datetime.timedelta( seconds=float(tmp_options['USER']['time_search_range'])) self.location_data_names = [ 'time', 'latitude', 'longitude', 'velocity', 'precision', 'satellites' ] self.location_data = pd.DataFrame(columns=self.location_data_names) self.obstacle_match_data_names = ['time', 'video_file', 'init_bbox'] self.obstacle_match_data = pd.DataFrame( columns=self.obstacle_match_data_names) self.refresh_gps_data()
def __init__(self): logger.debug("TrackerClipExtractor created") self.tmp_options = ConfigurationHandler.get_configuration() self.number_of_process_workers = int( self.tmp_options['TRACKER_CLIP_SPECIFICATION'] ['number_of_process_workers']) return
def set_motion_detection_ROI(self): tempROISelector = MotionROISelector() tmpROI = tempROISelector.SelectROI(self.video_folder_text.get()) tmp_options = ConfigurationHandler.get_configuration() self.motion_ROI_text.set( tmp_options['MOTION_DETECTION']['search_box_dimensions']) logger.info("Setting motion ROI to: " + str(tmpROI))
def __init__(self): tmp_options = ConfigurationHandler.get_configuration() self.obstacle_approach_location = [ float(tmp_options['OBSTACLE']['approach_location_lat']), float(tmp_options['OBSTACLE']['approach_location_long']) ] self.user_match_minimum_interval = float( tmp_options['OBSTACLE']['user_match_minimum_interval']) return
def step_impl(context): assert os.path.isfile(ROOT_DIR + "/../../etc/engine.config") root_dir = ROOT_DIR + "/../../" config_file = ROOT_DIR + "/../../etc/engine.config" config_data = ConfigurationHandler(config_file).get() context.module_inst = ModuleHandler(root_dir, config_data) context.modules_list = context.module_inst.loaded_modules status = type(context.modules_list) == list assert status
def has_associated_motion_file(arg_motion_file_list, arg_video_file): tmp_options = ConfigurationHandler.get_configuration() tmp_motion_file_ending = tmp_options['MOTION_DETECTION'][ 'motion_file_ending'] logger.debug("Checking if motion file already exists for file: " + arg_video_file.name) for motion_file in arg_motion_file_list: # look through all found motion files for a match # logger.debug("Matching: " + motion_file.name + " and " + os.path.splitext(arg_video_file.name)[0] + motion_file_ending + ".csv") if motion_file.name == os.path.splitext( arg_video_file.name)[0] + tmp_motion_file_ending + ".csv": return True return False #Not match found
def __init__(self, arg_options_obj=None): self.videoreader_obj = 0 self.current_filename = "" self.creation_time = 0 # datetime self.width = 0 self.height = 0 self.fps = 0 self.frames = 0 # total number of frames self.current_frame = 0 if arg_options_obj is None: arg_options_obj = ConfigurationHandler.get_configuration() self.tool_folder = arg_options_obj['GOPRO_VIDEO']['tool_folder']
def run(self): logger.debug("run()") tmp_options = ConfigurationHandler.get_configuration() if tmp_options is None: self.status_label_text.set("No parameters") return self.status_label_text.set("Busy") self.status_label.update() # print("Running selections: " + str(self.run_options.curselection())) self.app_ref.run(self.video_folder_text.get(), self.user_folder_text.get(), self.run_options.curselection()) self.status_label_text.set("Ready")
def __create_output_path(arg_input_file: os.DirEntry, arg_output_folder_path: str): if not (os.path.isdir(arg_output_folder_path) and os.path.exists(arg_output_folder_path)): raise ValueError("Output folder is not a valid folder: " + arg_output_folder_path) tmp_options = ConfigurationHandler.get_configuration() tmp_output_file_ending = tmp_options['GPS_FILE_PARSING'][ 'converted_file_ending'] output_filename_short = os.path.splitext( arg_input_file.name)[0] + tmp_output_file_ending + ".csv" output_path = os.path.join(arg_output_folder_path, output_filename_short) return output_path
def get_motion_file_list(arg_input_video_folder): tmp_options = ConfigurationHandler.get_configuration() tmp_motion_file_ending = tmp_options['MOTION_DETECTION'][ 'motion_file_ending'] tmp_motion_file_ending_regex = re.compile(".+" + tmp_motion_file_ending + "\.csv$") motion_file_list = [] for dir_file in os.scandir(arg_input_video_folder): # logger.debug("Checking if the following file is a motion start file: " + dir_file.name) if tmp_motion_file_ending_regex.match(dir_file.name): logger.debug("Motion start file found: " + dir_file.name) motion_file_list.append(dir_file) return motion_file_list # list of found motion files
def get_associated_video_file(arg_motion_file): logger.debug("Checking if associated video file exists for file: " + arg_motion_file.name) tmp_options = ConfigurationHandler.get_configuration() tmp_motion_file_ending = tmp_options['MOTION_DETECTION'][ 'motion_file_ending'] motion_file_dir = os.path.dirname(arg_motion_file.path) video_file_name = arg_motion_file.name.replace( tmp_motion_file_ending + ".csv", ".MP4") for dir_file in os.scandir( motion_file_dir ): # Only look for ass. video file in same dir as the motion file #print(dir_file.name + " the same as: " + video_file_name) if dir_file.name == video_file_name: return dir_file return False # Not match found
class TrainingSetHandler: def __init__(self): self.__configuration_handler = ConfigurationHandler() self.__languages_path = [] self.__training_set = {} self.__is_training_set_loaded = False #region Properties @property def language_list(self): return self.__configuration_handler.languages @property def training_set(self): return self.__training_set @property def is_training_set_loaded(self): return self.__is_training_set_loaded #endregion def _read_configuration_file(self, configuration_file=None): if configuration_file is not None: self.__configuration_handler.configuration_file = configuration_file self.__languages_path = self.__configuration_handler.get_langages_folder_absolute_path( ) def _read_lines_from_folder(self, folder_path): lines = "" for file in os.listdir(folder_path): if file.endswith(Constants.VALID_TRAINING_FILE_EXTENTION): with open(os.path.join(folder_path, file), "r") as f: text = f.read() lines += text return lines def _load_data(self): for idx, fp in enumerate(self.__languages_path): self.__training_set[ self.language_list[idx]] = self._read_lines_from_folder(fp) self.__is_training_set_loaded = True def load_training_set(self, configuration_file=None): self._read_configuration_file(configuration_file) self._load_data()
def create_motion_start_files(self, arg_input_video_folder): logger.info("Processing input video files which does not have a associated motion file") tmp_options = ConfigurationHandler.get_configuration() process_video_list = self.__get_list_of_videos_for_processing(arg_input_video_folder) process_video_path_list = [] for video_for_process in process_video_list: process_video_path_list.append(video_for_process.path) # Single process #for video_path in process_video_path_list: # MotionStartDetector.process_video(video_path) # multiprocess with Pool(processes=self.number_of_process_workers) as pool: pool.map(partial(MotionStartDetector.process_video, tmp_options), process_video_path_list) return
def SelectROI(self, arg_input_video_folder): logger.debug("SelectROI() called") tmp_options = ConfigurationHandler.get_configuration() tmpVideoFileName = filedialog.askopenfilename(initialdir = arg_input_video_folder, title = "Select video file") MyGoproVideo = GoproVideo.GoproVideo(tmp_options) MyGoproVideo.init(tmpVideoFileName) MyGoproVideo.set_start_point(int(MyGoproVideo.frames/2)) # Start in the middle of the clip read_return_value, frame, frame_number = MyGoproVideo.read_frame() tmp_relative_search_box_dimensions = ast.literal_eval(tmp_options['MOTION_DETECTION']['search_box_dimensions']) # [-] current ROI logger.debug("Current relative ROI: " + str(tmp_relative_search_box_dimensions)) tmp_absolute_search_box_dimensions = [ int(tmp_relative_search_box_dimensions[0] * MyGoproVideo.height), # Y start int(tmp_relative_search_box_dimensions[1] * MyGoproVideo.height), # Y end int(tmp_relative_search_box_dimensions[2] * MyGoproVideo.width), # X start int(tmp_relative_search_box_dimensions[3] * MyGoproVideo.width) # X end ] logger.debug("Current absolute ROI: " + str(tmp_absolute_search_box_dimensions)) # Draw the current ROI tmp_p1 = (tmp_absolute_search_box_dimensions[0], tmp_absolute_search_box_dimensions[2]) tmp_p2 = (tmp_absolute_search_box_dimensions[1], tmp_absolute_search_box_dimensions[3]) cv2.rectangle(frame, tmp_p1, tmp_p2, (0, 0, 255), 4) AbsoluteROISelection = cv2.selectROI("Select the ROI for motion detection", frame, False) AbsoluteROISelection = (AbsoluteROISelection[0], AbsoluteROISelection[0]+AbsoluteROISelection[2], AbsoluteROISelection[1], AbsoluteROISelection[1]+AbsoluteROISelection[3]) # To match standart of BearVision (y_start,y_end,x_start,x_end) logger.debug("New absolute ROI: " + str(AbsoluteROISelection)) RelativeROISelection = (AbsoluteROISelection[0] / MyGoproVideo.height, AbsoluteROISelection[1] / MyGoproVideo.height, AbsoluteROISelection[2] / MyGoproVideo.width, AbsoluteROISelection[3] / MyGoproVideo.width, ) RelativeROISelection = [round(x, 2) for x in RelativeROISelection] logger.debug("New relative ROI: " + str(RelativeROISelection)) tmp_options['MOTION_DETECTION']['search_box_dimensions'] = str(RelativeROISelection) return RelativeROISelection
def step_impl(context): assert os.path.isfile(ROOT_DIR + "/../../etc/engine.config") context.root = ROOT_DIR + "/../../" config_file = ROOT_DIR + "/../../etc/engine.config" context.config_data = ConfigurationHandler(config_file).get()
from behave import * import os import sys import json import time import inspect ROOT_DIR = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) sys.path.append(ROOT_DIR + "/../../") from ConfigurationHandler import ConfigurationHandler from classes.DatabaseHandler import DatabaseHandler CONFIG_FILE = ROOT_DIR + "/../../etc/engine.config" CONFIG = ConfigurationHandler(CONFIG_FILE).get() DATABASE = DatabaseHandler(CONFIG, ROOT_DIR) JOB_DATA = SESSION_DATA = { "job_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "data": "this is just test data" } ISSUE_DATA = { "job_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "mutant_index": 101, "target": {}, "name": "TEST", "process_status": {}, "request": "REQUEST DATA" }
logging.basicConfig(filename='debug.log', level=logging.DEBUG, format='%(asctime)s:%(levelname)-8s:%(name)s:%(message)s', filemode=write_mode) if __name__ == "__main__": import sys, tkinter sys.path.append('code\Modules') sys.path.append('code\Application') sys.path.append('code\external_modules') from Application import Application from GUI import BearVisionGUI from ConfigurationHandler import ConfigurationHandler logger = logging.getLogger(__name__) logger.debug("------------------------Start------------------------------------") ConfigurationHandler.read_last_used_config_file() app_instance = Application() #Start GUI GUI_root = tkinter.Tk() my_gui = BearVisionGUI(GUI_root, app_instance) GUI_root.mainloop() logger.debug("-------------------------End-------------------------------------")
def __init__(self): logger.debug("MotionStartDetector created") tmp_options = ConfigurationHandler.get_configuration() self.number_of_process_workers = int(tmp_options['MOTION_DETECTION']['number_of_process_workers'])
def __init__(self): logger.debug("MotionROISelector created") tmp_options = ConfigurationHandler.get_configuration()
from ConfigurationHandler import ConfigurationHandler logger = logging.getLogger(__name__) #tmp_video_folder = os.path.abspath("F:/GoPro/Kabelpark/20180603") #tmp_video_folder = os.path.abspath("E:/DCIM/100GOPRO") # - very slow to read from SD card using converter and build-in reader #tmp_user_folder = os.path.abspath("F:/GoPro/BearVision/users") tmp_video_folder = os.path.abspath("input_video") tmp_user_folder = os.path.abspath("users") tmp_config_file = os.path.abspath("test_config.ini") # list of actions to do in the test tmp_action_list = [ ActionOptions.GENERATE_MOTION_FILES.value, ActionOptions.INIT_USERS.value, ActionOptions.MATCH_LOCATION_IN_MOTION_FILES.value, ActionOptions.GENERATE_FULL_CLIP_OUTPUTS.value, ActionOptions.GENERATE_TRACKER_CLIP_OUTPUTS.value ] print("Starting test!\n") logger.debug( "------------------------Start------------------------------------") tmp_options = ConfigurationHandler.read_config_file(tmp_config_file) app_instance = Application.Application() app_instance.run(tmp_video_folder, tmp_user_folder, tmp_action_list) print("\nFinished test!") logger.debug( "-------------------------End-------------------------------------")
def __init__(self, arg_master, arg_app_ref): tmp_options = ConfigurationHandler.get_configuration() self.master = arg_master self.app_ref = arg_app_ref self.master.title("BearVision - WakeVision") self.master.geometry("500x500") self.welcome_label = Label(self.master, text="BearVision - WakeVison", bg='red', font=('Helvetica', '20')) self.welcome_label.pack(fill=X, side=TOP) self.folder_selection_frame = Frame(self.master) self.folder_selection_frame.pack(fill=X, pady=10, side=TOP) self.folder_selection_frame.columnconfigure(0, weight=3) self.folder_selection_frame.columnconfigure(1, weight=1) self.video_folder_text = StringVar() if tmp_options is not None: self.video_folder_text.set( os.path.abspath(tmp_options['GUI']['video_path'])) self.video_folder_entry = Entry(self.folder_selection_frame, textvariable=self.video_folder_text) self.video_folder_entry.grid(row=0, column=0, sticky=W + E) self.video_folder_button = Button(self.folder_selection_frame, text="Select input video folder", command=self.set_input_video_folder) self.video_folder_button.grid(row=0, column=1, sticky=W + E) self.user_folder_text = StringVar() if tmp_options is not None: self.user_folder_text.set( os.path.abspath(tmp_options['GUI']['user_path'])) self.user_folder_entry = Entry(self.folder_selection_frame, textvariable=self.user_folder_text, width=60) self.user_folder_entry.grid(row=1, column=0, sticky=W + E) self.user_folder_button = Button(self.folder_selection_frame, text="Select user base folder", command=self.set_user_folder) self.user_folder_button.grid(row=1, column=1, sticky=W + E) self.run_options = Listbox(self.master, selectmode=MULTIPLE) for alias in commands: self.run_options.insert(END, commands[alias]) self.run_options.pack(fill=X, pady=10) self.run_options.selection_set( 0, self.run_options.size()) # select all options # Frame and button for motion ROI selection self.motion_ROI_selection_frame = Frame(self.master) self.motion_ROI_selection_frame.pack(fill=X, pady=10, side=TOP) self.motion_ROI_selection_frame.columnconfigure(0, weight=3) self.motion_ROI_selection_frame.columnconfigure(1, weight=1) self.motion_ROI_text = StringVar() if tmp_options is not None: self.motion_ROI_text.set( tmp_options['MOTION_DETECTION']['search_box_dimensions']) self.video_folder_entry = Entry(self.motion_ROI_selection_frame, textvariable=self.motion_ROI_text) self.video_folder_entry.grid(row=0, column=0, sticky=W + E) self.video_folder_button = Button( self.motion_ROI_selection_frame, text="Select motion detection ROI", command=self.set_motion_detection_ROI) self.video_folder_button.grid(row=0, column=1, sticky=W + E) # Create button frame self.button_frame = Frame(self.master) self.button_frame.pack(fill=X, pady=10) self.config_load_button = Button(self.button_frame, text="Load Config", command=self.load_config, bg='green3', height=1, width=10, font=('Helvetica', '20')) self.config_load_button.pack(side=LEFT) self.run_button = Button(self.button_frame, text="Run", command=self.run, bg='green3', height=1, width=10, font=('Helvetica', '20')) self.run_button.pack(side=RIGHT, pady=10) self.status_label_text = StringVar() self.status_label_text.set("Ready") if tmp_options is None: self.status_label_text.set("No parameters") self.status_label = Label(self.master, textvariable=self.status_label_text, bg='yellow', font=('Helvetica', '20')) self.status_label.pack(fill=X, side=BOTTOM, pady=10)
""" Run the whole thing """ # Get the shell arguments args = parse_shell_parameters() # Transfer shell arguments to variables destination_file = args.output bucket = args.bucket image_key = args.key # Ok, all set! We can download the file ... log.debug( 'Downloading with key: "{0}" from bucket: "{1}" to output file: "{2}" ' .format(image_key, bucket, destination_file)) download(destination_file, image_key, bucket) return 0 #################################################################### # # MAIN # #################################################################### if __name__ == "__main__": log = logger.get_logger('s3-image-download') config = ConfigurationHandler().read_configuration() main()
def step_impl(context): context.config_data = ConfigurationHandler(context.config_file).get()
def __init__(self): self.__configuration_handler = ConfigurationHandler() self.__languages_path = [] self.__training_set = {} self.__is_training_set_loaded = False
def __init__(self, arg_input_file: os.DirEntry): tmp_options = ConfigurationHandler.get_configuration() tree = xml.etree.ElementTree.parse(arg_input_file.path) root = tree.getroot() data_names = [ 'time', 'latitude', 'longitude', 'speed', 'horizontal_dilution', 'satellites' ] self.data = pd.DataFrame() # Namespaces of the XML fields root_ns = "{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2}" ns3 = "{http://www.garmin.com/xmlschemas/ActivityExtension/v2}" if root.tag != root_ns + 'TrainingCenterDatabase': print('Unknown root found: ' + root.tag) return activities = root.find(root_ns + 'Activities') if not activities: print('Unable to find Activities under root') return activity = activities.find(root_ns + 'Activity') if not activity: print('Unable to find Activity under Activities') return for lap in activity.iter(root_ns + 'Lap'): for track in lap.iter(root_ns + 'Track'): for trackpoint in track.iter(root_ns + 'Trackpoint'): try: time_str = trackpoint.find(root_ns + 'Time').text.strip() except: time_str = '2000-01-01T00:00:00.000Z' # Format example: 2018-05-15T15:43:44.000Z time = dt.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S.%fZ") try: latitude = trackpoint.find(root_ns + 'Position').find( root_ns + 'LatitudeDegrees').text.strip() except: latitude = '' try: longitude = trackpoint.find(root_ns + 'Position').find( root_ns + 'LongitudeDegrees').text.strip() except: longitude = '' try: speed = trackpoint.find(root_ns + 'Extensions').find(ns3 + 'TPX')\ .find(ns3 + 'Speed').text.strip() except: speed = '' # logger.debug("Speed entry: " + speed) #Add the extracted data to the panda dataframe dummy_hdop = float(tmp_options['GPS_FILE_PARSING'] ['TCX_dummy_hdop']) # [m] dummy_satellites = int(tmp_options['GPS_FILE_PARSING'] ['TCX_dummy_satellites']) # [-] data_entry = [ time.strftime("%Y%m%d_%H_%M_%S_%f"), latitude, longitude, speed, dummy_hdop, dummy_satellites ] # format for panda frame (table) data_entry = pd.DataFrame([data_entry], columns=data_names) self.data = pd.concat([ self.data, data_entry ]) # I'm sure this is not the smartest way to do this