【发布时间】:2018-02-08 15:56:30
【问题描述】:
我有以下代码:
from tkinter import *
from tkinter import filedialog
from PIL import Image, ImageTk
import cv2
import os
import glob
import numpy as np
image_path = ""
image_list = []
class Proj:
def __init__(self, master):
self.master = master
#GUI height and width
w = 1250
h = 600
# open folder manager to select image folder
image_path = filedialog.askdirectory()
master.geometry("%dx%d%+d%+d" % (w ,h ,0,0))
master.resizable(True,True)
#read in images from folder
self.read_images(master, image_path)
#cv2.imshow('image',cv2.imread(image_list[0], 1))
self.img = cv2.imread(image_list[0])
self.img = Image.fromarray(np.array(self.img).copy())
self.img.thumbnail((w//2, w//2+10))
self.img = ImageTk.PhotoImage(self.img)
image_frame = Frame(master)
image_frame.grid(row = 0, column = 0, columnspan = 3, rowspan = 5)
left_panel = Canvas(image_frame, width=w//2, height=h-70)
left_panel.grid(row=0, column=0, columnspan=4)
imgA_handler = left_panel.create_image((0,0), image = self.img, anchor="nw")
right_panel = Canvas(image_frame, width=w//2, height=h-70)
right_panel.grid(row=0, column=5, columnspan=4)
def read_images(self, master, path):
images = path + '/*.tif'
for img in glob.glob(images): #will only read in tif images
image_list.append(img)
root = Tk()
example = Proj(root)
root.mainloop()
我正在阅读彩色 .tif 图像,然后尝试在 left_panel. 中显示它们但是,当我这样做时,它 仅以红色显示正常彩色图像规模即使虽然我从来没有只提取红色信号。我完全无法诊断问题。我该如何解决这个问题?
最终,我想做的是在这个 GUI 上显示两个图像。左边是原始图像,右边是修改后的图像。目前,我的 gui 布局已按照我上面的编码进行设置。但是,如果您认为有更简单的方法可以做到这一点,那么我很想听听。
【问题讨论】:
-
您提供的代码不完整,无法使用。请提供Minimal, Complete, and Verifiable example,以便我们实际测试您的代码。
-
我只附上了代码的相关部分来重现问题。
标签: python user-interface opencv tkinter