diff --git a/dzien_05/klasy_03_tl.py b/dzien_05/klasy_03_tl.py new file mode 100644 index 0000000..f3720ab --- /dev/null +++ b/dzien_05/klasy_03_tl.py @@ -0,0 +1,33 @@ +class Computer: + def __init__(self): + print("Startujemy...") + # definicja właściwości obiektów tej lasy + self.procesor = "CPU at start" + self.speed = "5 GHz" + self.cpu_speed = 5000 + + def __str__(self): + return f"To jest {id(self)=}" + + +komputer1 = Computer() +komputer2 = Computer() + +print(komputer1) +print('-------------------') +print(dir(komputer1)) +print(dir(komputer2)) +print('-------------------') +print(komputer1.procesor) +print(komputer2.procesor) + +komputer1.procesor = "AMD M6" +print('-------------------') +print(komputer1.procesor) +print(komputer2.procesor) +print('-------------------') + +komputer1.nowe_property = "Jakaś tam" +print(dir(komputer1)) +print(dir(komputer2)) +print('-------------------') \ No newline at end of file diff --git a/dzien_05/przyklady/funkcje/__init__.py b/dzien_05/przyklady/funkcje/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dzien_05/przyklady/funkcje/obraz.py b/dzien_05/przyklady/funkcje/obraz.py new file mode 100644 index 0000000..da1ceb6 --- /dev/null +++ b/dzien_05/przyklady/funkcje/obraz.py @@ -0,0 +1,94 @@ +import os + +import cv2 +import cv2 as cv +import os + +class Obraz: + def __init__(self, filename:str, mode:int = cv.IMREAD_COLOR_BGR): + self.filename = filename + self.mode = mode + self.loaded = False + self.img = None + self.img_other = None + self.transform_name = "NOTHING" + + def load_image(self): + if self.loaded: + return True + if not os.path.exists(self.filename): + return False + # raise FileNotFoundError(self.filename) + try: + self.img = cv.imread(self.filename, flags=self.mode) + self.loaded = True + except Exception as e: + print(e) + + return True + + def show_image(self, window_name:str="Window"): + if not self.loaded: + return False + window_name += f" - {self.filename}" + cv.imshow(window_name, self.img) + cv.waitKey(0) + cv.destroyAllWindows() + return None + + def show_image_other(self, window_name:str="Window after "): + if not self.loaded: + return False + if self.img_other is None: + return False + window_name += f" - {self.filename} - {self.transform_name}" + combined = cv.hconcat([self.img, self.img_other]) + cv.imshow(window_name, combined) + cv.waitKey(0) + cv.destroyAllWindows() + return None + + def transform_equalize_histogram(self): + if not self.loaded: + return False + if self.mode == cv.IMREAD_COLOR or self.mode == cv.IMREAD_COLOR_BGR: + gray_image = cv2.cvtColor(self.img, cv2.COLOR_BGR2GRAY) + self.img_other = cv.equalizeHist(gray_image) + self.transform_name = "Equalize Histogram" + return True + + def transform_smoothing(self, smoothing_type="GaussianBlur"): + """ + + :param smoothing_type: GaussianBlur (default) or medianBlur + :return: True or False + """ + if not self.loaded: + return False + try: + if smoothing_type == "GaussianBlur": + self.img_other = cv.GaussianBlur(self.img, (5, 5), 0) + else: + self.img_other = cv.medianBlur(self.img, 5) + self.transform_name = smoothing_type + return True + except Exception as e: + print(e) + return False + + def return_image_stream(self, type:str="other"): + """ + + :param type: other | original + :return: + """ + if not self.loaded: + return None + if type == "original": + return self.img + elif type == "other": + if self.img_other is None: + return None + return self.img_other + else: + return None