cv
This commit is contained in:
0
dzien_05/gui/funkcje/__init__.py
Normal file
0
dzien_05/gui/funkcje/__init__.py
Normal file
94
dzien_05/gui/funkcje/obraz.py
Normal file
94
dzien_05/gui/funkcje/obraz.py
Normal file
@@ -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
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from funkcje.obraz import Obraz
|
||||||
import FreeSimpleGUI as sg
|
import FreeSimpleGUI as sg
|
||||||
|
|
||||||
# sg.theme('DarkAmber') # Add a touch of color
|
# sg.theme('DarkAmber') # Add a touch of color
|
||||||
@@ -7,7 +8,7 @@ layout = [ [sg.Text('Wybrana data'), sg.In(key='data') ,sg.CalendarButton("Data
|
|||||||
[sg.Text('Enter something on Row 2'), sg.InputText(key="row2")],
|
[sg.Text('Enter something on Row 2'), sg.InputText(key="row2")],
|
||||||
[sg.Text('Enter something on Row XX'), sg.InputText(key="inna")],
|
[sg.Text('Enter something on Row XX'), sg.InputText(key="inna")],
|
||||||
[sg.Text('Wybrany plik'), sg.In(key='input'), sg.FileBrowse(target='input')],
|
[sg.Text('Wybrany plik'), sg.In(key='input'), sg.FileBrowse(target='input')],
|
||||||
[sg.Button('Ok'), sg.Button('Przerwij'), sg.Button('HELP'), sg.Button("AKCJA")] ]
|
[sg.Button('Ok'), sg.Button('Przerwij'),sg.Button("OBRAZ"), sg.Button('HELP'), sg.Button("AKCJA")] ]
|
||||||
# ZADANIE:
|
# ZADANIE:
|
||||||
# dodaj przycisk o nazwie SYSTEM, wtedy na ekranie ma być
|
# dodaj przycisk o nazwie SYSTEM, wtedy na ekranie ma być
|
||||||
# print(sys.version)
|
# print(sys.version)
|
||||||
@@ -33,6 +34,17 @@ while True:
|
|||||||
dane = plik_odczyt.read()
|
dane = plik_odczyt.read()
|
||||||
sg.easy_print(dane)
|
sg.easy_print(dane)
|
||||||
|
|
||||||
|
if event =="OBRAZ":
|
||||||
|
pliczek = values['input']
|
||||||
|
if pliczek:
|
||||||
|
if pliczek[-3:] == 'png':
|
||||||
|
obrazek = Obraz(pliczek)
|
||||||
|
if obrazek.load_image():
|
||||||
|
obrazek.show_image()
|
||||||
|
obrazek.transform_smoothing()
|
||||||
|
obrazek.show_image_other()
|
||||||
|
|
||||||
|
|
||||||
if event == "Ok":
|
if event == "Ok":
|
||||||
sg.easy_print(f"{values=}")
|
sg.easy_print(f"{values=}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user