def update(new_vehicles: list, frame: Frame, mask: np.ndarray): """ Aktualizuje śledzone pojazdy. :param new_vehicles: Nowe pojazdy. :param Frame frame: Klatka obrazu. :param np.ndarray mask: Binarna maska obrazu :return: Zidentyfikowane pojazdy(?), None jeśli żadnego nie wykryto. :rtype: list """ if len(new_vehicles) == 0: return None # Pobierz szerokość obrazu. _, Follower.__frame_width = frame.size() result = [] Follower.__detected_left = False Follower.__detected_right = False if len(new_vehicles) > 1: Logger.warning("Otrzymano więcej niż jeden pojazd.") for new_car in new_vehicles: # detekcja z prawej strony if Follower.__is_on_right(new_car): Follower.__detected_right = True if not Follower.__right_lock: Follower.__right_lock = True # jeżeli nie ma nic po drugiej stronie to odłóż na stos if not len(Follower.__tracked_left): Follower.__tracked_right.append((new_car, frame)) Logger.info("Obiekt zarejestrwany po prawej stronie.") # jeżeli bo drugiej stronie coś było to pobierz ze stosu else: old_car, oldframe = Follower.__tracked_left.pop() record = ObjectRecord(new_car, old_car, frame, oldframe, mask) Logger.info("Wykryto przejazd samochodu.") result.append(record) # detekcja z lewej strony elif Follower.__is_on_left(new_car): Follower.__detected_left = True if not Follower.__left_lock: Follower.__left_lock = True # jeżeli nie ma nic po drugiej stronie to odłóż na stos if not len(Follower.__tracked_right): Follower.__tracked_left.append((new_car, frame)) Logger.info("Obiekt zarejestrwany po lewej stronie.") # jeżeli bo drugiej stronie coś było to pobierz ze stosu else: old_car, oldframe = Follower.__tracked_right.pop() record = ObjectRecord(new_car, old_car, frame, oldframe, mask) Logger.info("Wykryto przejazd samochodu.") result.append(record) Follower.__check_locks() return result if len(result) else None
def open_database(self): name = "Wybierz bazę danych" response = self.__run_file_chooser_dialog(name, allow_multiple=False) if response is not None: path = response[0] if not self.__database_path_valid(path): self.window.write_on_statusbar("Wybrano zły plik!") Logger.error("Wybrano zły plik bazy danych.") else: dialog = DatabaseDialog() dialog.read_database(path) dialog.run()
def clear(): """ Czyści wewnętrzne dane algorytmu śledzenia pojazdów. """ if len(Follower.__tracked_left) or len(Follower.__tracked_right): Logger.warning("Usunięto niewykorzystane dane.") Follower.__tracked_left = [] Follower.__tracked_right = [] Follower.__detected_right = False Follower.__detected_left = False Follower.__left_lock = False Follower.__right_lock = False Follower.__frame_width = 0 Follower.__border = 0
def open_files(self): name = "Wybierz pliki wideo..." response = self.__run_file_chooser_dialog(name) if response is not None: # Sprawdzenie poprawności ścieżek do plików for path in response: if not self.__video_path_valid(path): self.window.write_on_statusbar("Wybrano błędy plik!") Logger.error("Przy otwieraniu plików wykryto błędny plik.") else: self.__add_file_to_list(path) if self.__files_list_length(): self.__play_button_enable(True)
def __init__(self): self.logs = Logger() self.utils = Utils() self.config = self.utils.readConfig() self.base_url = self.config['api_url'] self.api_url = '%s/api/v1' % self.config['api_url'] self.api_token = self.config['api_token'] self.maxRetries = self.config['retries'] try: if self.checkInitialPing() == 200: self.checkSites() else: exit() except Exception as e: self.logs.error(e) exit()
class Cachet(object): httpErrors = { # Cloudflare Errors 520: "Web server is returning an unknown error (Cloudflare)", 521: "Web server is down (Cloudflare)", 522: "Connection timed out (Cloudflare)", 523: "Origin is unreachable (Cloudflare)", 524: "A timeout occurred (Cloudflare)", 525: "SSL handshake failed (Cloudflare)", 526: "Invalid SSL certificate (Cloudflare)", # Nginx Errors 444: "No Response (Nginx)", 494: "Request Header Too Large (Nginx)", 495: "Cert Error (Nginx)", 496: "No Cert (Nginx)", 497: "HTTP to HTTPS (Nginx)", 499: "Client Closed Request (Nginx)", # Other # 1xx 102: "Server has received and is processing the request", 103: "resume aborted PUT or POST requests", 122: "URI is longer than a maximum of 2083 characters", # 2xx 207: "XML return with possible multiple seperate responses.", 208: "The results are previously returned.", 226: "The request has been fulfilled amd response is in instance manipulations.", # 3xx 308: "Please connect again to the different URL using the same method.", # 4xx 418: "I'm a teapot.", 420: "Method Failure", 421: "Enhance Your Calm", 422: "Unprocessable Entity", 423: "Locked", 424: "Failed Dependency", 426: "Upgrade Required", 428: "Precondition Required", 429: "Too Many Requests", 431: "Request Header Fields Too Large", 440: "Login Timeout (Microsoft)", 449: "Retry With (Microsoft)", 450: "Blocked by Windows Parental Controls", 451: "Unavailable For Legal Reasons", # 5xx 506: "Variant Also Negotiates (RFC 2295)", 507: "Insufficient Storage (WebDAV; RFC 4918)", 508: "Loop Detected (WebDAV; RFC 5842)", 509: "Bandwidth Limit Exceeded (Apache bw/limited extension)", 510: "Not Extended (RFC 2774)", 511: "Network Authentication Required" } def __init__(self): self.logs = Logger() self.utils = Utils() self.config = self.utils.readConfig() self.base_url = self.config['api_url'] self.api_url = '%s/api/v1' % self.config['api_url'] self.api_token = self.config['api_token'] self.maxRetries = self.config['retries'] try: if self.checkInitialPing() == 200: self.checkSites() else: exit() except Exception as e: self.logs.error(e) exit() def checkSites(self): # Count how many sites to monitor monitor_count = len(self.config['monitoring']) x = 0 # Loop through sites to monitor while x < monitor_count: isEnabled = self.config['monitoring'][x]['enabled'] status_codes = self.config['monitoring'][x]['expected_status_code'] url = self.config['monitoring'][x]['url'] request_method = self.config['monitoring'][x]['method'] c_id = self.config['monitoring'][x]['component_id'] localtime = time.asctime(time.localtime(time.time())) current_status = self.utils.getComponentsByID( c_id).json()['data']['status'] incident_id = self.checkForIncident(c_id) check_timeout = self.config['monitoring'][x]['timeout'] payload = "" if request_method.lower() == "jsonrpc": payload = self.config['monitoring'][x]['payload'] try: if isEnabled: pass if request_method.lower() == "get": post_latency_metric(url, c_id) r = requests.get(url, verify=True, timeout=check_timeout) # self.utils.postMetricsPointsByID(1, r.elapsed.total_seconds() * 1000) if r.status_code not in status_codes and r.status_code not in self.httpErrors: error_code = '%s check **failed** - %s \n\n`%s %s HTTP StatusError: %s`' % ( url, localtime, request_method, url, http.client.responses[r.status_code]) c_status = 4 if not incident_id: self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn( "%s" % error_code.replace('\n', '').replace('`', '')) elif r.status_code not in status_codes and r.status_code in self.httpErrors: error_code = '%s check **failed** - %s \n\n`%s %s HTTP Status Error: %s`' % ( url, localtime, request_method, url, self.httpErrors[r.status_code]) c_status = 4 if not incident_id: self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn( "%s" % error_code.replace('\n', '').replace('`', '')) elif request_method.lower() == "post": post_latency_metric(url, c_id) r = requests.get(url, verify=True, timeout=check_timeout) if r.status_code not in status_codes and r.status_code not in self.httpErrors: error_code = '%s check **failed** - %s \n\n`%s %s HTTP Status Error: %s`' % ( url, localtime, request_method, url, http.client.responses[r.status_code]) c_status = 4 if not incident_id: self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn( "%s" % error_code.replace('\n', '').replace('`', '')) elif r.status_code not in status_codes and r.status_code in self.httpErrors: error_code = '%s check **failed** - %s \n\n`%s %s HTTP Status Error: %s`' % ( url, localtime, request_method, url, self.httpErrors[r.status_code]) c_status = 4 if not incident_id: self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn( "%s" % error_code.replace('\n', '').replace('`', '')) elif request_method.lower() == "jsonrpc": post_latency_metric(url, c_id) r = requests.post(url, verify=True, json=payload) if r.status_code not in status_codes and r.status_code not in self.httpErrors: error_code = '%s check **failed** - %s \n\n`%s %s HTTP Status Error: %s`' % ( url, localtime, request_method, url, http.client.responses[r.status_code]) c_status = 4 if not incident_id: self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn( "%s" % error_code.replace('\n', '').replace('`', '')) elif r.status_code not in status_codes and r.status_code in self.httpErrors: error_code = '%s check **failed** - %s \n\n`%s %s HTTP Status Error: %s`' % ( url, localtime, request_method, url, self.httpErrors[r.status_code]) c_status = 4 if not incident_id: self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn( "%s" % error_code.replace('\n', '').replace('`', '')) except requests.exceptions.HTTPError as e: error_code = '%s check **failed** - %s \n\n`%s %s HTTP Error: %s`' % ( url, localtime, request_method, url, e) c_status = 4 if not incident_id: self.utils.postIncidents('%s: HTTP Error' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn(error_code.replace('\n', '').replace('`', '')) except requests.exceptions.SSLError as e: error_code = '%s check **failed** - %s \n\n`%s %s SSL Error: %s`' % ( url, localtime, request_method, url, e) c_status = 4 if not incident_id: self.utils.postIncidents('%s: SSL Error' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn(error_code.replace('\n', '').replace('`', '')) except requests.exceptions.ConnectionError as e: error_code = '%s check **failed** - %s \n\n`%s %s Connection Error: %s`' % ( url, localtime, request_method, url, e) c_status = 4 if not incident_id: self.utils.postIncidents('%s: Connection Error' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn(error_code.replace('\n', '').replace('`', '')) except requests.exceptions.Timeout as e: error_code = '%s check **failed** - %s \n\n`%s %s Request Timeout: %s`' % ( url, localtime, request_method, url, e) c_status = 2 if not incident_id: self.utils.postIncidents('%s: Request Timeout' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn(error_code.replace('\n', '').replace('`', '')) except requests.exceptions.TooManyRedirects as e: error_code = '%s check **failed** - %s \n\n`%s %s Too Many Redirects: %s`' % ( url, localtime, request_method, url, e) c_status = 4 if not incident_id: self.utils.postIncidents('%s: Too Many Redirects' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn(error_code.replace('\n', '').replace('`', '')) except requests.exceptions.RetryError as e: error_code = '%s check **failed** - %s \n\n`%s %s Retry Error: %s`' % ( url, localtime, request_method, url, e) c_status = 4 if not incident_id: self.utils.postIncidents('%s: Retry Error' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.warn(error_code.replace('\n', '').replace('`', '')) except http.client.BadStatusLine as e: self.logs.error("%s \nCould not fetch %s" % (e, url)) except Exception as e: error_code = '%s check **failed** - %s \n\n`%s %s Unexpected Error: %s`' % ( url, localtime, request_method, url, e) c_status = 4 if not incident_id: self.utils.postIncidents('%s: Unexpected Error' % url, error_code, 1, 1, component_id=c_id, component_status=c_status) if current_status is not 4: self.utils.putComponentsByID(c_id, status=c_status) self.logs.error(error_code.replace('\n', '').replace('`', '')) else: if r.status_code in status_codes: if current_status is not 1 and not incident_id: self.utils.putComponentsByID(c_id, status=1) self.logs.info("Issue with %s has been resolved" % url) elif current_status is not 1 and incident_id: incident_description = "Resolved at %s\n\n***\n\n%s" % ( localtime, self.getIncidentInfo(incident_id)) self.utils.putIncidentsByID( incident_id, message=incident_description, status=4, component_id=c_id, component_status=1) else: self.logs.info("%s no issues found" % url) x += 1 self.logs.info("############################") def checkForIncident(self, component_id): current_incidents = self.utils.getIncidents().json() incidents = len(current_incidents['data']) x = 0 while x < incidents: incident_id = current_incidents['data'][x]['id'] incident_component_id = current_incidents['data'][x][ 'component_id'] incident_status = current_incidents['data'][x]['status'] if component_id == incident_component_id and incident_status is not 4: return incident_id x += 1 def getIncidentInfo(self, i_id): incident = self.utils.getIncidentsByID(i_id).json() i_description = incident['data']['message'] return i_description def checkInitialPing(self): rPing = requests.get(self.base_url, verify=True, timeout=10) return rPing.status_code
folder = "/media/Dane/Dropbox/Studia/IV rok/inżynierka/Dane_AVI" avi_files = listdir("/media/Dane/Dropbox/Studia/IV rok/inżynierka/Dane_AVI") # zapisywanie wyników db = Database() img_saver = ImageSaver() used_files_count = 0 unused_files_count = 0 not_found_files_count = 0 valid_detection_count = 0 bad_detection_count = 0 speed_errors = [] length_errors = [] Logger.start() Configuration.load_config() 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
def perform(obj: ObjectRecord, file): """ Przeprowadza ocenę koloru, rozmiaru i prędkości obiektu. :param ObjectRecord obj: Obiekt wykryty przez klasę Follower. :return: Parametry pojazdu. :rtype: dict """ # Pobierz dane o pojeździe. new_car, old_car, new_frame, old_frame, mask = obj.unpack() # Wybierz rejon obrazu: x, y, w, h = new_car.get_coordinates() image = new_frame.img image_roi = new_frame.img[y:y+h, x:x+w, :] mask_roi = mask[y:y+h, x:x+w] # Wyznaczenie rozmiaru car_width = SizeMeasurment.calculate_width(new_car) car_height = SizeMeasurment.calculate_height(new_car) car_area = SizeMeasurment.calculate_area(mask_roi) # Wyznaczenie kolorów color_bar, color = ColorDetector.find_color(image_roi) # Wyznaczenie prędkości. speed = SpeedMeasurment.calculate_speed(new_car, new_frame, old_car, old_frame) # Narysowanie wyników na obrazie # Kontur if Configuration.draw_conturs(): image = SizeMeasurment.draw_car_contour(image, new_car, mask) # Rozmiar if Configuration.draw_size_info(): image = SizeMeasurment.draw_size_info(image, car_width, car_height, car_area) # Kolor if Configuration.draw_color_bar(): image = ColorDetector.draw_color_bar(image, color_bar) # Prędkość if Configuration.draw_speed_info(): image = SpeedMeasurment.draw_speed_info(new_car, speed, image) # Połącz obrazy pojazdu image = Classyfication.combine_images(old_frame.orginal_img, image, file) # Rekord zawierający informacje o pojeździe result = {"width": car_width, "height": car_height, "area": car_area, "speed": speed, "image": image, "date": new_frame.creationTime, "color": color} msg = "Przprowadzono klasyfikację pojadu: " msg += "długość: %.2f, " % car_width msg += "wysokość: %.2f, " % car_height msg += "pole karoseri bocznej: %.2f, " % car_area msg += "prędkość: %.2f, " % speed msg += "data: %s." % str(new_frame.creationTime) Logger.info(msg) return result
#!/usr/bin/env python3 __author__ = 'rafal' __doc__ = 'Skrypt służacy do uruchamiania programu z wiersza poleceń.' from gi.repository import Gtk from gui.window_view import ProgramView from src.logs import Logger from src.config import Configuration if __name__ == '__main__': Configuration.load_config() Logger.start() window = ProgramView() Logger.info("Uruchamiano główne okna programu.") Gtk.main()