我正在使用python 3,opencv和tkinter创建一个GUI,可以在其中上传图像,然后在最终图像旁边的面板中显示该图像,该图像是与输入图像相同文件夹中所有图像的堆叠版本。stacker()函数只是将图像堆叠在文件夹中。
由于某些原因,在运行该程序时,将显示应该在panelA中的图像,而不会显示来自panelB的图像。
如何同时显示图像(输入和输出)?还有什么办法可以加快这段代码的速度吗?
def select_image():
# grab a reference to the image panels
global panelA, panelB
# open a file chooser dialog and allow the user to select an input
# image
path = tkinter.filedialog.askopenfilename()
# ensure a file path was selected
if len(path) > 0:
# load the image from disk, convert it to grayscale, and detect
# edges in it
image = cv2.imread(path)
edged = stacker(os.path.dirname(os.path.dirname(path)))
# OpenCV represents images in BGR order; however PIL represents
# images in RGB order, so we need to swap the channels
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# convert the images to PIL format...
image = Image.fromarray(image)
edged = Image.fromarray(edged)
# ...and then to ImageTk format
image = ImageTk.PhotoImage(image)
edged = ImageTk.PhotoImage(edged)
# if the panels are None, initialize them
if panelA is None or panelB is None:
# the first panel will store our original image
panelA = tk.Label(image=image)
panelA.image = image
panelA.pack(side="left", padx=10, pady=10)
# while the second panel will store the edge map
panelB = tk.Label(image=edged)
panelB.image = edged
panelB.pack(side="right", padx=10, pady=10)
# otherwise, update the image panels
else:
# update the pannels
panelA.configure(image=image)
panelB.configure(image=edged)
panelA.image = image
panelB.image = edged
# initialize the window toolkit along with the two image panels
root = tk.Tk()
panelA = None
panelB = None
print("done")
慕码人2483693
ITMISS
阿晨1998
随时随地看视频慕课网APP
相关分类