В настоящее время я работаю над проектом, в котором я использую mri-изображения, чтобы обнаружить наличие опухоли головного мозга. Я делаю tkinter GUI и могу открыть его, но мне нужна помощь, чтобы отослать это изображение в мою функцию предварительной обработки. , Вот что я придумал:
import cv2
import numpy as np
from tkinter import *
from PIL import ImageTk, Image
from tkinter import filedialog
root = Tk()
root.title("Image Loader")
root.resizable(width = True, height = True)
def openfilename():
# open file dialog box to select image
# The dialogue box has a title "Open"
filename = filedialog.askopenfilename(title ='images')
return filename
def open_img():
global img
x = openfilename()
img = Image.open(x)
img = img.resize((250, 250), Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)
panel = Label(root, image = img)
panel.image = img
panel.grid(row = 2)
btn = Button(root, text ='open image', command = open_img).grid(row = 1, columnspan = 4)
def process():
image = cv2.imread(img)
blur = cv2.GaussianBlur(image,(5,5),0)
cv2.imwrite('testgau.jpg',blur)
image = Image.open(testgau.jpg)
btn = Button(root, text ='process', command = process).grid(row = 3, columnspan = 5)
root.mainloop()
и я получаю следующую ошибку:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\91974\AppData\Local\Continuum\anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "<ipython-input-11-c7d724a7fdb8>", line 48, in process
image = cv2.imread(img)
SystemError: <built-in function imread> returned NULL without setting an error